Skip to content

Commit aa9b98f

Browse files
committed
95% done
1 parent 5f463a4 commit aa9b98f

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

libs/openFrameworks/utils/ofFpsCounter.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@
22

33
ofFpsCounter::ofFpsCounter()
44
:nFrameCount(0)
5+
,now(steady_clock::now())
56
,then(steady_clock::now())
67
,fps(0)
7-
,lastFrameTime(0)
8-
,filteredTime(0)
8+
,lastFrameTime()
9+
,filteredTime()
910
,filterAlpha(0.9){}
1011

1112

1213

1314
ofFpsCounter::ofFpsCounter(double targetFPS)
1415
:nFrameCount(0)
16+
,now(steady_clock::now())
1517
,then(steady_clock::now())
1618
,fps(targetFPS)
17-
,lastFrameTime(0)
18-
,filteredTime(0)
19+
,lastFrameTime()
20+
,filteredTime()
1921
,filterAlpha(0.9){}
2022

2123
void ofFpsCounter::newFrame(){
2224
now = steady_clock::now();
23-
24-
// auto now = ofGetCurrentTime();
2525
update(now);
2626
timestamps.push(now);
27-
2827
lastFrameTime = now - then;
29-
// auto filtered =
30-
// filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha);
28+
29+
filteredTime = std::ratio<9, 10>(lastFrameTime);
3130
// filteredTime = filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha);
3231
then = now;
3332
nFrameCount++;
@@ -63,19 +62,19 @@ uint64_t ofFpsCounter::getNumFrames() const{
6362
}
6463

6564
uint64_t ofFpsCounter::getLastFrameNanos() const{
66-
return lastFrameTime.count();
65+
return duration_cast<nanoseconds>(lastFrameTime).count();
6766
}
6867

6968
double ofFpsCounter::getLastFrameSecs() const{
70-
return std::chrono::duration<double>(lastFrameTime).count();
69+
return duration_cast<seconds>(lastFrameTime).count();
7170
}
7271

7372
uint64_t ofFpsCounter::getLastFrameFilteredNanos() const{
74-
return lastFrameTime.count();
73+
return duration_cast<nanoseconds>(lastFrameTime).count();
7574
}
7675

7776
double ofFpsCounter::getLastFrameFilteredSecs() const{
78-
return std::chrono::duration<double>(filteredTime).count();
77+
return duration_cast<seconds>(filteredTime).count();
7978
}
8079

8180
void ofFpsCounter::setFilterAlpha(float alpha){

libs/openFrameworks/utils/ofFpsCounter.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ class ofFpsCounter {
3939
void update(time_point<steady_clock> now);
4040
uint64_t nFrameCount;
4141
// ofTime then;
42-
43-
time_point<steady_clock> now;
44-
time_point<steady_clock> then;
4542
double fps;
43+
4644

4745
using space = std::chrono::duration<long long, std::nano>;
46+
// space lastFrameTime;
47+
// space filteredTime;
48+
49+
time_point<steady_clock> now;
50+
time_point<steady_clock> then = steady_clock::now();
4851
space lastFrameTime;
4952
space filteredTime;
5053
double filterAlpha;

0 commit comments

Comments
 (0)