-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfpsCtrl.cpp
43 lines (37 loc) · 1.07 KB
/
fpsCtrl.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
//////////////////////////////////////////////////
// FPS コントローラー
// 作成:kanaaa224
//////////////////////////////////////////////////
#include "fpsCtrl.h"
int FPSCtrl::frameTime = 0;
int FPSCtrl::waitTime = 0;
int FPSCtrl::lastTime = 0;
int FPSCtrl::nowTime = 0;
int FPSCtrl::updateTime = 0;
int FPSCtrl::lastUpdate = 0;
float FPSCtrl::count = 0.0f;
float FPSCtrl::fps = 0.0f;
void FPSCtrl::SetLimitRate(float refreshRate) {
frameTime = (int)(1000.0f / refreshRate); // 1フレームの時間の計算
};
void FPSCtrl::SetUpdateInterval(int updateInterval) {
updateTime = updateInterval;
};
void FPSCtrl::Limit() {
nowTime = GetNowCount();
waitTime = frameTime - (nowTime - lastTime);
if (waitTime > 0) WaitTimer(waitTime);
lastTime = GetNowCount();
};
void FPSCtrl::Update() {
int time = GetNowCount();
count += 1.0f;
if (updateTime < (time - lastUpdate)) {
fps = count / (float)(time - lastUpdate) * 1000.0f;
lastUpdate = time;
count = 0.0f;
};
};
float FPSCtrl::Get() {
return fps;
};