reduce CPU usage by removing calls to SDL_GetTicks
This commit is contained in:
parent
412cb40be1
commit
decbe85b18
4 changed files with 11 additions and 5 deletions
|
@ -191,6 +191,7 @@ Detailed changelog and internal changes:
|
|||
the game easily
|
||||
* better handling of SDL_ListModes return code (no user impact)
|
||||
* first turn of a game is saved again (fixes bug #7909 and bug #8117)
|
||||
* reduce CPU usage by removing calls to SDL_GetTicks for idle animations
|
||||
|
||||
Version 1.2:
|
||||
* campaigns:
|
||||
|
|
|
@ -28,6 +28,11 @@ void new_animation_frame()
|
|||
current_ticks = SDL_GetTicks();
|
||||
}
|
||||
|
||||
int get_current_animation_tick()
|
||||
{
|
||||
return current_ticks;
|
||||
}
|
||||
|
||||
template<typename T, typename T_void_value>
|
||||
const T animated<T,T_void_value>::void_value_ = T_void_value()();
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
#include <vector>
|
||||
|
||||
void new_animation_frame();
|
||||
int get_current_animation_tick();
|
||||
|
||||
|
||||
template<typename T>
|
||||
class void_value
|
||||
|
|
|
@ -1648,9 +1648,8 @@ void unit::refresh(const display& disp,const gamemap::location& loc)
|
|||
if(state_ == STATE_IDLING && anim_ && anim_->animation_finished()) set_standing(disp, loc);
|
||||
if(state_ != STATE_STANDING) return;
|
||||
if(incapacitated()) return;
|
||||
unsigned int tmp = SDL_GetTicks();
|
||||
if(tmp < next_idling) return;
|
||||
if(tmp > next_idling + 1000) {set_standing(disp,loc); return; }// prevent all units animating at the same time
|
||||
if(get_current_animation_tick() < next_idling) return;
|
||||
if(get_current_animation_tick() > next_idling + 1000) {set_standing(disp,loc); return; }// prevent all units animating at the same time
|
||||
set_idling(disp, loc);
|
||||
}
|
||||
|
||||
|
@ -1665,8 +1664,7 @@ void unit::set_standing(const display &disp,const gamemap::location& loc, bool w
|
|||
anim_ = new standing_animation(stand_animation(disp,loc));
|
||||
anim_->start_animation(anim_->get_begin_time(),true,disp.turbo_speed());
|
||||
frame_begin_time = anim_->get_begin_time() -1;
|
||||
next_idling= SDL_GetTicks() +10000;
|
||||
//next_idling= SDL_GetTicks() +10000 +rand()%10000;
|
||||
next_idling= get_current_animation_tick() +10000 +rand()%10000;
|
||||
}
|
||||
void unit::set_defending(const display &disp,const gamemap::location& loc, int damage,const attack_type* attack,const attack_type* secondary_attack,int swing_num)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue