]> git.mxchange.org Git - flightgear.git/commitdiff
Implimented a simple frame rate throttle.
authorcurt <curt>
Mon, 2 Jun 2003 16:35:36 +0000 (16:35 +0000)
committercurt <curt>
Mon, 2 Jun 2003 16:35:36 +0000 (16:35 +0000)
Normally for smoothest frame rates you would configure to sync
to your monitor's vertical refresh signal.  This is card/platform
dependent ... for instance with Linux/Nvidia there is
an environment variable you can set to enable this feature.

However, if your monitor is refreshing at 60hz and you can't quite sustain
that with flightgear, you can get smoother frame rates by artificially
throttling yourself to 30hz.  Note that once you are about about 24fps, it
is *change* or inconsistancy in frame rate that leads to percieved jerkiness.

You want to do whole divisors of your monitor refresh rate, so if your
display is syncing at 75 hz, you might want to try throttling to 25 hz.

src/Main/main.cxx
src/Network/native_fdm.cxx
src/Network/native_fdm.hxx

index 1cc9fe5c096de4d65ee359b9fdd6e24e69330f0c..75646c6af4273d4387a376858f64c278ca6ad3d3 100644 (file)
@@ -1019,10 +1019,24 @@ static void fgMainLoop( void ) {
         last_time_stamp.stamp();
         first_time = false;
     }
-    current_time_stamp.stamp();
+
+    double throttle_hz = fgGetDouble("/sim/frame-rate-throttle-hz", 0.0);
+    if ( throttle_hz > 0.0 ) {
+        // simple frame rate throttle
+        double dt = 1000000.0 / throttle_hz;
+        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();
+    }
+
     delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
-    if (clock_freeze->getBoolValue())
+    if ( clock_freeze->getBoolValue() ) {
         delta_time_sec = 0;
+    }
     last_time_stamp = current_time_stamp;
     globals->inc_sim_time_sec( delta_time_sec );
     SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
index 70c98c6bf7690764a89d608634930a2633526f54..4f7afe65f20fe0a6dc02d51ec497cbedbaafa5b0 100644 (file)
@@ -406,23 +406,15 @@ bool FGNativeFDM::process() {
                FGNetFDM2Props( &buf );
            }
        } else {
-            // double dt = 1000000.0 / 30.0;
-            // SGTimeStamp current; current.stamp();
             int result;
             result = io->read( (char *)(& buf), length );
-            if ( result == length ) {
-                SG_LOG( SG_IO, SG_DEBUG, "  Success reading data." );
-                FGNetFDM2Props( &buf );
-            }
-           while ( result == length /* || current - last_time < dt */ ) {
-                result = io->read( (char *)(& buf), length );
+           while ( result == length ) {
                 if ( result == length ) {
                     SG_LOG( SG_IO, SG_DEBUG, "  Success reading data." );
                     FGNetFDM2Props( &buf );
                 }
-                // current.stamp();
+                result = io->read( (char *)(& buf), length );
            }
-            // last_time = current;
        }
     }
 
index 7d55b36385acda31551fc484db0371c9e8f2c58d..b7013d13dab4a2dd7b3fc1b9d96ed76373338c80 100644 (file)
@@ -39,7 +39,6 @@ class FGNativeFDM : public FGProtocol, public FGInterface {
 
     FGNetFDM buf;
     int length;
-    SGTimeStamp last_time;
 
 public: