redesign the internals of unit animations, preparing for future great stuff

This commit is contained in:
Jérémy Rosen 2007-10-12 18:57:45 +00:00
parent b73de377e9
commit 29e3c21f87
2 changed files with 76 additions and 61 deletions

View file

@ -96,44 +96,17 @@ config unit_animation::prepare_animation(const config &cfg,const std::string ani
}
unit_animation::unit_animation(int start_time,const unit_frame & frame , const std::string & event,const int variation):
animated<unit_frame>(start_time), frequency_(0),base_score_(variation)
frequency_(0),base_score_(variation), unit_anim_(start_time)
{
event_.push_back(event);
add_frame(frame.duration(),frame,!frame.does_not_change());
}
unit_animation::unit_animation(const config& cfg,const std::string frame_string ) :
terrain_types_(t_translation::read_list(cfg["terrain"])),base_score_(0)
terrain_types_(t_translation::read_list(cfg["terrain"])),base_score_(0),
missile_anim_(cfg,"missile_frame"),unit_anim_(cfg,frame_string)
{
event_ =utils::split(cfg["apply_to"]);
config::const_child_itors range = cfg.child_range(frame_string);
if(cfg["start_time"].empty() &&range.first != range.second) {
starting_frame_time_ = atoi((**range.first)["begin"].c_str());
} else {
starting_frame_time_ = atoi(cfg["start_time"].c_str());
}
for(; range.first != range.second; ++range.first) {
unit_frame tmp_frame(**range.first);
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
}
halo_ = progressive_string(cfg["halo"],get_animation_duration());
halo_x_ = progressive_int(cfg["halo_x"],get_animation_duration());
halo_y_ = progressive_int(cfg["halo_y"],get_animation_duration());
std::vector<std::string> tmp_blend=utils::split(cfg["blend_color"]);
if(tmp_blend.size() ==3) blend_with_= display::rgb(atoi(tmp_blend[0].c_str()),atoi(tmp_blend[1].c_str()),atoi(tmp_blend[2].c_str()));
blend_ratio_ = progressive_double(cfg["blend_ratio"],get_animation_duration());
highlight_ratio_ = progressive_double(cfg["alpha"],get_animation_duration());
offset_ = progressive_double(cfg["offset"],get_animation_duration());
if(!halo_.does_not_change() ||
!halo_x_.does_not_change() ||
!halo_y_.does_not_change() ||
!blend_ratio_.does_not_change() ||
!highlight_ratio_.does_not_change() ||
!offset_.does_not_change() ) {
force_change();
}
const std::vector<std::string>& my_directions = utils::split(cfg["direction"]);
for(std::vector<std::string>::const_iterator i = my_directions.begin(); i != my_directions.end(); ++i) {
@ -180,12 +153,6 @@ unit_animation::unit_animation(const config& cfg,const std::string frame_string
for(itor = cfg.child_range("secondary_attack_filter").first; itor <cfg.child_range("secondary_attack_filter").second;itor++) {
secondary_attack_filter_.push_back(**itor);
}
// this whole block is a temporary hack that will stay until proper multi-frame in anim is supported...
range = cfg.child_range("missile_frame");
for(; range.first != range.second; ++range.first) {
unit_frame tmp_frame(**range.first);
missile_anim_.add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
}
}
@ -302,38 +269,38 @@ void unit_animation::back_compat_add_name(const std::string name,const std::stri
const std::string &unit_animation::halo(const std::string&default_val ) const
{
return get_current_frame().halo(get_current_frame_time(),halo_.get_current_element(get_animation_time(),default_val));
return unit_anim_.get_current_frame().halo(unit_anim_.get_current_frame_time(),unit_anim_.halo_.get_current_element(unit_anim_.get_animation_time(),default_val));
}
int unit_animation::halo_x(const int default_val) const
{
return get_current_frame().halo_x(get_current_frame_time(),halo_x_.get_current_element(get_animation_time(),default_val));
return unit_anim_.get_current_frame().halo_x(unit_anim_.get_current_frame_time(),unit_anim_.halo_x_.get_current_element(unit_anim_.get_animation_time(),default_val));
}
int unit_animation::halo_y(const int default_val) const
{
return get_current_frame().halo_y(get_current_frame_time(),halo_y_.get_current_element(get_animation_time(),default_val));
return unit_anim_.get_current_frame().halo_y(unit_anim_.get_current_frame_time(),unit_anim_.halo_y_.get_current_element(unit_anim_.get_animation_time(),default_val));
}
Uint32 unit_animation::blend_with() const
{
#warning TBSL: "this should become a progressive param somehow..."
return get_current_frame().blend_with();
return unit_anim_.get_current_frame().blend_with();
}
double unit_animation::blend_ratio(const double default_val) const
{
return get_current_frame().blend_ratio(get_current_frame_time(),blend_ratio_.get_current_element(get_animation_time(),default_val));
return unit_anim_.get_current_frame().blend_ratio(unit_anim_.get_current_frame_time(),unit_anim_.blend_ratio_.get_current_element(unit_anim_.get_animation_time(),default_val));
}
fixed_t unit_animation::highlight_ratio(const float default_val) const
{
return get_current_frame().highlight_ratio(get_current_frame_time(),highlight_ratio_.get_current_element(get_animation_time(),default_val));
return unit_anim_.get_current_frame().highlight_ratio(unit_anim_.get_current_frame_time(),unit_anim_.highlight_ratio_.get_current_element(unit_anim_.get_animation_time(),default_val));
}
double unit_animation::offset(double default_val) const
{
return get_current_frame().offset(get_current_frame_time(),offset_.get_current_element(get_animation_time(),default_val)) ;
return unit_anim_.get_current_frame().offset(unit_anim_.get_current_frame_time(),unit_anim_.offset_.get_current_element(unit_anim_.get_animation_time(),default_val)) ;
}
bool unit_animation::need_update() const
bool unit_animation::crude_animation::need_update() const
{
if(animated<unit_frame>::need_update()) return true;
if(get_current_frame().need_update()) return true;
@ -347,3 +314,35 @@ bool unit_animation::need_update() const
}
return false;
}
unit_animation::crude_animation::crude_animation(const config& cfg,const std::string frame_string )
{
config::const_child_itors range = cfg.child_range(frame_string);
if(cfg["start_time"].empty() &&range.first != range.second) {
starting_frame_time_ = atoi((**range.first)["begin"].c_str());
} else {
starting_frame_time_ = atoi(cfg["start_time"].c_str());
}
for(; range.first != range.second; ++range.first) {
unit_frame tmp_frame(**range.first);
add_frame(tmp_frame.duration(),tmp_frame,!tmp_frame.does_not_change());
}
halo_ = progressive_string(cfg["halo"],get_animation_duration());
halo_x_ = progressive_int(cfg["halo_x"],get_animation_duration());
halo_y_ = progressive_int(cfg["halo_y"],get_animation_duration());
std::vector<std::string> tmp_blend=utils::split(cfg["blend_color"]);
if(tmp_blend.size() ==3) blend_with_= display::rgb(atoi(tmp_blend[0].c_str()),atoi(tmp_blend[1].c_str()),atoi(tmp_blend[2].c_str()));
blend_ratio_ = progressive_double(cfg["blend_ratio"],get_animation_duration());
highlight_ratio_ = progressive_double(cfg["alpha"],get_animation_duration());
offset_ = progressive_double(cfg["offset"],get_animation_duration());
if(!halo_.does_not_change() ||
!halo_x_.does_not_change() ||
!halo_y_.does_not_change() ||
!blend_ratio_.does_not_change() ||
!highlight_ratio_.does_not_change() ||
!offset_.does_not_change() ) {
force_change();
}
}

View file

@ -29,7 +29,7 @@
class game_display;
class attack_type;
class unit_animation:public animated<unit_frame>
class unit_animation
{
public:
typedef enum { MATCH_FAIL=-2 , DEFAULT_ANIM=-1};
@ -41,24 +41,49 @@ class unit_animation:public animated<unit_frame>
explicit unit_animation(int start_time,const unit_frame &frame,const std::string& even="",const int variation=0);
int matches(const game_display &disp,const gamemap::location& loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int swing_num =0) const;
image::locator image() const { return get_current_frame().image() ; }
image::locator image_diagonal() const { return get_current_frame().image_diagonal() ; }
std::string sound() const { return get_current_frame().sound() ; };
image::locator image() const { return unit_anim_.get_current_frame().image() ; }
image::locator image_diagonal() const { return unit_anim_.get_current_frame().image_diagonal() ; }
std::string sound() const { return unit_anim_.get_current_frame().sound() ; };
const std::string &halo(const std::string&default_val ="") const;
int halo_x(const int default_val = 0) const;
int halo_y(const int default_val = 0) const;
//int duration() const { return get_current_frame().duration(); }
Uint32 blend_with() const;
double blend_ratio(const double default_val = 0) const;
fixed_t highlight_ratio(const float default_val = 1.0) const;
double offset(double default_val =0.0) const;
bool need_update() const;
bool need_update() const{return unit_anim_.need_update();};
bool animation_finished() const{ return unit_anim_.animation_finished() ; };
bool animation_would_finish() const{ return unit_anim_.animation_would_finish() ; };
const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; };
void add_frame(int duration, const unit_frame& value,bool force_change =false){ return unit_anim_.add_frame(duration,value,force_change) ; };
void start_animation(int start_time, bool cycles=false, double acceleration=1){ return unit_anim_.start_animation(start_time, cycles, acceleration);};
int get_begin_time() const{ return unit_anim_.get_begin_time() ; };
void update_last_draw_time(){unit_anim_.update_last_draw_time();};
const int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
int get_animation_time() const{ return unit_anim_.get_animation_time() ; };
int get_end_time() const{ return unit_anim_.get_end_time() ; };
// only to support all [attack_anim] format, to remove at 1.3.10 time
void back_compat_add_name(const std::string name="",const std::string range ="");
const animated<unit_frame> &get_missile_anim() const {return missile_anim_;}
private:
class crude_animation:public animated<unit_frame>
{
public:
explicit crude_animation(int start_time=0):animated<unit_frame>(start_time){};
explicit crude_animation(const config& cfg,const std::string frame_string ="frame");
bool need_update() const;
//animation params that can be locally overridden by frames
progressive_string halo_;
progressive_int halo_x_;
progressive_int halo_y_;
Uint32 blend_with_;
progressive_double blend_ratio_;
progressive_double highlight_ratio_;
progressive_double offset_;
};
t_translation::t_list terrain_types_;
std::vector<config> unit_filter_;
std::vector<config> secondary_unit_filter_;
@ -71,17 +96,8 @@ class unit_animation:public animated<unit_frame>
std::vector<config> secondary_attack_filter_;
std::vector<hit_type> hits_;
std::vector<int> swing_num_;
animated<unit_frame> missile_anim_;
// prevent people from using the current frame directly
const unit_frame& get_current_frame() const { return animated<unit_frame>::get_current_frame(); }
//animation params that can be locally overridden by frames
progressive_string halo_;
progressive_int halo_x_;
progressive_int halo_y_;
Uint32 blend_with_;
progressive_double blend_ratio_;
progressive_double highlight_ratio_;
progressive_double offset_;
crude_animation missile_anim_;
crude_animation unit_anim_;
};