-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimer.cpp
More file actions
75 lines (59 loc) · 1.22 KB
/
Timer.cpp
File metadata and controls
75 lines (59 loc) · 1.22 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
72
73
74
75
#include "stdafx.h"
#include "Timer.h"
#include <mmsystem.h>
//TimeGetTime() 함수를 사용하기 위한 라이브러리
#pragma comment (lib, "winmm.lib")
Timer::Timer()
{
}
Timer::~Timer()
{
}
HRESULT Timer::init()
{
//
if (QueryPerformanceFrequency((LARGE_INTEGER*)&_periodFrequency))
{
QueryPerformanceCounter((LARGE_INTEGER*)&_lastTime);
_timeScale = 1.0f / _periodFrequency;
}
_frameRate = 0;
_FPSframeCount = 0;
_FPSTimeElapsed = 0;
_worldTime = 0.0f;
_timeElapsed = 0.0f;
return S_OK;
}
void Timer::tick(float lockFPS)
{
QueryPerformanceCounter((LARGE_INTEGER*)&_curTime);
//
_timeElapsed = (_curTime - _lastTime) * _timeScale;
if (lockFPS > 0.0f)
{
//보통 이부분을 프레임 스키핑이라고 함
while (_timeElapsed < (1.0f / lockFPS))
{
QueryPerformanceCounter((LARGE_INTEGER*)&_curTime);
_timeElapsed = (_curTime - _lastTime) * _timeScale;
}
}
_lastTime = _curTime;
_FPSframeCount++;
_FPSTimeElapsed += _timeElapsed;
_worldTime += _timeElapsed;
if (_FPSTimeElapsed > 1.0f)
{
_frameRate = _FPSframeCount;
_FPSframeCount = 0;
_FPSTimeElapsed = 0.0f;
}
}
unsigned long Timer::getFrameRate(char* str) const
{
if (str != NULL)
{
wsprintf(str, "FPS : %d", _frameRate);
}
return _frameRate;
}