-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimer.cpp
112 lines (88 loc) · 1.78 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "stdafx.h"
float Timer::TotalTime() const
{
if (mbStopped)
{
return static_cast<float>(((mllStopTime - mllPausedTime) - mllBaseTime) * mdSecondsPerCount);
}
else
{
return static_cast<float>(((mllCurrTime - mllPausedTime) - mllBaseTime)*mdSecondsPerCount);
}
}
float Timer::DeltaTime() const
{
return static_cast<float>(mdDeltaTime * mfScale);
}
void Timer::Start()
{
long long currTime;
// 현재 하드웨어의 시간
QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
mllBaseTime = currTime;
mllPrevTime = currTime;
mllStopTime = 0;
mbStopped = false;
}
void Timer::Resumte()
{
long long startTime;
// 현재 하드웨어의 시간
QueryPerformanceCounter((LARGE_INTEGER*)&startTime);
if (mbStopped)
{
mllPausedTime += startTime - mllStopTime;
mllStopTime = mllCurrTime;
mllStopTime = 0;
mbStopped = false;
}
}
void Timer::Stop()
{
if (!mbStopped)
{
long long currTime;
// 현재 하드웨어의 시간
QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
mllStopTime = currTime;
mbStopped = true;
}
}
void Timer::Update()
{
if (mbStopped)
{
mdDeltaTime = 0;
return ;
}
else
{
__int64 currTime;
// 현재 하드웨어의 시간
QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
mllCurrTime = currTime;
mdDeltaTime = (mllCurrTime - mllPrevTime) * mdSecondsPerCount;
mllPrevTime = mllCurrTime;
if (mdDeltaTime < 0.0)
{
mdDeltaTime = 0.0;
}
}
}
Timer::Timer() : mdSecondsPerCount(0.0f),
mdDeltaTime(-1.0f),
mfScale(1.0f),
mllBaseTime(0),
mllPausedTime(0),
mllStopTime(0),
mllPrevTime(0),
mllCurrTime(0)
{
long long countsPerSec;
// 현재 하드웨어의 싸이클(주파수, 초당반복횟수)
QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
mdSecondsPerCount = 1.0 / (double)countsPerSec;
}
Timer::~Timer()
{
}