From: curt Date: Mon, 2 Jun 2003 16:35:36 +0000 (+0000) Subject: Implimented a simple frame rate throttle. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9c0c54ef6cfab99d8a6065124e4c0721a84cd0fd;p=flightgear.git Implimented a simple frame rate throttle. 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. --- diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 1cc9fe5c0..75646c6af 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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() ); diff --git a/src/Network/native_fdm.cxx b/src/Network/native_fdm.cxx index 70c98c6bf..4f7afe65f 100644 --- a/src/Network/native_fdm.cxx +++ b/src/Network/native_fdm.cxx @@ -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; } } diff --git a/src/Network/native_fdm.hxx b/src/Network/native_fdm.hxx index 7d55b3638..b7013d13d 100644 --- a/src/Network/native_fdm.hxx +++ b/src/Network/native_fdm.hxx @@ -39,7 +39,6 @@ class FGNativeFDM : public FGProtocol, public FGInterface { FGNetFDM buf; int length; - SGTimeStamp last_time; public: