]> git.mxchange.org Git - flightgear.git/commitdiff
Make FGAircraftModel more subsystem-alike, move update to fgMainLoop.
authorJames Turner <jmt@Dulux.local>
Sat, 12 Jun 2010 13:52:21 +0000 (15:52 +0200)
committerJames Turner <zakalawe@mac.com>
Sat, 26 Jun 2010 09:31:21 +0000 (10:31 +0100)
src/Aircraft/aircraft.cxx
src/Main/main.cxx
src/Model/acmodel.cxx
src/Model/acmodel.hxx

index ba760a33ba96bdad702c2d2ab9818afb2499828b..c3514e29afcc75d02f89075efce8e14a4b170c37 100644 (file)
@@ -204,14 +204,8 @@ fgLoadAircraft (const SGPropertyNode * arg)
         globals->get_current_panel()->update(0);
     }
 
-    // Load the new 3D model
-    //
-    globals->get_aircraft_model()->unbind();
-    delete globals->get_aircraft_model();
-    globals->set_aircraft_model(new FGAircraftModel);
-    globals->get_aircraft_model()->init();
-    globals->get_aircraft_model()->bind();
-
+    globals->get_aircraft_model()->reinit();
+        
     // TODO:
     //    load new electrical system
     //
@@ -227,11 +221,7 @@ fgLoadAircraft (const SGPropertyNode * arg)
     t = fgInitTime();
     globals->set_time_params( t );
 
-    globals->get_viewmgr()->reinit();
-    globals->get_controls()->reset_all();
-    globals->get_aircraft_model()->reinit();
     globals->get_subsystem("xml-autopilot")->reinit();
-
     fgReInitSubsystems();
 
     if ( !freeze ) {
index 762e3e28875236a719193c2425178306dda98f73..679c0e0b5901dcd6dc822485bf303fa3eee905db 100644 (file)
@@ -183,8 +183,6 @@ void fgUpdateTimeDepCalcs() {
         // do nothing, fdm isn't inited yet
     }
 
-    globals->get_aircraft_model()->update(delta_time_sec);
-
     // Update solar system
     globals->get_ephem()->update( globals->get_time_params()->getMjd(),
                                   globals->get_time_params()->getLst(),
@@ -455,7 +453,8 @@ static void fgMainLoop( void ) {
         SG_LOG( SG_ALL, SG_DEBUG,
                 "Elapsed time is zero ... we're zinging" );
     }
-
+  
+    globals->get_aircraft_model()->update(delta_time_sec);
     globals->get_subsystem_mgr()->update(delta_time_sec);
 
     //
@@ -697,9 +696,11 @@ static void fgIdleFunction ( void ) {
         // Initialize the 3D aircraft model subsystem (has a dependency on
         // the scenery subsystem.)
         ////////////////////////////////////////////////////////////////////
-        globals->set_aircraft_model(new FGAircraftModel);
-        globals->get_aircraft_model()->init();
-        globals->get_aircraft_model()->bind();
+        FGAircraftModel* acm = new FGAircraftModel;
+        globals->set_aircraft_model(acm);
+        //globals->add_subsystem("aircraft-model", acm);
+        acm->init();
+        acm->bind();
 
         ////////////////////////////////////////////////////////////////////
         // Initialize the view manager subsystem.
index 2df6e0abfb29caff2bbe0d0314133456bd4fe8f9..5c63963a98eaac3ff90cdac8f05068b138ebac13 100644 (file)
@@ -55,10 +55,7 @@ FGAircraftModel::FGAircraftModel ()
 
 FGAircraftModel::~FGAircraftModel ()
 {
-  osg::Node* node = _aircraft->getSceneGraph();
-  globals->get_scenery()->get_aircraft_branch()->removeChild(node);
-
-  delete _aircraft;
+  deinit();
 }
 
 void 
@@ -83,6 +80,27 @@ FGAircraftModel::init ()
   globals->get_scenery()->get_aircraft_branch()->addChild(node);
 }
 
+void
+FGAircraftModel::reinit()
+{
+  deinit();
+  init();
+}
+
+void
+FGAircraftModel::deinit()
+{
+  if (!_aircraft) {
+    return;
+  }
+  
+  osg::Node* node = _aircraft->getSceneGraph();
+  globals->get_scenery()->get_aircraft_branch()->removeChild(node);
+
+  delete _aircraft;
+  _aircraft = NULL;
+}
+
 void
 FGAircraftModel::bind ()
 {
index 59e6034dd26c0126af99aa4d5dc5e3d74b064899..7965658cd719b682815b36773dd3b290efe63eda 100644 (file)
@@ -6,16 +6,6 @@
 #ifndef __ACMODEL_HXX
 #define __ACMODEL_HXX 1
 
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-#include <vector>
-#include <string>
-
-using std::string;
-using std::vector;
-
 #include <osg/ref_ptr>
 #include <osg/Group>
 #include <osg/Switch>
@@ -35,6 +25,7 @@ public:
   virtual ~FGAircraftModel ();
 
   virtual void init ();
+  virtual void reinit ();
   virtual void bind ();
   virtual void unbind ();
   virtual void update (double dt);
@@ -42,7 +33,8 @@ public:
   virtual SGVec3d& getVelocity() { return _velocity; }
 
 private:
-
+  void deinit ();
+  
   SGModelPlacement * _aircraft;
   SGVec3d _velocity;
   SGSharedPtr<FGFX>  _fx;