-
Notifications
You must be signed in to change notification settings - Fork 1
/
Timer.hpp
96 lines (72 loc) · 2.4 KB
/
Timer.hpp
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
94
95
96
// ========================================================================= //
// Fighting game framework (2D) with online multiplayer.
// Copyright(C) 2014 Jordan Sparks <[email protected]>
//
// This program is free software; you can redistribute it and / or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or(at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// ========================================================================= //
// File: Timer.hpp
// Author: Jordan Sparks <[email protected]>
// ================================================ //
// Defines Timer class.
// ================================================ //
#ifndef __TIMER_HPP__
#define __TIMER_HPP__
// ================================================ //
// A timer that starts from zero. Uses milliseconds.
class Timer
{
public:
// Empty constructor.
explicit Timer(void);
// Empty destructor.
~Timer(void);
// Starts the timer, erasing any previous time.
Uint32 restart(void);
// Stops the timer.
void stop(void);
// Pauses the timer.
void pause(void);
// Unpauses the timer.
void unpause(void);
// Get the time in milliseconds since the timer was started.
Uint32 getTicks(void);
// Getters
// Returns true if the timer is active.
bool isStarted(void) const;
// Returns true if the timer is paused.
bool isPaused(void) const;
// Setters
// Manually set the start ticks value (determined by SDL_GetTicks() when started).
void setStartTicks(const int ticks);
private:
Uint32 m_startTicks;
Uint32 m_pausedTicks;
bool m_paused;
bool m_started;
};
// ================================================ //
// Getters
inline bool Timer::isStarted(void) const{
return m_started;
}
inline bool Timer::isPaused(void) const{
return m_paused;
}
// Setters
inline void Timer::setStartTicks(const int ticks){
m_startTicks = ticks;
}
// ================================================ //
#endif
// ================================================ //