From 3fbf3aa080159fb5dc41af7c4885b080013c8295 Mon Sep 17 00:00:00 2001 From: James Turner <jmt@Dulux.local> Date: Sat, 12 Jun 2010 15:52:21 +0200 Subject: [PATCH] Make FGAircraftModel more subsystem-alike, move update to fgMainLoop. --- src/Aircraft/aircraft.cxx | 14 ++------------ src/Main/main.cxx | 13 +++++++------ src/Model/acmodel.cxx | 26 ++++++++++++++++++++++---- src/Model/acmodel.hxx | 14 +++----------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/src/Aircraft/aircraft.cxx b/src/Aircraft/aircraft.cxx index ba760a33b..c3514e29a 100644 --- a/src/Aircraft/aircraft.cxx +++ b/src/Aircraft/aircraft.cxx @@ -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 ) { diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 762e3e288..679c0e0b5 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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. diff --git a/src/Model/acmodel.cxx b/src/Model/acmodel.cxx index 2df6e0abf..5c63963a9 100644 --- a/src/Model/acmodel.cxx +++ b/src/Model/acmodel.cxx @@ -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 () { diff --git a/src/Model/acmodel.hxx b/src/Model/acmodel.hxx index 59e6034dd..7965658cd 100644 --- a/src/Model/acmodel.hxx +++ b/src/Model/acmodel.hxx @@ -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;