]> git.mxchange.org Git - flightgear.git/commitdiff
Move three more subsystems into the init + update scheme - fixes some crashes found...
authorJames Turner <zakalawe@mac.com>
Fri, 22 Oct 2010 11:22:00 +0000 (12:22 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 22 Oct 2010 15:44:37 +0000 (16:44 +0100)
src/Autopilot/route_mgr.cxx
src/Cockpit/hud_rwy.cxx
src/Instrumentation/HUD/HUD_runway.cxx
src/Main/fg_init.cxx
src/Main/globals.cxx
src/Main/main.cxx
src/Main/viewmgr.cxx
src/Main/viewmgr.hxx

index fac7dc628f39ee84d32ffc54de37226d040fad15..d5411b8af7d73960644590d5d37714e423d007f4 100644 (file)
@@ -237,7 +237,7 @@ void FGRouteMgr::postinit()
     SG_LOG(SG_AUTOPILOT, SG_INFO, "loaded initial waypoints:" << _route.size());
   }
 
-  weightOnWheels = fgGetNode("/gear/gear[0]/wow", false);
+  weightOnWheels = fgGetNode("/gear/gear[0]/wow", true);
   // check airbone flag agrees with presets
 }
 
index e884c7cfb39c579819dc37a13f10964c2297279c..222975fdbe901991b8d0a5d75c1b51d24f562029 100644 (file)
@@ -97,11 +97,6 @@ void runway_instr::draw()
         double sPitch = sin(pitch), cPitch = cos(pitch),
                sYaw = sin(yaw), cYaw = cos(yaw);
 
-        //Assuming that the "Cockpit View" is always at position zero!!!
-        if (curr_view_id != 0) {
-            globals->get_viewmgr()->set_view(0);
-            globals->get_viewmgr()->copyToCurrent();
-        }
         //Set the camera to the cockpit view to get the view of the runway from the cockpit
         // OSGFIXME
 //         ssgSetCamera((sgVec4 *)cockpit_view->get_VIEW());
@@ -156,15 +151,6 @@ void runway_instr::draw()
             drawArrow(); //draw indication arrow
         }
 
-        //Restore the current view and any offsets
-        if (curr_view_id != 0) {
-            globals->get_viewmgr()->set_view(curr_view_id);
-            globals->get_viewmgr()->copyToCurrent();
-            curr_view->setHeadingOffset_deg(ho);
-            curr_view->setPitchOffset_deg(po);
-            curr_view->setGoalHeadingOffset_deg(gho);
-            curr_view->setGoalPitchOffset_deg(gpo);
-        }
         //Set the camera back to the current view
         // OSGFIXME
 //         ssgSetCamera((sgVec4 *)curr_view);
index a31d0ff6038b33cd3780916bf49f5509192244c5..fcf4f11277c0da885f716419582feb96ef3388df 100644 (file)
@@ -93,11 +93,6 @@ void HUD::Runway::draw()
     double sPitch = sin(pitch), cPitch = cos(pitch),
            sYaw = sin(yaw), cYaw = cos(yaw);
 
-    //Assuming that the "Cockpit View" is always at position zero!!!
-    if (curr_view_id != 0) {
-        globals->get_viewmgr()->set_view(0);
-        globals->get_viewmgr()->copyToCurrent();
-    }
     //Set the camera to the cockpit view to get the view of the runway from the cockpit
     // OSGFIXME
 //     ssgSetCamera((sgVec4 *)_cockpit_view->get_VIEW());
@@ -152,15 +147,6 @@ void HUD::Runway::draw()
         drawArrow(); //draw indication arrow
     }
 
-    //Restore the current view and any offsets
-    if (curr_view_id != 0) {
-        globals->get_viewmgr()->set_view(curr_view_id);
-        globals->get_viewmgr()->copyToCurrent();
-        curr_view->setHeadingOffset_deg(ho);
-        curr_view->setPitchOffset_deg(po);
-        curr_view->setGoalHeadingOffset_deg(gho);
-        curr_view->setGoalPitchOffset_deg(gpo);
-    }
     //Set the camera back to the current view
     // OSGFIXME
 //     ssgSetCamera((sgVec4 *)curr_view);
index fa2cc45a567e6efec7c57d2362464c4b2249462c..f154ab658fd46665a809e9d4203085bae0970d8f 100644 (file)
@@ -93,6 +93,7 @@
 #include <Input/input.hxx>
 #include <Instrumentation/instrument_mgr.hxx>
 #include <Model/acmodel.hxx>
+#include <Model/modelmgr.hxx>
 #include <AIModel/submodel.hxx>
 #include <AIModel/AIManager.hxx>
 #include <Navaids/navdb.hxx>
@@ -1309,9 +1310,6 @@ bool fgInitSubsystems() {
     // Initialize the scenery management subsystem.
     ////////////////////////////////////////////////////////////////////
 
-    globals->add_subsystem("tile-manager", globals->get_tile_mgr(), 
-      SGSubsystemMgr::DISPLAY);
-
     globals->get_scenery()->get_scene_graph()
         ->addChild(simgear::Particles::getCommonRoot());
     simgear::GlobalParticleCallback::setSwitch(fgGetNode("/sim/rendering/particles", true));
@@ -1361,23 +1359,12 @@ bool fgInitSubsystems() {
 
     globals->add_subsystem("gui", new NewGUI, SGSubsystemMgr::INIT);
 
-    ////////////////////////////////////////////////////////////////////
-    // Initialize the lighting subsystem.
-    ////////////////////////////////////////////////////////////////////
-
-    globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
-
     //////////////////////////////////////////////////////////////////////
     // Initialize the 2D cloud subsystem.
     ////////////////////////////////////////////////////////////////////
     fgGetBool("/sim/rendering/bump-mapping", false);
 
-#ifdef ENABLE_AUDIO_SUPPORT
-    ////////////////////////////////////////////////////////////////////
-    // Initialize the sound-effects subsystem.
-    ////////////////////////////////////////////////////////////////////
-    globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
-#endif
+
 
     ////////////////////////////////////////////////////////////////////
     // Initialise the ATC Manager 
@@ -1461,7 +1448,37 @@ bool fgInitSubsystems() {
     ////////////////////////////////////////////////////////////////////
     globals->add_subsystem("replay", new FGReplay);
 
+#ifdef ENABLE_AUDIO_SUPPORT
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the sound-effects subsystem.
+    ////////////////////////////////////////////////////////////////////
+    globals->add_subsystem("voice", new FGVoiceMgr, SGSubsystemMgr::DISPLAY);
+#endif
 
+    ////////////////////////////////////////////////////////////////////
+    // Initialize the lighting subsystem.
+    ////////////////////////////////////////////////////////////////////
+
+    globals->add_subsystem("lighting", new FGLight, SGSubsystemMgr::DISPLAY);
+    
+    // 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);
+
+    FGViewMgr *viewmgr = new FGViewMgr;
+    globals->set_viewmgr( viewmgr );
+    globals->add_subsystem("view-manager", viewmgr, SGSubsystemMgr::DISPLAY);
+
+    globals->add_subsystem("tile-manager", globals->get_tile_mgr(), 
+      SGSubsystemMgr::DISPLAY);
+      
     ////////////////////////////////////////////////////////////////////
     // Bind and initialize subsystems.
     ////////////////////////////////////////////////////////////////////
index 7fafd0516c891658a85c14bc85e3676396f03b7a..ee5fcf2fdcd800e9a31ea9d6310e708fe60ec47f 100644 (file)
@@ -170,7 +170,6 @@ FGGlobals::~FGGlobals()
 
     subsystem_mgr->unbind();
     delete subsystem_mgr;
-    delete event_mgr;
     
     delete time_params;
     delete mag;
@@ -180,10 +179,7 @@ FGGlobals::~FGGlobals()
 
     delete ATC_mgr;
     delete controls;
-    delete viewmgr;
 
-//     delete commands;
-    delete model_mgr;
     delete channel_options_list;
     delete initial_waypoints;
     delete scenery;
index 1cfe91ba2054598a255eb6a71c0eb8811d26582e..8849644b3cd28a26bad5ea17779d40593ffef476 100644 (file)
@@ -54,7 +54,6 @@
 #include <Cockpit/cockpit.hxx>
 #include <Cockpit/hud.hxx>
 #include <Model/panelnode.hxx>
-#include <Model/modelmgr.hxx>
 #include <Model/acmodel.hxx>
 #include <Scenery/scenery.hxx>
 #include <Scenery/tilemgr.hxx>
@@ -149,16 +148,6 @@ static void fgMainLoop( void ) {
     
     globals->get_subsystem_mgr()->update(sim_dt);
 
-    // run Nasal's settimer() loops right before the view manager
-    globals->get_event_mgr()->update(sim_dt);
-
-    // pick up model coordidnates that Nasal code may have set relative to the
-    // aircraft's
-    globals->get_model_mgr()->update(sim_dt);
-
-    // update the view angle as late as possible, but before sound calculations
-    globals->get_viewmgr()->update(real_dt);
-
     // Update the sound manager last so it can use the CPU while the GPU
     // is processing the scenery (doubled the frame-rate for me) -EMH-
 #ifdef ENABLE_AUDIO_SUPPORT
@@ -375,33 +364,12 @@ static void fgIdleFunction ( void ) {
         globals->set_tile_mgr( new FGTileMgr );
 
 
-        ////////////////////////////////////////////////////////////////////
-        // Initialize the general model subsystem.
-        ////////////////////////////////////////////////////////////////////
-        globals->set_model_mgr(new FGModelMgr);
-        globals->get_model_mgr()->init();
-        globals->get_model_mgr()->bind();
         fgSplashProgress("loading aircraft");
 
 
     } else if ( idle_state == 5 ) {
         idle_state++;
 
-        ////////////////////////////////////////////////////////////////////
-        // Initialize the 3D aircraft model subsystem (has a dependency on
-        // the scenery subsystem.)
-        ////////////////////////////////////////////////////////////////////
-        FGAircraftModel* acm = new FGAircraftModel;
-        globals->set_aircraft_model(acm);
-        globals->add_subsystem("aircraft-model", acm, SGSubsystemMgr::DISPLAY);
-
-        ////////////////////////////////////////////////////////////////////
-        // Initialize the view manager subsystem.
-        ////////////////////////////////////////////////////////////////////
-        FGViewMgr *viewmgr = new FGViewMgr;
-        globals->set_viewmgr( viewmgr );
-        viewmgr->init();
-        viewmgr->bind();
         fgSplashProgress("generating sky elements");
 
 
index 6859c8f412ee5306ddaf1d91630b717149ce77d4..5a978be63608ffa4634a553b405effd6dbcbc8d1 100644 (file)
@@ -39,6 +39,7 @@
 FGViewMgr::FGViewMgr( void ) :
   axis_long(0),
   axis_lat(0),
+  inited(false),
   view_number(fgGetNode("/sim/current-view/view-number", true)),
   config_list(fgGetNode("/sim", true)->getChildren("view")),
   current(0)
@@ -53,6 +54,13 @@ FGViewMgr::~FGViewMgr( void ) {
 void
 FGViewMgr::init ()
 {
+  if (inited) {
+    SG_LOG(SG_GENERAL, SG_WARN, "duplicate init of view manager");
+    return;
+  }
+  
+  inited = true;
+  
   double aspect_ratio_multiplier
       = fgGetDouble("/sim/current-view/aspect-ratio-multiplier");
 
@@ -118,6 +126,7 @@ FGViewMgr::init ()
   }
 
   copyToCurrent();
+  do_bind();
 }
 
 void
@@ -160,7 +169,14 @@ FGViewMgr::reinit ()
 typedef double (FGViewMgr::*double_getter)() const;
 
 void
-FGViewMgr::bind ()
+FGViewMgr::bind()
+{
+  // view-manager code was designed to init before bind, so
+  // this is a no-op; init() calls the real bind() impl below
+}
+
+void
+FGViewMgr::do_bind()
 {
   // these are bound to the current view properties
   fgTie("/sim/current-view/heading-offset-deg", this,
@@ -352,6 +368,10 @@ FGViewMgr::update (double dt)
 void
 FGViewMgr::copyToCurrent()
 {
+  if (!inited) {
+    return;
+  }
+  
     SGPropertyNode *n = config_list[current];
     fgSetString("/sim/current-view/name", n->getStringValue("name"));
     fgSetString("/sim/current-view/type", n->getStringValue("type"));
@@ -719,15 +739,9 @@ FGViewMgr::setView (int newview)
     newview = 0;
 
   // set new view
-  set_view(newview);
+  current = newview;
   // copy in view data
   copyToCurrent();
-
-  // Copy the fdm's position into the SGLocation which is shared with
-  // some views ...
-  globals->get_aircraft_model()->update(0);
-  // Do the update ...
-  update(0);
 }
 
 
@@ -755,7 +769,7 @@ FGViewMgr::getARM_deg () const
 
 void
 FGViewMgr::setARM_deg (double aspect_ratio_multiplier)
-{
+{  
   FGViewer * view = get_current_view();
   if (view != 0)
     view->set_aspect_ratio_multiplier(aspect_ratio_multiplier);
index c296b71559b50e2018d585e3272c58d52f1ebcb3..c14347e26921205a34da761f59b30d9ad94bc443 100644 (file)
@@ -69,14 +69,12 @@ public:
       
     // setters
     void clear();
-    inline void set_view( const int v ) { current = v; }
+
     void add_view( FGViewer * v );
     
-    // copies current offset settings to current-view path...
-    void copyToCurrent ();
-
 private:
-
+    void do_bind();
+    
     list<const char*> tied_props;
 
     double axis_long;
@@ -136,6 +134,10 @@ private:
 
     bool stationary () const;
 
+    // copies current offset settings to current-view path...
+    void copyToCurrent ();
+    
+    bool inited;
     SGPropertyNode_ptr view_number;
     vector<SGPropertyNode_ptr> config_list;
     typedef std::vector<FGViewerPtr> viewer_list;