Merge pull request #707 from CelticMinstrel/uanim_output_cleanup

Clean up the debug output for unit animations
This commit is contained in:
Celtic Minstrel 2016-07-29 18:54:42 -04:00 committed by GitHub
commit 7ca8897ff5
7 changed files with 67 additions and 101 deletions

View file

@ -32,10 +32,10 @@ class plugins_context {
public:
typedef std::function<bool(config)> callback_function;
typedef struct { char const * name; callback_function func; } Reg;
struct Reg { char const * name; callback_function func; };
typedef std::function<config(config)> accessor_function;
typedef struct { char const * name; accessor_function func; } aReg;
struct aReg { char const * name; accessor_function func; };
plugins_context( const std::string & name );
plugins_context( const std::string & name, const std::vector<Reg>& callbacks, const std::vector<aReg>& accessors);

View file

@ -25,7 +25,7 @@
#include <SDL_video.h>
typedef struct { size_t x1,y1,x2,y2; } _rect;
struct _rect { size_t x1,y1,x2,y2; };
struct theme_info
{

View file

@ -349,13 +349,13 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
std::vector<std::string>::iterator hit;
for(hit=hits_str.begin() ; hit != hits_str.end() ; ++hit) {
if(*hit == "yes" || *hit == "hit") {
hits_.push_back(HIT);
hits_.push_back(hit_type::HIT);
}
if(*hit == "no" || *hit == "miss") {
hits_.push_back(MISS);
hits_.push_back(hit_type::MISS);
}
if(*hit == "yes" || *hit == "kill" ) {
hits_.push_back(KILL);
hits_.push_back(hit_type::KILL);
}
}
std::vector<std::string> value2_str = utils::split(cfg["value_second"]);
@ -535,8 +535,8 @@ void unit_animation::fill_initial_animations( std::vector<unit_animation> & anim
animations.push_back(*itor);
animations.back().event_ = utils::split("defend");
animations.back().unit_anim_.override(0,animations.back().unit_anim_.get_animation_duration(),particule::NO_CYCLE,"","0.0,0.5:75,0.0:75,0.5:75,0.0",game_display::rgb(255,0,0));
animations.back().hits_.push_back(HIT);
animations.back().hits_.push_back(KILL);
animations.back().hits_.push_back(hit_type::HIT);
animations.back().hits_.push_back(hit_type::KILL);
animations.push_back(*itor);
animations.back().event_ = utils::split("defend");
@ -1096,95 +1096,61 @@ std::string unit_animation::debug() const
std::ostream& operator << (std::ostream& outstream, const unit_animation& u_animation)
{
std::cout << "[";
int i=0;
for (std::string event : u_animation.event_) {
if (i>0) std::cout << ','; i++;
std::cout << event;
}
std::cout << "]\n";
std::string events_string = utils::join(u_animation.event_);
outstream << "[" << events_string << "]\n";
std::cout << "\tstart_time=" << u_animation.get_begin_time() << '\n';
outstream << "\tstart_time=" << u_animation.get_begin_time() << '\n';
if (u_animation.hits_.size() > 0) {
std::cout << "\thits=";
i=0;
for (const unit_animation::hit_type hit_type : u_animation.hits_) {
if (i>0) std::cout << ','; i++;
switch (hit_type) {
case (unit_animation::HIT) : std::cout << "hit"; break;
case (unit_animation::MISS) : std::cout << "miss"; break;
case (unit_animation::KILL) : std::cout << "kill"; break;
case (unit_animation::INVALID) : std::cout << "invalid"; break;
}
}
std::cout << '\n';
std::vector<std::string> hits;
std::transform(u_animation.hits_.begin(), u_animation.hits_.end(), std::back_inserter(hits), unit_animation::hit_type::enum_to_string);
outstream << "\thits=" << utils::join(hits) << '\n';
}
if (u_animation.directions_.size() > 0) {
std::cout << "\tdirections=";
i=0;
for (const map_location::DIRECTION direction : u_animation.directions_) {
if (i>0) std::cout << ','; i++;
switch (direction) {
case (map_location::NORTH) : std::cout << "n"; break;
case (map_location::NORTH_EAST): std::cout << "ne"; break;
case (map_location::SOUTH_EAST): std::cout << "se"; break;
case (map_location::SOUTH) : std::cout << "s"; break;
case (map_location::SOUTH_WEST): std::cout << "sw"; break;
case (map_location::NORTH_WEST): std::cout << "nw"; break;
default: break;
}
}
std::cout << '\n';
std::vector<std::string> dirs;
std::transform(u_animation.directions_.begin(), u_animation.directions_.end(), std::back_inserter(dirs), map_location::write_direction);
outstream << "\tdirections=" << utils::join(dirs) << '\n';
}
if (u_animation.terrain_types_.size() > 0) {
i=0;
std::cout << "\tterrain=";
for (const t_translation::t_terrain terrain : u_animation.terrain_types_) {
if (i>0) std::cout << ','; i++;
std::cout << terrain;
}
std::cout << '\n';
outstream << "\tterrain=" << utils::join(u_animation.terrain_types_) << '\n';
}
if (u_animation.frequency_>0) std::cout << "frequency=" << u_animation.frequency_ << '\n';
if (u_animation.frequency_>0) outstream << "frequency=" << u_animation.frequency_ << '\n';
if (u_animation.unit_filter_.size() > 0) {
std::cout << "[filter]\n";
outstream << "[filter]\n";
for (const config & cfg : u_animation.unit_filter_) {
std::cout << cfg.debug();
outstream << cfg.debug();
}
//std::cout << "TODO: create debugging output for unit filters";
std::cout << "[/filter]\n";
outstream << "[/filter]\n";
}
if (u_animation.secondary_unit_filter_.size() > 0) {
std::cout << "[filter_second]\n";
outstream << "[filter_second]\n";
for (const config & cfg : u_animation.secondary_unit_filter_) {
std::cout << cfg.debug();
outstream << cfg.debug();
}
//std::cout << "TODO: create debugging output for unit filters";
std::cout << "[/filter_second]\n";
outstream << "[/filter_second]\n";
}
if (u_animation.primary_attack_filter_.size() > 0) {
std::cout << "[filter_attack]\n";
outstream << "[filter_attack]\n";
for (const config cfg : u_animation.primary_attack_filter_) {
std::cout << cfg.debug();
outstream << cfg.debug();
}
std::cout << "[/filter_attack]\n";
outstream << "[/filter_attack]\n";
}
if (u_animation.secondary_attack_filter_.size() > 0) {
std::cout << "[filter_second_attack]\n";
outstream << "[filter_second_attack]\n";
for (const config cfg : u_animation.secondary_attack_filter_) {
std::cout << cfg.debug();
outstream << cfg.debug();
}
std::cout << "[/filter_second_attack]\n";
outstream << "[/filter_second_attack]\n";
}
for (size_t i=0; i<u_animation.unit_anim_.get_frames_count(); i++) {
std::cout << "\t[frame]\n";
outstream << "\t[frame]\n";
for (const std::string frame_string : u_animation.unit_anim_.get_frame(i).debug_strings()) {
std::cout << "\t\t" << frame_string <<"\n";
outstream << "\t\t" << frame_string <<"\n";
}
std::cout << "\t[/frame]\n";
outstream << "\t[/frame]\n";
}
for (std::pair<std::string, unit_animation::particule> p : u_animation.sub_anims_) {
@ -1192,22 +1158,16 @@ std::ostream& operator << (std::ostream& outstream, const unit_animation& u_anim
std::string sub_frame_name = p.first;
size_t pos = sub_frame_name.find("_frame");
if (pos != std::string::npos) sub_frame_name = sub_frame_name.substr(0,pos);
std::cout << "\t" << sub_frame_name << "_start_time=" << p.second.get_begin_time() << '\n';
std::cout << "\t[" << p.first << "]\n";
outstream << "\t" << sub_frame_name << "_start_time=" << p.second.get_begin_time() << '\n';
outstream << "\t[" << p.first << "]\n";
for (const std::string frame_string : p.second.get_frame(i).debug_strings()) {
std::cout << "\t\t" << frame_string << '\n';
outstream << "\t\t" << frame_string << '\n';
}
std::cout << "\t[/" << p.first << "]\n";
outstream << "\t[/" << p.first << "]\n";
}
}
std::cout << "[/";
i=0;
for (std::string event : u_animation.event_) {
if (i>0) std::cout << ','; i++;
std::cout << event;
}
std::cout << "]\n";
outstream << "[/" << events_string << "]\n";
return outstream;
}

View file

@ -19,6 +19,7 @@
#include "halo.hpp"
#include "units/frame.hpp"
#include "units/ptr.hpp"
#include "utils/make_enum.hpp"
class attack_type;
class display;
@ -29,14 +30,19 @@ class unit_animation
/** Shouldn't be used so only declared. */
unit_animation();
public:
typedef enum { MATCH_FAIL=-10 , DEFAULT_ANIM=-9} variation_type;
typedef enum { HIT, MISS, KILL, INVALID} hit_type;
enum variation_type { MATCH_FAIL=-10 , DEFAULT_ANIM=-9};
MAKE_ENUM(hit_type,
(HIT, "hit")
(MISS, "miss")
(KILL, "kill")
(INVALID, "invalid")
);
static const std::vector<std::string>& all_tag_names();
static void fill_initial_animations( std::vector<unit_animation> & animations, const config & cfg);
static void add_anims( std::vector<unit_animation> & animations, const config & cfg);
int matches(const display &disp,const map_location& loc,const map_location& second_loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=nullptr,const attack_type* second_attack = nullptr, int value2 =0) const;
int matches(const display &disp,const map_location& loc,const map_location& second_loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=hit_type::INVALID,const attack_type* attack=nullptr,const attack_type* second_attack = nullptr, int value2 =0) const;
const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; }
@ -100,7 +106,7 @@ class unit_animation
virtual ~particule();
bool need_update() const;
bool need_minimal_update() const;
typedef enum { UNSET,CYCLE,NO_CYCLE} cycle_state;
enum cycle_state { UNSET,CYCLE,NO_CYCLE};
void override(int start_time
, int duration
, const cycle_state cycles
@ -173,7 +179,7 @@ class unit_animator
, const std::string& text = ""
, const Uint32 text_color = 0
, const unit_animation::hit_type hit_type =
unit_animation::INVALID
unit_animation::hit_type::INVALID
, const attack_type* attack = nullptr
, const attack_type* second_attack = nullptr
, int value2 = 0);
@ -186,7 +192,7 @@ class unit_animator
, const std::string& text = ""
, const Uint32 text_color = 0
, const unit_animation::hit_type hit_type =
unit_animation::INVALID
unit_animation::hit_type::INVALID
, const attack_type* attack = nullptr
, const attack_type* second_attack = nullptr
, int value2 = 0);

View file

@ -65,7 +65,7 @@ public:
const map_location& loc, const std::string& event,
const map_location& second_loc = map_location::null_location(),
const int damage=0,
const unit_animation::hit_type hit_type = unit_animation::INVALID,
const unit_animation::hit_type hit_type = unit_animation::hit_type::INVALID,
const attack_type* attack=nullptr,const attack_type* second_attack = nullptr,
int swing_num =0);

View file

@ -65,7 +65,7 @@ public:
typedef progressive_<int> progressive_int;
typedef progressive_<double> progressive_double;
typedef enum tristate {t_false,t_true,t_unset} tristate;
enum tristate {t_false,t_true,t_unset};
bool tristate_to_bool(tristate tri, bool def);
/** All parameters from a frame at a given instant */
class frame_parameters{

View file

@ -128,7 +128,7 @@ static int move_unit_between(const map_location& a, const map_location& b,
disp.invalidate(a);
temp_unit->set_facing(a.get_relative_dir(b));
animator.replace_anim_if_invalid(temp_unit.get(),"movement",a,b,step_num,
false,"",0,unit_animation::INVALID,nullptr,nullptr,step_left);
false,"",0,unit_animation::hit_type::INVALID,nullptr,nullptr,step_left);
animator.start_animations();
animator.pause_animation();
disp.scroll_to_tiles(a, b, game_display::ONSCREEN, true, 0.0, false);
@ -507,8 +507,8 @@ void unit_draw_weapon(const map_location& loc, unit& attacker,
unit_animator animator;
attacker.set_facing(loc.get_relative_dir(defender_loc));
defender->set_facing(defender_loc.get_relative_dir(loc));
animator.add_animation(&attacker,"draw_weapon",loc,defender_loc,0,false,"",0,unit_animation::HIT,attack,secondary_attack,0);
animator.add_animation(defender,"draw_weapon",defender_loc,loc,0,false,"",0,unit_animation::MISS,secondary_attack,attack,0);
animator.add_animation(&attacker,"draw_weapon",loc,defender_loc,0,false,"",0,unit_animation::hit_type::HIT,attack,secondary_attack,0);
animator.add_animation(defender,"draw_weapon",defender_loc,loc,0,false,"",0,unit_animation::hit_type::MISS,secondary_attack,attack,0);
animator.start_animations();
animator.wait_for_end();
@ -524,10 +524,10 @@ void unit_sheath_weapon(const map_location& primary_loc, unit* primary_unit,
}
unit_animator animator;
if(primary_unit) {
animator.add_animation(primary_unit,"sheath_weapon",primary_loc,secondary_loc,0,false,"",0,unit_animation::INVALID,primary_attack,secondary_attack,0);
animator.add_animation(primary_unit,"sheath_weapon",primary_loc,secondary_loc,0,false,"",0,unit_animation::hit_type::INVALID,primary_attack,secondary_attack,0);
}
if(secondary_unit) {
animator.add_animation(secondary_unit,"sheath_weapon",secondary_loc,primary_loc,0,false,"",0,unit_animation::INVALID,secondary_attack,primary_attack,0);
animator.add_animation(secondary_unit,"sheath_weapon",secondary_loc,primary_loc,0,false,"",0,unit_animation::hit_type::INVALID,secondary_attack,primary_attack,0);
}
if(primary_unit || secondary_unit) {
@ -554,10 +554,10 @@ void unit_die(const map_location& loc, unit& loser,
}
unit_animator animator;
// hide the hp/xp bars of the loser (useless and prevent bars around an erased unit)
animator.add_animation(&loser,"death",loc,winner_loc,0,false,"",0,unit_animation::KILL,attack,secondary_attack,0);
animator.add_animation(&loser,"death",loc,winner_loc,0,false,"",0,unit_animation::hit_type::KILL,attack,secondary_attack,0);
// but show the bars of the winner (avoid blinking and show its xp gain)
animator.add_animation(winner,"victory",winner_loc,loc,0,true,"",0,
unit_animation::KILL,secondary_attack,attack,0);
unit_animation::hit_type::KILL,secondary_attack,attack,0);
animator.start_animations();
animator.wait_for_end();
@ -609,11 +609,11 @@ void unit_attack(display * disp, game_board & board,
unit_animation::hit_type hit_type;
if(damage >= defender.hitpoints()) {
hit_type = unit_animation::KILL;
hit_type = unit_animation::hit_type::KILL;
} else if(damage > 0) {
hit_type = unit_animation::HIT;
hit_type = unit_animation::hit_type::HIT;
}else {
hit_type = unit_animation::MISS;
hit_type = unit_animation::hit_type::MISS;
}
animator.add_animation(&attacker, "attack", att->get_location(),
def->get_location(), damage, true, text_2,
@ -802,7 +802,7 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
attack_type *primary = nullptr;
attack_type *secondary = nullptr;
Uint32 text_color;
unit_animation::hit_type hits= unit_animation::INVALID;
unit_animation::hit_type hits= unit_animation::hit_type::INVALID;
std::vector<attack_type> attacks = u->attacks();
std::vector<attack_type>::iterator itor;
boost::scoped_ptr<attack_type> dummy_primary;
@ -849,13 +849,13 @@ void wml_animation_internal(unit_animator &animator, const vconfig &cfg, const m
}
if(cfg["hits"] == "yes" || cfg["hits"] == "hit") {
hits = unit_animation::HIT;
hits = unit_animation::hit_type::HIT;
}
if(cfg["hits"] == "no" || cfg["hits"] == "miss") {
hits = unit_animation::MISS;
hits = unit_animation::hit_type::MISS;
}
if( cfg["hits"] == "kill" ) {
hits = unit_animation::KILL;
hits = unit_animation::hit_type::KILL;
}
if(cfg["red"].empty() && cfg["green"].empty() && cfg["blue"].empty()) {
text_color = display::rgb(0xff,0xff,0xff);