|
2 | 2 |
|
3 | 3 | ofFpsCounter::ofFpsCounter()
|
4 | 4 | :nFrameCount(0)
|
| 5 | +,now(steady_clock::now()) |
5 | 6 | ,then(steady_clock::now())
|
6 | 7 | ,fps(0)
|
7 |
| -,lastFrameTime(0) |
8 |
| -,filteredTime(0) |
| 8 | +,lastFrameTime() |
| 9 | +,filteredTime() |
9 | 10 | ,filterAlpha(0.9){}
|
10 | 11 |
|
11 | 12 |
|
12 | 13 |
|
13 | 14 | ofFpsCounter::ofFpsCounter(double targetFPS)
|
14 | 15 | :nFrameCount(0)
|
| 16 | +,now(steady_clock::now()) |
15 | 17 | ,then(steady_clock::now())
|
16 | 18 | ,fps(targetFPS)
|
17 |
| -,lastFrameTime(0) |
18 |
| -,filteredTime(0) |
| 19 | +,lastFrameTime() |
| 20 | +,filteredTime() |
19 | 21 | ,filterAlpha(0.9){}
|
20 | 22 |
|
21 | 23 | void ofFpsCounter::newFrame(){
|
22 | 24 | now = steady_clock::now();
|
23 |
| - |
24 |
| -// auto now = ofGetCurrentTime(); |
25 | 25 | update(now);
|
26 | 26 | timestamps.push(now);
|
27 |
| - |
28 | 27 | lastFrameTime = now - then;
|
29 |
| -// auto filtered = |
30 |
| -// filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha); |
| 28 | + |
| 29 | + filteredTime = std::ratio<9, 10>(lastFrameTime); |
31 | 30 | // filteredTime = filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha);
|
32 | 31 | then = now;
|
33 | 32 | nFrameCount++;
|
@@ -63,19 +62,19 @@ uint64_t ofFpsCounter::getNumFrames() const{
|
63 | 62 | }
|
64 | 63 |
|
65 | 64 | uint64_t ofFpsCounter::getLastFrameNanos() const{
|
66 |
| - return lastFrameTime.count(); |
| 65 | + return duration_cast<nanoseconds>(lastFrameTime).count(); |
67 | 66 | }
|
68 | 67 |
|
69 | 68 | double ofFpsCounter::getLastFrameSecs() const{
|
70 |
| - return std::chrono::duration<double>(lastFrameTime).count(); |
| 69 | + return duration_cast<seconds>(lastFrameTime).count(); |
71 | 70 | }
|
72 | 71 |
|
73 | 72 | uint64_t ofFpsCounter::getLastFrameFilteredNanos() const{
|
74 |
| - return lastFrameTime.count(); |
| 73 | + return duration_cast<nanoseconds>(lastFrameTime).count(); |
75 | 74 | }
|
76 | 75 |
|
77 | 76 | double ofFpsCounter::getLastFrameFilteredSecs() const{
|
78 |
| - return std::chrono::duration<double>(filteredTime).count(); |
| 77 | + return duration_cast<seconds>(filteredTime).count(); |
79 | 78 | }
|
80 | 79 |
|
81 | 80 | void ofFpsCounter::setFilterAlpha(float alpha){
|
|
0 commit comments