]> git.mxchange.org Git - flightgear.git/commitdiff
1. Added src/Main/fgfs.hxx as a standard, top-level include file for
authorcurt <curt>
Fri, 5 Jan 2001 17:38:58 +0000 (17:38 +0000)
committercurt <curt>
Fri, 5 Jan 2001 17:38:58 +0000 (17:38 +0000)
FlightGear subsystems -- it isolates some of the config and #ifdef
stuff in a single place.

2. Added a new FGSubsystem interface, defined in fgfs.hxx; so far,
only FGControls implements it, but if that works, we can start letting
it propagate through the system and simplify the code in main.cxx and
fg_init.cxx (which is terrifyingly complex for anyone new to the
project).

3. Added new src/Main/fgfs_props.[hc]xx files with convenience
functions for tying properties under FlightGear.

4. Experimentally modified src/Controls/controls.cxx to tie properties
directly (rather than tying to BFI functions).  I'd appreciate it if
you could get this into CVS as soon as possible, so we can see if the
template stuff causes trouble for any other platforms before I add
properties to the other subsystems.

5. Miscellaneous superficial modifications to other files.

In addition, I've made a couple of further changes:

6. Modified BFI to add support for setting the view axes (i.e. with a
joystick hat).

7. Cleaned up bfi.cxx and removed all cout statements.

15 files changed:
src/Cockpit/radiostack.cxx
src/Cockpit/radiostack.hxx
src/Cockpit/steam.cxx
src/Controls/controls.cxx
src/Controls/controls.hxx
src/GUI/gui.cxx
src/Main/Makefile.am
src/Main/bfi.cxx
src/Main/bfi.hxx
src/Main/fg_init.cxx
src/Main/keyboard.cxx
src/Main/save.cxx [deleted file]
src/Main/save.hxx [deleted file]
src/Navaids/Makefile.am
src/Navaids/nav.hxx

index c4f04923472cbfa855fd08e8a657818cf9424b08..d8ccdd181468de1c7c32273f526ba63108750817 100644 (file)
@@ -58,7 +58,10 @@ FGRadioStack *current_radiostack;
 
 // Constructor
 FGRadioStack::FGRadioStack() {
+    nav1_radial = 0.0;
     nav1_dme_dist = 0.0;
+    nav2_radial = 0.0;
+    nav2_dme_dist = 0.0;
     need_update = true;
 }
 
@@ -102,7 +105,7 @@ void FGRadioStack::update( double lon, double lat, double elev ) {
            geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, 
                                nav1_loclat, nav1_loclon,
                                &az1, &az2, &s );
-           nav1_heading = az1;
+           nav1_heading = az1 - nav1_offset;
            // Alex: nav1_heading = - (az1 - FGBFI::getMagVar() / RAD_TO_DEG);
 
            // cout << " heading = " << nav1_heading
@@ -117,6 +120,7 @@ void FGRadioStack::update( double lon, double lat, double elev ) {
        }
     } else {
        nav1_inrange = false;
+       nav1_dme_dist = 0.0;
        // cout << "not picking up vor. :-(" << endl;
     }
 
@@ -146,7 +150,7 @@ void FGRadioStack::update( double lon, double lat, double elev ) {
            geo_inverse_wgs_84( elev, lat * RAD_TO_DEG, lon * RAD_TO_DEG, 
                                nav2_loclat, nav2_loclon,
                                &az1, &az2, &s );
-           nav2_heading = az1;
+           nav2_heading = az1 - nav2_offset;
            // Alex: nav2_heading = - (az1 - FGBFI::getMagVar() / RAD_TO_DEG);
 
            // cout << " heading = " << nav2_heading
@@ -208,6 +212,7 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        nav1_dmelon = ils.get_dmelon();
        nav1_dmelat = ils.get_dmelat();
        nav1_elev = ils.get_gselev();
+       nav1_offset = 0;
        nav1_effective_range = FG_ILS_DEFAULT_RANGE;
        nav1_target_gs = ils.get_gsangle();
        nav1_radial = ils.get_locheading();
@@ -232,6 +237,7 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        nav1_loclon = nav.get_lon();
        nav1_loclat = nav.get_lat();
        nav1_elev = nav.get_elev();
+       nav1_offset = nav.get_offset();
        nav1_effective_range = kludgeRange(nav1_elev, elev, nav.get_range());
        nav1_target_gs = 0.0;
        nav1_radial = nav1_sel_radial;
@@ -242,6 +248,8 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        // cout << " id = " << nav.get_ident() << endl;
     } else {
        nav1_valid = false;
+       nav1_radial = 0;
+       nav2_dme_dist = 0;
        // cout << "not picking up vor1. :-(" << endl;
     }
 
@@ -254,6 +262,7 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        nav2_loclon = ils.get_loclon();
        nav2_loclat = ils.get_loclat();
        nav2_elev = ils.get_gselev();
+       nav2_offset = 0;
        nav2_effective_range = FG_ILS_DEFAULT_RANGE;
        nav2_target_gs = ils.get_gsangle();
        nav2_radial = ils.get_locheading();
@@ -278,6 +287,7 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        nav2_loclon = nav.get_lon();
        nav2_loclat = nav.get_lat();
        nav2_elev = nav.get_elev();
+       nav2_offset = nav.get_offset();
        nav2_effective_range = kludgeRange(nav2_elev, elev, nav.get_range());
        nav2_target_gs = 0.0;
        nav2_radial = nav2_sel_radial;
@@ -288,6 +298,8 @@ void FGRadioStack::search( double lon, double lat, double elev ) {
        // cout << " id = " << nav.get_ident() << endl;
     } else {
        nav2_valid = false;
+       nav2_radial = 0;
+       nav2_dme_dist = 0;
        // cout << "not picking up vor2. :-(" << endl;
     }
 
index f13e5338b669e43ca4f3eccb90093e7e84081491..dc4472564514d8c248d34f3eaf515786ebdbde3d 100644 (file)
@@ -66,6 +66,7 @@ class FGRadioStack {
     double nav1_effective_range;
     double nav1_heading;
     double nav1_target_gs;
+    int nav1_offset;
 
     bool nav2_valid;
     bool nav2_inrange;
@@ -98,6 +99,7 @@ class FGRadioStack {
     double nav2_effective_range;
     double nav2_heading;
     double nav2_target_gs;
+    int nav2_offset;
 
     bool adf_valid;
     bool adf_inrange;
index df7a507a1cdf0747501d9da81e3b349f132049ac..3c159e86b038e170efdb5c6f2c130e6423dca3f8 100644 (file)
@@ -401,6 +401,8 @@ double FGSteam::get_HackVOR1_deg () {
     double r;
 
     if ( current_radiostack->get_nav1_inrange() ) {
+#if 0
+       // depricated
        if ( current_radiostack->get_nav1_loc() ) {
            // localizer doesn't need magvar offset
            r = current_radiostack->get_nav1_heading()
@@ -409,6 +411,9 @@ double FGSteam::get_HackVOR1_deg () {
            r = current_radiostack->get_nav1_heading() - FGBFI::getMagVar()
                - current_radiostack->get_nav1_radial();
        }
+#endif
+        r = current_radiostack->get_nav1_heading()
+           - current_radiostack->get_nav1_radial();
        // cout << "Radial = " << current_radiostack->get_nav1_radial() 
        //      << "  Bearing = " << current_radiostack->get_nav1_heading()
        //      << endl;
@@ -431,6 +436,8 @@ double FGSteam::get_HackVOR2_deg () {
     double r;
 
     if ( current_radiostack->get_nav2_inrange() ) {
+#if 0
+       // Depricated
        if ( current_radiostack->get_nav2_loc() ) {
            // localizer doesn't need magvar offset
            r = current_radiostack->get_nav2_heading()
@@ -439,6 +446,9 @@ double FGSteam::get_HackVOR2_deg () {
            r = current_radiostack->get_nav2_heading() - FGBFI::getMagVar()
                - current_radiostack->get_nav2_radial();
        }
+#endif
+        r = current_radiostack->get_nav2_heading()
+           - current_radiostack->get_nav2_radial();
        // cout << "Radial = " << current_radiostack->get_nav1_radial() 
        // << "  Bearing = " << current_radiostack->get_nav1_heading() << endl;
     
index e4f828c1e7f577bcd5a150774b3ef1b794c95372..d5152c739396c3b70a999705c3d30e8a96422128 100644 (file)
@@ -23,6 +23,9 @@
 
 #include "controls.hxx"
 
+#include <simgear/debug/logstream.hxx>
+#include <Main/fg_props.hxx>
+
 
 FGControls controls;
 
@@ -37,6 +40,8 @@ FGControls::FGControls() :
 {
     for ( int engine = 0; engine < MAX_ENGINES; engine++ ) {
        throttle[engine] = 0.0;
+       mixture[engine] = 1.0;
+       prop_advance[engine] = 1.0;
     }
 
     for ( int wheel = 0; wheel < MAX_WHEELS; wheel++ ) {
@@ -61,3 +66,82 @@ FGControls::~FGControls() {
 }
 
 
+void
+FGControls::init ()
+{
+}
+
+
+void
+FGControls::bind ()
+{
+  fgTie("/controls/aileron", this,
+                   &FGControls::get_aileron, &FGControls::set_aileron);
+  fgTie("/controls/elevator", this,
+       &FGControls::get_elevator, &FGControls::set_elevator);
+  fgTie("/controls/elevator-trim", this,
+       &FGControls::get_elevator_trim, &FGControls::set_elevator_trim);
+  fgTie("/controls/rudder", this,
+       &FGControls::get_rudder, &FGControls::set_rudder);
+  fgTie("/controls/flaps", this,
+       &FGControls::get_flaps, &FGControls::set_flaps);
+  for (int index = 0; index < MAX_ENGINES; index++) {
+    char name[32];
+    sprintf(name, "/controls/throttle[%d]", index);
+    fgTie(name, this, index,
+         &FGControls::get_throttle, &FGControls::set_throttle);
+    sprintf(name, "/controls/mixture[%d]", index);
+    fgTie(name, this, index,
+        &FGControls::get_mixture, &FGControls::set_mixture);
+    sprintf(name, "/controls/propellor-pitch[%d]", index);
+    fgTie(name, this, index,
+        &FGControls::get_prop_advance, &FGControls::set_prop_advance);
+  }
+  fgTie("/controls/throttle/all", this, ALL_ENGINES,
+       &FGControls::get_throttle, &FGControls::set_throttle);
+  fgTie("/controls/mixture/all", this, ALL_ENGINES,
+       &FGControls::get_mixture, &FGControls::set_mixture);
+  fgTie("/controls/propellor-pitch/all", this, ALL_ENGINES,
+       &FGControls::get_prop_advance, &FGControls::set_prop_advance);
+  for (int index = 0; index < MAX_WHEELS; index++) {
+    char name[32];
+    sprintf(name, "/controls/brakes[%d]", index);
+    fgTie(name, this, index,
+        &FGControls::get_brake, &FGControls::set_brake);
+  }
+  fgTie("/controls/brakes/all", this, ALL_WHEELS,
+       &FGControls::get_brake, &FGControls::set_brake);
+}
+
+
+void
+FGControls::unbind ()
+{
+                               // Tie control properties.
+  fgUntie("/controls/aileron");
+  fgUntie("/controls/elevator");
+  fgUntie("/controls/elevator-trim");
+  fgUntie("/controls/rudder");
+  fgUntie("/controls/flaps");
+  for (int index = 0; index < MAX_ENGINES; index++) {
+    char name[32];
+    sprintf(name, "/controls/throttle[%d]", index);
+    fgUntie(name);
+    sprintf(name, "/controls/mixture[%d]", index);
+    fgUntie(name);
+    sprintf(name, "/controls/propellor-pitch[%d]", index);
+    fgUntie(name);
+  }
+  for (int index = 0; index < MAX_WHEELS; index++) {
+    char name[32];
+    sprintf(name, "/controls/brakes[%d]", index);
+    fgUntie(name);
+  }
+}
+
+
+void
+FGControls::update ()
+{
+}
+
index e12c4362e971b9962bf3965810330f39c1132dad..3a615cb2f86be104a1eb7706d5ff4bcc98440db9 100644 (file)
@@ -24,6 +24,7 @@
 #ifndef _CONTROLS_HXX
 #define _CONTROLS_HXX
 
+#include <Main/fgfs.hxx>
 #include <Main/globals.hxx>
 
 #ifndef __cplusplus                                                          
@@ -33,7 +34,8 @@
 
 // Define a structure containing the control parameters
 
-class FGControls {
+class FGControls : public FGSubsystem
+{
 
 public:
 
@@ -72,6 +74,12 @@ public:
     FGControls();
     ~FGControls();
 
+    // Implementation of FGSubsystem.
+    void init ();
+    void bind ();
+    void unbind ();
+    void update ();
+
     // Reset function
     void reset_all(void);
        
index 9521d276b19bb4a81dc8b9f4731644d33695b3fc..32198d4d0f7b5ce3b1ad1ca9b66e4319a239b8c2 100644 (file)
@@ -68,7 +68,7 @@
 #include <Main/fg_init.hxx>
 #include <Main/fg_io.hxx>
 #include <Main/globals.hxx>
-#include <Main/save.hxx>
+#include <Main/fg_props.hxx>
 #ifdef FG_NETWORK_OLK
 #include <NetworkOLK/network.h>
 #endif
index a72bd935c27e4a0294d1da211d77480f1c1ea27d..7fb27f5e27e7752ba3c40072527dbe4524052cf0 100644 (file)
@@ -38,10 +38,11 @@ fgfs_SOURCES = \
        bfi.cxx bfi.hxx \
        fg_init.cxx fg_init.hxx \
        fg_io.cxx fg_io.hxx \
+       fg_props.cxx fg_props.hxx \
+        fgfs.cxx fgfs.hxx \
        globals.cxx globals.hxx \
        keyboard.cxx keyboard.hxx \
        options.cxx options.hxx \
-       save.cxx save.hxx \
        splash.cxx splash.hxx \
        viewer.cxx viewer.hxx \
        viewer_lookat.cxx viewer_lookat.hxx \
index e9707e022a593050bf97b988d2f7f812bbd5af75..96a34c7b96e670528db958ea7451b5955b65ec74 100644 (file)
 //
 // $Id$
 
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
-#  include <iostream.h>
-#else
-#  include <iostream>
-#endif
+#include "fgfs.hxx"
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
@@ -56,9 +47,8 @@
 #endif
 
 #include "globals.hxx"
-#include "save.hxx"
 #include "fg_init.hxx"
-#include <simgear/misc/props.hxx>
+#include "fg_props.hxx"
 
 FG_USING_NAMESPACE(std);
 
@@ -91,7 +81,7 @@ reinit ()
                                // that's going to get clobbered
                                // when we reinit the subsystems.
 
-  cout << "BFI: start reinit\n";
+  FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI reinit");
 
                                // TODO: add more AP stuff
   double elevator = FGBFI::getElevator();
@@ -111,7 +101,6 @@ reinit ()
   // double gpsLongitude = FGBFI::getGPSTargetLongitude();
 
   FGBFI::setTargetAirport("");
-  cout << "Target airport is " << globals->get_options()->get_airport_id() << endl;
 
   fgReInitSubsystems();
 
@@ -143,7 +132,7 @@ reinit ()
 
   _needReinit = false;
 
-  cout << "BFI: end reinit\n";
+  FG_LOG(FG_GENERAL, FG_INFO, "Ending BFI reinit");
 }
 
 // BEGIN: kludge 2000-12-07
@@ -175,30 +164,53 @@ static inline void _check_lighting ()
 // END: kludge
 
 
-\f
-////////////////////////////////////////////////////////////////////////
-// Local functions
-////////////////////////////////////////////////////////////////////////
+// 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 
-TIE_BOOL(const char * name, bool (*getter)(), void (*setter)(bool)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<bool>(getter, setter));
-}
+static inline void
+_set_view_from_axes ()
+{
+                               // Take no action when hat is centered
+  if (axisLong == 0 && axisLat == 0)
+    return;
 
-static inline void 
-TIE_INT(const char * name, int (*getter)(), void (*setter)(int)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<int>(getter, setter));
-}
+  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;
+  }
 
-static inline void 
-TIE_DOUBLE(const char * name, double (*getter)(), void (*setter)(double)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<double>(getter, setter));
+  globals->get_current_view()->set_goal_view_offset(viewDir*DEG_TO_RAD);
+//   globals->get_current_view()->set_view_offset(viewDir*DEG_TO_RAD);
 }
 
-static inline void 
-TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) {
-  globals->get_props()->tie(name, SGRawValueFunctions<string>(getter, setter));
-}
+// END: kludge
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Local functions
+////////////////////////////////////////////////////////////////////////
 
 /**
  * Initialize the BFI by binding its functions to properties.
@@ -211,95 +223,105 @@ FGBFI::init ()
 {
   FG_LOG(FG_GENERAL, FG_INFO, "Starting BFI init");
                                // Simulation
-  TIE_INT("/sim/flight-model", getFlightModel, setFlightModel);
-  TIE_STRING("/sim/aircraft", getAircraft, setAircraft);
-  TIE_STRING("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
-  TIE_STRING("/sim/time/gmt", getDateString, setDateString);
-  TIE_STRING("/sim/time/gmt-string", getGMTString, 0);
-  TIE_BOOL("/sim/hud/visibility", getHUDVisible, setHUDVisible);
-  TIE_BOOL("/sim/panel/visibility", getPanelVisible, setPanelVisible);
-  TIE_INT("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
-  TIE_INT("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
+  fgTie("/sim/flight-model", getFlightModel, setFlightModel);
+  fgTie("/sim/aircraft", getAircraft, setAircraft);
+  fgTie("/sim/aircraft-dir", getAircraftDir, setAircraftDir);
+  fgTie("/sim/time/gmt", getDateString, setDateString);
+  fgTie("/sim/time/gmt-string", getGMTString);
+  fgTie("/sim/hud/visibility", getHUDVisible, setHUDVisible);
+  fgTie("/sim/panel/visibility", getPanelVisible, setPanelVisible);
+  fgTie("/sim/panel/x-offset", getPanelXOffset, setPanelXOffset);
+  fgTie("/sim/panel/y-offset", getPanelYOffset, setPanelYOffset);
 
                                // Position
-  TIE_STRING("/position/airport-id", getTargetAirport, setTargetAirport);
-  TIE_DOUBLE("/position/latitude", getLatitude, setLatitude);
-  TIE_DOUBLE("/position/longitude", getLongitude, setLongitude);
-  TIE_DOUBLE("/position/altitude", getAltitude, setAltitude);
-  TIE_DOUBLE("/position/altitude-agl", getAGL, 0);
+  fgTie("/position/airport-id", getTargetAirport, setTargetAirport);
+  fgTie("/position/latitude", getLatitude, setLatitude);
+  fgTie("/position/longitude", getLongitude, setLongitude);
+  fgTie("/position/altitude", getAltitude, setAltitude);
+  fgTie("/position/altitude-agl", getAGL);
 
                                // Orientation
-  TIE_DOUBLE("/orientation/heading", getHeading, setHeading);
-  TIE_DOUBLE("/orientation/heading-magnetic", getHeadingMag, 0);
-  TIE_DOUBLE("/orientation/pitch", getPitch, setPitch);
-  TIE_DOUBLE("/orientation/roll", getRoll, setRoll);
+  fgTie("/orientation/heading", getHeading, setHeading);
+  fgTie("/orientation/heading-magnetic", getHeadingMag);
+  fgTie("/orientation/pitch", getPitch, setPitch);
+  fgTie("/orientation/roll", getRoll, setRoll);
 
                                // Engine
-  TIE_DOUBLE("/engines/engine0/rpm", getRPM, 0);
-  TIE_DOUBLE("/engines/engine0/egt", getEGT, 0);
-  TIE_DOUBLE("/engines/engine0/cht", getCHT, 0);
-  TIE_DOUBLE("/engines/engine0/mp", getMP, 0);
+  fgTie("/engines/engine0/rpm", getRPM);
+  fgTie("/engines/engine0/egt", getEGT);
+  fgTie("/engines/engine0/cht", getCHT);
+  fgTie("/engines/engine0/mp", getMP);
 
                                // Velocities
-  TIE_DOUBLE("/velocities/airspeed", getAirspeed, setAirspeed);
-  TIE_DOUBLE("/velocities/side-slip", getSideSlip, 0);
-  TIE_DOUBLE("/velocities/vertical-speed", getVerticalSpeed, 0);
-  TIE_DOUBLE("/velocities/speed-north", getSpeedNorth, 0);
-  TIE_DOUBLE("/velocities/speed-east", getSpeedEast, 0);
-  TIE_DOUBLE("/velocities/speed-down", getSpeedDown, 0);
+  fgTie("/velocities/airspeed", getAirspeed, setAirspeed);
+  fgTie("/velocities/side-slip", getSideSlip);
+  fgTie("/velocities/vertical-speed", getVerticalSpeed);
+  fgTie("/velocities/speed-north", getSpeedNorth);
+  fgTie("/velocities/speed-east", getSpeedEast);
+  fgTie("/velocities/speed-down", getSpeedDown);
 
                                // Controls
-  TIE_DOUBLE("/controls/throttle", getThrottle, setThrottle);
-  TIE_DOUBLE("/controls/mixture", getMixture, setMixture);
-  TIE_DOUBLE("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
-  TIE_DOUBLE("/controls/flaps", getFlaps, setFlaps);
-  TIE_DOUBLE("/controls/aileron", getAileron, setAileron);
-  TIE_DOUBLE("/controls/rudder", getRudder, setRudder);
-  TIE_DOUBLE("/controls/elevator", getElevator, setElevator);
-  TIE_DOUBLE("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
-  TIE_DOUBLE("/controls/brakes/all", getBrakes, setBrakes);
-  TIE_DOUBLE("/controls/brakes/left", getLeftBrake, setLeftBrake);
-  TIE_DOUBLE("/controls/brakes/right", getRightBrake, setRightBrake);
-  TIE_DOUBLE("/controls/brakes/center", getRightBrake, setCenterBrake);
+#if 0
+  fgTie("/controls/throttle", getThrottle, setThrottle);
+  fgTie("/controls/mixture", getMixture, setMixture);
+  fgTie("/controls/propellor-pitch", getPropAdvance, setPropAdvance);
+  fgTie("/controls/flaps", getFlaps, setFlaps);
+  fgTie("/controls/aileron", getAileron, setAileron);
+  fgTie("/controls/rudder", getRudder, setRudder);
+  fgTie("/controls/elevator", getElevator, setElevator);
+  fgTie("/controls/elevator-trim", getElevatorTrim, setElevatorTrim);
+  fgTie("/controls/brakes/all", getBrakes, setBrakes);
+  fgTie("/controls/brakes/left", getLeftBrake, setLeftBrake);
+  fgTie("/controls/brakes/right", getRightBrake, setRightBrake);
+  fgTie("/controls/brakes/center", getRightBrake, setCenterBrake);
+#endif
 
                                // Autopilot
-  TIE_BOOL("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
-  TIE_DOUBLE("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
-  TIE_BOOL("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
-  TIE_DOUBLE("/autopilot/settings/heading", getAPHeading, setAPHeading);
-  TIE_DOUBLE("/autopilot/settings/heading-magnetic",
+  fgTie("/autopilot/locks/altitude", getAPAltitudeLock, setAPAltitudeLock);
+  fgTie("/autopilot/settings/altitude", getAPAltitude, setAPAltitude);
+  fgTie("/autopilot/locks/heading", getAPHeadingLock, setAPHeadingLock);
+  fgTie("/autopilot/settings/heading", getAPHeading, setAPHeading);
+  fgTie("/autopilot/settings/heading-magnetic",
              getAPHeadingMag, setAPHeadingMag);
-  TIE_BOOL("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
+  fgTie("/autopilot/locks/nav1", getAPNAV1Lock, setAPNAV1Lock);
 
                                // Radio navigation
-  TIE_DOUBLE("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
-  TIE_DOUBLE("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
-  TIE_DOUBLE("/radios/nav1/radials/actual", getNAV1Radial, 0);
-  TIE_DOUBLE("/radios/nav1/radials/selected",
+  fgTie("/radios/nav1/frequencies/selected", getNAV1Freq, setNAV1Freq);
+  fgTie("/radios/nav1/frequencies/standby", getNAV1AltFreq, setNAV1AltFreq);
+  fgTie("/radios/nav1/radials/actual", getNAV1Radial);
+  fgTie("/radios/nav1/radials/selected",
              getNAV1SelRadial, setNAV1SelRadial);
-  TIE_DOUBLE("/radios/nav1/dme/distance", getNAV1DistDME, 0);
-  TIE_BOOL("/radios/nav1/to-flag", getNAV1TO, 0);
-  TIE_BOOL("/radios/nav1/from-flag", getNAV1FROM, 0);
-  TIE_BOOL("/radios/nav1/in-range", getNAV1InRange, 0);
-  TIE_BOOL("/radios/nav1/dme/in-range", getNAV1DMEInRange, 0);
+  fgTie("/radios/nav1/dme/distance", getNAV1DistDME);
+  fgTie("/radios/nav1/to-flag", getNAV1TO);
+  fgTie("/radios/nav1/from-flag", getNAV1FROM);
+  fgTie("/radios/nav1/in-range", getNAV1InRange);
+  fgTie("/radios/nav1/dme/in-range", getNAV1DMEInRange);
                               
-  TIE_DOUBLE("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
-  TIE_DOUBLE("/radios/nav2/frequencies/standby",
+  fgTie("/radios/nav2/frequencies/selected", getNAV2Freq, setNAV2Freq);
+  fgTie("/radios/nav2/frequencies/standby",
              getNAV2AltFreq, setNAV2AltFreq);
-  TIE_DOUBLE("/radios/nav2/radials/actual", getNAV2Radial, 0);
-  TIE_DOUBLE("/radios/nav2/radials/selected",
+  fgTie("/radios/nav2/radials/actual", getNAV2Radial);
+  fgTie("/radios/nav2/radials/selected",
              getNAV2SelRadial, setNAV2SelRadial);
-  TIE_DOUBLE("/radios/nav2/dme/distance", getNAV2DistDME, 0);
-  TIE_BOOL("/radios/nav2/to-flag", getNAV2TO, 0);
-  TIE_BOOL("/radios/nav2/from-flag", getNAV2FROM, 0);
-  TIE_BOOL("/radios/nav2/in-range", getNAV2InRange, 0);
-  TIE_BOOL("/radios/nav2/dme/in-range", getNAV2DMEInRange, 0);
-
-  TIE_DOUBLE("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
-  TIE_DOUBLE("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
-  TIE_DOUBLE("/radios/adf/rotation", getADFRotation, setADFRotation);
-
-  TIE_DOUBLE("/environment/visibility", getVisibility, setVisibility);
+  fgTie("/radios/nav2/dme/distance", getNAV2DistDME);
+  fgTie("/radios/nav2/to-flag", getNAV2TO);
+  fgTie("/radios/nav2/from-flag", getNAV2FROM);
+  fgTie("/radios/nav2/in-range", getNAV2InRange);
+  fgTie("/radios/nav2/dme/in-range", getNAV2DMEInRange);
+
+  fgTie("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
+  fgTie("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
+  fgTie("/radios/adf/rotation", getADFRotation, setADFRotation);
+
+                               // Weather
+  fgTie("/environment/visibility", getVisibility, setVisibility);
+  fgTie("/environment/wind-north", getWindNorth);
+  fgTie("/environment/wind-east", getWindEast);
+  fgTie("/environment/wind-down", getWindDown);
+
+                               // View
+  fgTie("/sim/view/axes/long", (double(*)())0, setViewAxisLong);
+  fgTie("/sim/view/axes/lat", (double(*)())0, setViewAxisLat);
 
   _needReinit = false;
 
@@ -320,6 +342,7 @@ FGBFI::update ()
 {
   _check_altitude();
   _check_lighting();
+  _set_view_from_axes();
   if (_needReinit) {
     reinit();
   }
@@ -1394,13 +1417,14 @@ FGBFI::getNAV1TO ()
   if (current_radiostack->get_nav1_inrange()) {
     double heading = current_radiostack->get_nav1_heading();
     double radial = current_radiostack->get_nav1_radial();
-    double var = FGBFI::getMagVar();
+//     double var = FGBFI::getMagVar();
     if (current_radiostack->get_nav1_loc()) {
       double offset = fabs(heading - radial);
       return (offset<= 8.0 || offset >= 352.0);
     } else {
-      double offset =
-       fabs(heading - var - radial);
+//       double offset =
+//     fabs(heading - var - radial);
+      double offset = fabs(heading - radial);
       return (offset <= 20.0 || offset >= 340.0);
     }
   } else {
@@ -1414,13 +1438,14 @@ FGBFI::getNAV1FROM ()
   if (current_radiostack->get_nav1_inrange()) {
     double heading = current_radiostack->get_nav1_heading();
     double radial = current_radiostack->get_nav1_radial();
-    double var = FGBFI::getMagVar();
+//     double var = FGBFI::getMagVar();
     if (current_radiostack->get_nav1_loc()) {
       double offset = fabs(heading - radial);
       return (offset >= 172.0 && offset<= 188.0);
     } else {
-      double offset =
-       fabs(heading - var - radial);
+//       double offset =
+//     fabs(heading - var - radial);
+      double offset = fabs(heading - radial);
       return (offset >= 160.0 && offset <= 200.0);
     }
   } else {
@@ -1477,13 +1502,14 @@ FGBFI::getNAV2TO ()
   if (current_radiostack->get_nav2_inrange()) {
     double heading = current_radiostack->get_nav2_heading();
     double radial = current_radiostack->get_nav2_radial();
-    double var = FGBFI::getMagVar();
+//     double var = FGBFI::getMagVar();
     if (current_radiostack->get_nav2_loc()) {
       double offset = fabs(heading - radial);
       return (offset<= 8.0 || offset >= 352.0);
     } else {
-      double offset =
-       fabs(heading - var - radial);
+//       double offset =
+//     fabs(heading - var - radial);
+      double offset = fabs(heading - radial);
       return (offset <= 20.0 || offset >= 340.0);
     }
   } else {
@@ -1497,13 +1523,14 @@ FGBFI::getNAV2FROM ()
   if (current_radiostack->get_nav2_inrange()) {
     double heading = current_radiostack->get_nav2_heading();
     double radial = current_radiostack->get_nav2_radial();
-    double var = FGBFI::getMagVar();
+//     double var = FGBFI::getMagVar();
     if (current_radiostack->get_nav2_loc()) {
       double offset = fabs(heading - radial);
       return (offset >= 172.0 && offset<= 188.0);
     } else {
-      double offset =
-       fabs(heading - var - radial);
+//       double offset =
+//     fabs(heading - var - radial);
+      double offset = fabs(heading - radial);
       return (offset >= 160.0 && offset <= 200.0);
     }
   } else {
@@ -1652,7 +1679,6 @@ FGBFI::getTargetAirport ()
 void
 FGBFI::setTargetAirport (string airportId)
 {
-  // cout << "setting target airport id = " << airportId << endl;
   globals->get_options()->set_airport_id(airportId);
 }
 
@@ -1722,6 +1748,53 @@ FGBFI::setVisibility (double visibility)
 }
 
 
+/**
+ * Get the current wind north velocity.
+ */
+double
+FGBFI::getWindNorth ()
+{
+  return current_aircraft.fdm_state->get_V_north_airmass();
+}
+
+
+/**
+ * Get the current wind east velocity.
+ */
+double
+FGBFI::getWindEast ()
+{
+  return current_aircraft.fdm_state->get_V_east_airmass();
+}
+
+
+/**
+ * Get the current wind down velocity.
+ */
+double
+FGBFI::getWindDown ()
+{
+  return current_aircraft.fdm_state->get_V_down_airmass();
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// View.
+////////////////////////////////////////////////////////////////////////
+
+void
+FGBFI::setViewAxisLong (double axis)
+{
+  axisLong = axis;
+}
+
+void
+FGBFI::setViewAxisLat (double axis)
+{
+  axisLat = axis;
+}
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Time
index cda9bc9eeda27bf13606a794d68c767d277ab96f..48681cbbc46020f496b1cc0855a8dfad66c17319 100644 (file)
@@ -259,6 +259,13 @@ public:
                                // Weather
   static double getVisibility ();
   static void setVisibility (double visiblity);
+  static double getWindNorth ();
+  static double getWindEast ();
+  static double getWindDown ();
+
+                               // View
+  static void setViewAxisLong (double axis);
+  static void setViewAxisLat (double axis);
 
 
                                 // Time (this varies with time) huh, huh
index 4ab671e0272eab3fc3191c2545e47150877ae1ab..ec69b9aca5973e44c6da9d6570960ecd331582bc 100644 (file)
@@ -751,6 +751,9 @@ bool fgInitSubsystems( void ) {
     // Initialize the BFI
     FGBFI::init();
 
+    controls.init();
+    controls.bind();
+
     FG_LOG( FG_GENERAL, FG_INFO, endl);
 
     return true;
index 6d0f763e47cd777336c71a9f8ee29e607106241c..e44497ea4d8524b1bac3defdb99ad6eab938f24e 100644 (file)
@@ -70,7 +70,7 @@
 #include "bfi.hxx"
 #include "globals.hxx"
 #include "keyboard.hxx"
-#include "save.hxx"
+#include "fg_props.hxx"
 
                                // From main.cxx
 extern void fgReshape( int width, int height );
@@ -434,7 +434,9 @@ void GLUTspecialkey(int k, int x, int y) {
        }
        case GLUT_KEY_F2: {
            FG_LOG(FG_INPUT, FG_INFO, "Saving flight");
+           cerr << "Opening output stream" << endl;
            ofstream output("fgfs.sav");
+           cerr << "output stream opened" << endl;
            if (output.good() && fgSaveFlight(output)) {
                output.close();
                FG_LOG(FG_INPUT, FG_INFO, "Saved flight to fgfs.sav");
diff --git a/src/Main/save.cxx b/src/Main/save.cxx
deleted file mode 100644 (file)
index 0ae2cbd..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-// save.cxx -- class to save and restore a flight.
-//
-// Written by Curtis Olson, started November 1999.
-//
-// Copyright (C) 1999  David Megginson - david@megginson.com
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-#include <simgear/compiler.h>
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <iostream>
-
-#include <simgear/misc/props.hxx>
-
-                               // FIXME: just for the temporary
-                               // tile cache update stuff.
-#include <simgear/debug/logstream.hxx>
-#include <simgear/constants.h>
-#include <Aircraft/aircraft.hxx>
-#include <GUI/gui.h>
-#include <Scenery/tilemgr.hxx>
-#include "globals.hxx"
-                               // end FIXME
-
-using std::istream;
-using std::ostream;
-
-
-/**
- * Save the current state of the simulator to a stream.
- */
-bool
-fgSaveFlight (ostream &output)
-{
-  return writeProperties(output, globals->get_props());
-}
-
-
-/**
- * Restore the current state of the simulator from a stream.
- */
-bool
-fgLoadFlight (istream &input)
-{
-  return readProperties(input, globals->get_props());
-}
-
-// end of save.cxx
diff --git a/src/Main/save.hxx b/src/Main/save.hxx
deleted file mode 100644 (file)
index 56626d4..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-// save.hxx -- class to save and restore a flight.
-//
-// Written by Curtis Olson, started November 1999.
-//
-// Copyright (C) 1999  David Megginson - david@megginson.com
-//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License as
-// published by the Free Software Foundation; either version 2 of the
-// License, or (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful, but
-// WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-// General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
-// $Id$
-
-#ifndef _SAVE_HXX
-#define _SAVE_HXX
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif                                   
-
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
-#include <simgear/math/sg_types.hxx>
-#include <iostream>
-
-FG_USING_NAMESPACE(std);
-
-extern bool fgSaveFlight (ostream &output);
-extern bool fgLoadFlight (istream &input);
-
-#endif // __SAVE_HXX
index a024c4113a333ab4f717356c9f5e8394111bc270..2f893375ae681646643fb71ee7bb22ce09cce4d0 100644 (file)
@@ -8,6 +8,6 @@ libNavaids_a_SOURCES = \
        nav.hxx navlist.hxx navlist.cxx
 
 testnavs_SOURCES = testnavs.cxx
-testnavs_LDADD = libNavaids.a -lsgmath -lsgmisc -lsgdebug -lz
+testnavs_LDADD = libNavaids.a -lsgmath -lsgmisc -lsgdebug -lsgmagvar -lz
 
 INCLUDES += -I$(top_srcdir) -I$(top_srcdir)/src
index 57a0c00a911dc316d5c9ba10ea85fa83236fe002..df7c63a4c9138a3f5f0fa7ef2486cebac694cb85 100644 (file)
 #ifndef _FG_NAV_HXX
 #define _FG_NAV_HXX
 
+#include <stdio.h>
 
 #include <simgear/compiler.h>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/misc/fgstream.hxx>
+#include <simgear/magvar/magvar.hxx>
 
 #ifdef FG_HAVE_STD_INCLUDES
 #  include <istream>
@@ -53,7 +55,8 @@ class FGNav {
     int freq;
     int range;
     bool has_dme;
-    char ident[5];
+    string ident;              // to avoid a core dump with corrupt data
+    int offset;                        // offset from true north (negative = W)
 
 public:
 
@@ -70,7 +73,8 @@ public:
     inline int get_freq() const { return freq; }
     inline int get_range() const { return range; }
     inline bool get_has_dme() const { return has_dme; }
-    inline char *get_ident() { return ident; }
+    inline const char *get_ident() { return ident.c_str(); }
+    inline int get_offset () const { return offset; }
 
     /* inline void set_type( char t ) { type = t; }
     inline void set_lon( double l ) { lon = l; }
@@ -89,9 +93,11 @@ inline istream&
 operator >> ( istream& in, FGNav& n )
 {
     double f;
-    char c;
+    char c /* , offset_dir */ ;
+    string offset_s;
+    
     in >> n.type >> n.lat >> n.lon >> n.elev >> f >> n.range 
-       >> c >> n.ident;
+       >> c >> n.ident >> offset_s;
 
     n.freq = (int)(f*100.0 + 0.5);
     if ( c == 'Y' ) {
@@ -100,6 +106,30 @@ operator >> ( istream& in, FGNav& n )
        n.has_dme = false;
     }
 
+    // Calculate the offset from true north.
+    // cout << "Calculating offset for navaid " << n.ident << endl;
+    if (offset_s == "XXX") {
+       // default to mag var as of 1990-01-01 (Julian 2447892.5)
+       double var = sgGetMagVar(n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD,
+                                n.elev * FEET_TO_METER,
+                                2447892.5) * RAD_TO_DEG;
+       // cout << "Default variation at " << n.lon << ',' << n.lat
+       //      << " is " << var << endl;
+       if (var - int(var) >= 0.5)
+           n.offset = int(var) + 1;
+       else if (var - int(var) <= -0.5)
+           n.offset = int(var) - 1;
+       else
+           n.offset = int(var);
+       // cout << "Defaulted to offset of " << n.offset << endl;
+    } else {
+       char direction;
+       sscanf(offset_s.c_str(), "%d%c", &(n.offset), &direction);
+       if (direction == 'W')
+           n.offset = 0 - n.offset;
+       // cout << "Explicit offset of " << n.offset << endl;
+    }
+
     // generate cartesian coordinates
     Point3D geod( n.lon * DEG_TO_RAD, n.lat * DEG_TO_RAD, n.elev );
     Point3D cart = sgGeodToCart( geod );