X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=lib%2Fspecial%2Ftimer.h;h=1866a2cc9076f8842d586ff3e96e7a5e6c3788f1;hb=40e6e7cdc59c09befbd2595aea0c6e10428315d4;hp=734c896a07ecc6251a7ab95de0c5f8e8956d1c03;hpb=9c511ea692d3a2339597211f08f18ea74fad35ec;p=supertux.git diff --git a/lib/special/timer.h b/lib/special/timer.h index 734c896a0..1866a2cc9 100644 --- a/lib/special/timer.h +++ b/lib/special/timer.h @@ -21,46 +21,77 @@ #ifndef SUPERTUX_TIMER_H #define SUPERTUX_TIMER_H -extern unsigned int st_pause_ticks, st_pause_count; - -unsigned int st_get_ticks(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); - -class Timer -{ - public: - unsigned int period; - unsigned int time; - unsigned int (*get_ticks) (void); - - public: - Timer(); - - void init(bool st_ticks); - void start(unsigned int period); - void stop(); - - /*====================================================================== - return: NO = the timer is not started - or it is over - YES = otherwise - ======================================================================*/ - int check(); - int started(); - - /*====================================================================== - 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); -}; +#include + +namespace SuperTux + { + + class Ticks + { + public: + /// Time a game is running. (Non-pause mode, etc.) + static unsigned int get(); + + static void pause_init(); + static void pause_start(); + static void pause_stop(); + static bool pause_started(); + + 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 Ticks::get(). */ + class Timer + { + public: + unsigned int period; + unsigned int time; + unsigned int (*get_ticks) (void); + + public: + Timer(); + + /// Initialize the timer. + /** @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); + + /// Stop the timer. + void stop(); + + /// Check if the timer is started and within its period. + /** If one of these requirements isn't the case the timer + is automatically reseted. */ + int check(); + + /// Is the timer started? + int started(); + + /// Get time left until the last timing period is finished. + /** The returned value can be negative. */ + int get_left(); + + /// Get the gone time, since last timer start. + /** The returned value can be negative. */ + int get_gone(); + + /// Write the timer value to a file (For save games in example). + void fwrite(FILE* fi); + /// Read a timer value from a file (From save games in example). + void fread(FILE* fi); + }; + +} //namespace SuperTux #endif /*SUPERTUX_TIMER_H*/