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.
This commit is contained in:
parent
f30f40a2fb
commit
9c0c54ef6c
3 changed files with 18 additions and 13 deletions
|
@ -1019,10 +1019,24 @@ static void fgMainLoop( void ) {
|
||||||
last_time_stamp.stamp();
|
last_time_stamp.stamp();
|
||||||
first_time = false;
|
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;
|
delta_time_sec = double(current_time_stamp - last_time_stamp) / 1000000.0;
|
||||||
if (clock_freeze->getBoolValue())
|
if ( clock_freeze->getBoolValue() ) {
|
||||||
delta_time_sec = 0;
|
delta_time_sec = 0;
|
||||||
|
}
|
||||||
last_time_stamp = current_time_stamp;
|
last_time_stamp = current_time_stamp;
|
||||||
globals->inc_sim_time_sec( delta_time_sec );
|
globals->inc_sim_time_sec( delta_time_sec );
|
||||||
SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
|
SGAnimation::set_sim_time_sec( globals->get_sim_time_sec() );
|
||||||
|
|
|
@ -406,23 +406,15 @@ bool FGNativeFDM::process() {
|
||||||
FGNetFDM2Props( &buf );
|
FGNetFDM2Props( &buf );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// double dt = 1000000.0 / 30.0;
|
|
||||||
// SGTimeStamp current; current.stamp();
|
|
||||||
int result;
|
int result;
|
||||||
result = io->read( (char *)(& buf), length );
|
result = io->read( (char *)(& buf), length );
|
||||||
if ( result == length ) {
|
while ( 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 );
|
|
||||||
if ( result == length ) {
|
if ( result == length ) {
|
||||||
SG_LOG( SG_IO, SG_DEBUG, " Success reading data." );
|
SG_LOG( SG_IO, SG_DEBUG, " Success reading data." );
|
||||||
FGNetFDM2Props( &buf );
|
FGNetFDM2Props( &buf );
|
||||||
}
|
}
|
||||||
// current.stamp();
|
result = io->read( (char *)(& buf), length );
|
||||||
}
|
}
|
||||||
// last_time = current;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,6 @@ class FGNativeFDM : public FGProtocol, public FGInterface {
|
||||||
|
|
||||||
FGNetFDM buf;
|
FGNetFDM buf;
|
||||||
int length;
|
int length;
|
||||||
SGTimeStamp last_time;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue