forked from G-A-I-N/gainlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timer.cpp
84 lines (76 loc) · 1.37 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
/*
* Timer.cpp
*
* Created on: 11 Dec 2014
* Author: Ville
*/
#include "Timer.h"
#include "Logger.h"
namespace Gain {
Timer::Timer():
super(),
pTimerOriginal(),
pTimerLeft(0),
pRunning(0),
pRunningCount(0)
{
//add to current scene, and its graphical time
CORE->addRenderClient(this, 0);
}
Timer::~Timer() {
// TODO Auto-generated destructor stub
}
void Timer::setIntervalCount(float interval, unsigned int count, bool autoStart)
{
LOGI("%s %f %u", __FUNCTION__, interval, count);
pTimerOriginal = interval;
pRunningCount = count;
if(autoStart)
{
LOGSCOPE;
start();
}
}
void Timer::setOneShot(float time, bool autoStart)
{
setIntervalCount(time, 1, autoStart);
}
void Timer::setInterval(float interval, bool autoStart)
{
setIntervalCount(interval, 0xffffffff, autoStart);
}
void Timer::start()
{
pRunning = 1;
pTimerLeft = pTimerOriginal;
}
void Timer::stop()
{
pRunning = 0;
}
void Timer::updateG(float /*time*/, float deltaTime)
{
if(pRunning >0 && pRunningCount>0)
{
pTimerLeft-=deltaTime;
if(pTimerLeft <= 0)
{
triggerEvent(EVENT_TIMER);
pRunningCount--;
if(pRunningCount>0)
{
pTimerLeft += pTimerOriginal;
}
}
}
}
bool Timer::setupGraphics()
{
setReady();
return true;
}
bool Timer::initVariables()
{
return true;
}
} /* namespace Gain */