-
Notifications
You must be signed in to change notification settings - Fork 0
/
HRTimer.cpp
69 lines (62 loc) · 2.09 KB
/
HRTimer.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
//-----------------------------------------------------------------
#include "global.h"
//#include "HRTimer.h"
//-----------------------------------------------------------------
///*****************************************************************
//GAME - THREAD - CONSTRUCTORS
///*****************************************************************
HRTimer::HRTimer(void)
{
//-------------------------------------------------------------
HRT_TargetTime = 1.0 / 60.0; //60 updates a second
HRT_DeltaTime = 0.0;
HRT_CurrentTime = 0.0;
HRT_NewTime = 0.0;
HRT_Offset = 0.0;
HRT_Accumulator = 0.0;
iFrequency = { };
counter = { };
//-------------------------------------------------------------
}
HRTimer::~HRTimer(void)
{
//-------------------------------------------------------------
//-------------------------------------------------------------
}
//*****************************************************************
//Init
//*****************************************************************
void HRTimer::Init(void)
{
//initialize the counter
QueryPerformanceFrequency(&iFrequency);
double frequency = 1.0 / iFrequency.QuadPart;
// get the current time
QueryPerformanceCounter(&counter);
HRT_NewTime = counter.QuadPart * frequency;
HRT_CurrentTime = HRT_NewTime;
}
//*****************************************************************
//HRTimer
//*****************************************************************
void HRTimer::Update(void)
{
//initialize the counter
QueryPerformanceFrequency(&iFrequency);
double frequency = 1.0 / iFrequency.QuadPart;
// get the current time
QueryPerformanceCounter(&counter);
HRT_NewTime = counter.QuadPart * frequency;
HRT_DeltaTime = HRT_NewTime - HRT_CurrentTime;
HRT_CurrentTime = HRT_NewTime;
///Update Accumulator
HRT_Accumulator += HRT_DeltaTime;
if (HRT_Accumulator >= 1.0)
HRT_Accumulator -= 1.0;
//Grab the offset for: Delta time vs User update time
HRT_Offset = HRT_DeltaTime - updateTimerSpeed;
if (abs(HRT_Offset) >= updateTimerSpeed)
HRT_Offset = 0.0;
//Grab our Delta multiplier (for use in tendto etc)
gET_Multi = HRT_DeltaTime * 60.0;
}