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

Reply via email to