mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-07 22:24:19 +00:00
move animations vector to animation component, drop header in unit
This commit is contained in:
parent
027a135118
commit
6603de667b
@ -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"
|
||||
|
@ -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 <boost/foreach.hpp>
|
||||
|
||||
|
@ -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>
|
||||
|
@ -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>
|
||||
|
21
src/unit.cpp
21
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<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();
|
||||
}*/
|
||||
}
|
||||
@ -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<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"];
|
||||
|
||||
|
@ -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"
|
||||
@ -473,7 +473,6 @@ private:
|
||||
|
||||
protected:
|
||||
boost::scoped_ptr<unit_animation_component> anim_comp_;
|
||||
std::vector<unit_animation> animations_;
|
||||
|
||||
bool getsHit_;
|
||||
mutable bool hidden_;
|
||||
|
@ -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<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);
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,9 @@
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
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<unit_animation> anim_;
|
||||
std::vector<unit_animation> animations_;
|
||||
|
||||
STATE state_; //animation state
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user