various cleanups in animations, and unreported bugfix
This commit is contained in:
parent
56e14f5aa9
commit
20bf7fa2e9
5 changed files with 14 additions and 16 deletions
|
@ -53,7 +53,7 @@ public:
|
|||
//! Starts an animation cycle.
|
||||
//! The first frame of the animation to start may be set
|
||||
//! to any value by using a start_time different to 0.
|
||||
void start_animation(int start_time, bool cycles=false, double acceleration=1);
|
||||
void start_animation(int start_time, bool cycles=false);
|
||||
|
||||
int get_begin_time() const;
|
||||
int get_end_time() const;
|
||||
|
|
|
@ -39,7 +39,6 @@ int get_current_animation_tick()
|
|||
return current_ticks;
|
||||
}
|
||||
|
||||
extern int animation_debug;
|
||||
template<typename T, typename T_void_value>
|
||||
const T animated<T,T_void_value>::void_value_ = T_void_value()();
|
||||
|
||||
|
@ -92,14 +91,13 @@ void animated<T,T_void_value>::add_frame(int duration, const T& value,bool force
|
|||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
void animated<T,T_void_value>::start_animation(int start_time, bool cycles, double acceleration)
|
||||
void animated<T,T_void_value>::start_animation(int start_time, bool cycles)
|
||||
{
|
||||
started_ = true;
|
||||
last_update_tick_ = current_ticks;
|
||||
acceleration_ = acceleration;
|
||||
acceleration_ = 1.0; //assume acceleration is 1, this will be fixed at first update_last_draw_time
|
||||
start_tick_ = last_update_tick_ +
|
||||
static_cast<int>(( starting_frame_time_ - start_time)/acceleration_);
|
||||
//if(animation_debug) printf("clock %d starting sft %d st %d acc %f\n",SDL_GetTicks(),starting_frame_time_,start_tick_,acceleration_);
|
||||
|
||||
cycles_ = cycles;
|
||||
if(acceleration_ <=0) acceleration_ = 1;
|
||||
|
@ -112,11 +110,11 @@ template<typename T, typename T_void_value>
|
|||
void animated<T,T_void_value>::update_last_draw_time(double acceleration)
|
||||
{
|
||||
if (acceleration > 0 && acceleration_ != acceleration) {
|
||||
int tmp = tick_to_time(start_tick_);
|
||||
int tmp = tick_to_time(last_update_tick_);
|
||||
acceleration_ = acceleration;
|
||||
start_tick_ = time_to_tick(tmp);
|
||||
start_tick_ = last_update_tick_ +
|
||||
static_cast<int>(( starting_frame_time_ - tmp)/acceleration_);
|
||||
}
|
||||
//if(animation_debug) printf("%s clock %d time %d sft %d st %d acc %f\n",__FUNCTION__,SDL_GetTicks(),last_update_tick_,starting_frame_time_,start_tick_,acceleration_);
|
||||
last_update_tick_ = current_ticks;
|
||||
if (need_first_update_) {
|
||||
need_first_update_ = false;
|
||||
|
|
|
@ -1607,7 +1607,7 @@ void unit::start_animation(const int start_time, const gamemap::location &loc,co
|
|||
if(anim_) delete anim_;
|
||||
anim_ = new unit_animation(*animation);
|
||||
const int real_start_time = start_time == INT_MAX ? anim_->get_begin_time() : start_time;
|
||||
anim_->start_animation(real_start_time,loc, loc.get_direction(facing_), cycles,text,text_color, disp->turbo_speed());
|
||||
anim_->start_animation(real_start_time,loc, loc.get_direction(facing_), cycles,text,text_color);
|
||||
frame_begin_time_ = anim_->get_begin_time() -1;
|
||||
if (disp->idle_anim()) {
|
||||
next_idling_ = get_current_animation_tick()
|
||||
|
|
|
@ -727,9 +727,9 @@ int unit_animation::get_begin_time() const
|
|||
return result;
|
||||
}
|
||||
|
||||
void unit_animation::start_animation(int start_time,const gamemap::location &src, const gamemap::location &dst, bool cycles, const std::string text, const Uint32 text_color, double acceleration)
|
||||
void unit_animation::start_animation(int start_time,const gamemap::location &src, const gamemap::location &dst, bool cycles, const std::string text, const Uint32 text_color)
|
||||
{
|
||||
unit_anim_.start_animation(start_time, src, dst, cycles,acceleration);
|
||||
unit_anim_.start_animation(start_time, src, dst, cycles);
|
||||
if(!text.empty()) {
|
||||
crude_animation crude_build;
|
||||
crude_build.add_frame(1,unit_frame());
|
||||
|
@ -738,7 +738,7 @@ void unit_animation::start_animation(int start_time,const gamemap::location &src
|
|||
}
|
||||
std::map<std::string,crude_animation>::iterator anim_itor =sub_anims_.begin();
|
||||
for( /*null*/; anim_itor != sub_anims_.end() ; anim_itor++) {
|
||||
anim_itor->second.start_animation(start_time,src,dst,cycles,acceleration);
|
||||
anim_itor->second.start_animation(start_time,src,dst,cycles);
|
||||
}
|
||||
}
|
||||
void unit_animation::redraw()
|
||||
|
@ -847,11 +847,11 @@ unit_animation::crude_animation::~crude_animation()
|
|||
|
||||
void unit_animation::crude_animation::start_animation(int start_time,
|
||||
const gamemap::location &src, const gamemap::location &dst,
|
||||
bool cycles, double acceleration)
|
||||
bool cycles)
|
||||
{
|
||||
halo::remove(halo_id_);
|
||||
halo_id_ = halo::NO_HALO;
|
||||
animated<unit_frame>::start_animation(start_time,cycles,acceleration);
|
||||
animated<unit_frame>::start_animation(start_time,cycles);
|
||||
last_frame_begin_time_ = get_begin_time() -1;
|
||||
if(src != gamemap::location::null_location || dst != gamemap::location::null_location) {
|
||||
src_ = src;
|
||||
|
|
|
@ -51,7 +51,7 @@ class unit_animation
|
|||
int time_to_tick(int animation_time) const { return unit_anim_.time_to_tick(animation_time); };
|
||||
int get_animation_time() const{ return unit_anim_.get_animation_time() ; };
|
||||
int get_animation_time_potential() const{ return unit_anim_.get_animation_time_potential() ; };
|
||||
void start_animation(int start_time,const gamemap::location &src = gamemap::location::null_location, const gamemap::location &dst = gamemap::location::null_location , bool cycles=false, const std::string text="", const Uint32 text_color=0, double acceleration=1);
|
||||
void start_animation(int start_time,const gamemap::location &src = gamemap::location::null_location, const gamemap::location &dst = gamemap::location::null_location , bool cycles=false, const std::string text="", const Uint32 text_color=0);
|
||||
const int get_current_frame_begin_time() const{ return unit_anim_.get_current_frame_begin_time() ; };
|
||||
void redraw();
|
||||
|
||||
|
@ -105,7 +105,7 @@ class unit_animation
|
|||
double offset(double default_val =0.0) const;
|
||||
std::pair<std::string,Uint32> text() const ;
|
||||
void redraw( );
|
||||
void start_animation(int start_time,const gamemap::location& src,const gamemap::location& dst, bool cycles=false, double acceleration=1);
|
||||
void start_animation(int start_time,const gamemap::location& src,const gamemap::location& dst, bool cycles=false);
|
||||
bool accelerate;
|
||||
private:
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue