to shared state inside Flight Gear.
#include <simgear/debug/logstream.hxx>
#include <simgear/misc/fgpath.hxx>
#include <Main/options.hxx>
+#include <Main/bfi.hxx>
#include <Objects/texload.h>
#include <Autopilot/autopilot.hxx>
#include <Time/fg_time.hxx>
// or BFI (Big Friendly Interface).
////////////////////////////////////////////////////////////////////////
-/**
- * Return the indicated airspeed in knots.
- */
-static double
-panelGetSpeed ()
-{
- return get_speed();
-}
-
-/**
- * Return the roll in degrees.
- */
-static double
-panelGetRoll ()
-{
- return get_roll() * RAD_TO_DEG;
-}
-
-/**
- * Return the pitch in degrees.
- */
-static double
-panelGetPitch ()
-{
- return get_pitch() * RAD_TO_DEG;
-}
-
-/**
- * Return the altitude in feet.
- */
-static double
-panelGetAltitude ()
-{
- return get_altitude();
-}
-
-/**
- * Return the sideslip (units unknown).
- */
-static double
-panelGetSideSlip ()
-{
- return get_sideslip();
-}
-
-/**
- * Return the heading in degrees.
- */
-static double
-panelGetHeading ()
-{
- return get_heading();
-}
-
-/**
- * Return the current autopilot heading in degrees.
- */
-static double
-panelGetAPHeading ()
-{
- return fgAPget_TargetHeading();
-}
-
-/**
- * Return the climb rate in feet/minute.
- */
-static double
-panelGetVerticalVelocity ()
-{
- return get_climb_rate();
-}
-
-/**
- * Return the throttle setting (0.0 - 1.0).
- */
-static double
-panelGetThrottle ()
-{
- return get_throttleval();
-}
-
-/**
- * Return the flaps setting (0.0 - 1.0).
- */
-static double
-panelGetFlaps ()
-{
- return controls.get_flaps();
-}
-
-static double
-panelGetAileron ()
-{
- return controls.get_aileron();
-}
-
-static double
-panelGetRudder ()
-{
- return controls.get_rudder();
-}
-
-static double
-panelGetElevator ()
-{
- return controls.get_elevator();
-}
-
-static double
-panelGetElevatorTrim ()
-{
- return controls.get_elevator_trim();
-}
-
static char * panelGetTime (char * buf)
{
struct tm * t = FGTime::cur_time_params->getGmt();
// they're hard-coded.
////////////////////////////////////////////////////////////////////////
+static ssgTexture *
+createTexture (const char * relativePath)
+{
+ return FGPanel::OurPanel->createTexture(relativePath);
+}
+
/**
* Construct an airspeed indicator for a single-engine prop.
*/
static FGPanelInstrument *
-makeAirspeedIndicator (int x, int y)
+createAirspeedIndicator (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: gauge background.
- inst->addLayer(0, "Textures/Panel/airspeed.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/airspeed.rgb"));
// Layer 1: needle.
// Rotates with airspeed.
- inst->addLayer(1, "Textures/Panel/long-needle.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/long-needle.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetSpeed,
+ FGBFI::getAirspeed,
30.0, 220.0, 36.0 / 20.0, -54.0);
return inst;
}
* Construct an artificial horizon.
*/
static FGPanelInstrument *
-makeHorizon (int x, int y)
+createHorizon (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: coloured background
// moves with roll only
- inst->addLayer(0, "Textures/Panel/horizon-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/horizon-bg.rgb"));
inst->addTransformation(0, FGInstrumentLayer::ROTATION,
- panelGetRoll,
+ FGBFI::getRoll,
-360.0, 360.0, -1.0, 0.0);
// Layer 1: floating horizon
// moves with roll and pitch
- inst->addLayer(1, "Textures/Panel/horizon-float.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/horizon-float.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetRoll,
+ FGBFI::getRoll,
-360.0, 360.0, -1.0, 0.0);
inst->addTransformation(1, FGInstrumentLayer::YSHIFT,
- panelGetPitch,
+ FGBFI::getPitch,
-20.0, 20.0, -(1.5 / 160.0) * SIX_W, 0.0);
// Layer 2: rim
// moves with roll only
- inst->addLayer(2, "Textures/Panel/horizon-rim.rgb");
+ inst->addLayer(2, createTexture("Textures/Panel/horizon-rim.rgb"));
inst->addTransformation(2, FGInstrumentLayer::ROTATION,
- panelGetRoll,
+ FGBFI::getRoll,
-360.0, 360.0, -1.0, 0.0);
// Layer 3: glass front of gauge
// fixed, with markings
- inst->addLayer(3, "Textures/Panel/horizon-fg.rgb");
+ inst->addLayer(3, createTexture("Textures/Panel/horizon-fg.rgb"));
return inst;
}
* Construct an altimeter.
*/
static FGPanelInstrument *
-makeAltimeter (int x, int y)
+createAltimeter (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/altimeter.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/altimeter.rgb"));
// Layer 1: hundreds needle (long)
// moves with altitude
- inst->addLayer(1, "Textures/Panel/long-needle.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/long-needle.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetAltitude,
+ FGBFI::getAltitude,
0.0, 100000.0, 360.0 / 1000.0, 0.0);
// Layer 2: thousands needle (short)
// moves with altitude
- inst->addLayer(2, "Textures/Panel/short-needle.rgb");
+ inst->addLayer(2, createTexture("Textures/Panel/short-needle.rgb"));
inst->addTransformation(2, FGInstrumentLayer::ROTATION,
- panelGetAltitude,
+ FGBFI::getAltitude,
0.0, 100000.0, 360.0 / 10000.0, 0.0);
// Layer 3: ten thousands bug (outside)
// moves with altitude
- inst->addLayer(3, "Textures/Panel/bug.rgb");
+ inst->addLayer(3, createTexture("Textures/Panel/bug.rgb"));
inst->addTransformation(3, FGInstrumentLayer::ROTATION,
- panelGetAltitude,
+ FGBFI::getAltitude,
0.0, 100000.0, 360.0 / 100000.0, 0.0);
return inst;
* Construct a turn coordinator.
*/
static FGPanelInstrument *
-makeTurnCoordinator (int x, int y)
+createTurnCoordinator (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: background
- inst->addLayer(0, "Textures/Panel/turn-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/turn-bg.rgb"));
// Layer 1: little plane
// moves with roll
- inst->addLayer(1, "Textures/Panel/turn.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/turn.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetRoll,
+ FGBFI::getRoll,
-30.0, 30.0, 1.0, 0.0);
// Layer 2: little ball
// moves with slip/skid
- inst->addLayer(2, "Textures/Panel/ball.rgb");
+ inst->addLayer(2, createTexture("Textures/Panel/ball.rgb"));
inst->addTransformation(2, FGInstrumentLayer::ROTATION,
- panelGetSideSlip,
+ FGBFI::getSideSlip,
-0.1, 0.1, 450.0, 0.0);
return inst;
* Construct a gyro compass.
*/
static FGPanelInstrument *
-makeGyroCompass (int x, int y)
+createGyroCompass (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: compass background
// rotates with heading
- inst->addLayer(0, "Textures/Panel/gyro-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/gyro-bg.rgb"));
inst->addTransformation(0, FGInstrumentLayer::ROTATION,
- panelGetHeading,
+ FGBFI::getHeading,
-360.0, 360.0, -1.0, 0.0);
// Layer 1: heading bug
// rotates with heading and AP heading
- inst->addLayer(1, "Textures/Panel/bug.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/bug.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetHeading,
+ FGBFI::getHeading,
-360.0, 360.0, -1.0, 0.0);
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetAPHeading,
+ FGBFI::getAPHeading,
-360.0, 360.0, 1.0, 0.0);
// Layer 2: fixed center
- inst->addLayer(2, "Textures/Panel/gyro-fg.rgb");
+ inst->addLayer(2, createTexture("Textures/Panel/gyro-fg.rgb"));
return inst;
}
* Construct a vertical velocity indicator.
*/
static FGPanelInstrument *
-makeVerticalVelocity (int x, int y)
+createVerticalVelocity (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/vertical.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/vertical.rgb"));
// Layer 1: needle
// moves with vertical velocity
- inst->addLayer(1, "Textures/Panel/long-needle.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/long-needle.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetVerticalVelocity,
+ FGBFI::getVerticalSpeed,
-2000.0, 2000.0, 42.0/500.0, 270.0);
return inst;
* Construct an RPM gauge.
*/
static FGPanelInstrument *
-makeRPMGauge (int x, int y)
+createRPMGauge (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SMALL_W, SMALL_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/rpm.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/rpm.rgb"));
// Layer 1: long needle
// FIXME: moves with throttle (for now)
- inst->addLayer(1, "Textures/Panel/long-needle.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/long-needle.rgb"));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetThrottle,
+ FGBFI::getThrottle,
0.0, 100.0, 300.0, -150.0);
return inst;
* Construct a flap position indicator.
*/
static FGPanelInstrument *
-makeFlapIndicator (int x, int y)
+createFlapIndicator (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SMALL_W, SMALL_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/flaps.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/flaps.rgb"));
// Layer 1: long needle
// shifted over, rotates with flap position
- inst->addLayer(1, "Textures/Panel/long-needle.rgb");
+ inst->addLayer(1, createTexture("Textures/Panel/long-needle.rgb"));
inst->addTransformation(1, FGInstrumentLayer::XSHIFT,
-(SMALL_W / 4) + (SMALL_W / 16));
inst->addTransformation(1, FGInstrumentLayer::ROTATION,
- panelGetFlaps,
+ FGBFI::getFlaps,
0.0, 1.0, 120.0, 30.0);
return inst;
}
static FGPanelInstrument *
-makeChronometer (int x, int y)
+createChronometer (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SMALL_W, SMALL_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/clock.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/clock.rgb"));
// Layer 1: text
// displays current GMT
* Construct control-position indicators.
*/
static FGPanelInstrument *
-makeControls (int x, int y)
+createControls (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SMALL_W, SMALL_W);
// Layer 0: gauge background
- inst->addLayer(0, "Textures/Panel/controls.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/controls.rgb"));
// Layer 1: bug
// moves left-right with aileron
- inst->addLayer(1, "Textures/Panel/bug.rgb");
- inst->addTransformation(1, FGInstrumentLayer::XSHIFT, panelGetAileron,
+ inst->addLayer(1, createTexture("Textures/Panel/bug.rgb"));
+ inst->addTransformation(1, FGInstrumentLayer::XSHIFT, FGBFI::getAileron,
-1.0, 1.0, SMALL_W * .75 / 2.0, 0.0);
// Layer 2: bug
// moves left-right with rudder
- inst->addLayer(2, "Textures/Panel/bug.rgb");
+ inst->addLayer(2, createTexture("Textures/Panel/bug.rgb"));
inst->addTransformation(2, FGInstrumentLayer::ROTATION, 180.0);
- inst->addTransformation(2, FGInstrumentLayer::XSHIFT, panelGetRudder,
+ inst->addTransformation(2, FGInstrumentLayer::XSHIFT, FGBFI::getRudder,
-1.0, 1.0, -SMALL_W * .75 / 2.0, 0.0);
// Layer 3: bug
// moves up-down with elevator trim
- inst->addLayer(3, "Textures/Panel/bug.rgb");
+ inst->addLayer(3, createTexture("Textures/Panel/bug.rgb"));
inst->addTransformation(3, FGInstrumentLayer::ROTATION, 270.0);
inst->addTransformation(3, FGInstrumentLayer::YSHIFT,
-SMALL_W * (3.0 / 8.0));
- inst->addTransformation(3, FGInstrumentLayer::XSHIFT, panelGetElevatorTrim,
+ inst->addTransformation(3, FGInstrumentLayer::XSHIFT, FGBFI::getElevatorTrim,
-1.0, 1.0, SMALL_W * .75 / 2.0, 0.0);
// Layer 4: bug
// moves up-down with elevator
- inst->addLayer(4, "Textures/Panel/bug.rgb");
+ inst->addLayer(4, createTexture("Textures/Panel/bug.rgb"));
inst->addTransformation(4, FGInstrumentLayer::ROTATION, 90.0);
inst->addTransformation(4, FGInstrumentLayer::YSHIFT,
-SMALL_W * (3.0 / 8.0));
- inst->addTransformation(4, FGInstrumentLayer::XSHIFT, panelGetElevator,
+ inst->addTransformation(4, FGInstrumentLayer::XSHIFT, FGBFI::getElevator,
-1.0, 1.0, -SMALL_W * .75 / 2.0, 0.0);
return inst;
* Construct a NAV1 gauge (dummy for now).
*/
static FGPanelInstrument *
-makeNAV1 (int x, int y)
+createNAV1 (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: background
- inst->addLayer(0, "Textures/Panel/gyro-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/gyro-bg.rgb"));
return inst;
}
* Construct a NAV2 gauge (dummy for now).
*/
static FGPanelInstrument *
-makeNAV2 (int x, int y)
+createNAV2 (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: background
- inst->addLayer(0, "Textures/Panel/gyro-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/gyro-bg.rgb"));
return inst;
}
* Construct an ADF gauge (dummy for now).
*/
static FGPanelInstrument *
-makeADF (int x, int y)
+createADF (int x, int y)
{
FGLayeredInstrument * inst = new FGLayeredInstrument(x, y, SIX_W, SIX_W);
// Layer 0: background
- inst->addLayer(0, "Textures/Panel/gyro-bg.rgb");
+ inst->addLayer(0, createTexture("Textures/Panel/gyro-bg.rgb"));
return inst;
}
int x = SIX_X;
int y = SIX_Y;
- FGPath tpath(current_options.get_fg_root());
- tpath.append("Textures/Panel/panel-bg.rgb");
- _bg = new ssgTexture((char *)tpath.c_str(), false, false);
+ _bg = createTexture("Textures/Panel/panel-bg.rgb");
// Chronometer alone at side
x = SIX_X - SIX_SPACING - 8;
- _instruments.push_back(makeChronometer(x, y));
+ _instruments.push_back(createChronometer(x, y));
// Top row
x = SIX_X;
- _instruments.push_back(makeAirspeedIndicator(x, y));
+ _instruments.push_back(createAirspeedIndicator(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeHorizon(x, y));
+ _instruments.push_back(createHorizon(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeAltimeter(x, y));
+ _instruments.push_back(createAltimeter(x, y));
x += SIX_SPACING + 20;
- _instruments.push_back(makeNAV1(x, y));
+ _instruments.push_back(createNAV1(x, y));
// Middle row
x = SIX_X;
y -= SIX_SPACING;
- _instruments.push_back(makeTurnCoordinator(x, y));
+ _instruments.push_back(createTurnCoordinator(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeGyroCompass(x, y));
+ _instruments.push_back(createGyroCompass(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeVerticalVelocity(x, y));
+ _instruments.push_back(createVerticalVelocity(x, y));
x += SIX_SPACING + 20;
- _instruments.push_back(makeNAV2(x, y));
+ _instruments.push_back(createNAV2(x, y));
// Bottom row
x = SIX_X;
y -= SIX_SPACING + 10;
- _instruments.push_back(makeControls(x, y));
+ _instruments.push_back(createControls(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeFlapIndicator(x, y));
+ _instruments.push_back(createFlapIndicator(x, y));
x += SIX_SPACING;
- _instruments.push_back(makeRPMGauge(x, y));
+ _instruments.push_back(createRPMGauge(x, y));
x += SIX_SPACING + 20;
y += 10;
- _instruments.push_back(makeADF(x, y));
+ _instruments.push_back(createADF(x, y));
}
FGPanel::~FGPanel ()
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
+ssgTexture *
+FGPanel::createTexture (const char * relativePath)
+{
+ ssgTexture *texture;
+
+ texture = _textureMap[relativePath];
+ if (texture == 0) {
+ FGPath tpath(current_options.get_fg_root());
+ tpath.append(relativePath);
+ texture = new ssgTexture((char *)tpath.c_str(), false, false);
+ _textureMap[relativePath] = texture;
+ cerr << "Created texture " << relativePath
+ << " handle=" << texture->getHandle() << endl;
+ }
+
+ return texture;
+}
+
\f
////////////////////////////////////////////////////////////////////////
}
void
-FGLayeredInstrument::addLayer (int layer, const char *textureName)
+FGLayeredInstrument::addLayer (int layer, ssgTexture * texture)
{
- addLayer(new FGTexturedInstrumentLayer(textureName, _w, _h, layer));
+ addLayer(new FGTexturedInstrumentLayer(texture, _w, _h, layer));
}
void
FGInstrumentLayer::~FGInstrumentLayer ()
{
- transformation_list::iterator it;
- transformation_list::iterator end;
+ transformation_list::iterator it = _transformations.begin();
+ transformation_list::iterator end = _transformations.end();
while (it != end) {
delete *it;
it++;
// Implementation of FGTexturedInstrumentLayer.
////////////////////////////////////////////////////////////////////////
-FGTexturedInstrumentLayer::FGTexturedInstrumentLayer (const char *tname,
- int w, int h, int z)
- : FGInstrumentLayer(w, h, z)
-{
- setTexture(tname);
-}
+// FGTexturedInstrumentLayer::FGTexturedInstrumentLayer (const char *tname,
+// int w, int h, int z)
+// : FGInstrumentLayer(w, h, z)
+// {
+// setTexture(tname);
+// }
FGTexturedInstrumentLayer::FGTexturedInstrumentLayer (ssgTexture * texture,
int w, int h, int z)
glPopMatrix();
}
-void
-FGTexturedInstrumentLayer::setTexture (const char *textureName)
-{
- FGPath tpath(current_options.get_fg_root());
- tpath.append(textureName);
- ssgTexture * texture = new ssgTexture((char *)tpath.c_str(), false, false);
- cerr << "Loaded texture " << textureName << endl;
- setTexture(texture);
-}
+// void
+// FGTexturedInstrumentLayer::setTexture (const char *textureName)
+// {
+// FGPath tpath(current_options.get_fg_root());
+// tpath.append(textureName);
+// ssgTexture * texture = new ssgTexture((char *)tpath.c_str(), false, false);
+// setTexture(texture);
+// }
\f
#include <plib/ssg.h>
#include <vector>
+#include <hash_map>
#include <plib/fnt.h>
FG_USING_STD(vector);
+FG_USING_STD(hash_map);
class FGPanelInstrument;
-
\f
////////////////////////////////////////////////////////////////////////
// Instrument panel class.
{
public:
- typedef vector<FGPanelInstrument *> instrument_list_type;
-
FGPanel ();
virtual ~FGPanel ();
+ virtual ssgTexture * createTexture (const char * relativePath);
+
// Legacy interface from old panel.
static FGPanel * OurPanel;
virtual float get_height () const;
virtual void Update () const;
private:
+
+ typedef vector<FGPanelInstrument *> instrument_list_type;
+
int _x, _y, _w, _h;
int _panel_h;
ssgTexture * _bg;
+ // Internalization table.
+ hash_map<const char *,ssgTexture *> _textureMap;
+
+ // List of instruments in panel.
instrument_list_type _instruments;
};
virtual void draw () const;
virtual void addLayer (FGInstrumentLayer *layer);
- virtual void addLayer (int i, const char *textureName);
+ virtual void addLayer (int i, ssgTexture * texture);
virtual void addTransformation (int layer,
FGInstrumentLayer::transform_type type,
FGInstrumentLayer::transform_func func,
class FGTexturedInstrumentLayer : public FGInstrumentLayer
{
public:
- FGTexturedInstrumentLayer (const char * textureName,
- int w, int h, int z);
FGTexturedInstrumentLayer (ssgTexture * texture,
int w, int h, int z);
virtual ~FGTexturedInstrumentLayer ();
virtual void draw () const;
- virtual void setTexture (const char *textureName);
virtual void setTexture (ssgTexture * texture) { _texture = texture; }
private:
bin_SCRIPTS = runfgfs runfgfs.bat
fgfs_SOURCES = \
+ bfi.cxx bfi.hxx \
fg_init.cxx fg_init.hxx \
fg_io.cxx fg_io.hxx \
keyboard.cxx keyboard.hxx \
--- /dev/null
+// bfi.cxx - Big Friendly Interface implementation
+//
+// Written by David Megginson, started February, 2000.
+//
+// Copyright (C) 2000 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$
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#if defined( FG_HAVE_NATIVE_SGI_COMPILERS )
+# include <iostream.h>
+#else
+# include <iostream>
+#endif
+
+#include <simgear/constants.h>
+#include <simgear/math/fg_types.hxx>
+
+#include <Aircraft/aircraft.hxx>
+#include <Controls/controls.hxx>
+#include <Autopilot/autopilot.hxx>
+#include <Time/fg_time.hxx>
+#include <Astro/solarsystem.hxx>
+#ifndef FG_OLD_WEATHER
+# include <WeatherCM/FGLocalWeatherDatabase.h>
+#else
+# include <Weather/weather.hxx>
+#endif
+
+#include "options.hxx"
+#include "save.hxx"
+#include "fg_init.hxx"
+
+FG_USING_NAMESPACE(std);
+
+ // FIXME: these are not part of the
+ // published interface!!!
+extern fgAPDataPtr APDataGlobal;
+extern void fgAPAltitudeSet (double new_altitude);
+extern void fgAPHeadingSet (double new_heading);
+
+
+#include "bfi.hxx"
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Static variables.
+////////////////////////////////////////////////////////////////////////
+
+bool FGBFI::_needReinit = false;
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Local functions
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Reinitialize FGFS if required.
+ *
+ * Some changes (especially those in aircraft position) require that
+ * FGFS be reinitialized afterwards. Rather than reinitialize after
+ * every change, the setter methods simply set a flag so that there
+ * can be a single reinit at the end of the frame.
+ */
+void
+FGBFI::update ()
+{
+ if (_needReinit) {
+ reinit();
+ }
+}
+
+
+/**
+ * Reinitialize FGFS to use the new BFI settings.
+ */
+void
+FGBFI::reinit ()
+{
+ // Save the state of everything
+ // that's going to get clobbered
+ // when we reinit the subsystems.
+
+ // TODO: add more AP stuff
+ double elevator = getElevator();
+ double aileron = getAileron();
+ double rudder = getRudder();
+ double throttle = getThrottle();
+ double elevator_trim = getElevatorTrim();
+ double flaps = getFlaps();
+ double brake = getBrake();
+ bool apHeadingLock = getAPHeadingLock();
+ double apHeading = getAPHeading();
+ bool apAltitudeLock = getAPAltitudeLock();
+ double apAltitude = getAPAltitude();
+ const string &targetAirport = getTargetAirport();
+ bool gpsLock = getGPSLock();
+ double gpsLatitude = getGPSTargetLatitude();
+ double gpsLongitude = getGPSTargetLongitude();
+
+ fgReInitSubsystems();
+ solarSystemRebuild();
+ cur_light_params.Update();
+
+ // Restore all of the old states.
+ setElevator(elevator);
+ setAileron(aileron);
+ setRudder(rudder);
+ setThrottle(throttle);
+ setElevatorTrim(elevator_trim);
+ setFlaps(flaps);
+ setBrake(brake);
+ setAPHeadingLock(apHeadingLock);
+ setAPHeading(apHeading);
+ setAPAltitudeLock(apAltitudeLock);
+ setAPAltitude(apAltitude);
+ setTargetAirport(targetAirport);
+ setGPSLock(gpsLock);
+ setGPSTargetLatitude(gpsLatitude);
+ setGPSTargetLongitude(gpsLongitude);
+
+ _needReinit = false;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Simulation.
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Return the flight model as an integer.
+ *
+ * TODO: use a string instead.
+ */
+int
+FGBFI::getFlightModel ()
+{
+ return current_options.get_flight_model();
+}
+
+
+/**
+ * Set the flight model as an integer.
+ *
+ * TODO: use a string instead.
+ */
+void
+FGBFI::setFlightModel (int model)
+{
+ current_options.set_flight_model(model);
+ needReinit();
+}
+
+
+/**
+ * Return the current Zulu time.
+ */
+time_t
+FGBFI::getTimeGMT ()
+{
+ // FIXME: inefficient
+ return mktime(FGTime::cur_time_params->getGmt());
+}
+
+
+/**
+ * Set the current Zulu time.
+ */
+void
+FGBFI::setTimeGMT (time_t time)
+{
+ // FIXME: need to update lighting
+ // and solar system
+ current_options.set_time_offset(time);
+ current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
+ FGTime::cur_time_params->init(*cur_fdm_state);
+ FGTime::cur_time_params->update(*cur_fdm_state);
+ needReinit();
+}
+
+
+/**
+ * Return true if the HUD is visible.
+ */
+bool
+FGBFI::getHUDVisible ()
+{
+ return current_options.get_hud_status();
+}
+
+
+/**
+ * Ensure that the HUD is visible or hidden.
+ */
+void
+FGBFI::setHUDVisible (bool visible)
+{
+ current_options.set_hud_status(visible);
+}
+
+
+/**
+ * Return true if the 2D panel is visible.
+ */
+bool
+FGBFI::getPanelVisible ()
+{
+ return current_options.get_panel_status();
+}
+
+
+/**
+ * Ensure that the 2D panel is visible or hidden.
+ */
+void
+FGBFI::setPanelVisible (bool visible)
+{
+ if (current_options.get_panel_status() != visible) {
+ current_options.toggle_panel();
+ }
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Position
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Return the current latitude in degrees (negative for south).
+ */
+double
+FGBFI::getLatitude ()
+{
+ return current_aircraft.fdm_state->get_Latitude() * RAD_TO_DEG;
+}
+
+
+/**
+ * Set the current latitude in degrees (negative for south).
+ */
+void
+FGBFI::setLatitude (double latitude)
+{
+ current_options.set_lat(latitude);
+ needReinit();
+}
+
+
+/**
+ * Return the current longitude in degrees (negative for west).
+ */
+double
+FGBFI::getLongitude ()
+{
+ return current_aircraft.fdm_state->get_Longitude() * RAD_TO_DEG;
+}
+
+
+/**
+ * Set the current longitude in degrees (negative for west).
+ */
+void
+FGBFI::setLongitude (double longitude)
+{
+ current_options.set_lon(longitude);
+ needReinit();
+}
+
+
+/**
+ * Return the current altitude in feet.
+ */
+double
+FGBFI::getAltitude ()
+{
+ return current_aircraft.fdm_state->get_Altitude();
+}
+
+
+/**
+ * Set the current altitude in feet.
+ */
+void
+FGBFI::setAltitude (double altitude)
+{
+ current_options.set_altitude(altitude * FEET_TO_METER);
+ needReinit();
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Attitude
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Return the current heading in degrees.
+ */
+double
+FGBFI::getHeading ()
+{
+ return current_aircraft.fdm_state->get_Psi() * RAD_TO_DEG;
+}
+
+
+/**
+ * Set the current heading in degrees.
+ */
+void
+FGBFI::setHeading (double heading)
+{
+ current_options.set_heading(heading);
+ needReinit();
+}
+
+
+/**
+ * Return the current pitch in degrees.
+ */
+double
+FGBFI::getPitch ()
+{
+ return current_aircraft.fdm_state->get_Theta() * RAD_TO_DEG;
+}
+
+
+/**
+ * Set the current pitch in degrees.
+ */
+void
+FGBFI::setPitch (double pitch)
+{
+
+ current_options.set_pitch(pitch);
+ needReinit();
+}
+
+
+/**
+ * Return the current roll in degrees.
+ */
+double
+FGBFI::getRoll ()
+{
+ return current_aircraft.fdm_state->get_Phi() * RAD_TO_DEG;
+}
+
+
+/**
+ * Set the current roll in degrees.
+ */
+void
+FGBFI::setRoll (double roll)
+{
+ current_options.set_roll(roll);
+ needReinit();
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Velocities
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Return the current airspeed in knots.
+ */
+double
+FGBFI::getAirspeed ()
+{
+ // FIXME: should we add speed-up?
+ return current_aircraft.fdm_state->get_V_calibrated_kts();
+}
+
+
+/**
+ * Return the current sideslip (FIXME: units unknown).
+ */
+double
+FGBFI::getSideSlip ()
+{
+ return current_aircraft.fdm_state->get_Beta();
+}
+
+
+/**
+ * Return the current climb rate in feet/second (FIXME: verify).
+ */
+double
+FGBFI::getVerticalSpeed ()
+{
+ // What about meters?
+ return current_aircraft.fdm_state->get_Climb_Rate() * 60.0;
+}
+
+
+/**
+ * Get the current north velocity (units??).
+ */
+double
+FGBFI::getSpeedNorth ()
+{
+ return current_aircraft.fdm_state->get_V_north();
+}
+
+
+/**
+ * Set the current north velocity (units??).
+ */
+void
+FGBFI::setSpeedNorth (double speed)
+{
+ current_options.set_uBody(speed);
+ needReinit();
+}
+
+
+/**
+ * Get the current east velocity (units??).
+ */
+double
+FGBFI::getSpeedEast ()
+{
+ return current_aircraft.fdm_state->get_V_east();
+}
+
+
+/**
+ * Set the current east velocity (units??).
+ */
+void
+FGBFI::setSpeedEast (double speed)
+{
+ current_options.set_vBody(speed);
+ needReinit();
+}
+
+
+/**
+ * Get the current down velocity (units??).
+ */
+double
+FGBFI::getSpeedDown ()
+{
+ return current_aircraft.fdm_state->get_V_down();
+}
+
+
+/**
+ * Set the current down velocity (units??).
+ */
+void
+FGBFI::setSpeedDown (double speed)
+{
+ current_options.set_wBody(speed);
+ needReinit();
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Controls
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Get the throttle setting, from 0.0 (none) to 1.0 (full).
+ */
+double
+FGBFI::getThrottle ()
+{
+ // FIXME: add throttle selector
+ return controls.get_throttle(0);
+}
+
+
+/**
+ * Set the throttle, from 0.0 (none) to 1.0 (full).
+ */
+void
+FGBFI::setThrottle (double throttle)
+{
+ // FIXME: allow throttle selection
+ // FIXME: clamp?
+ controls.set_throttle(0, throttle);
+}
+
+
+/**
+ * Get the flaps setting, from 0.0 (none) to 1.0 (full).
+ */
+double
+FGBFI::getFlaps ()
+{
+ return controls.get_flaps();
+}
+
+
+/**
+ * Set the flaps, from 0.0 (none) to 1.0 (full).
+ */
+void
+FGBFI::setFlaps (double flaps)
+{
+ // FIXME: clamp?
+ controls.set_flaps(flaps);
+}
+
+
+/**
+ * Get the aileron, from -1.0 (left) to 1.0 (right).
+ */
+double
+FGBFI::getAileron ()
+{
+ return controls.get_aileron();
+}
+
+
+/**
+ * Set the aileron, from -1.0 (left) to 1.0 (right).
+ */
+void
+FGBFI::setAileron (double aileron)
+{
+ // FIXME: clamp?
+ controls.set_aileron(aileron);
+}
+
+
+/**
+ * Get the rudder setting, from -1.0 (left) to 1.0 (right).
+ */
+double
+FGBFI::getRudder ()
+{
+ return controls.get_rudder();
+}
+
+
+/**
+ * Set the rudder, from -1.0 (left) to 1.0 (right).
+ */
+void
+FGBFI::setRudder (double rudder)
+{
+ // FIXME: clamp?
+ controls.set_rudder(rudder);
+}
+
+
+/**
+ * Get the elevator setting, from -1.0 (down) to 1.0 (up).
+ */
+double
+FGBFI::getElevator ()
+{
+ return controls.get_elevator();
+}
+
+
+/**
+ * Set the elevator, from -1.0 (down) to 1.0 (up).
+ */
+void
+FGBFI::setElevator (double elevator)
+{
+ // FIXME: clamp?
+ controls.set_elevator(elevator);
+}
+
+
+/**
+ * Get the elevator trim, from -1.0 (down) to 1.0 (up).
+ */
+double
+FGBFI::getElevatorTrim ()
+{
+ return controls.get_elevator_trim();
+}
+
+
+/**
+ * Set the elevator trim, from -1.0 (down) to 1.0 (up).
+ */
+void
+FGBFI::setElevatorTrim (double trim)
+{
+ // FIXME: clamp?
+ controls.set_elevator_trim(trim);
+}
+
+
+/**
+ * Get the brake setting, from 0.0 (none) to 1.0 (full).
+ */
+double
+FGBFI::getBrake ()
+{
+ // FIXME: add brake selector
+ return controls.get_brake(0);
+}
+
+
+/**
+ * Set the brake, from 0.0 (none) to 1.0 (full).
+ */
+void
+FGBFI::setBrake (double brake)
+{
+ // FIXME: clamp?
+ // FIXME: allow brake selection
+ controls.set_brake(0, brake);
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Autopilot
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Get the autopilot altitude lock (true=on).
+ */
+bool
+FGBFI::getAPAltitudeLock ()
+{
+ return fgAPAltitudeEnabled();
+}
+
+
+/**
+ * Set the autopilot altitude lock (true=on).
+ */
+void
+FGBFI::setAPAltitudeLock (bool lock)
+{
+ APDataGlobal->altitude_hold = lock;
+}
+
+
+/**
+ * Get the autopilot target altitude in feet.
+ */
+double
+FGBFI::getAPAltitude ()
+{
+ return fgAPget_TargetAltitude() * METER_TO_FEET;
+}
+
+
+/**
+ * Set the autopilot target altitude in feet.
+ */
+void
+FGBFI::setAPAltitude (double altitude)
+{
+ fgAPAltitudeSet(altitude);
+}
+
+
+/**
+ * Get the autopilot heading lock (true=on).
+ */
+bool
+FGBFI::getAPHeadingLock ()
+{
+ return fgAPHeadingEnabled();
+}
+
+
+/**
+ * Set the autopilot heading lock (true=on).
+ */
+void
+FGBFI::setAPHeadingLock (bool lock)
+{
+ APDataGlobal->heading_hold = lock;
+}
+
+
+/**
+ * Get the autopilot target heading in degrees.
+ */
+double
+FGBFI::getAPHeading ()
+{
+ return fgAPget_TargetHeading();
+}
+
+
+/**
+ * Set the autopilot target heading in degrees.
+ */
+void
+FGBFI::setAPHeading (double heading)
+{
+ fgAPHeadingSet(heading);
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// GPS
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Get the autopilot GPS lock (true=on).
+ */
+bool
+FGBFI::getGPSLock ()
+{
+ return fgAPWayPointEnabled();
+}
+
+
+/**
+ * Set the autopilot GPS lock (true=on).
+ */
+void
+FGBFI::setGPSLock (bool lock)
+{
+ APDataGlobal->waypoint_hold = lock;
+}
+
+
+/**
+ * Get the GPS target airport code.
+ */
+const string
+FGBFI::getTargetAirport ()
+{
+ return current_options.get_airport_id();
+}
+
+
+/**
+ * Set the GPS target airport code.
+ */
+void
+FGBFI::setTargetAirport (const string &airportId)
+{
+ current_options.set_airport_id(airportId);
+}
+
+
+/**
+ * Get the GPS target latitude in degrees (negative for south).
+ */
+double
+FGBFI::getGPSTargetLatitude ()
+{
+ return fgAPget_TargetLatitude();
+}
+
+
+/**
+ * Set the GPS target latitude in degrees (negative for south).
+ */
+void
+FGBFI::setGPSTargetLatitude (double latitude)
+{
+ APDataGlobal->TargetLatitude = latitude;
+}
+
+
+/**
+ * Get the GPS target longitude in degrees (negative for west).
+ */
+double
+FGBFI::getGPSTargetLongitude ()
+{
+ return fgAPget_TargetLongitude();
+}
+
+
+/**
+ * Set the GPS target longitude in degrees (negative for west).
+ */
+void
+FGBFI::setGPSTargetLongitude (double longitude)
+{
+ APDataGlobal->TargetLongitude = longitude;
+}
+
+
+\f
+////////////////////////////////////////////////////////////////////////
+// Weather
+////////////////////////////////////////////////////////////////////////
+
+
+/**
+ * Get the current visible (units??).
+ */
+double
+FGBFI::getVisibility ()
+{
+#ifndef FG_OLD_WEATHER
+ return WeatherDatabase->getWeatherVisibility();
+#else
+ return current_weather.get_visibility();
+#endif
+}
+
+
+/**
+ * Set the current visibility (units??).
+ */
+void
+FGBFI::setVisibility (double visibility)
+{
+#ifndef FG_OLD_WEATHER
+ WeatherDatabase->setWeatherVisibility(visibility);
+#else
+ current_weather.set_visibility(visibility);
+#endif
+}
+
+
+// end of bfi.cxx
--- /dev/null
+// bfi.hxx - Big Flat Interface
+//
+// Written by David Megginson, started February, 2000.
+//
+// Copyright (C) 2000 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 <time.h>
+#include <string>
+
+FG_USING_NAMESPACE(std);
+
+
+/**
+ * Big Flat Interface
+ *
+ * This class implements the Facade design pattern (GOF p.185) to provide
+ * a single, (deceptively) simple flat interface for the FlightGear
+ * subsystems.
+ *
+ * To help cut down on interdependence, subsystems should
+ * use the BFI whenever possible for inter-system communication.
+ *
+ * TODO:
+ * - add selectors to switch the current plane, throttle, brake, etc.
+ * - add more autopilot settings
+ */
+class FGBFI
+{
+public:
+
+ // Reinit if necessary.
+ static void update ();
+
+ // Simulation
+ static int getFlightModel ();
+ static time_t getTimeGMT ();
+ static bool getHUDVisible ();
+ static bool getPanelVisible ();
+
+ static void setFlightModel (int flightModel);
+ static void setTimeGMT (time_t time);
+ static void setHUDVisible (bool hudVisible);
+ static void setPanelVisible (bool panelVisible);
+
+
+ // Position
+ static double getLatitude ();
+ static double getLongitude ();
+ static double getAltitude ();
+
+ static void setLatitude (double latitude);
+ static void setLongitude (double longitude);
+ static void setAltitude (double altitude);
+
+
+ // Attitude
+ static double getHeading ();
+ static double getPitch ();
+ static double getRoll ();
+
+ static void setHeading (double heading);
+ static void setPitch (double pitch);
+ static void setRoll (double roll);
+
+
+ // Velocities
+ static double getAirspeed ();
+ static double getSideSlip ();
+ static double getVerticalSpeed ();
+ static double getSpeedNorth ();
+ static double getSpeedEast ();
+ static double getSpeedDown ();
+
+ static void setSpeedNorth (double speed);
+ static void setSpeedEast (double speed);
+ static void setSpeedDown (double speed);
+
+
+ // Controls
+ static double getThrottle ();
+ static double getFlaps ();
+ static double getAileron ();
+ static double getRudder ();
+ static double getElevator ();
+ static double getElevatorTrim ();
+ static double getBrake ();
+
+ static void setThrottle (double throttle);
+ static void setFlaps (double flaps);
+ static void setAileron (double aileron);
+ static void setRudder (double rudder);
+ static void setElevator (double elevator);
+ static void setElevatorTrim (double trim);
+ static void setBrake (double brake);
+
+
+ // Autopilot
+ static bool getAPAltitudeLock ();
+ static double getAPAltitude ();
+ static bool getAPHeadingLock ();
+ static double getAPHeading ();
+
+ static void setAPAltitudeLock (bool lock);
+ static void setAPAltitude (double altitude);
+ static void setAPHeadingLock (bool lock);
+ static void setAPHeading (double heading);
+
+
+ // GPS
+ static const string getTargetAirport ();
+ static bool getGPSLock ();
+ static double getGPSTargetLatitude ();
+ static double getGPSTargetLongitude ();
+
+ static void setTargetAirport (const string &targetAirport);
+ static void setGPSLock (bool lock);
+ static void setGPSTargetLatitude (double latitude);
+ static void setGPSTargetLongitude (double longitude);
+
+
+ // Weather
+ static double getVisibility ();
+
+ static void setVisibility (double visiblity);
+
+
+private:
+ // Will cause a linking error if invoked.
+ FGBFI ();
+
+ static void reinit ();
+ static void needReinit () { _needReinit = true; }
+ static bool _needReinit;
+};
+
+// end of bfi.hxx
/*
-CHANGES:
-- time is now working
-- autopilot is working (even with GPS)
-
TODO:
- use a separate options object so that we can roll back on error
- use proper FGFS logging
#include <simgear/constants.h>
#include <simgear/math/fg_types.hxx>
-#include <Aircraft/aircraft.hxx>
-#include <Controls/controls.hxx>
-#include <Autopilot/autopilot.hxx>
-#include <Time/fg_time.hxx>
-#ifndef FG_OLD_WEATHER
-# include <WeatherCM/FGLocalWeatherDatabase.h>
-#else
-# include <Weather/weather.hxx>
-#endif
-
-#include "options.hxx"
-#include "save.hxx"
-#include "fg_init.hxx"
+#include "bfi.hxx"
FG_USING_NAMESPACE(std);
- // FIXME: these are not part of the
- // published interface!!!
-extern fgAPDataPtr APDataGlobal;
-extern void fgAPAltitudeSet (double new_altitude);
-extern void fgAPHeadingSet (double new_heading);
-
#define SAVE(name, value) { output << name << ": " << value << endl; }
/**
bool
fgSaveFlight (ostream &output)
{
- char tb[100];
- const FGInterface * f = current_aircraft.fdm_state;
- struct tm *t = FGTime::cur_time_params->getGmt();
-
output << "#!fgfs" << endl;
//
// Simulation
//
- SAVE("flight-model", current_options.get_flight_model());
- SAVE("time", mktime(t));
- SAVE("hud", current_options.get_hud_status());
- SAVE("panel", current_options.get_panel_status());
+ SAVE("flight-model", FGBFI::getFlightModel());
+ SAVE("time", FGBFI::getTimeGMT());
+ SAVE("hud", FGBFI::getHUDVisible());
+ SAVE("panel", FGBFI::getPanelVisible());
//
// Location
//
- SAVE("latitude", (f->get_Latitude() * RAD_TO_DEG));
- SAVE("longitude", (f->get_Longitude() * RAD_TO_DEG));
- SAVE("altitude", f->get_Altitude());
+ SAVE("latitude", FGBFI::getLatitude());
+ SAVE("longitude", FGBFI::getLongitude());
+ SAVE("altitude", FGBFI::getAltitude());
//
// Orientation
//
- SAVE("heading", (f->get_Psi() * RAD_TO_DEG));
- SAVE("pitch", (f->get_Theta() * RAD_TO_DEG));
- SAVE("roll", (f->get_Phi() * RAD_TO_DEG));
+ SAVE("heading", FGBFI::getHeading());
+ SAVE("pitch", FGBFI::getPitch());
+ SAVE("roll", FGBFI::getRoll());
//
// Velocities
//
- SAVE("speed-north", f->get_V_north());
- SAVE("speed-east", f->get_V_east());
- SAVE("speed-down", f->get_V_down());
+ SAVE("speed-north", FGBFI::getSpeedNorth());
+ SAVE("speed-east", FGBFI::getSpeedEast());
+ SAVE("speed-down", FGBFI::getSpeedDown());
//
// Primary controls
//
- SAVE("elevator", controls.get_elevator());
- SAVE("aileron", controls.get_aileron());
- SAVE("rudder", controls.get_rudder());
+ SAVE("elevator", FGBFI::getElevator());
+ SAVE("aileron", FGBFI::getAileron());
+ SAVE("rudder", FGBFI::getRudder());
// FIXME: save each throttle separately
- SAVE("throttle", controls.get_throttle(0));
+ SAVE("throttle", FGBFI::getThrottle());
//
// Secondary controls
//
- SAVE("elevator-trim", controls.get_elevator_trim());
- SAVE("flaps", controls.get_flaps());
+ SAVE("elevator-trim", FGBFI::getElevatorTrim());
+ SAVE("flaps", FGBFI::getFlaps());
// FIXME: save each brake separately
- SAVE("brake", controls.get_brake(0));
+ SAVE("brake", FGBFI::getBrake());
//
// Navigation.
//
- if (current_options.get_airport_id().length() > 0) {
- SAVE("target-airport", current_options.get_airport_id());
+ if (FGBFI::getTargetAirport().length() > 0) {
+ SAVE("target-airport", FGBFI::getTargetAirport());
}
- SAVE("autopilot-altitude-lock", fgAPAltitudeEnabled());
- SAVE("autopilot-altitude", fgAPget_TargetAltitude() * METER_TO_FEET);
- SAVE("autopilot-heading-lock", fgAPHeadingEnabled());
- SAVE("autopilot-heading", fgAPget_TargetHeading());
- SAVE("autopilot-gps-lock", fgAPWayPointEnabled());
- SAVE("autopilot-gps-lat", fgAPget_TargetLatitude());
- SAVE("autopilot-gps-lon", fgAPget_TargetLongitude());
+ SAVE("autopilot-altitude-lock", FGBFI::getAPAltitudeLock());
+ SAVE("autopilot-altitude", FGBFI::getAPAltitude());
+ SAVE("autopilot-heading-lock", FGBFI::getAPHeadingLock());
+ SAVE("autopilot-heading", FGBFI::getAPHeading());
+ SAVE("autopilot-gps-lock", FGBFI::getGPSLock());
+ SAVE("autopilot-gps-lat", FGBFI::getGPSTargetLatitude());
+ SAVE("autopilot-gps-lon", FGBFI::getGPSTargetLongitude());
//
// Environment.
//
-#ifndef FG_OLD_WEATHER
- SAVE("visibility", WeatherDatabase->getWeatherVisibility());
-#else
- SAVE("visibility", current_weather.get_visibility());
-#endif
+ SAVE("visibility", FGBFI::getVisibility());
return true;
}
bool
fgLoadFlight (istream &input)
{
- FGInterface * f = current_aircraft.fdm_state;
+// FGInterface * f = current_aircraft.fdm_state;
string text;
double n;
long int i;
- double elevator = controls.get_elevator();
- double aileron = controls.get_aileron();
- double rudder = controls.get_rudder();
- double throttle = controls.get_throttle(0);
- double elevator_trim = controls.get_elevator_trim();
- double flaps = controls.get_flaps();
- double brake = controls.get_brake(FGControls::ALL_WHEELS);
-
- bool ap_heading_lock = false;
- double ap_heading = 0;
- bool ap_altitude_lock = false;
- double ap_altitude = 0;
- bool ap_gps_lock = false;
- double ap_gps_lat = 0;
- double ap_gps_lon = 0;
-
- string airport_id = current_options.get_airport_id();
- current_options.set_airport_id("");
- current_options.set_time_offset(0);
- current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_OFFSET);
-
if (!input.good() || input.eof()) {
cout << "Stream is no good!\n";
return false;
input >> text;
if (text != "#!fgfs") {
- printf("Bad save file format!\n");
+ cerr << "Bad save file format!\n";
return false;
}
if (text == "flight-model:") {
input >> i;
cout << "flight model is " << i << endl;
- current_options.set_flight_model(i);
+ FGBFI::setFlightModel(i);
}
else if (text == "time:") {
input >> i;
cout << "saved time is " << i << endl;
- current_options.set_time_offset(i);
- current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
- FGTime::cur_time_params->init(*cur_fdm_state);
- FGTime::cur_time_params->update(*cur_fdm_state);
+ FGBFI::setTimeGMT(i);
}
else if (text == "hud:") {
input >> i;
cout << "hud status is " << i << endl;
- current_options.set_hud_status(i);
+ FGBFI::setHUDVisible(i);
}
else if (text == "panel:") {
input >> i;
cout << "panel status is " << i << endl;
- if (current_options.get_panel_status() != i) {
- current_options.toggle_panel();
- }
+ FGBFI::setPanelVisible(i);
}
//
else if (text == "latitude:") {
input >> n;
cout << "latitude is " << n << endl;
- current_options.set_lat(n);
- } else if (text == "longitude:") {
+ FGBFI::setLatitude(n);
+ }
+
+ else if (text == "longitude:") {
input >> n;
cout << "longitude is " << n << endl;
- current_options.set_lon(n);
- } else if (text == "altitude:") {
+ FGBFI::setLongitude(n);
+ }
+
+ else if (text == "altitude:") {
input >> n;
cout << "altitude is " << n << endl;
- current_options.set_altitude(n * FEET_TO_METER);
+ FGBFI::setAltitude(n);
}
//
else if (text == "heading:") {
input >> n;
cout << "heading is " << n << endl;
- current_options.set_heading(n);
- } else if (text == "pitch:") {
+ FGBFI::setHeading(n);
+ }
+
+ else if (text == "pitch:") {
input >> n;
cout << "pitch is " << n << endl;
- current_options.set_pitch(n);
- } else if (text == "roll:") {
+ FGBFI::setPitch(n);
+ }
+
+ else if (text == "roll:") {
input >> n;
cout << "roll is " << n << endl;
- current_options.set_roll(n);
+ FGBFI::setRoll(n);
}
//
else if (text == "speed-north:") {
input >> n;
cout << "speed north is " << n << endl;
- current_options.set_uBody(n);
- } else if (text == "speed-east:") {
+ FGBFI::setSpeedNorth(n);
+ }
+
+ else if (text == "speed-east:") {
input >> n;
cout << "speed east is " << n << endl;
- current_options.set_vBody(n);
- } else if (text == "speed-down:") {
+ FGBFI::setSpeedEast(n);
+ }
+
+ else if (text == "speed-down:") {
input >> n;
cout << "speed down is " << n << endl;
- current_options.set_wBody(n);
+ FGBFI::setSpeedDown(n);
}
//
//
else if (text == "elevator:") {
- input >> elevator;
- cout << "elevator is " << elevator << endl;
+ input >> n;
+ cout << "elevator is " << n << endl;
+ FGBFI::setElevator(n);
}
else if (text == "aileron:") {
- input >> aileron;
- cout << "aileron is " << aileron << endl;
+ input >> n;
+ cout << "aileron is " << n << endl;
+ FGBFI::setAileron(n);
}
else if (text == "rudder:") {
- input >> rudder;
- cout << "rudder is " << rudder << endl;
+ input >> n;
+ cout << "rudder is " << n << endl;
+ FGBFI::setRudder(n);
}
// FIXME: assumes single engine
else if (text == "throttle:") {
- input >> throttle;
- cout << "throttle is " << throttle << endl;
+ input >> n;
+ cout << "throttle is " << n << endl;
+ FGBFI::setThrottle(n);
}
//
// Secondary controls
else if (text == "elevator-trim:") {
- input >> elevator_trim;
- cout << "elevator trim is " << elevator_trim << endl;
+ input >> n;
+ cout << "elevator trim is " << n << endl;
+ FGBFI::setElevatorTrim(n);
}
else if (text == "flaps:") {
- input >> flaps;
- cout << "flaps are " << flaps << endl;
+ input >> n;
+ cout << "flaps are " << n << endl;
+ FGBFI::setFlaps(n);
}
else if (text == "brake:") {
- input >> brake;
- cout << "brake is " << brake << endl;
+ input >> n;
+ cout << "brake is " << n << endl;
+ FGBFI::setBrake(n);
}
//
//
else if (text == "target-airport:") {
- input >> airport_id;
- cout << "target airport is " << airport_id << endl;
+ input >> text;
+ cout << "target airport is " << text << endl;
+ FGBFI::setTargetAirport(text);
}
else if (text == "autopilot-altitude-lock:") {
- input >> ap_altitude_lock;
- cout << "autopilot altitude lock is " << ap_altitude_lock << endl;
+ input >> i;
+ cout << "autopilot altitude lock is " << i << endl;
+ FGBFI::setAPAltitudeLock(i);
}
else if (text == "autopilot-altitude:") {
- input >> ap_altitude;
- cout << "autopilot altitude is " << ap_altitude << endl;
+ input >> n;
+ cout << "autopilot altitude is " << n << endl;
+ FGBFI::setAPAltitude(n);
}
else if (text == "autopilot-heading-lock:") {
- input >> ap_heading_lock;
- cout << "autopilot heading lock is " << ap_heading_lock << endl;
+ input >> i;
+ cout << "autopilot heading lock is " << i << endl;
+ FGBFI::setAPHeadingLock(i);
}
else if (text == "autopilot-heading:") {
- input >> ap_heading;
- cout << "autopilot heading is " << ap_heading << endl;
+ input >> n;
+ cout << "autopilot heading is " << n << endl;
+ FGBFI::setAPHeading(n);
}
else if (text == "autopilot-gps-lock:") {
- input >> ap_gps_lock;
- cout << "autopilot GPS lock is " << ap_gps_lock << endl;
+ input >> i;
+ cout << "autopilot GPS lock is " << i << endl;
+ FGBFI::setGPSLock(i);
}
else if (text == "autopilot-gps-lat:") {
- input >> ap_gps_lat;
+ input >> n;
+ cout << "GPS target latitude is " << n << endl;
+ FGBFI::setGPSTargetLatitude(n);
}
else if (text == "autopilot-gps-lon:") {
- input >> ap_gps_lon;
+ input >> n;
+ cout << "GPS target longitude is " << n << endl;
+ FGBFI::setGPSTargetLongitude(n);
}
//
else if (text == "visibility:") {
input >> n;
cout << "visibility is " << n << endl;
-
-#ifndef FG_OLD_WEATHER
- WeatherDatabase->setWeatherVisibility(n);
-#else
- current_weather.set_visibility(n);
-#endif
+ FGBFI::setVisibility(n);
}
//
}
}
- fgReInitSubsystems();
-
- // Set airport and controls after the
- // re-init.
- current_options.set_airport_id(airport_id);
-
- // The controls have to be set after
- // the reinit
- controls.set_elevator(elevator);
- controls.set_aileron(aileron);
- controls.set_rudder(rudder);
- controls.set_throttle(FGControls::ALL_ENGINES, throttle);
- controls.set_elevator_trim(elevator_trim);
- controls.set_flaps(flaps);
- controls.set_brake(FGControls::ALL_WHEELS, brake);
-
- // Ditto for the autopilot.
- // FIXME: shouldn't have to use
- // APDataGlobal.
- APDataGlobal->heading_hold = ap_heading_lock;
- APDataGlobal->altitude_hold = ap_altitude_lock;
- fgAPHeadingSet(ap_heading);
- fgAPAltitudeSet(ap_altitude);
- // GPS overrides heading
- APDataGlobal->waypoint_hold = ap_gps_lock;
- APDataGlobal->TargetLatitude = ap_gps_lat;
- APDataGlobal->TargetLongitude = ap_gps_lon;
+ FGBFI::update();
return true;
}