Frederic,
I've been hacking on your patch a bit more and I see that we rarely oversleep by more than 2ms. So backing off by 2ms (instead of 1ms) seems to work pretty well here. I also switched to doing all the math in microseconds rather than milleseconds (and converting at the latest possible moment) in hopes that it would be slighty more accurate.
This is only tested on the 2.6.x kernels. I suspsect that usleep() will be much less accurate on 2.4.x kernels. I don't know if anyone else is using the frame rate throttling feature so it may not matter?
Regards,
Curt.
Frederic Bouvier wrote:
I wrote:
Maybe it is doable to sleep for a millisecond less than computed and achieve
the
targeted framerate with the loop.
Could you try this patch :
cvs -z4 -q diff -u main.cxx (in directory I:\FlightGear\cvs\FlightGear\src\Main\) Index: main.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/FlightGear/src/Main/main.cxx,v retrieving revision 1.194 diff -u -r1.194 main.cxx --- main.cxx 9 Mar 2005 15:12:01 -0000 1.194 +++ main.cxx 9 Mar 2005 16:53:34 -0000 @@ -233,12 +233,11 @@
double throttle_hz = fgGetDouble("/sim/frame-rate-throttle-hz", 0.0); if ( throttle_hz > 0.0 && scenery_loaded ) { - static double remainder = 0.0; - // simple frame rate throttle - double dt = 1000000.0 / throttle_hz + remainder; + double dt = 1000000.0 / throttle_hz; int wait = dt / 1000; - remainder = dt - ( wait * 1000.0 ); + if ( wait > 0 ) + wait -= 1;
current_time_stamp.stamp(); int t_ms = (int) ( ( current_time_stamp - last_time_stamp ) / 1000 ) ; /* Convert to ms */ @@ -246,6 +245,9 @@ ulMilliSecondSleep ( wait - t_ms ) ; } current_time_stamp.stamp(); + while ( current_time_stamp - last_time_stamp < dt ) { + current_time_stamp.stamp(); + } } else { // run as fast as the app will go current_time_stamp.stamp();
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d
-- Curtis Olson http://www.flightgear.org/~curt HumanFIRST Program http://www.humanfirst.umn.edu/ FlightGear Project http://www.flightgear.org Unique text: 2f585eeea02e2c79d7b1d8c4963bae2d
_______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d