]> git.mxchange.org Git - flightgear.git/commitdiff
Blame this on David Megginson ... :-)
authorcurt <curt>
Fri, 8 Dec 2000 17:36:07 +0000 (17:36 +0000)
committercurt <curt>
Fri, 8 Dec 2000 17:36:07 +0000 (17:36 +0000)
Save/restore seems to be working now, thanks to a couple of
unspeakable kludges:

1. Every time the altitude changes, pause the flight simulator for
five frames and then change it a second time.

2. Every time the latitude or longitude changes, wait five frames,
then invoke fgUpdateSkyAndLightingParams() a second time.

src/Main/bfi.cxx
src/Main/keyboard.cxx
src/Main/save.cxx

index 8ab72ac792a041d85e110986c8ccc9fc3391d7da..3c54cae184e1a056474e2077feb9f6137a1acba8 100644 (file)
@@ -146,6 +146,34 @@ reinit ()
   cout << "BFI: end reinit\n";
 }
 
+// BEGIN: kludge 2000-12-07
+// This is a kludge around a LaRCsim problem; see setAltitude()
+// for details.
+static int _altitude_countdown = 0;
+static double _requested_altitude = -9999;
+static bool _saved_freeze = false;
+static inline void _check_altitude ()
+{
+  if (_altitude_countdown > 0) {
+    _altitude_countdown--;
+    if (_altitude_countdown == 0) {
+      current_aircraft.fdm_state->set_Altitude(_requested_altitude);
+      globals->set_freeze(_saved_freeze);
+    }
+  }
+}
+
+static int _lighting_countdown = 0;
+static inline void _check_lighting ()
+{
+  if (_lighting_countdown > 0) {
+    _lighting_countdown--;
+    if (_lighting_countdown == 0)
+      fgUpdateSkyAndLightingParams();
+  }
+}
+// END: kludge
+
 
 \f
 ////////////////////////////////////////////////////////////////////////
@@ -337,6 +365,8 @@ FGBFI::init ()
 void
 FGBFI::update ()
 {
+  _check_altitude();
+  _check_lighting();
   if (_needReinit) {
     reinit();
   }
@@ -620,6 +650,8 @@ FGBFI::setLatitude (double latitude)
 {
   current_aircraft.fdm_state->set_Latitude(latitude * DEG_TO_RAD);
   fgUpdateSkyAndLightingParams();
+  if (_lighting_countdown <= 0)
+    _lighting_countdown = 5;
 }
 
 
@@ -641,6 +673,8 @@ FGBFI::setLongitude (double longitude)
 {
   current_aircraft.fdm_state->set_Longitude(longitude * DEG_TO_RAD);
   fgUpdateSkyAndLightingParams();
+  if (_lighting_countdown <= 0)
+    _lighting_countdown = 5;
 }
 
 
@@ -673,7 +707,22 @@ void
 FGBFI::setAltitude (double altitude)
 {
   current_aircraft.fdm_state->set_Altitude(altitude);
-  fgUpdateSkyAndLightingParams();
+
+                               // 2000-12-07
+                               // This is an ugly kludge around a
+                               // LaRCsim problem; if the
+                               // requested altitude cannot be
+                               // set right away (because it's
+                               // below the last-calculated ground
+                               // level), pause FGFS, wait for
+                               // five frames, and then try again.
+  if (_altitude_countdown <= 0 &&
+      fabs(getAltitude() - altitude) > 5.0) {
+    _altitude_countdown = 5;
+    _requested_altitude = altitude;
+    _saved_freeze = globals->get_freeze();
+    globals->set_freeze(true);
+  }
 }
 
 
index 3c90785a3a5c4b51f35f46bd4286f2ef81e957f1..7ebc023a1e910f612cb05588bb615f836c2e41ca 100644 (file)
@@ -146,10 +146,9 @@ void GLUTkey(unsigned char k, int x, int y) {
            // add 1000' of emergency altitude.  Possibly good for 
            // unflipping yourself :-)
            {
-               FGBFI::setAltitude(FGBFI::getAltitude() + 1000);
-//             double alt = cur_fdm_state->get_Altitude() + 1000;
-//             fgFDMForceAltitude( globals->get_options()->get_flight_model(), 
-//                                 alt * FEET_TO_METER );
+               double alt = cur_fdm_state->get_Altitude() + 1000;
+               fgFDMForceAltitude( globals->get_options()->get_flight_model(), 
+                                   alt * FEET_TO_METER );
            }
            return;
        case 49: // numeric keypad 1
index dfb3711cd1e8ccef5bcb7a9314f2689da38d5e1b..275d4dba9b57acbe5f06ebefce3e78a7971bb3e3 100644 (file)
@@ -60,36 +60,7 @@ fgSaveFlight (ostream &output)
 bool
 fgLoadFlight (istream &input)
 {
-  bool retval = readPropertyList(input, &current_properties);
-
-                               // FIXME: from keyboard.cxx
-                               // this makes sure that the tile
-                               // cache is updated after a restore;
-                               // it would be better if FGFS just
-                               // noticed the new lat/lon.
-  if (retval) {
-    bool freeze = globals->get_freeze();
-    FG_LOG(FG_INPUT, FG_INFO, "ReIniting TileCache");
-    if ( !freeze ) 
-      globals->set_freeze( true );
-    BusyCursor(0);
-    if ( global_tile_mgr.init() ) {
-      // Load the local scenery data
-      global_tile_mgr.update( 
-                            cur_fdm_state->get_Longitude() * RAD_TO_DEG,
-                            cur_fdm_state->get_Latitude() * RAD_TO_DEG );
-    } else {
-      FG_LOG( FG_GENERAL, FG_ALERT, 
-             "Error in Tile Manager initialization!" );
-      exit(-1);
-    }
-    BusyCursor(1);
-    if ( !freeze )
-      globals->set_freeze( false );
-  }
-                               // end FIXME
-
-  return retval;
+  return readPropertyList(input, &current_properties);
 }
 
 // end of save.cxx