From 029012b8b94f0719fc824f2b6afff43afe2cb9c2 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 19 Sep 2012 18:17:44 +0100 Subject: [PATCH] Kill off some globals. Break some subsystem dependencies, by explicitly using properties to read the primary position, orientation and velocities. (Instead of directly accessing the primary model placement). This means a couple more globals can die. --- src/Main/fg_init.cxx | 9 ++------ src/Main/globals.cxx | 47 ++++++++++++++++------------------------ src/Main/globals.hxx | 49 ++++-------------------------------------- src/Viewer/viewer.cxx | 24 +++++++-------------- src/Viewer/viewmgr.cxx | 9 ++++++-- src/Viewer/viewmgr.hxx | 3 ++- 6 files changed, 41 insertions(+), 100 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 85fc261e3..4be803c39 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -709,14 +709,9 @@ void fgCreateSubsystems() { // ordering here is important : Nasal (via events), then models, then views globals->add_subsystem("events", globals->get_event_mgr(), SGSubsystemMgr::DISPLAY); - - FGAircraftModel* acm = new FGAircraftModel; - globals->set_aircraft_model(acm); - globals->add_subsystem("aircraft-model", acm, SGSubsystemMgr::DISPLAY); - FGModelMgr* mm = new FGModelMgr; - globals->set_model_mgr(mm); - globals->add_subsystem("model-manager", mm, SGSubsystemMgr::DISPLAY); + globals->add_subsystem("aircraft-model", new FGAircraftModel, SGSubsystemMgr::DISPLAY); + globals->add_subsystem("model-manager", new FGModelMgr, SGSubsystemMgr::DISPLAY); FGViewMgr *viewmgr = new FGViewMgr; globals->set_viewmgr( viewmgr ); diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index c63129866..6b5dc8ce7 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -39,7 +39,6 @@ #include #include #include -#include #include #include @@ -47,8 +46,6 @@ #include #include #include -#include -#include #include #include #include @@ -136,24 +133,24 @@ FGGlobals::FGGlobals() : controls( NULL ), viewmgr( NULL ), commands( SGCommandMgr::instance() ), - acmodel( NULL ), - model_mgr( NULL ), channel_options_list( NULL ), initial_waypoints( NULL ), scenery( NULL ), tile_mgr( NULL ), fontcache ( new FGFontCache ), - navlist( NULL ), - loclist( NULL ), - gslist( NULL ), - dmelist( NULL ), - tacanlist( NULL ), - carrierlist( NULL ), channellist( NULL ), haveUserSettings(false) { simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider()); simgear::PropertyObjectBase::setDefaultRoot(props); + + positionLon = props->getNode("position/longitude-deg", true); + positionLat = props->getNode("position/latitude-deg", true); + positionAlt = props->getNode("position/altitude-ft", true); + + orientPitch = props->getNode("orientation/pitch-deg", true); + orientHeading = props->getNode("orientation/heading-deg", true); + orientRoll = props->getNode("orientation/roll-deg", true); } // Destructor @@ -199,12 +196,6 @@ FGGlobals::~FGGlobals() delete scenery; delete fontcache; - delete navlist; - delete loclist; - delete gslist; - delete dmelist; - delete tacanlist; - delete carrierlist; delete channellist; delete sound; @@ -389,18 +380,9 @@ FGGlobals::get_event_mgr () const SGGeod FGGlobals::get_aircraft_position() const { - if( acmodel != NULL ) { - SGModelPlacement * mp = acmodel->get3DModel(); - if( mp != NULL ) - return mp->getPosition(); - } - - // fall back to reading the property tree. this can occur during - // startup before the acmodel is initialised - - return SGGeod::fromDegFt(fgGetDouble("/position/longitude-deg"), - fgGetDouble("/position/latitude-deg"), - fgGetDouble("/position/altitude-ft")); + return SGGeod::fromDegFt(positionLon->getDoubleValue(), + positionLat->getDoubleValue(), + positionAlt->getDoubleValue()); } SGVec3d @@ -409,6 +391,13 @@ FGGlobals::get_aircraft_positon_cart() const return SGVec3d::fromGeod(get_aircraft_position()); } +void FGGlobals::get_aircraft_orientation(double& heading, double& pitch, double& roll) +{ + heading = orientHeading->getDoubleValue(); + pitch = orientPitch->getDoubleValue(); + roll = orientRoll->getDoubleValue(); +} + // Save the current state as the initial state. void diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index a057abc08..40c2b697e 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -55,13 +55,9 @@ class SGSubsystem; class SGSoundMgr; class FGATISMgr; -class FGAircraftModel; class FGControls; -class FGFlightPlanDispatcher; -class FGNavList; class FGTACANList; class FGLocale; -class FGModelMgr; class FGRouteMgr; class FGScenery; class FGTileMgr; @@ -128,12 +124,6 @@ private: SGCommandMgr *commands; - //FGFlightPlanDispatcher *fpDispatcher; - - FGAircraftModel *acmodel; - - FGModelMgr * model_mgr; - // list of serial port-like configurations string_list *channel_options_list; @@ -150,12 +140,6 @@ private: FGFontCache *fontcache; // Navigational Aids - FGNavList *navlist; - FGNavList *loclist; - FGNavList *gslist; - FGNavList *dmelist; - FGNavList *tacanlist; - FGNavList *carrierlist; FGTACANList *channellist; /// roots of Aircraft trees @@ -163,6 +147,8 @@ private: bool haveUserSettings; + SGPropertyNode_ptr positionLon, positionLat, positionAlt; + SGPropertyNode_ptr orientHeading, orientPitch, orientRoll; public: FGGlobals(); @@ -261,24 +247,12 @@ public: inline SGCommandMgr *get_commands () { return commands; } - inline FGAircraftModel *get_aircraft_model () { return acmodel; } - - inline void set_aircraft_model (FGAircraftModel * model) - { - acmodel = model; - } - SGGeod get_aircraft_position() const; SGVec3d get_aircraft_positon_cart() const; - - inline FGModelMgr *get_model_mgr () { return model_mgr; } - - inline void set_model_mgr (FGModelMgr * mgr) - { - model_mgr = mgr; - } + void get_aircraft_orientation(double& heading, double& pitch, double& roll); + inline string_list *get_channel_options_list () { return channel_options_list; } @@ -301,21 +275,6 @@ public: inline void set_tile_mgr ( FGTileMgr *t ) { tile_mgr = t; } inline FGFontCache *get_fontcache() const { return fontcache; } - -#if 0 - inline FGNavList *get_navlist() const { return navlist; } - inline void set_navlist( FGNavList *n ) { navlist = n; } - inline FGNavList *get_loclist() const { return loclist; } - inline void set_loclist( FGNavList *n ) { loclist = n; } - inline FGNavList *get_gslist() const { return gslist; } - inline void set_gslist( FGNavList *n ) { gslist = n; } - inline FGNavList *get_dmelist() const { return dmelist; } - inline void set_dmelist( FGNavList *n ) { dmelist = n; } - inline FGNavList *get_tacanlist() const { return tacanlist; } - inline void set_tacanlist( FGNavList *n ) { tacanlist = n; } - inline FGNavList *get_carrierlist() const { return carrierlist; } - inline void set_carrierlist( FGNavList *n ) { carrierlist = n; } -#endif inline FGTACANList *get_channellist() const { return channellist; } inline void set_channellist( FGTACANList *c ) { channellist = c; } diff --git a/src/Viewer/viewer.cxx b/src/Viewer/viewer.cxx index d26b282b5..98e5fe24f 100644 --- a/src/Viewer/viewer.cxx +++ b/src/Viewer/viewer.cxx @@ -370,12 +370,8 @@ FGViewer::recalcLookFrom () { // Update location data ... if ( _from_model ) { - SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel(); - _position = placement->getPosition(); - - _heading_deg = placement->getHeadingDeg(); - _pitch_deg = placement->getPitchDeg(); - _roll_deg = placement->getRollDeg(); + _position = globals->get_aircraft_position(); + globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg); } double head = _heading_deg; @@ -419,11 +415,10 @@ FGViewer::recalcLookAt () { // The geodetic position of our target to look at if ( _at_model ) { - SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel(); - _target = placement->getPosition(); - _target_heading_deg = placement->getHeadingDeg(); - _target_pitch_deg = placement->getPitchDeg(); - _target_roll_deg = placement->getRollDeg(); + _target = globals->get_aircraft_position(); + globals->get_aircraft_orientation(_target_heading_deg, + _target_pitch_deg, + _target_roll_deg); } else { // if not model then calculate our own target position... setDampTarget(_target_roll_deg, _target_pitch_deg, _target_heading_deg); @@ -437,11 +432,8 @@ FGViewer::recalcLookAt () if ( _from_model ) { - SGModelPlacement* placement = globals->get_aircraft_model()->get3DModel(); - _position = placement->getPosition(); - _heading_deg = placement->getHeadingDeg(); - _pitch_deg = placement->getPitchDeg(); - _roll_deg = placement->getRollDeg(); + _position = globals->get_aircraft_position(); + globals->get_aircraft_orientation(_heading_deg, _pitch_deg, _roll_deg); } else { // update from our own data, just the rotation here... setDampTarget(_roll_deg, _pitch_deg, _heading_deg); diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index f3101a21a..76a1eb3df 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -31,7 +31,6 @@ #include #include -#include #include
#include "viewer.hxx" @@ -181,6 +180,10 @@ FGViewMgr::bind() void FGViewMgr::do_bind() { + velocityNorthFPS = fgGetNode("velocities/speed-north-fps", true); + velocityEastFPS = fgGetNode("velocities/speed-east-fps", true); + velocityDownFPS = fgGetNode("velocities/speed-down-fps", true); + // these are bound to the current view properties _tiedProperties.setRoot(fgGetNode("/sim/current-view", true)); _tiedProperties.Tie("heading-offset-deg", this, @@ -338,7 +341,9 @@ FGViewMgr::update (double dt) // get the model velocity SGVec3d velocity = SGVec3d::zeros(); if ( !stationary() ) { - velocity = globals->get_aircraft_model()->getVelocity(); + velocity = SGVec3d( velocityNorthFPS->getDoubleValue(), + velocityEastFPS->getDoubleValue(), + velocityDownFPS->getDoubleValue() ); } smgr->set_velocity( velocity ); } diff --git a/src/Viewer/viewmgr.hxx b/src/Viewer/viewmgr.hxx index d094a3d65..a53b880e5 100644 --- a/src/Viewer/viewmgr.hxx +++ b/src/Viewer/viewmgr.hxx @@ -149,7 +149,8 @@ private: SGQuatd current_view_orientation, current_view_or_offset; SGSoundMgr *smgr; - + + SGPropertyNode_ptr velocityNorthFPS, velocityEastFPS, velocityDownFPS; }; // This takes the conventional aviation XYZ body system -- 2.39.5