From 3fbf3aa080159fb5dc41af7c4885b080013c8295 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 12 Jun 2010 15:52:21 +0200 Subject: [PATCH 1/6] 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 -#include - -using std::string; -using std::vector; - #include #include #include @@ -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 _fx; From 4756cd4882adcc0341abe217bb9272fb23861d10 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sat, 12 Jun 2010 17:08:04 +0200 Subject: [PATCH 2/6] Wrap SGEphemeris in a subsytem/property interface, and remove from mainloop. --- projects/VC90/FlightGear/FlightGear.vcproj | 8 +++ src/Environment/Makefile.am | 3 +- src/Environment/ephemeris.cxx | 62 ++++++++++++++++++++++ src/Environment/ephemeris.hxx | 31 +++++++++++ src/Main/globals.cxx | 1 - src/Main/main.cxx | 19 ++----- src/Time/sunsolver.cxx | 14 ++--- 7 files changed, 116 insertions(+), 22 deletions(-) create mode 100644 src/Environment/ephemeris.cxx create mode 100644 src/Environment/ephemeris.hxx diff --git a/projects/VC90/FlightGear/FlightGear.vcproj b/projects/VC90/FlightGear/FlightGear.vcproj index 7661650cf..ce1edc982 100644 --- a/projects/VC90/FlightGear/FlightGear.vcproj +++ b/projects/VC90/FlightGear/FlightGear.vcproj @@ -3485,6 +3485,14 @@ RelativePath="..\..\..\src\Environment\ridge_lift.hxx" > + + + + + +#include +#include + +#include
+#include
+ +Ephemeris::Ephemeris() : + _impl(NULL), + _latProp(NULL) +{ +} + +Ephemeris::~Ephemeris() +{ + delete _impl; +} + +void Ephemeris::init() +{ + if (_impl) { + return; + } + + SGPath ephem_data_path(globals->get_fg_root()); + ephem_data_path.append("Astro"); + _impl = new SGEphemeris(ephem_data_path.c_str()); + globals->set_ephem(_impl); +} + +void Ephemeris::postinit() +{ + update(0.0); +} + +static void tieStar(const char* prop, Star* s, double (Star::*getter)() const) +{ + fgGetNode(prop, true)->tie(SGRawValueMethods(*s, getter, NULL)); +} + +void Ephemeris::bind() +{ + _latProp = fgGetNode("/position/latitude-deg", true); + + tieStar("/ephemeris/sun/xs", _impl->get_sun(), &Star::getxs); + tieStar("/ephemeris/sun/ys", _impl->get_sun(), &Star::getys); + tieStar("/ephemeris/sun/ze", _impl->get_sun(), &Star::getze); + tieStar("/ephemeris/sun/ye", _impl->get_sun(), &Star::getye); + + tieStar("/ephemeris/sun/lat-deg", _impl->get_sun(), &Star::getLat); +} + +void Ephemeris::unbind() +{ +} + +void Ephemeris::update(double) +{ + SGTime* st = globals->get_time_params(); + _impl->update(st->getMjd(), st->getLst(), _latProp->getDoubleValue()); +} diff --git a/src/Environment/ephemeris.hxx b/src/Environment/ephemeris.hxx new file mode 100644 index 000000000..3a03de5c3 --- /dev/null +++ b/src/Environment/ephemeris.hxx @@ -0,0 +1,31 @@ +#ifndef FG_ENVIRONMENT_EPHEMERIS_HXX +#define FG_ENVIRONMENT_EPHEMERIS_HXX + +#include + +class SGEphemeris; +class SGPropertyNode; + +/** + * Wrap SGEphemeris in a susbsytem/property interface + */ +class Ephemeris : public SGSubsystem +{ +public: + + Ephemeris(); + ~Ephemeris(); + + virtual void bind(); + virtual void unbind(); + virtual void update(double dt); + virtual void init(); + virtual void postinit(); + +private: + SGEphemeris* _impl; + SGPropertyNode* _latProp; +}; + +#endif // of FG_ENVIRONMENT_EPHEMERIS_HXX + diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index da3de6a46..1ae7c81d2 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -131,7 +131,6 @@ FGGlobals::~FGGlobals() delete subsystem_mgr; delete event_mgr; delete time_params; - delete ephem; delete mag; delete matlib; delete route_mgr; diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 679c0e0b5..edf2f84e4 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -41,7 +41,6 @@ #include // Class references -#include #include #include #include @@ -71,6 +70,7 @@ #include #include