-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
71 lines (61 loc) · 1.12 KB
/
Timer.cpp
File metadata and controls
71 lines (61 loc) · 1.12 KB
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
#include "Timer.h"
void Timer::Init()
{
isHardware = false;
timeScale = 0.0f;
timeElapsed = 0.0f;
currTime = 0;
lastTime = 0;
periodFrequency = 0;
fpsTimeElapsed = 0.0f;
fpsFrameCount = 0;
FPS = 0;
isHardware = QueryPerformanceFrequency((LARGE_INTEGER*)&periodFrequency); //초당 진동수를 periodFrequency에 저장
if (isHardware)
{
QueryPerformanceCounter((LARGE_INTEGER*)&lastTime); //
timeScale = 1.0f / periodFrequency;
}
else
{
lastTime = timeGetTime();
timeScale = 0.0f;
}
}
void Timer::Release()
{
}
void Timer::Tick() //update 느낌
{
if (isHardware)
{
QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
}
else
{
currTime = timeGetTime();
}
timeElapsed = (currTime - lastTime) * timeScale; //업데이트 될 때까지 걸리는 시간 0.01초
fpsTimeElapsed += timeElapsed;
fpsFrameCount++;
if(fpsTimeElapsed>=1.0f)
{
FPS = fpsFrameCount;
fpsFrameCount = 0;
fpsTimeElapsed = 0;
}
lastTime = currTime;
}
float Timer::GetCurrTime()
{
__int64 time;
if (isHardware)
{
QueryPerformanceCounter((LARGE_INTEGER*)&currTime);
}
else
{
time = timeGetTime();
}
return time * timeScale;
}