-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
47 lines (39 loc) · 787 Bytes
/
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
#include "Timer.h"
#include "KeyListener.h"
#include <Windows.h>
Timer* Timer::_instance = nullptr;
Timer* Timer::Instance()
{
if (!_instance) {
_instance = new Timer();
}
return _instance;
}
void Timer::callUpdateFunc(){
if (updateFunc) {
clock_t now = clock();
updateFunc(now - _lastCallTime);
_lastCallTime = now;
}
}
void Timer::loop(){
size_t loopn = 0;
while (true) {
loopn += 1;
if (loopn >= fractional) {
loopn = 0;
callUpdateFunc();
}
else {
KeyListener::Instance()->getLuminance();
}
Sleep(sleepTime);
}
}
Timer::Timer() {
updateFunc = nullptr;
sleepTime = 100;
_lastCallTime = clock();
}
Timer::~Timer() {
}