1
0
Fork 0

More tweaking of position reset logic.

This commit is contained in:
curt 2001-01-17 23:30:35 +00:00
parent a5e4e6be11
commit e9b492af4f
5 changed files with 80 additions and 15 deletions

View file

@ -79,10 +79,11 @@ void AptDialog_OK (puObject *)
if ( airports.search( AptId, &a ) )
{
fgSetString("/sim/startup/airport-id", AptId.c_str() );
fgSetDouble("/position/altitude", -9999.0 );
// fgSetPosFromAirportID( AptId );
// fgSetDouble("/position/altitude", -9999.0 );
// fgSetPosFromAirportID( AptId );
fgSetPosFromAirportIDandHdg( AptId,
cur_fdm_state->get_Psi() * RAD_TO_DEG);
cur_fdm_state->get_Psi() *
RAD_TO_DEG);
BusyCursor(0);
fgReInitSubsystems();
BusyCursor(1);

View file

@ -358,10 +358,18 @@ bool fgInitPosition( void ) {
FG_LOG( FG_GENERAL, FG_INFO,
"scenery.cur_elev = " << scenery.cur_elev );
FG_LOG( FG_GENERAL, FG_INFO,
"/position/altitude = " << fgGetDouble("/position/altitude") );
// if ( scenery.cur_elev > fgGetDouble("/position/altitude") - 1) {
fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
// }
// if we requested on ground startups
if ( fgGetBool( "/sim/startup/onground" ) ) {
fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
}
// if requested altitude is below ground level
if ( scenery.cur_elev > fgGetDouble("/position/altitude") - 1) {
fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
}
FG_LOG( FG_GENERAL, FG_INFO,
"starting altitude is = " <<
@ -776,6 +784,9 @@ bool fgInitSubsystems( void ) {
void fgReInitSubsystems( void )
{
FG_LOG( FG_GENERAL, FG_INFO,
"/position/altitude = " << fgGetDouble("/position/altitude") );
bool freeze = globals->get_freeze();
if( !freeze )
globals->set_freeze( true );

View file

@ -135,7 +135,7 @@ FGGeneral general;
// our initializations out of the glutIdleLoop() so that we can get a
// splash screen up and running right away.
static int idle_state = 0;
static int global_multi_loop;
static long global_multi_loop;
// attempt to avoid a large bounce at startup
static bool initial_freeze = true;
@ -731,13 +731,21 @@ void fgRenderFrame( void ) {
// Update internal time dependent calculations (i.e. flight model)
void fgUpdateTimeDepCalcs() {
static bool inited = false;
fgLIGHT *l = &cur_light_params;
int i;
int multi_loop = 1;
long multi_loop = 1;
if ( !globals->get_freeze() && !initial_freeze ) {
// conceptually, this could be done for each fdm instance ...
if ( !inited ) {
cur_fdm_state->stamp();
inited = true;
}
SGTimeStamp current;
current.stamp();
long elapsed = current - cur_fdm_state->get_time_stamp();
@ -745,12 +753,20 @@ void fgUpdateTimeDepCalcs() {
elapsed += cur_fdm_state->get_remainder();
// cout << "elapsed = " << elapsed << endl;
// cout << "dt = " << cur_fdm_state->get_delta_t() << endl;
multi_loop = (int)(((double)elapsed * 0.000001) /
multi_loop = (long)(((double)elapsed * 0.000001) /
cur_fdm_state->get_delta_t() );
cur_fdm_state->set_multi_loop( multi_loop );
long remainder = elapsed - ( (multi_loop*1000000) *
cur_fdm_state->get_delta_t() );
cur_fdm_state->set_remainder( remainder );
// cout << "remainder = " << remainder << endl;
// chop max interations to something reasonable if the sim was
// delayed for an excesive amount of time
if ( multi_loop > 2.0 / cur_fdm_state->get_delta_t() ) {
multi_loop = (int)(2.0 / cur_fdm_state->get_delta_t());
cur_fdm_state->set_remainder( 0 );
}
// cout << "multi_loop = " << multi_loop << endl;
for ( i = 0; i < multi_loop; ++i ) {
@ -979,7 +995,7 @@ static void fgMainLoop( void ) {
// Calculate model iterations needed for next frame
elapsed += remainder;
global_multi_loop = (int)(((double)elapsed * 0.000001) *
global_multi_loop = (long)(((double)elapsed * 0.000001) *
fgGetInt("/sim/model-hz"));
remainder = elapsed - ( (global_multi_loop*1000000) /
fgGetInt("/sim/model-hz") );
@ -987,6 +1003,13 @@ static void fgMainLoop( void ) {
"Model iterations needed = " << global_multi_loop
<< ", new remainder = " << remainder );
// chop max interations to something reasonable if the sim was
// delayed for an excesive amount of time
if ( global_multi_loop > 2.0 * fgGetInt("/sim/model-hz") ) {
global_multi_loop = (int)(2.0 * fgGetInt("/sim/model-hz") );
remainder = 0;
}
// flight model
if ( global_multi_loop > 0 ) {
fgUpdateTimeDepCalcs();

View file

@ -149,6 +149,7 @@ fgSetDefaults ()
fgSetInt("/sim/model-hz", NEW_DEFAULT_MODEL_HZ);
fgSetInt("/sim/speed-up", 1);
fgSetBool("/sim/startup/trim", false);
fgSetBool("/sim/startup/onground", true);
// Rendering options
fgSetString("/sim/rendering/fog", "nicest");
@ -566,6 +567,7 @@ parse_option (const string& arg)
parse_degree(arg.substr(6)));
fgSetString("/position/airport-id", "");
} else if ( arg.find( "--altitude=" ) != string::npos ) {
fgSetBool("/sim/startup/onground", false);
if ( fgGetString("/sim/startup/units") == "feet" )
fgSetDouble("/position/altitude", atof(arg.substr(11)));
else
@ -646,9 +648,13 @@ parse_option (const string& arg)
} else if ( arg.find( "--speed=" ) != string::npos ) {
fgSetInt("/sim/speed-up", atoi(arg.substr(8)));
} else if ( arg.find( "--trim") != string::npos) {
fgSetInt("/sim/startup/trim", true);
fgSetBool("/sim/startup/trim", true);
} else if ( arg.find( "--notrim") != string::npos) {
fgSetInt("/sim/startup/trim", false);
fgSetBool("/sim/startup/trim", false);
} else if ( arg.find( "--on-ground") != string::npos) {
fgSetBool("/sim/startup/onground", true);
} else if ( arg.find( "--in-air") != string::npos) {
fgSetBool("/sim/startup/onground", false);
} else if ( arg == "--fog-disable" ) {
fgSetString("/sim/rendering/fog", "disabled");
} else if ( arg == "--fog-fastest" ) {
@ -1031,6 +1037,9 @@ fgUsage ()
<< endl;
cout << "\t--speed=n: run the FDM this much faster than real time" << endl;
cout << "\t--notrim: Do NOT attempt to trim the model when initializing JSBsim" << endl;
cout << "\t--on-ground: Start up at ground level (default)" << endl;
cout << "\t--in-air: Start up in air (implied by specifying an initial"
<< " altitude above ground level." << endl;
cout << "\t--wind=DIR@SPEED: specify wind coming from DIR (degrees) at SPEED (knots)" << endl;
cout << endl;

View file

@ -228,11 +228,32 @@ void FGTileMgr::schedule_needed() {
global_tile_cache.set_max_cache_size( (2*xrange + 2) * (2*yrange + 2) );
SGBucket b;
// schedule center tile first so it can be loaded first
b = sgBucketOffset( longitude, latitude, 0, 0 );
sched_tile( b );
// schedule next ring of 8 tiles
for ( int x = -1; x <= 1; ++x ) {
for ( int y = -1; y <= 1; ++y ) {
if ( x != 0 || y != 0 ) {
b = sgBucketOffset( longitude, latitude, x, y );
if ( ! global_tile_cache.exists( b ) ) {
sched_tile( b );
}
}
}
}
// schedule remaining tiles
for ( int x = -xrange; x <= xrange; ++x ) {
for ( int y = -yrange; y <= yrange; ++y ) {
SGBucket b = sgBucketOffset( longitude, latitude, x, y );
if ( ! global_tile_cache.exists( b ) ) {
sched_tile( b );
if ( x < -1 || x > 1 || y < -1 || y > 1 ) {
SGBucket b = sgBucketOffset( longitude, latitude, x, y );
if ( ! global_tile_cache.exists( b ) ) {
sched_tile( b );
}
}
}
}