+ // Yech -- not thread-safe, etc. etc.
+static bool _needReinit = false;
+static string _temp;
+
+static inline void needReinit ()
+{
+ _needReinit = true;
+}
+
+
+/**
+ * Reinitialize FGFS to use the new BFI settings.
+ */
+static inline void
+reinit ()
+{
+ // Save the state of everything
+ // that's going to get clobbered
+ // when we reinit the subsystems.
+
+ FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
+
+ // TODO: add more AP stuff
+ double elevator = FGBFI::getElevator();
+ double aileron = FGBFI::getAileron();
+ double rudder = FGBFI::getRudder();
+ double throttle = FGBFI::getThrottle();
+ double elevator_trim = FGBFI::getElevatorTrim();
+ double flaps = FGBFI::getFlaps();
+ double brake = FGBFI::getBrakes();
+ bool apHeadingLock = FGBFI::getAPHeadingLock();
+ double apHeadingMag = FGBFI::getAPHeadingMag();
+ bool apAltitudeLock = FGBFI::getAPAltitudeLock();
+ double apAltitude = FGBFI::getAPAltitude();
+ const string &targetAirport = FGBFI::getTargetAirport();
+ bool gpsLock = FGBFI::getGPSLock();
+ // double gpsLatitude = FGBFI::getGPSTargetLatitude();
+ // double gpsLongitude = FGBFI::getGPSTargetLongitude();
+
+ FGBFI::setTargetAirport("");
+
+ fgReInitSubsystems();
+
+ // FIXME: this is wrong.
+ // All of these are scheduled events,
+ // and it should be possible to force
+ // them all to run once.
+ fgUpdateSunPos();
+ fgUpdateMoonPos();
+ cur_light_params.Update();
+ fgUpdateLocalTime();
+ fgUpdateWeatherDatabase();
+ fgRadioSearch();
+
+ // Restore all of the old states.
+ FGBFI::setElevator(elevator);
+ FGBFI::setAileron(aileron);
+ FGBFI::setRudder(rudder);
+ FGBFI::setThrottle(throttle);
+ FGBFI::setElevatorTrim(elevator_trim);
+ FGBFI::setFlaps(flaps);
+ FGBFI::setBrakes(brake);
+ FGBFI::setAPHeadingLock(apHeadingLock);
+ FGBFI::setAPHeadingMag(apHeadingMag);
+ FGBFI::setAPAltitudeLock(apAltitudeLock);
+ FGBFI::setAPAltitude(apAltitude);
+ FGBFI::setTargetAirport(targetAirport);
+ FGBFI::setGPSLock(gpsLock);
+
+ _needReinit = false;
+
+ FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
+}
+
+// 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
+
+
+// BEGIN: kludge
+// Allow the view to be set from two axes (i.e. a joystick hat)
+// This needs to be in FGViewer itself, somehow.
+static double axisLong = 0.0;
+static double axisLat = 0.0;
+
+static inline void
+_set_view_from_axes ()
+{
+ // Take no action when hat is centered
+ if (axisLong == 0 && axisLat == 0)
+ return;
+
+ double viewDir = 0;
+
+ if (axisLong < 0) { // Longitudinal axis forward
+ if (axisLat < 0)
+ viewDir = 45;
+ else if (axisLat > 0)
+ viewDir = 315;
+ else
+ viewDir = 0;
+ } else if (axisLong > 0) { // Longitudinal axis backward
+ if (axisLat < 0)
+ viewDir = 135;
+ else if (axisLat > 0)
+ viewDir = 225;
+ else
+ viewDir = 180;
+ } else { // Longitudinal axis neutral
+ if (axisLat < 0)
+ viewDir = 90;
+ else
+ viewDir = 270;
+ }
+
+ globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
+// globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
+}
+
+// END: kludge