-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
52 lines (42 loc) · 968 Bytes
/
Copy pathtimer.cpp
File metadata and controls
52 lines (42 loc) · 968 Bytes
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
#include "timer.h"
#include <sstream>
#include <chrono>
#include <thread>
#include <iostream>
using namespace std::chrono;
auto starttime = steady_clock::now();
duration<float> deltatime;
//
int fpsLimit() {
return 30;
}
int stop() {
return 1;
}
using dTime = duration<double>;
auto frameLimit = duration_cast<system_clock::duration>(dTime{ 1. / fpsLimit() });
auto startFrame = system_clock::now();
auto endFrame = startFrame + frameLimit;
auto prevTime = time_point_cast<seconds>(startFrame);
unsigned fps = 0;
//
void ResetTime() {
startFrame = system_clock::now();
};
void StopTime() {
auto frameLimit = duration_cast<system_clock::duration>(dTime{ 1. / stop() });
};
void Tick() {
std::this_thread::sleep_until(endFrame);
startFrame = endFrame;
endFrame = startFrame + frameLimit;
}
unsigned timeCount() {
auto time = time_point_cast<seconds>(system_clock::now());
fps++;
if (time > prevTime) {
fps = 0;
prevTime = time;
}
return(fps);
}