]> git.mxchange.org Git - flightgear.git/commitdiff
Kill off some globals.
authorJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:17:44 +0000 (18:17 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 19 Sep 2012 17:17:44 +0000 (18:17 +0100)
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
src/Main/globals.cxx
src/Main/globals.hxx
src/Viewer/viewer.cxx
src/Viewer/viewmgr.cxx
src/Viewer/viewmgr.hxx

index 85fc261e36657f73bc2efb299b62d94b8537415f..4be803c39ec64640b00d6d4249489a9dd6bc7642 100644 (file)
@@ -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 );
index c63129866c95da9758c0e788f66e8d12f70b608a..6b5dc8ce77f5c25ca94390952dba257bde0277bd 100644 (file)
@@ -39,7 +39,6 @@
 #include <simgear/misc/ResourceManager.hxx>
 #include <simgear/props/propertyObject.hxx>
 #include <simgear/props/props_io.hxx>
-#include <simgear/scene/model/placement.hxx>
 
 #include <Aircraft/controls.hxx>
 #include <Airports/runways.hxx>
@@ -47,8 +46,6 @@
 #include <Autopilot/route_mgr.hxx>
 #include <GUI/FGFontCache.hxx>
 #include <GUI/gui.h>
-#include <Model/acmodel.hxx>
-#include <Model/modelmgr.hxx>
 #include <MultiPlayer/multiplaymgr.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
@@ -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
index a057abc0813fdec96277fff532e5e4f52bf2e128..40c2b697ee838bd34a260668c55cbaf8e0466cc9 100644 (file)
@@ -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; }
index d26b282b526bbdff094c66e2e3f31d2b66cae67c..98e5fe24f6eb635cde9b7b126c544adbb60e877f 100644 (file)
@@ -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);
index f3101a21a91e182ede913265e7b883117927888e..76a1eb3df6fe9096523eba916694616ba9257719 100644 (file)
@@ -31,7 +31,6 @@
 
 #include <simgear/compiler.h>
 #include <simgear/sound/soundmgr_openal.hxx>
-#include <Model/acmodel.hxx>
 #include <Main/fg_props.hxx>
 #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 );
 }
index d094a3d65961eefea0a20739448571700011e510..a53b880e516252b83853c25b0437a2d799f0325e 100644 (file)
@@ -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