2
2
3
3
ofFpsCounter::ofFpsCounter ()
4
4
:nFrameCount(0 )
5
- ,then(ofGetCurrentTime ())
5
+ ,then(steady_clock::now ())
6
6
,fps(0 )
7
7
,lastFrameTime(0 )
8
8
,filteredTime(0 )
@@ -12,40 +12,43 @@ ofFpsCounter::ofFpsCounter()
12
12
13
13
ofFpsCounter::ofFpsCounter (double targetFPS)
14
14
:nFrameCount(0 )
15
- ,then(ofGetCurrentTime ())
15
+ ,then(steady_clock::now ())
16
16
,fps(targetFPS)
17
17
,lastFrameTime(0 )
18
18
,filteredTime(0 )
19
19
,filterAlpha(0.9 ){}
20
20
21
21
void ofFpsCounter::newFrame (){
22
- auto now = ofGetCurrentTime ();
23
- update (now.getAsSeconds ());
24
- timestamps.push (now.getAsSeconds ());
22
+ now = steady_clock::now ();
23
+
24
+ // auto now = ofGetCurrentTime();
25
+ update (now);
26
+ timestamps.push (now);
25
27
26
28
lastFrameTime = now - then;
27
- uint64_t filtered = filteredTime.count () * filterAlpha + lastFrameTime.count () * (1 -filterAlpha);
28
- filteredTime = std::chrono::nanoseconds (filtered);
29
+ // auto filtered =
30
+ // filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha);
31
+ // filteredTime = filteredTime * filterAlpha + lastFrameTime * (1-filterAlpha);
29
32
then = now;
30
33
nFrameCount++;
31
34
}
32
35
33
36
void ofFpsCounter::update (){
34
- auto now = ofGetCurrentTime ();
35
- update (now. getAsSeconds () );
37
+ now = steady_clock::now ();
38
+ update (now);
36
39
}
37
40
38
- void ofFpsCounter::update (double now){
39
- while (!timestamps.empty () && timestamps.front () + 2 < now){
41
+ void ofFpsCounter::update (time_point<steady_clock> now){
42
+ while (!timestamps.empty () && timestamps.front () + 2s < now){
40
43
timestamps.pop ();
41
44
}
42
45
43
- auto diff = 0.0 ;
44
- if (!timestamps.empty () && timestamps.front () + 0.5 < now){
46
+ space diff;
47
+ if (!timestamps.empty () && timestamps.front () + 0 .5s < now){
45
48
diff = now - timestamps.front ();
46
49
}
47
- if (diff> 0.0 ){
48
- fps = timestamps.size () / diff;
50
+ if (diff > 0 .0s ){
51
+ fps = ( double ) timestamps.size () / std::chrono::duration< double >( diff). count () ;
49
52
}else {
50
53
fps = timestamps.size ();
51
54
}
0 commit comments