The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
animation.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2006 - 2016 by Jeremy Rosen <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13  */
14 #ifndef UNIT_ANIMATION_H_INCLUDED
15 #define UNIT_ANIMATION_H_INCLUDED
16 
17 #include "animated.hpp"
18 #include "config.hpp"
19 #include "halo.hpp"
20 #include "units/frame.hpp"
21 #include "units/ptr.hpp"
22 
23 class attack_type;
24 class display;
25 class unit;
26 
28 {
29  /** Shouldn't be used so only declared. */
31  public:
32  typedef enum { MATCH_FAIL=-10 , DEFAULT_ANIM=-9} variation_type;
33  typedef enum { HIT, MISS, KILL, INVALID} hit_type;
34 
35  static const std::vector<std::string>& all_tag_names();
36  static void fill_initial_animations( std::vector<unit_animation> & animations, const config & cfg);
37  static void add_anims( std::vector<unit_animation> & animations, const config & cfg);
38 
39  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;
40 
41 
42  const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; }
43  void add_frame(int duration, const unit_frame& value,bool force_change =false){ unit_anim_.add_frame(duration,value,force_change) ; }
44 
45  bool need_update() const;
46  bool need_minimal_update() const;
47  bool animation_finished() const;
48  bool animation_finished_potential() const;
49  void update_last_draw_time();
50  int get_begin_time() const;
51  int get_end_time() const;
52  int time_to_tick(int animation_time) const { return unit_anim_.time_to_tick(animation_time); }
55  void start_animation(int start_time
58  , const std::string& text = ""
59  , const Uint32 text_color = 0
60  , const bool accelerate = true);
61  void update_parameters(const map_location &src, const map_location &dst);
62  void pause_animation();
63  void restart_animation();
65  void redraw(frame_parameters& value, halo::manager & halo_man);
66  void clear_haloes();
68  std::string debug() const;
69  friend std::ostream& operator << (std::ostream& outstream, const unit_animation& u_animation);
70 
71  friend class unit;
72  friend class unit_drawer;
73 
74  explicit unit_animation(const config &cfg, const std::string &frame_string = "");
75 
76  protected:
77  // reserved to class unit, for the special case of redrawing the unit base frame
78  const frame_parameters get_current_params(const frame_parameters & default_val = frame_parameters()) const { return unit_anim_.parameters(default_val); }
79  private:
80  explicit unit_animation(int start_time
81  , const unit_frame &frame
82  , const std::string& event = ""
83  , const int variation=DEFAULT_ANIM
84  , const frame_builder & builder = frame_builder());
85 
86  class particule:public animated<unit_frame>
87  {
88  public:
89  explicit particule(int start_time=0,const frame_builder &builder = frame_builder()) :
90  animated<unit_frame>(start_time),
91  accelerate(true),
92  parameters_(builder),
93  halo_id_(),
95  cycles_(false)
96  {}
97  explicit particule(const config& cfg
98  , const std::string& frame_string ="frame");
99 
100  virtual ~particule();
101  bool need_update() const;
102  bool need_minimal_update() const;
103  typedef enum { UNSET,CYCLE,NO_CYCLE} cycle_state;
104  void override(int start_time
105  , int duration
106  , const cycle_state cycles
107  , const std::string& highlight = ""
108  , const std::string& blend_ratio =""
109  , Uint32 blend_color = 0
110  , const std::string& offset = ""
111  , const std::string& layer = ""
112  , const std::string& modifiers = "");
113  void redraw( const frame_parameters& value,const map_location &src, const map_location &dst, halo::manager & halo_man);
114  std::set<map_location> get_overlaped_hex(const frame_parameters& value,const map_location &src, const map_location &dst);
115  void start_animation(int start_time);
117  void clear_halo();
119  private:
120 
121  //animation params that can be locally overridden by frames
125  bool cycles_;
126 
127  };
129  std::vector<config> unit_filter_;
130  std::vector<config> secondary_unit_filter_;
131  std::vector<map_location::DIRECTION> directions_;
134  std::vector<std::string> event_;
135  std::vector<int> value_;
136  std::vector<config> primary_attack_filter_;
137  std::vector<config> secondary_attack_filter_;
138  std::vector<hit_type> hits_;
139  std::vector<int> value2_;
140  std::map<std::string,particule> sub_anims_;
142  /* these are drawing parameters, but for efficiency reason they are in the anim and not in the particle */
145  // optimization
148  std::set<map_location> overlaped_hex_;
149 };
150 
152 {
153  public:
155  animated_units_(),
156  start_time_(INT_MIN)
157  {
158  }
159 
160 
161  void add_animation(const unit* animated_unit
162  , const unit_animation * animation
164  , bool with_bars = false
165  , const std::string& text = ""
166  , const Uint32 text_color = 0);
167  void add_animation(const unit* animated_unit
168  , const std::string& event
171  , const int value = 0
172  , bool with_bars = false
173  , const std::string& text = ""
174  , const Uint32 text_color = 0
175  , const unit_animation::hit_type hit_type =
177  , const attack_type* attack = nullptr
178  , const attack_type* second_attack = nullptr
179  , int value2 = 0);
180  void replace_anim_if_invalid(const unit* animated_unit
181  , const std::string& event
184  , const int value = 0
185  , bool with_bars = false
186  , const std::string& text = ""
187  , const Uint32 text_color = 0
188  , const unit_animation::hit_type hit_type =
190  , const attack_type* attack = nullptr
191  , const attack_type* second_attack = nullptr
192  , int value2 = 0);
193  void start_animations();
194  void pause_animation();
195  void restart_animation();
196  void clear(){start_time_ = INT_MIN ; animated_units_.clear();}
197  void set_all_standing();
198 
199 
200  bool would_end() const;
201  int get_animation_time() const;
202  int get_animation_time_potential() const;
203  int get_end_time() const;
204  void wait_for_end() const;
205  void wait_until( int animation_time) const;
206  private:
207  struct anim_elem {
208 
210  my_unit(0),
211  animation(0),
212  text(),
213  text_color(0),
214  src(),
215  with_bars(false)
216  {}
217 
221  Uint32 text_color;
223  bool with_bars;
224  };
225 
226  std::vector<anim_elem> animated_units_;
228 };
229 #endif
Describe a unit's animation sequence.
Definition: frame.hpp:204
void start_animations()
Definition: animation.cpp:1346
particule(int start_time=0, const frame_builder &builder=frame_builder())
Definition: animation.hpp:89
void wait_until(int animation_time) const
Definition: animation.cpp:1380
std::vector< hit_type > hits_
Definition: animation.hpp:138
Definition: unit.hpp:95
keep most parameters in a separate class to simplify handling of large number of parameters handling ...
Definition: frame.hpp:159
bool need_update() const
Definition: animation.cpp:907
bool need_update() const
Definition: animation.cpp:860
int get_animation_time_potential() const
Definition: animation.cpp:1420
std::string debug() const
Definition: animation.cpp:1091
bool cycles() const
Definition: animated.hpp:75
int time_to_tick(int animation_time) const
std::vector< map_location::DIRECTION > directions_
Definition: animation.hpp:131
Frame for unit's animation sequence.
static void add_anims(std::vector< unit_animation > &animations, const config &cfg)
Definition: animation.cpp:618
int get_current_frame_begin_time() const
int get_end_time() const
Definition: animation.cpp:960
std::vector< config > secondary_attack_filter_
Definition: animation.hpp:137
void start_animation(int start_time)
Definition: animation.cpp:1256
int get_current_frame_time() const
int get_begin_time() const
Definition: animation.cpp:970
void add_frame(int duration, const unit_frame &value, bool force_change=false)
Definition: animation.hpp:43
void clear_haloes()
Definition: animation.cpp:1040
const unit_animation * animation
Definition: animation.hpp:219
std::vector< int > value_
Definition: animation.hpp:135
int get_animation_time() const
Definition: animation.hpp:53
void add_frame(int duration, const T &value, bool force_change=false)
Adds a frame to an animation.
int time_to_tick(int animation_time) const
Definition: animation.hpp:52
bool animation_finished_potential() const
Definition: animation.cpp:940
int get_animation_time() const
GLenum src
Definition: glew.h:2392
All parameters from a frame at a given instant.
Definition: frame.hpp:71
Definitions for the interface to Wesnoth Markup Language (WML).
const frame_parameters parameters(int current_time) const
getters for the different parameters
Definition: frame.cpp:516
map_location dst_
Definition: animation.hpp:144
int get_begin_time() const
std::vector< anim_elem > animated_units_
Definition: animation.hpp:226
void pause_animation()
Definition: animation.cpp:1009
bool would_end() const
Definition: animation.cpp:1371
const frame_parameters merge_parameters(int current_time, const frame_parameters &animation_val, const frame_parameters &engine_val=frame_parameters()) const
Definition: frame.cpp:857
GLintptr offset
Definition: glew.h:1650
int get_animation_time_potential() const
Definition: animation.hpp:54
const T & get_last_frame() const
void restart_animation()
Definition: animation.cpp:1444
unit_animation()
Shouldn't be used so only declared.
int get_end_time() const
Definition: animation.cpp:1424
GLenum GLenum GLuint GLint GLint layer
Definition: glew.h:3455
static const std::vector< std::string > & all_tag_names()
Definition: animation.cpp:65
void replace_anim_if_invalid(const unit *animated_unit, const std::string &event, const map_location &src=map_location::null_location(), const map_location &dst=map_location::null_location(), const int value=0, bool with_bars=false, const std::string &text="", const Uint32 text_color=0, const unit_animation::hit_type hit_type=unit_animation::INVALID, const attack_type *attack=nullptr, const attack_type *second_attack=nullptr, int value2=0)
Definition: animation.cpp:1315
Animate units.
GLsizei const GLfloat * value
Definition: glew.h:1817
GLenum GLenum dst
Definition: glew.h:2392
std::set< map_location > overlaped_hex_
Definition: animation.hpp:148
const unit_frame & get_current_frame() const
int get_current_frame_begin_time() const
Definition: animation.hpp:64
const frame_parameters parameters(const frame_parameters &default_val) const
Definition: animation.hpp:116
unit_const_ptr my_unit
Definition: animation.hpp:218
std::vector< config > secondary_unit_filter_
Definition: animation.hpp:130
std::vector< std::string > event_
Definition: animation.hpp:134
static const map_location & null_location()
Definition: location.hpp:195
void restart_animation()
Definition: animation.cpp:1018
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
Definition: animation.cpp:377
int get_animation_time_potential() const
Encapsulates the map of the game.
Definition: location.hpp:38
friend std::ostream & operator<<(std::ostream &outstream, const unit_animation &u_animation)
Definition: animation.cpp:1098
void pause_animation()
Definition: animation.cpp:1435
particule unit_anim_
Definition: animation.hpp:141
map_location src_
Definition: animation.hpp:143
std::set< map_location > get_overlaped_hex(const frame_parameters &value, const map_location &src, const map_location &dst)
Definition: animation.cpp:1243
std::vector< int > value2_
Definition: animation.hpp:139
static void fill_initial_animations(std::vector< unit_animation > &animations, const config &cfg)
Definition: animation.cpp:469
void add_animation(const unit *animated_unit, const unit_animation *animation, const map_location &src=map_location::null_location(), bool with_bars=false, const std::string &text="", const Uint32 text_color=0)
Definition: animation.cpp:1294
std::vector< config > unit_filter_
Definition: animation.hpp:129
const unit_frame & get_last_frame() const
Definition: animation.hpp:42
std::vector< config > primary_attack_filter_
Definition: animation.hpp:136
std::map< std::string, particule > sub_anims_
Definition: animation.hpp:140
void update_parameters(const map_location &src, const map_location &dst)
Definition: animation.cpp:1004
cl_event event
Definition: glew.h:3070
void set_all_standing()
Definition: animation.cpp:1453
frame_parsed_parameters parameters_
Definition: animation.hpp:122
void redraw(frame_parameters &value, halo::manager &halo_man)
Definition: animation.cpp:1027
void update_last_draw_time()
Definition: animation.cpp:950
void redraw(const frame_parameters &value, const map_location &src, const map_location &dst, halo::manager &halo_man)
Definition: animation.cpp:1216
int get_animation_time() const
Definition: animation.cpp:1416
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
t_translation::t_list terrain_types_
Definition: animation.hpp:128
bool play_offscreen_
Definition: animation.hpp:147
bool animation_finished() const
Definition: animation.cpp:930
GLsizei const GLcharARB ** string
Definition: glew.h:4503
bool need_minimal_update() const
Definition: animation.cpp:917
const frame_parameters get_current_params(const frame_parameters &default_val=frame_parameters()) const
Definition: animation.hpp:78
void wait_for_end() const
Definition: animation.cpp:1399
void start_animation(int start_time, const map_location &src=map_location::null_location(), const map_location &dst=map_location::null_location(), const std::string &text="", const Uint32 text_color=0, const bool accelerate=true)
Definition: animation.cpp:980
std::vector< t_terrain > t_list
Definition: translation.hpp:75
bool need_minimal_update() const
Definition: animation.cpp:868
bool invalidate(frame_parameters &value)
Definition: animation.cpp:1049