GameKit
0.0.1a
C++ gamedev tools
source
core
Timer.cpp
Go to the documentation of this file.
1
/*
2
* =====================================================================================
3
*
4
* Filename: Timer.cpp
5
*
6
* Description:
7
*
8
* Created: 15/09/2014 19:31:35
9
*
10
* Author: Quentin Bazin, <gnidmoo@gmail.com>
11
*
12
* =====================================================================================
13
*/
14
#include "
gk/core/Timer.hpp
"
15
#include "
gk/core/GameClock.hpp
"
16
17
namespace
gk
{
18
19
Timer::Timer
(
bool
useRealTime) {
20
m_useRealTime
= useRealTime;
21
m_t
=
GameClock::getTicks
(
m_useRealTime
);
22
}
23
24
void
Timer::stop
() {
25
if
(
m_isStarted
) {
26
m_isStarted
=
false
;
27
m_tick
=
GameClock::getTicks
(
m_useRealTime
) -
m_t
;
28
}
29
}
30
31
void
Timer::start
() {
32
if
(!
m_isStarted
) {
33
m_isStarted
=
true
;
34
m_t
=
GameClock::getTicks
(
m_useRealTime
) -
m_tick
;
35
}
36
}
37
38
void
Timer::reset
() {
39
m_isStarted
=
false
;
40
m_t
=
GameClock::getTicks
(
m_useRealTime
);
41
m_tick
= 0;
42
}
43
44
u32
Timer::time
()
const
{
45
if
(
m_isStarted
) {
46
return
GameClock::getTicks
(
m_useRealTime
) -
m_t
;
47
}
else
{
48
return
m_tick
;
49
}
50
}
51
52
void
Timer::setTime
(
u32
time
) {
53
if
(
m_isStarted
) {
54
m_t
=
GameClock::getTicks
(
m_useRealTime
) -
time
;
55
}
else
{
56
m_tick
=
time
;
57
}
58
}
59
60
}
// namespace gk
61
GameClock.hpp
gk::Timer::start
void start()
Start the timer.
Definition:
Timer.cpp:31
gk
Definition:
AudioPlayer.hpp:21
gk::Timer::setTime
void setTime(u32 time)
Set time.
Definition:
Timer.cpp:52
gk::Timer::stop
void stop()
Stop the timer.
Definition:
Timer.cpp:24
gk::Timer::m_t
u32 m_t
Definition:
Timer.hpp:85
gk::Timer::reset
void reset()
Reset the timer.
Definition:
Timer.cpp:38
u32
unsigned int u32
Definition:
IntTypes.hpp:23
gk::Timer::m_useRealTime
bool m_useRealTime
The timer will use system time instead of simulated time if set to true.
Definition:
Timer.hpp:81
gk::Timer::m_isStarted
bool m_isStarted
Is true if the timer is running.
Definition:
Timer.hpp:83
gk::Timer::time
u32 time() const
Get time.
Definition:
Timer.cpp:44
gk::Timer::Timer
Timer(bool useRealTime=false)
Constructor.
Definition:
Timer.cpp:19
gk::GameClock::getTicks
static u32 getTicks(bool realTime=false)
Definition:
GameClock.cpp:21
gk::Timer::m_tick
u32 m_tick
Definition:
Timer.hpp:86
Timer.hpp
Generated by
1.8.12