1
0
Fork 0

1. Added src/Main/fgfs.hxx as a standard, top-level include file for

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.
This commit is contained in:
curt 2001-01-05 17:38:58 +00:00
parent 5ef00ab621
commit 66650e4148
15 changed files with 359 additions and 235 deletions

View 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;
}

View 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;

View 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;

View 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 ()
{
}

View 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);

View 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

View 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 \

View file

@ -20,16 +20,7 @@
//
// $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,31 +164,54 @@ static inline void _check_lighting ()
// 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
////////////////////////////////////////////////////////////////////////
// Local functions
////////////////////////////////////////////////////////////////////////
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
TIE_INT(const char * name, int (*getter)(), void (*setter)(int)) {
globals->get_props()->tie(name, SGRawValueFunctions<int>(getter, setter));
}
static inline void
TIE_DOUBLE(const char * name, double (*getter)(), void (*setter)(double)) {
globals->get_props()->tie(name, SGRawValueFunctions<double>(getter, setter));
}
static inline void
TIE_STRING(const char * name, string (*getter)(), void (*setter)(string)) {
globals->get_props()->tie(name, SGRawValueFunctions<string>(getter, setter));
}
/**
* 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);
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);
TIE_DOUBLE("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
TIE_DOUBLE("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
TIE_DOUBLE("/radios/adf/rotation", getADFRotation, setADFRotation);
fgTie("/radios/adf/frequencies/selected", getADFFreq, setADFFreq);
fgTie("/radios/adf/frequencies/standby", getADFAltFreq, setADFAltFreq);
fgTie("/radios/adf/rotation", getADFRotation, setADFRotation);
TIE_DOUBLE("/environment/visibility", getVisibility, setVisibility);
// 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();
}
////////////////////////////////////////////////////////////////////////
// View.
////////////////////////////////////////////////////////////////////////
void
FGBFI::setViewAxisLong (double axis)
{
axisLong = axis;
}
void
FGBFI::setViewAxisLat (double axis)
{
axisLat = axis;
}
////////////////////////////////////////////////////////////////////////
// Time

View 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

View 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;

View 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");

View file

@ -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

View file

@ -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

View 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

View file

@ -24,10 +24,12 @@
#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 );