mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-10 21:28:48 +00:00
standing animation, second try
Soliton, this should be OK preformance wise, but please provide feedback
This commit is contained in:
parent
19d075af1e
commit
21d2d982d1
@ -71,6 +71,7 @@ public:
|
||||
const T& get_first_frame() const;
|
||||
const T& get_last_frame() const;
|
||||
int get_frames_count() const;
|
||||
const bool does_not_change() const {return does_not_change_;}
|
||||
|
||||
|
||||
|
||||
|
@ -2048,10 +2048,15 @@ void display::invalidate_animations()
|
||||
for(int y = topleft.y; y <= bottomright.y; ++y) {
|
||||
gamemap::location loc(x,y);
|
||||
if(builder_.update_animation(loc) || (map_.is_village(loc) && animate_flags)) {
|
||||
invalidated_.insert(loc);
|
||||
invalidate(loc);
|
||||
}
|
||||
}
|
||||
}
|
||||
unit_map::iterator unit;
|
||||
for(unit=units_.begin() ; unit != units_.end() ; unit++) {
|
||||
if (unit->second.get_animation() && !unit->second.get_animation()->does_not_change())
|
||||
invalidate(unit->first);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
31
src/unit.cpp
31
src/unit.cpp
@ -280,6 +280,7 @@ void unit::advance_to(const unit_type* t)
|
||||
extra_animations_ = t->extra_animations_;
|
||||
death_animations_ = t->death_animations_;
|
||||
movement_animations_ = t->movement_animations_;
|
||||
standing_animations_ = t->standing_animations_;
|
||||
flag_rgb_ = t->flag_rgb();
|
||||
|
||||
backup_state();
|
||||
@ -1086,6 +1087,14 @@ void unit::read(const config& cfg)
|
||||
movement_animations_.push_back(movement_animation(absolute_image()));
|
||||
// always have a movement animation
|
||||
}
|
||||
const config::child_list& standing_anims = cfg_.get_children("standing_anim");
|
||||
for(config::child_list::const_iterator standing_anim = standing_anims.begin(); standing_anim != standing_anims.end(); ++standing_anim) {
|
||||
standing_animations_.push_back(standing_animation(**standing_anim));
|
||||
}
|
||||
if(standing_animations_.empty()) {
|
||||
standing_animations_.push_back(standing_animation(absolute_image()));
|
||||
// always have a standing animation
|
||||
}
|
||||
}
|
||||
}
|
||||
void unit::write(config& cfg) const
|
||||
@ -1256,7 +1265,7 @@ void unit::set_standing(const display &disp,const gamemap::location& loc)
|
||||
delete anim_;
|
||||
anim_ = NULL;
|
||||
}
|
||||
anim_ = new unit_animation(absolute_image());
|
||||
anim_ = new standing_animation(stand_animation(disp.get_map().underlying_union_terrain(loc),facing_));
|
||||
anim_->start_animation(anim_->get_first_frame_time(),unit_animation::INFINITE_CYCLES,disp.turbo()?5:1);
|
||||
frame_begin_time = anim_->get_first_frame_time() -1;
|
||||
anim_->update_current_frame();
|
||||
@ -2533,6 +2542,26 @@ const movement_animation& unit::move_animation(const std::string terrain,gamemap
|
||||
return *options[rand()%options.size()];
|
||||
}
|
||||
|
||||
const standing_animation& unit::stand_animation(const std::string terrain,gamemap::location::DIRECTION dir) const
|
||||
{
|
||||
//select one of the matching animations at random
|
||||
std::vector<const standing_animation*> options;
|
||||
int max_val = -1;
|
||||
for(std::vector<standing_animation>::const_iterator i = standing_animations_.begin(); i != standing_animations_.end(); ++i) {
|
||||
int matching = i->matches(terrain,dir);
|
||||
if(matching == max_val) {
|
||||
options.push_back(&*i);
|
||||
} else if(matching > max_val) {
|
||||
max_val = matching;
|
||||
options.erase(options.begin(),options.end());
|
||||
options.push_back(&*i);
|
||||
}
|
||||
}
|
||||
|
||||
wassert(!options.empty());
|
||||
return *options[rand()%options.size()];
|
||||
}
|
||||
|
||||
|
||||
|
||||
void unit::apply_modifications()
|
||||
|
@ -246,6 +246,7 @@ class unit
|
||||
const death_animation& die_animation(const std::string &terrain,
|
||||
fighting_animation::hit_type hits,const attack_type* attack) const;
|
||||
const movement_animation& move_animation(const std::string terrain,gamemap::location::DIRECTION) const;
|
||||
const standing_animation& stand_animation(const std::string terrain,gamemap::location::DIRECTION) const;
|
||||
|
||||
bool get_ability_bool(const std::string& ability, const gamemap::location& loc) const;
|
||||
unit_ability_list get_abilities(const std::string& ability, const gamemap::location& loc) const;
|
||||
@ -346,6 +347,8 @@ class unit
|
||||
std::vector<death_animation> death_animations_;
|
||||
|
||||
std::vector<movement_animation> movement_animations_;
|
||||
|
||||
std::vector<standing_animation> standing_animations_;
|
||||
unit_animation *anim_;
|
||||
int frame_begin_time;
|
||||
double offset_;
|
||||
|
@ -88,5 +88,15 @@ class movement_animation:public unit_animation
|
||||
private:
|
||||
};
|
||||
|
||||
class standing_animation:public unit_animation
|
||||
{
|
||||
public:
|
||||
explicit standing_animation(const config& cfg):unit_animation(cfg){};
|
||||
explicit standing_animation(const std::string& image):
|
||||
unit_animation(image,0,150){};
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
@ -617,6 +617,7 @@ unit_type::unit_type(const unit_type& o)
|
||||
genders_(o.genders_), defensive_animations_(o.defensive_animations_),
|
||||
teleport_animations_(o.teleport_animations_), extra_animations_(o.extra_animations_),
|
||||
death_animations_(o.death_animations_), movement_animations_(o.movement_animations_),
|
||||
standing_animations_(o.standing_animations_),
|
||||
flag_rgb_(o.flag_rgb_)
|
||||
{
|
||||
gender_types_[0] = o.gender_types_[0] != NULL ? new unit_type(*o.gender_types_[0]) : NULL;
|
||||
@ -827,6 +828,15 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
||||
// always have a movement animation
|
||||
}
|
||||
|
||||
const config::child_list& standing_anims = cfg_.get_children("standing_anim");
|
||||
for(config::child_list::const_iterator standing_anim = standing_anims.begin(); standing_anim != standing_anims.end(); ++standing_anim) {
|
||||
standing_animations_.push_back(standing_animation(**standing_anim));
|
||||
}
|
||||
if(standing_animations_.empty()) {
|
||||
standing_animations_.push_back(standing_animation(image()));
|
||||
// always have a standing animation
|
||||
}
|
||||
|
||||
flag_rgb_ = string2rgb(cfg["flag_rgb"]);
|
||||
// deprecation messages, only seen when unit is parsed for the first time
|
||||
}
|
||||
|
@ -283,6 +283,7 @@ private:
|
||||
|
||||
std::vector<movement_animation> movement_animations_;
|
||||
|
||||
std::vector<standing_animation> standing_animations_;
|
||||
std::vector<Uint32> flag_rgb_;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user