]> git.mxchange.org Git - flightgear.git/commitdiff
More tweaking of position reset logic.
authorcurt <curt>
Wed, 17 Jan 2001 23:30:35 +0000 (23:30 +0000)
committercurt <curt>
Wed, 17 Jan 2001 23:30:35 +0000 (23:30 +0000)
src/GUI/apt_dlg.cxx
src/Main/fg_init.cxx
src/Main/main.cxx
src/Main/options.cxx
src/Scenery/tilemgr.cxx

index 7636a0be7687dfe5ac3a53d97d6a9bc6cf121684..1c7d7f3e2b049247b6e33dff96664aa109249aec 100644 (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);
index 881b225bffe17d52e70c1d91a3d606d285fb4e34..3581a5818d544982d42d86fbf072de2fdd2b4983 100644 (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 we requested on ground startups
+    if ( fgGetBool( "/sim/startup/onground" ) ) {
+       fgSetDouble("/position/altitude", scenery.cur_elev + 1 );
+    }
 
-    // if ( scenery.cur_elev > fgGetDouble("/position/altitude") - 1) {
-    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 );
index 703071fa7adf8c4f20983ec6cce06dad809cecf5..1d4b266f67123382a2fe896990cf1ab815114f63 100644 (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();
index 6b30f62ac55587d2d5121bc9812e35820d5d8c13..0cb6bebb264742c314f1f1c74e5bd01d02ca46f5 100644 (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;
 
index efc925ad6386931aed226777afe2e7a43a247973..314e3678bfc08a5a1440c785c40df089802657bf 100644 (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 );
+               }
            }
        }
     }