Skip to content

Commit

Permalink
move animations vector to animation component, drop header in unit
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 17, 2014
1 parent 027a135 commit 6603de6
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
2 changes: 2 additions & 0 deletions src/dialogs.cpp
Expand Up @@ -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"
Expand Down
21 changes: 11 additions & 10 deletions src/play_controller.cpp
Expand Up @@ -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 "preferences_display.hpp"
#include "replay.hpp"
#include "random_new_deterministic.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 "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 <boost/foreach.hpp>

Expand Down
1 change: 1 addition & 0 deletions src/playmp_controller.cpp
Expand Up @@ -27,6 +27,7 @@
#include "savegame.hpp"
#include "sound.hpp"
#include "formula_string_utils.hpp"
#include "unit_animation.hpp"
#include "whiteboard/manager.hpp"

#include <boost/foreach.hpp>
Expand Down
3 changes: 2 additions & 1 deletion src/playsingle_controller.cpp
Expand Up @@ -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 <boost/foreach.hpp>
Expand Down
21 changes: 3 additions & 18 deletions src/unit.cpp
Expand Up @@ -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_),
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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<unit_animation>::const_iterator i = animations_.begin(); i != animations_.end(); ++i) {
/*for(std::vector<unit_animation>::const_iterator i = anim_comp_->animations_.begin(); i != anim_comp_->animations_.end(); ++i) {
std::cout << (*i).debug();
}*/
}
Expand Down Expand Up @@ -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_(),
Expand Down Expand Up @@ -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();


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<unit_animation> &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"];

Expand Down
3 changes: 1 addition & 2 deletions src/unit.hpp
Expand Up @@ -20,7 +20,7 @@
#include <boost/tuple/tuple.hpp>
#include <boost/scoped_ptr.hpp>

#include "unit_animation.hpp"
#include "sdl/utils.hpp"
#include "unit_types.hpp"
#include "unit_map.hpp"
#include "unit_ptr.hpp"
Expand Down Expand Up @@ -473,7 +473,6 @@ class unit

protected:
boost::scoped_ptr<unit_animation_component> anim_comp_;
std::vector<unit_animation> animations_;

bool getsHit_;
mutable bool hidden_;
Expand Down
24 changes: 22 additions & 2 deletions src/unit_animation_component.cpp
Expand Up @@ -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,
Expand All @@ -27,7 +31,7 @@ const unit_animation* unit_animation_component::choose_animation(const display&
// Select one of the matching animations at random
std::vector<const unit_animation*> options;
int max_val = unit_animation::MATCH_FAIL;
for(std::vector<unit_animation>::const_iterator i = u_.animations_.begin(); i != u_.animations_.end(); ++i) {
for(std::vector<unit_animation>::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);
Expand Down Expand Up @@ -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<unit_animation> &built = resources::controller->animation_cache[effect["id"]];
if(built.empty()) {
unit_animation::add_anims(built, effect);
}
animations_.insert(animations_.end(),built.begin(),built.end());
}
}
9 changes: 8 additions & 1 deletion src/unit_animation_component.hpp
Expand Up @@ -22,7 +22,9 @@

#include <boost/scoped_ptr.hpp>

class config;
class unit;
class unit_type;

class unit_animation_component
{
Expand All @@ -36,6 +38,7 @@ class unit_animation_component
unit_animation_component(unit & my_unit) :
u_(my_unit),
anim_(NULL),
animations_(),
state_(STATE_STANDING),
next_idling_(0),
frame_begin_time_(0),
Expand All @@ -46,6 +49,7 @@ class unit_animation_component
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_),
Expand Down Expand Up @@ -79,7 +83,9 @@ class unit_animation_component

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(); }

Expand All @@ -89,6 +95,7 @@ class unit_animation_component
const unit & u_;

boost::scoped_ptr<unit_animation> anim_;
std::vector<unit_animation> animations_;

STATE state_; //animation state

Expand Down

0 comments on commit 6603de6

Please sign in to comment.