From 6603de667b464d6f6bea04fa07dd25ac8493bc39 Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Tue, 17 Jun 2014 11:52:44 -0400 Subject: [PATCH] move animations vector to animation component, drop header in unit --- src/dialogs.cpp | 2 ++ src/play_controller.cpp | 23 ++++++++++++----------- src/playmp_controller.cpp | 1 + src/playsingle_controller.cpp | 3 ++- src/unit.cpp | 21 +++------------------ src/unit.hpp | 3 +-- src/unit_animation_component.cpp | 24 ++++++++++++++++++++++-- src/unit_animation_component.hpp | 9 ++++++++- 8 files changed, 51 insertions(+), 35 deletions(-) diff --git a/src/dialogs.cpp b/src/dialogs.cpp index c4ea94aa392..db896017cc8 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -46,6 +46,8 @@ #include "strftime.hpp" #include "synced_context.hpp" #include "thread.hpp" +#include "unit.hpp" +#include "unit_animation.hpp" #include "unit_helper.hpp" #include "unit_types.hpp" #include "wml_separators.hpp" diff --git a/src/play_controller.cpp b/src/play_controller.cpp index a43a95562bd..63cd4f51e1c 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -24,36 +24,37 @@ #include "actions/heal.hpp" #include "actions/undo.hpp" #include "actions/vision.hpp" +#include "ai/manager.hpp" +#include "ai/testing.hpp" #include "dialogs.hpp" #include "formula_string_utils.hpp" #include "game_events/handlers.hpp" #include "game_events/menu_item.hpp" #include "game_events/pump.hpp" #include "game_preferences.hpp" +#include "hotkey/hotkey_item.hpp" #include "map_label.hpp" #include "gettext.hpp" #include "halo.hpp" #include "loadscreen.hpp" #include "log.hpp" #include "pathfind/teleport.hpp" -#include "resources.hpp" -#include "savegame.hpp" -#include "saved_game.hpp" -#include "sound.hpp" -#include "unit_id.hpp" -#include "save_blocker.hpp" #include "preferences_display.hpp" #include "replay.hpp" #include "random_new_deterministic.hpp" +#include "resources.hpp" +#include "savegame.hpp" +#include "saved_game.hpp" +#include "save_blocker.hpp" +#include "scripting/lua.hpp" +#include "sound.hpp" #include "soundsource.hpp" #include "synced_context.hpp" #include "tooltips.hpp" -#include "wml_exception.hpp" -#include "ai/manager.hpp" -#include "ai/testing.hpp" +#include "unit_animation.hpp" +#include "unit_id.hpp" #include "whiteboard/manager.hpp" -#include "scripting/lua.hpp" -#include "hotkey/hotkey_item.hpp" +#include "wml_exception.hpp" #include diff --git a/src/playmp_controller.cpp b/src/playmp_controller.cpp index 6bbb26fdd25..388af9eb483 100644 --- a/src/playmp_controller.cpp +++ b/src/playmp_controller.cpp @@ -27,6 +27,7 @@ #include "savegame.hpp" #include "sound.hpp" #include "formula_string_utils.hpp" +#include "unit_animation.hpp" #include "whiteboard/manager.hpp" #include diff --git a/src/playsingle_controller.cpp b/src/playsingle_controller.cpp index ca891366ae9..1083c65bd06 100644 --- a/src/playsingle_controller.cpp +++ b/src/playsingle_controller.cpp @@ -45,8 +45,9 @@ #include "save_blocker.hpp" #include "soundsource.hpp" #include "storyscreen/interface.hpp" -#include "whiteboard/manager.hpp" +#include "unit_animation.hpp" #include "util.hpp" +#include "whiteboard/manager.hpp" #include "hotkey/hotkey_item.hpp" #include diff --git a/src/unit.cpp b/src/unit.cpp index 3b7bdc8515c..86aa5a2e916 100644 --- a/src/unit.cpp +++ b/src/unit.cpp @@ -204,8 +204,6 @@ unit::unit(const unit& o): anim_comp_(new unit_animation_component(*this, *o.anim_comp_)), - animations_(o.animations_), - getsHit_(o.getsHit_), hidden_(o.hidden_), hp_bar_scaling_(o.hp_bar_scaling_), @@ -273,7 +271,6 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) : is_healthy_(false), modification_descriptions_(), anim_comp_(new unit_animation_component(*this)), - animations_(), getsHit_(0), hidden_(false), hp_bar_scaling_(cfg["hp_bar_scaling"].blank() ? type_->hp_bar_scaling() : cfg["hp_bar_scaling"]), @@ -498,7 +495,7 @@ unit::unit(const config &cfg, bool use_traits, const vconfig* vcfg) : } //debug unit animations for units as they appear in game - /*for(std::vector::const_iterator i = animations_.begin(); i != animations_.end(); ++i) { + /*for(std::vector::const_iterator i = anim_comp_->animations_.begin(); i != anim_comp_->animations_.end(); ++i) { std::cout << (*i).debug(); }*/ } @@ -572,7 +569,6 @@ unit::unit(const unit_type &u_type, int side, bool real_unit, is_healthy_(false), modification_descriptions_(), anim_comp_(new unit_animation_component(*this)), - animations_(), getsHit_(0), hidden_(false), modifications_(), @@ -814,8 +810,6 @@ void unit::advance_to(const config &old_cfg, const unit_type &u_type, max_attacks_ = new_type.max_attacks(); - animations_ = new_type.animations(); - flag_rgb_ = new_type.flag_rgb(); @@ -849,7 +843,7 @@ void unit::advance_to(const config &old_cfg, const unit_type &u_type, game_events::add_events(cfg_.child_range("event"), new_type.id()); cfg_.clear_children("event"); - anim_comp_->reset_after_advance(); + anim_comp_->reset_after_advance(&new_type); } std::string unit::big_profile() const @@ -2193,16 +2187,7 @@ void unit::add_modification(const std::string& mod_type, const config& mod, bool game_config::add_color_info(effect); LOG_UT << "applying image_mod \n"; } else if (apply_to == "new_animation") { - if(effect["id"].empty()) { - unit_animation::add_anims(animations_, effect); - } else { - std::vector &built = resources::controller->animation_cache[effect["id"]]; - if(built.empty()) { - unit_animation::add_anims(built, effect); - } - animations_.insert(animations_.end(),built.begin(),built.end()); - } - + anim_comp_->apply_new_animation_effect(effect); } else if (apply_to == "ellipse") { cfg_["ellipse"] = effect["ellipse"]; diff --git a/src/unit.hpp b/src/unit.hpp index 9975c331c01..62e67e0b243 100644 --- a/src/unit.hpp +++ b/src/unit.hpp @@ -20,7 +20,7 @@ #include #include -#include "unit_animation.hpp" +#include "sdl/utils.hpp" #include "unit_types.hpp" #include "unit_map.hpp" #include "unit_ptr.hpp" @@ -473,7 +473,6 @@ private: protected: boost::scoped_ptr anim_comp_; - std::vector animations_; bool getsHit_; mutable bool hidden_; diff --git a/src/unit_animation_component.cpp b/src/unit_animation_component.cpp index 36f45e175a0..fa1cbd95df7 100644 --- a/src/unit_animation_component.cpp +++ b/src/unit_animation_component.cpp @@ -14,11 +14,15 @@ #include "unit_animation_component.hpp" +#include "config.hpp" #include "display.hpp" #include "map.hpp" +#include "play_controller.hpp" //Only needed to access animations cache +#include "resources.hpp" //Only needed to access animations cache #include "preferences.hpp" #include "unit_animation.hpp" #include "unit.hpp" +#include "unit_types.hpp" const unit_animation* unit_animation_component::choose_animation(const display& disp, const map_location& loc,const std::string& event, const map_location& second_loc,const int value,const unit_animation::hit_type hit, @@ -27,7 +31,7 @@ const unit_animation* unit_animation_component::choose_animation(const display& // Select one of the matching animations at random std::vector options; int max_val = unit_animation::MATCH_FAIL; - for(std::vector::const_iterator i = u_.animations_.begin(); i != u_.animations_.end(); ++i) { + for(std::vector::const_iterator i = animations_.begin(); i != animations_.end(); ++i) { int matching = i->matches(disp,loc,second_loc,&u_,event,value,hit,attack,second_attack,swing_num); if(matching > unit_animation::MATCH_FAIL && matching == max_val) { options.push_back(&*i); @@ -181,8 +185,24 @@ bool unit_animation_component::invalidate (const display & disp) } -void unit_animation_component::reset_after_advance() +void unit_animation_component::reset_after_advance(const unit_type * newtype) { + if (newtype) { + animations_ = newtype->animations(); + } + refreshing_ = false; anim_.reset(); } + +void unit_animation_component::apply_new_animation_effect(const config & effect) { + if(effect["id"].empty()) { + unit_animation::add_anims(animations_, effect); + } else { + std::vector &built = resources::controller->animation_cache[effect["id"]]; + if(built.empty()) { + unit_animation::add_anims(built, effect); + } + animations_.insert(animations_.end(),built.begin(),built.end()); + } +} diff --git a/src/unit_animation_component.hpp b/src/unit_animation_component.hpp index 0748aa2acda..3732ee92f46 100644 --- a/src/unit_animation_component.hpp +++ b/src/unit_animation_component.hpp @@ -22,7 +22,9 @@ #include +class config; class unit; +class unit_type; class unit_animation_component { @@ -36,6 +38,7 @@ public: unit_animation_component(unit & my_unit) : u_(my_unit), anim_(NULL), + animations_(), state_(STATE_STANDING), next_idling_(0), frame_begin_time_(0), @@ -46,6 +49,7 @@ public: unit_animation_component(unit & my_unit, const unit_animation_component & o) : u_(my_unit), anim_(NULL), + animations_(o.animations_), state_(o.state_), next_idling_(0), frame_begin_time_(o.frame_begin_time_), @@ -79,7 +83,9 @@ public: void clear_haloes(); - void reset_after_advance(); + void reset_after_advance(const unit_type * newtype = NULL); + + void apply_new_animation_effect(const config & effect); unit_animation* get_animation() const { return anim_.get(); } @@ -89,6 +95,7 @@ private: const unit & u_; boost::scoped_ptr anim_; + std::vector animations_; STATE state_; //animation state