Skip to content

Commit

Permalink
various cleanups in animations, and unreported bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
boucman committed Feb 11, 2008
1 parent 56e14f5 commit 20bf7fa
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/animated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class animated
//! 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;
Expand Down
12 changes: 5 additions & 7 deletions src/animated.i
Original file line number Diff line number Diff line change
Expand Up @@ -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()();

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions src/unit_animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/unit_animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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:

Expand Down

0 comments on commit 20bf7fa

Please sign in to comment.