Quando tu jogava num computador decente o sistema de rate para computadores ruins...
[Projeto-PCG.git] / timer.cpp
blob55cfc20971066bce2091e53c6f2a1a25ea56540a
1 #include "timer.h"
2 #include "SDL/SDL.h"
3 #include "SDL/SDL_opengl.h"
6 Timer::Timer()
8 //Initialize the variables
9 startTicks = 0;
10 pausedTicks = 0;
11 paused = false;
12 started = false;
15 void Timer::start()
17 //Start the timer
18 started = true;
20 //Unpause the timer
21 paused = false;
23 //Get the current clock time
24 startTicks = SDL_GetTicks();
27 void Timer::stop()
29 //Stop the timer
30 started = false;
32 //Unpause the timer
33 paused = false;
36 void Timer::pause()
38 //If the timer is running and isn't already paused
39 if( ( started == true ) && ( paused == false ) )
41 //Pause the timer
42 paused = true;
44 //Calculate the paused ticks
45 pausedTicks = SDL_GetTicks() - startTicks;
49 void Timer::unpause()
51 //If the timer is paused
52 if( paused == true )
54 //Unpause the timer
55 paused = false;
57 //Reset the starting ticks
58 startTicks = SDL_GetTicks() - pausedTicks;
60 //Reset the paused ticks
61 pausedTicks = 0;
65 int Timer::get_ticks()
67 //If the timer is running
68 if( started == true )
70 //If the timer is paused
71 if( paused == true )
73 //Return the number of ticks when the timer was paused
74 return pausedTicks;
76 else
78 //Return the current time minus the start time
79 return SDL_GetTicks() - startTicks;
83 //If the timer isn't running
84 return 0;
87 bool Timer::is_started()
89 return started;
92 bool Timer::is_paused()
94 return paused;