-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
executable file
·93 lines (78 loc) · 1.86 KB
/
Timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Timer.h"
//Initialises the variables
Timer::Timer()
{
//ctor
}
Timer::~Timer()
{
//dtor
}
/*Check if the timer hasnt already been started
if so do nothing else set the start ticks to the current
ticks and set started to true and paused to false*/
void Timer::start( void )
{
startTicks = SDL_GetTicks();
started = true;
paused = false;
}
//Set startTicks to zero started to false and paused to false
void Timer::stop( void )
{
if( started == true )
{
startTicks = 0;
started = false;
paused = false;
}
}
//check if not paused and if started if so Set paused ticks to the current ticks subtract startTicks then set the started ticks to zero
//paused to true and started to true
void Timer::pause( void )
{
if( (started == true) && (paused == false) )
{
paused = true;
//gets the difference between when the timer started
//and when it got paused so we can "reset" the startTicks to the
//same distance from the current ticks
pausedTicks = SDL_GetTicks() - startTicks;
}
}
//Check the timer has started and is paused set the start ticks to
//current ticks subtract paused ticks set paused to false and pausedTicks to 0
void Timer::unpause( void )
{
if( (started == true) && (paused == true) )
{
paused = false;
startTicks = SDL_GetTicks() - pausedTicks;
pausedTicks = 0;
}
}
Uint32 Timer::getTicks( void )
{
if( started == true )
{
if( paused == true )
{
return pausedTicks;
}
else
{
return SDL_GetTicks() - startTicks;
}
}
return 0;
}
//Check if the timer is paused
bool Timer::isPaused( void )
{
return paused;
}
//Check if the timer has started
bool Timer::isStarted( void )
{
return started;
}