-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFPSCounter.cpp
More file actions
48 lines (37 loc) · 1.09 KB
/
Copy pathFPSCounter.cpp
File metadata and controls
48 lines (37 loc) · 1.09 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
#include "FPSCounter.h"
using namespace std::chrono;
long double FPSCounter::_deltaTime = 0.0;
FPSCounter::FPSCounter(int samplingFrame)
: _samplingFrame(samplingFrame)
, _countingFrame(0)
, _totalTime(0)
, _avarageFPS(0)
{
}
FPSCounter::~FPSCounter()
{
}
void FPSCounter::Update()
{
//前フレームからここまでの時間をmicro秒で計測
_currentTime = system_clock::now();
auto delta = duration<long double, std::micro>(_currentTime - _beforeTime).count();
_deltaTime = delta / 1000000;
_totalTime += delta;
//計測時間更新
_beforeTime = _currentTime;
//フレームカウント更新
_countingFrame++;
//サンプリング数まで達したら再計算
if (_countingFrame == _samplingFrame)
{
//1フレーム当たりの時間を出して
long double avarageTime = (_totalTime / _samplingFrame);
//μ(マイクロ) = 1.000.000
_avarageFPS = 1000000 / (avarageTime);
//フレームカウンタをリセット
_countingFrame = 0;
_totalTime = 0;
return;
}
}