From 154464140528441f73da8a27d3e93ac04b72d277 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 10 Dec 2015 16:48:02 -0600 Subject: [PATCH] Remove view/tile/scenery members from globals - also fix sound manager creation --- src/Main/fg_init.cxx | 14 ++++++-------- src/Main/globals.cxx | 28 +++++++++++----------------- src/Main/globals.hxx | 18 +++--------------- src/Main/main.cxx | 4 ++-- src/Sound/soundmanager.hxx | 2 ++ src/Viewer/fgviewer.cxx | 6 +++--- src/Viewer/viewmgr.cxx | 2 -- src/Viewer/viewmgr.hxx | 1 + 8 files changed, 28 insertions(+), 47 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 785b2fa5c..d75325574 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -691,7 +691,7 @@ void fgCreateSubsystems(bool duringReset) { // to be updated in every loop. // Sound manager is updated last so it can use the CPU while the GPU // is processing the scenery (doubled the frame-rate for me) -EMH- - globals->add_subsystem("sound", new FGSoundManager, SGSubsystemMgr::SOUND); + globals->add_new_subsystem(SGSubsystemMgr::SOUND); //////////////////////////////////////////////////////////////////// // Initialize the event manager subsystem. @@ -716,7 +716,7 @@ void fgCreateSubsystems(bool duringReset) { //////////////////////////////////////////////////////////////////// // Add the FlightGear property utilities. //////////////////////////////////////////////////////////////////// - globals->add_subsystem("airport-dynamics", new flightgear::AirportDynamicsManager); + globals->add_new_subsystem(); //////////////////////////////////////////////////////////////////// // Add the performance monitoring system. @@ -897,10 +897,7 @@ void fgCreateSubsystems(bool duringReset) { globals->add_subsystem("aircraft-model", new FGAircraftModel, SGSubsystemMgr::DISPLAY); globals->add_subsystem("model-manager", new FGModelMgr, SGSubsystemMgr::DISPLAY); - globals->add_subsystem("view-manager", new FGViewMgr, SGSubsystemMgr::DISPLAY); - - globals->add_subsystem("tile-manager", globals->get_tile_mgr(), - SGSubsystemMgr::DISPLAY); + globals->add_new_subsystem(SGSubsystemMgr::DISPLAY); } void fgPostInitSubsystems() @@ -1050,8 +1047,9 @@ void fgStartNewReset() // order is important here since tile-manager shutdown needs to // access the scenery object - globals->set_tile_mgr(NULL); - globals->set_scenery(NULL); + subsystemManger->remove(FGTileMgr::subsystemName()); + subsystemManger->remove(FGScenery::subsystemName()); + FGScenery::getPagerSingleton()->clearRequests(); flightgear::CameraGroup::setDefault(NULL); diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index eedfd21bc..f2c57e15d 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -158,7 +158,6 @@ FGGlobals::FGGlobals() : fg_home( "" ), time_params( NULL ), ephem( NULL ), - viewmgr( NULL ), commands( SGCommandMgr::instance() ), channel_options_list( NULL ), initial_waypoints( NULL ), @@ -217,9 +216,9 @@ FGGlobals::~FGGlobals() subsystem_mgr->unbind(); subsystem_mgr->remove("aircraft-model"); - subsystem_mgr->remove("tile-manager"); subsystem_mgr->remove("model-manager"); - _tile_mgr.clear(); + + subsystem_mgr->remove(FGTileMgr::subsystemName()); osg::ref_ptr vw(renderer->getViewer()); if (vw) { @@ -238,10 +237,10 @@ FGGlobals::~FGGlobals() } osgDB::Registry::instance()->clearObjectCache(); + subsystem_mgr->remove(FGScenery::subsystemName()); // renderer touches subsystems during its destruction set_renderer(NULL); - _scenery.clear(); _chatter_queue.clear(); delete subsystem_mgr; @@ -694,12 +693,6 @@ FGGlobals::saveUserSettings() } } -FGViewer * -FGGlobals::get_current_view () const -{ - return viewmgr->get_current_view(); -} - long int FGGlobals::get_warp() const { return fgGetInt("/sim/time/warp"); @@ -722,22 +715,23 @@ void FGGlobals::set_warp_delta( long int d ) FGScenery* FGGlobals::get_scenery () const { - return _scenery.get(); + return get_subsystem(); } -void FGGlobals::set_scenery ( FGScenery *s ) +FGTileMgr* FGGlobals::get_tile_mgr () const { - _scenery = s; + return get_subsystem(); } -FGTileMgr* FGGlobals::get_tile_mgr () const +FGViewMgr *FGGlobals::get_viewmgr() const { - return _tile_mgr.get(); + return get_subsystem(); } -void FGGlobals::set_tile_mgr ( FGTileMgr *t ) +FGViewer* FGGlobals::get_current_view () const { - _tile_mgr = t; + FGViewMgr* vm = get_viewmgr(); + return vm ? vm->get_current_view() : 0; } void FGGlobals::set_matlib( SGMaterialLib *m ) diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index db882aee2..82dd12681 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -120,9 +120,6 @@ private: // Material properties library SGSharedPtr matlib; - // viewer manager - FGViewMgr *viewmgr; - SGCommandMgr *commands; // list of serial port-like configurations @@ -132,12 +129,6 @@ private: // and or flight-plan file during initialization string_list *initial_waypoints; - // FlightGear scenery manager - SGSharedPtr _scenery; - - // Tile manager - SGSharedPtr _tile_mgr; - FGFontCache *fontcache; // Navigational Aids @@ -304,10 +295,6 @@ public: inline SGMaterialLib *get_matlib() const { return matlib; } void set_matlib( SGMaterialLib *m ); - inline FGViewMgr *get_viewmgr() const { return viewmgr; } - inline void set_viewmgr( FGViewMgr *vm ) { viewmgr = vm; } - FGViewer *get_current_view() const; - inline SGPropertyNode *get_props () { return props; } /** @@ -345,13 +332,14 @@ public: initial_waypoints = list; } + FGViewMgr *get_viewmgr() const; + FGViewer *get_current_view() const; + FGControls *get_controls() const; FGScenery * get_scenery () const; - void set_scenery ( FGScenery *s ); FGTileMgr * get_tile_mgr () const; - void set_tile_mgr ( FGTileMgr *t ); inline FGFontCache *get_fontcache() const { return fontcache; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 2434d2058..996c05fa9 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -260,10 +260,10 @@ static void fgIdleFunction ( void ) { // Initialize the TG scenery subsystem. //////////////////////////////////////////////////////////////////// - globals->set_scenery( new FGScenery ); + globals->add_new_subsystem(SGSubsystemMgr::DISPLAY); globals->get_scenery()->init(); globals->get_scenery()->bind(); - globals->set_tile_mgr( new FGTileMgr ); + globals->add_new_subsystem(SGSubsystemMgr::DISPLAY); fgSplashProgress("creating-subsystems"); } else if (( idle_state == 7 ) || (idle_state == 2007)) { diff --git a/src/Sound/soundmanager.hxx b/src/Sound/soundmanager.hxx index f76be4b80..a22b73884 100644 --- a/src/Sound/soundmanager.hxx +++ b/src/Sound/soundmanager.hxx @@ -74,6 +74,8 @@ public: ~FGSoundManager() {} void update(double dt) {} + + static const char* subsystemName() { return "sound"; } }; #endif // ENABLE_AUDIO_SUPPORT diff --git a/src/Viewer/fgviewer.cxx b/src/Viewer/fgviewer.cxx index be10d7a64..aa0fbf9a1 100644 --- a/src/Viewer/fgviewer.cxx +++ b/src/Viewer/fgviewer.cxx @@ -199,9 +199,9 @@ fgviewerMain(int argc, char** argv) throw sg_io_exception("Error loading materials file", mpath); } - globals->set_scenery( new FGScenery ); - globals->get_scenery()->init(); - globals->get_scenery()->bind(); + FGScenery* scenery = globals->add_new_subsystem(); + scenery->init(); + scenery->bind(); // The file path list must be set in the registry. osgDB::Registry::instance()->getDataFilePathList() = filePathList; diff --git a/src/Viewer/viewmgr.cxx b/src/Viewer/viewmgr.cxx index 6d7035777..5e7339b77 100644 --- a/src/Viewer/viewmgr.cxx +++ b/src/Viewer/viewmgr.cxx @@ -45,13 +45,11 @@ FGViewMgr::FGViewMgr( void ) : current_view_orientation(SGQuatd::zeros()), current_view_or_offset(SGQuatd::zeros()) { - globals->set_viewmgr(this); } // Destructor FGViewMgr::~FGViewMgr( void ) { - globals->set_viewmgr(NULL); } void diff --git a/src/Viewer/viewmgr.hxx b/src/Viewer/viewmgr.hxx index b8711be8c..4043c6b08 100644 --- a/src/Viewer/viewmgr.hxx +++ b/src/Viewer/viewmgr.hxx @@ -73,6 +73,7 @@ public: void add_view( FGViewer * v ); + static const char* subsystemName() { return "view-mgr"; } private: void do_bind(); -- 2.39.5