### Author Topic: query the system's current FPS setting  (Read 9143 times)

0 Members and 1 Guest are viewing this topic.

#### Laurent

• Hero Member
• Posts: 32504
##### Re: query the system's current FPS setting
« Reply #15 on: April 29, 2017, 10:23:17 am »
Quote
tk = k * dt + ek
This formula rather matches a single measurement for the whole k-frames duration, but you said you were cumulating single frame times, which would rather be expressed as:
tk = sum(dt + ek)

And in this case, yes, the error does accumulate. If error is [-E, E] for one frame, then for N frames the error may indeed cancel out if it is uniformly distributed over the range, but in theory you get an error in range [-E.N, E.N] after N frames. And on a computer you may perfectly get one of these extremes, because the error is not actually truly random, but may be the result of a truncation or whatever constant stuff due to a known limitation of the underlying software or hardware (example: your millisecond truncation, which was removing 0.5 seconds at each frame: after N frames you lose 0.5 x N seconds).

A single time measurement will always be more accurate than a sum of multiple smaller measurements.
« Last Edit: April 29, 2017, 10:26:30 am by Laurent »
Laurent Gomila - SFML developer

#### kfj

• Newbie
• Posts: 19
##### Re: query the system's current FPS setting
« Reply #16 on: April 30, 2017, 08:54:38 am »
Quote
tk = k * dt + ek
This formula rather matches a single measurement for the whole k-frames duration, but you said you were cumulating single frame times, which would rather be expressed as:
tk = sum(dt + ek)
Sorry to go on about this, but I did say that I am cumulating the deltas *inside an animated sequence*. My software switches between showing still images and animated sequences, which happens when the user zooms, pans, etc.. So my measurement does indeed look at an average over several k-frame durations. I have a frame counter counter which is reset to zero whenever the system is at rest. When I get to the call to display I look at this counter, and if it's greater than zero, I know the previous frame was already inside the animation sequence and I cumulate the delta. Cumulating single deltas has the advantage that the average is right at hand at every moment, rather than having to bother with recording sequence starting times and counting frames per sequence.

When it comes to cumulating individual independent measurements, you and Hapax are of course totally right about the error cumulating, and the formulta you give is the correct one to use.

Here's the relevant part of the code I'm using:

p_window->display() ;

display_called = std::chrono::system_clock::now() ;
float dt = std::chrono::duration_cast<std::chrono::microseconds>
(display_called - display_last_called).count() ;
dt /= 1000.0 ; // use float milliseconds
display_last_called = display_called ;

if ( frames_in_sequence > 1 )
{
dt_count++ ;
total_ms += dt ;
if ( dt_count > 20 ) // only start using dt_average after having cumulated 20 deltas
dt_average = total_ms / dt_count ;
}

anything