using namespace SuperTux;
-unsigned int SuperTux::st_pause_ticks, SuperTux::st_pause_count;
+unsigned int Ticks::pause_ticks, Ticks::pause_count;
-unsigned int SuperTux::st_get_ticks(void)
+unsigned int Ticks::get(void)
{
- if(st_pause_count != 0)
- return /*SDL_GetTicks()*/ - st_pause_ticks /*- SDL_GetTicks()*/ + st_pause_count;
+ if(pause_count != 0)
+ return /*SDL_GetTicks()*/ - pause_ticks /*- SDL_GetTicks()*/ + pause_count;
else
- return SDL_GetTicks() - st_pause_ticks;
+ return SDL_GetTicks() - pause_ticks;
}
-void SuperTux::st_pause_ticks_init(void)
+void Ticks::pause_init(void)
{
- st_pause_ticks = 0;
- st_pause_count = 0;
+ pause_ticks = 0;
+ pause_count = 0;
}
-void SuperTux::st_pause_ticks_start(void)
+void Ticks::pause_start(void)
{
- if(st_pause_count == 0)
- st_pause_count = SDL_GetTicks();
+ if(pause_count == 0)
+ pause_count = SDL_GetTicks();
}
-void SuperTux::st_pause_ticks_stop(void)
+void Ticks::pause_stop(void)
{
-if(st_pause_count == 0)
+if(pause_count == 0)
return;
- st_pause_ticks += SDL_GetTicks() - st_pause_count;
- st_pause_count = 0;
+ pause_ticks += SDL_GetTicks() - pause_count;
+ pause_count = 0;
}
-bool SuperTux::st_pause_ticks_started(void)
+bool Ticks::pause_started(void)
{
-if(st_pause_count == 0)
+if(pause_count == 0)
return false;
else
return true;
}
void
-Timer::init(bool st_ticks)
+Timer::init(bool game_ticks)
{
period = 0;
time = 0;
- get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks;
+ get_ticks = game_ticks ? Ticks::get : SDL_GetTicks;
}
void
void
Timer::stop()
{
- if(get_ticks == st_get_ticks)
+ if(get_ticks == get_ticks)
init(true);
else
init(false);
::fwrite(&period,sizeof(unsigned int),1,fi);
::fwrite(&diff_ticks,sizeof(unsigned int),1,fi);
- if(get_ticks == st_get_ticks)
+ if(get_ticks == get_ticks)
tick_mode = true;
else
tick_mode = false;
::fread(&tick_mode,sizeof(unsigned int),1,fi);
if (tick_mode)
- get_ticks = st_get_ticks;
+ get_ticks = get_ticks;
else
get_ticks = SDL_GetTicks;
namespace SuperTux
{
- extern unsigned int st_pause_ticks, st_pause_count;
+ class Ticks
+ {
+ public:
+ /// Time a game is running. (Non-pause mode, etc.)
+ static unsigned int get(void);
- /// Time a game is running. (Non-pause mode, etc.)
- unsigned int st_get_ticks(void);
+ static void pause_init(void);
+ static void pause_start(void);
+ static void pause_stop(void);
+ static bool pause_started(void);
- void st_pause_ticks_init(void);
- void st_pause_ticks_start(void);
- void st_pause_ticks_stop(void);
- bool st_pause_ticks_started(void);
+ private:
+ static unsigned int pause_ticks;
+ static unsigned int pause_count;
+
+ };
/// Timer
/** This class can be used as stop watch
for example. It's also possible to calculate
frames per seconds and things like that with it.
It's a general timing class, but it
- can esspecially be used together with st_get_ticks(). */
+ can esspecially be used together with Ticks::get(). */
class Timer
{
public:
Timer();
/// Initialize the timer.
- /** @param st_ticks: If true internally st_get_ticks() is used, else SDL_GetTicks() is used. */
- void init(bool st_ticks);
+ /** @param st_ticks: If true internally Ticks::get() is used, else SDL_GetTicks() is used. */
+ void init(bool game_ticks);
/// Start the timer with the given period (in ms).
void start(unsigned int period);
GameSession::start_timers()
{
time_left.start(level->time_left*1000);
- st_pause_ticks_init();
- update_time = st_get_ticks();
+ Ticks::pause_init();
+ update_time = Ticks::get();
}
void
tux.key_event((SDLKey)keymap.fire, UP);
Menu::set_current(game_menu);
- st_pause_ticks_start();
+ Ticks::pause_start();
}
}
{
Menu::current()->event(event);
if(!Menu::current())
- st_pause_ticks_stop();
+ Ticks::pause_stop();
}
switch(event.type)
else // normal mode
{
if(!Menu::current() && !game_pause)
- st_pause_ticks_stop();
+ Ticks::pause_stop();
SDL_Event event;
while (SDL_PollEvent(&event))
{
Menu::current()->event(event);
if(!Menu::current())
- st_pause_ticks_stop();
+ Ticks::pause_stop();
}
else
{
if(game_pause)
{
game_pause = false;
- st_pause_ticks_stop();
+ Ticks::pause_stop();
}
else
{
game_pause = true;
- st_pause_ticks_start();
+ Ticks::pause_start();
}
}
break;
switch (game_menu->check())
{
case MNID_CONTINUE:
- st_pause_ticks_stop();
+ Ticks::pause_stop();
break;
case MNID_ABORTLEVEL:
- st_pause_ticks_stop();
+ Ticks::pause_stop();
exit_status = ES_LEVEL_ABORT;
break;
}
int fps_cnt = 0;
- update_time = last_update_time = st_get_ticks();
+ update_time = last_update_time = Ticks::get();
// Eat unneeded events
SDL_Event event;
/* Set the time of the last update and the time of the current update */
last_update_time = update_time;
- update_time = st_get_ticks();
+ update_time = Ticks::get();
/* Pause till next frame, if the machine running the game is too fast: */
/* FIXME: Works great for in OpenGl mode, where the CPU doesn't have to do that much. But
if(last_update_time >= update_time - 12)
{
SDL_Delay(10);
- update_time = st_get_ticks();
+ update_time = Ticks::get();
}
/* Handle time: */
Menu::set_current(main_menu);
- st_pause_ticks_stop();
+ Ticks::pause_stop();
return true;
}
else
walking = true;
- st_pause_ticks_init();
+ Ticks::pause_init();
titlesession = new GameSession(datadir + "/levels/misc/menu.stl", ST_GL_DEMO_GAME);
/* --- Main title loop: --- */
frame = 0;
- update_time = st_get_ticks();
+ update_time = Ticks::get();
random_timer.start(rand() % 2000 + 2000);
Menu::set_current(main_menu);
{
// if we spent to much time on a menu entry
if( (update_time - last_update_time) > 1000)
- update_time = last_update_time = st_get_ticks();
+ update_time = last_update_time = Ticks::get();
// Calculate the movement-factor
double frame_ratio = ((double)(update_time-last_update_time))/((double)FRAME_RATE);
leveleditor->run();
delete leveleditor;
Menu::set_current(main_menu);
- update_time = st_get_ticks();
+ update_time = Ticks::get();
break;
case MNID_CREDITS:
display_text_file("CREDITS", SCROLL_SPEED_CREDITS, white_big_text , white_text, white_small_text, blue_text );
update_load_save_game_menu(load_game_menu);
Menu::set_current(main_menu);
- update_time = st_get_ticks();
+ update_time = Ticks::get();
}
else if (process_load_game_menu())
{
titlesession->get_current_sector()->activate();
titlesession->set_current();
//titletux.level_begin();
- update_time = st_get_ticks();
+ update_time = Ticks::get();
}
}
else if(menu == contrib_menu)
/* Set the time of the last update and the time of the current update */
last_update_time = update_time;
- update_time = st_get_ticks();
+ update_time = Ticks::get();
/* Pause: */
frame++;
unsigned int last_update_time;
unsigned int update_time;
- last_update_time = update_time = st_get_ticks();
+ last_update_time = update_time = Ticks::get();
DrawingContext context;
while(!quit)
delta = .3f;
last_update_time = update_time;
- update_time = st_get_ticks();
+ update_time = Ticks::get();
Vector tux_pos = tux->get_pos();
if (1)