From: Ingo Ruhnke Date: Sun, 11 Apr 2004 16:33:11 +0000 (+0000) Subject: started to convert timer into a class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2c78a029e3c7915c34011ac12f2ad07d5a46e0df;p=supertux.git started to convert timer into a class SVN-Revision: 480 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index e99cee020..80cd1d6a1 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -609,7 +609,7 @@ GameSession::run() if (time_left.check()) { /* are we low on time ? */ - if ((timer_get_left(&time_left) < TIME_WARNING) + if (time_left.get_left() < TIME_WARNING && (get_current_music() != HURRYUP_MUSIC)) /* play the fast music */ { set_current_music(HURRYUP_MUSIC); @@ -624,7 +624,7 @@ GameSession::run() if(show_fps) { ++fps_cnt; - fps_fps = (1000.0 / (float)timer_get_gone(&fps_timer)) * (float)fps_cnt; + fps_fps = (1000.0 / (float)fps_timer.get_gone()) * (float)fps_cnt; if(!fps_timer.check()) { @@ -677,9 +677,9 @@ GameSession::drawstatus() text_draw(&white_text,"Press ESC To Return",0,20,1); } - if (timer_get_left(&time_left) > TIME_WARNING || (global_frame_counter % 10) < 5) + if (time_left.get_left() > TIME_WARNING || (global_frame_counter % 10) < 5) { - sprintf(str, "%d", timer_get_left(&time_left) / 1000 ); + sprintf(str, "%d", time_left.get_left() / 1000 ); text_draw(&white_text, "TIME", 224, 0, 1); text_draw(&gold_text, str, 304, 0, 1); } diff --git a/src/intro.cpp b/src/intro.cpp index 66fb3dbdc..1dfa485fb 100644 --- a/src/intro.cpp +++ b/src/intro.cpp @@ -108,7 +108,7 @@ int intro(void) /* Draw things: */ - if (timer_get_gone(&timer) < 2000 && scene == 0) + if (timer.get_gone() < 2000 && scene == 0) { ++scene; /* Gown and tux sitting: */ @@ -120,7 +120,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 2000 && scene == 1) + if (timer.get_gone() >= 2000 && scene == 1) { ++scene; /* Helicopter begins to fly in: */ @@ -130,19 +130,19 @@ int intro(void) } - if (timer_get_gone(&timer) >= 2000 && timer_get_gone(&timer) < 4000) + if (timer.get_gone() >= 2000 && timer.get_gone() < 4000) { /* Helicopter flying in: */ texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); texture_draw(&copter[i % 2], - (float)(timer_get_gone(&timer) - 2000) / 5 - (copter[0].w), 32); + (float)(timer.get_gone() - 2000) / 5 - (copter[0].w), 32); update_rect(screen, 0, 32, screen->w, (copter[0].h)); } - if (timer_get_gone(&timer) >= 2500 && scene == 2) + if (timer.get_gone() >= 2500 && scene == 2) { ++scene; /* Gown notices something... */ @@ -151,7 +151,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 3500 && scene == 3) + if (timer.get_gone() >= 3500 && scene == 3) { ++scene; /* Gown realizes it's bad! */ @@ -160,7 +160,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 4000 && timer_get_gone(&timer) < 8000) + if (timer.get_gone() >= 4000 && timer.get_gone() < 8000) { /* Helicopter sits: */ texture_draw_part(&bkgd,0,32, 0, 32, screen->w, (copter[0].h)); @@ -170,7 +170,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 5000 && scene == 4) + if (timer.get_gone() >= 5000 && scene == 4) { ++scene; /* Tux realizes something's happening: */ @@ -183,7 +183,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 5000 && timer_get_gone(&timer) <= 8000) + if (timer.get_gone() >= 5000 && timer.get_gone() <= 8000) { /* Beam gown up! */ @@ -210,7 +210,7 @@ int intro(void) texture_draw_part(&gown_upset,src.x,src.y,dest.x,dest.y,dest.w,dest.h); - height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer_get_gone(&timer) - 5000)/(float)3000.)); + height[j] = 400 + rand() % 10 - (int)(300. * ((float)(timer.get_gone() - 5000)/(float)3000.)); if(height[j] < 105) height[j] = 105; } @@ -223,7 +223,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 8000 && scene == 5) + if (timer.get_gone() >= 8000 && scene == 5) { texture_draw_part(&bkgd, 310, 32 + (copter[0].h), 310, @@ -241,7 +241,7 @@ int intro(void) } - if (timer_get_gone(&timer) >= 8000 && timer_get_gone(&timer) <= 8250) + if (timer.get_gone() >= 8000 && timer.get_gone() <= 8250) { /* Helicopter starting to speed off: */ @@ -254,14 +254,14 @@ int intro(void) } - if (timer_get_gone(&timer) >= 8250) + if (timer.get_gone() >= 8250) { /* Helicopter speeding off: */ texture_draw_part(&bkgd, 0, 32, 0, 32, screen->w, (copter_stretch.h)); texture_draw(&copter_stretch, - (timer_get_gone(&timer) - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), + (timer.get_gone() - 8250) /*(i - (8250 / FPS)) * 30*/ + 400 - (copter[0].w), 32); update_rect(screen, 0, 32, screen->w, (copter_stretch.h)); diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index a3a741f1f..9fd68a0a9 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -158,7 +158,8 @@ int leveleditor(int levelnb) { if(select_tilegroup_menu_effect.check()) { - select_tilegroup_menu->set_pos(screen->w - 64 + timer_get_left(&select_tilegroup_menu_effect),82,-0.5,0.5); + select_tilegroup_menu->set_pos(screen->w - 64 + select_tilegroup_menu_effect.get_left(), + 82,-0.5,0.5); } else select_tilegroup_menu->set_pos(screen->w - 64,82,-0.5,0.5); diff --git a/src/menu.cpp b/src/menu.cpp index 1f38a924c..f70453ea4 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -332,7 +332,7 @@ Menu::draw_item(int index, // Position of the current item in the menu { int effect_time = 0; if(effect.check()) - effect_time = timer_get_left(&effect) / 4; + effect_time = effect.get_left() / 4; effect_offset = (index % 2) ? effect_time : -effect_time; } diff --git a/src/mousecursor.cpp b/src/mousecursor.cpp index 9814fa84b..f7a5993a4 100644 --- a/src/mousecursor.cpp +++ b/src/mousecursor.cpp @@ -64,7 +64,7 @@ void MouseCursor::draw() cur_state = state_before_click; } - if(timer_get_left(&timer) < 0 && tot_frames > 1) + if(timer.get_left() < 0 && tot_frames > 1) { cur_frame++; if(cur_frame++ >= tot_frames) diff --git a/src/player.cpp b/src/player.cpp index 0af32406b..5c58bddb0 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -263,7 +263,7 @@ Player::action(double frame_ratio) */ // FIXME: Move this to gamesession - if (timer_get_left(&GameSession::current()->time_left) < TIME_WARNING) + if (GameSession::current()->time_left.get_left() < TIME_WARNING) { /* yes, we are in hurry stop the herring_song, prepare to play the correct diff --git a/src/timer.cpp b/src/timer.cpp index 9848f2928..d504fa92e 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -89,51 +89,57 @@ timer_type::started() return false; } -int timer_get_left(timer_type* ptimer) +int +timer_type::get_left() { - return (ptimer->period - (ptimer->get_ticks() - ptimer->time)); + return (period - (get_ticks() - time)); } -int timer_get_gone(timer_type* ptimer) +int +timer_type::get_gone() { - return (ptimer->get_ticks() - ptimer->time); + return (get_ticks() - time); } -void timer_fwrite(timer_type* ptimer, FILE* fi) +void +timer_type::fwrite(FILE* fi) { unsigned int diff_ticks; int tick_mode; - if(ptimer->time != 0) - diff_ticks = ptimer->get_ticks() - ptimer->time; + if(time != 0) + diff_ticks = get_ticks() - time; else diff_ticks = 0; - fwrite(&ptimer->period,sizeof(unsigned int),1,fi); - fwrite(&diff_ticks,sizeof(unsigned int),1,fi); - if(ptimer->get_ticks == st_get_ticks) + ::fwrite(&period,sizeof(unsigned int),1,fi); + ::fwrite(&diff_ticks,sizeof(unsigned int),1,fi); + if(get_ticks == st_get_ticks) tick_mode = true; else tick_mode = false; - fwrite(&tick_mode,sizeof(unsigned int),1,fi); + ::fwrite(&tick_mode,sizeof(unsigned int),1,fi); } -void timer_fread(timer_type* ptimer, FILE* fi) +void +timer_type::fread(FILE* fi) { unsigned int diff_ticks; int tick_mode; - fread(&ptimer->period,sizeof(unsigned int),1,fi); - fread(&diff_ticks,sizeof(unsigned int),1,fi); - fread(&tick_mode,sizeof(unsigned int),1,fi); + + ::fread(&period,sizeof(unsigned int),1,fi); + ::fread(&diff_ticks,sizeof(unsigned int),1,fi); + ::fread(&tick_mode,sizeof(unsigned int),1,fi); if (tick_mode) - ptimer->get_ticks = st_get_ticks; + get_ticks = st_get_ticks; else - ptimer->get_ticks = SDL_GetTicks; + get_ticks = SDL_GetTicks; if (diff_ticks != 0) - ptimer->time = ptimer->get_ticks() - diff_ticks; + time = get_ticks() - diff_ticks; else - ptimer->time = 0; + time = 0; } +/* EOF */ diff --git a/src/timer.h b/src/timer.h index 8c69b3d67..0d03ccb19 100644 --- a/src/timer.h +++ b/src/timer.h @@ -42,18 +42,20 @@ class timer_type ======================================================================*/ int check(); int started(); + + /*====================================================================== + int timer_get_left(timer_type* ptimer); + + param : pointer to a timer that you want to get the time left + return: the time left (in millisecond) + note : the returned value can be negative + ======================================================================*/ + int get_left(); + + int get_gone(); + void fwrite(FILE* fi); + void fread(FILE* fi); }; -/*====================================================================== - int timer_get_left(timer_type* ptimer); - - param : pointer to a timer that you want to get the time left - return: the time left (in millisecond) - note : the returned value can be negative - ======================================================================*/ -int timer_get_left(timer_type* ptimer); -int timer_get_gone(timer_type* ptimer); -void timer_fwrite(timer_type* ptimer, FILE* fi); -void timer_fread(timer_type* ptimer, FILE* fi); #endif /*SUPERTUX_TIMER_H*/ diff --git a/src/title.cpp b/src/title.cpp index 016b13df3..6b86242ea 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -502,7 +502,7 @@ void display_credits() SDL_Delay(35); - if(timer_get_left(&timer) < 0) + if(timer.get_left() < 0) { frame++; timer.start(50);