-
Notifications
You must be signed in to change notification settings - Fork 0
/
timerclass.cpp
55 lines (37 loc) · 864 Bytes
/
timerclass.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
#include "timerclass.h"
TimerClass::TimerClass()
{
}
TimerClass::TimerClass(const TimerClass& other)
{
}
TimerClass::~TimerClass()
{
}
bool TimerClass::Initialize()
{
// Check to see if this system supports high performance timers.
QueryPerformanceFrequency((LARGE_INTEGER*)&m_frequency);
if (m_frequency == 0)
{
return false;
}
// Find out how many times the frequency counter ticks every millisecond.
m_ticksPerMs = (float)(m_frequency / 1000);
QueryPerformanceCounter((LARGE_INTEGER*)&m_startTime);
return true;
}
void TimerClass::Frame()
{
INT64 currentTime;
float timeDifference;
QueryPerformanceCounter((LARGE_INTEGER*)& currentTime);
timeDifference = (float)(currentTime - m_startTime);
m_frameTime = timeDifference / m_ticksPerMs;
m_startTime = currentTime;
return;
}
float TimerClass::GetTime()
{
return m_frameTime;
}