diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index f1c542310..1ebff97b1 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1397,6 +1397,14 @@ bool fgInitSubsystems() { //////////////////////////////////////////////////////////////////// globals->add_subsystem("atis", new FGAtisManager, SGSubsystemMgr::POST_FDM); #endif + + + //////////////////////////////////////////////////////////////////// + // Initialize multiplayer subsystem + //////////////////////////////////////////////////////////////////// + + globals->add_subsystem("mp", new FGMultiplayMgr, SGSubsystemMgr::POST_FDM); + //////////////////////////////////////////////////////////////////// // Initialise the AI Model Manager //////////////////////////////////////////////////////////////////// @@ -1465,13 +1473,6 @@ bool fgInitSubsystems() { globals->get_subsystem_mgr()->bind(); globals->get_subsystem_mgr()->init(); - //////////////////////////////////////////////////////////////////// - // Initialize multiplayer subsystem - //////////////////////////////////////////////////////////////////// - - globals->set_multiplayer_mgr(new FGMultiplayMgr); - globals->get_multiplayer_mgr()->init(); - //////////////////////////////////////////////////////////////////////// // Initialize the Nasal interpreter. // Do this last, so that the loaded scripts see initialized state diff --git a/src/Main/fg_os_osgviewer.cxx b/src/Main/fg_os_osgviewer.cxx index 26ecbd266..483a7f417 100644 --- a/src/Main/fg_os_osgviewer.cxx +++ b/src/Main/fg_os_osgviewer.cxx @@ -292,6 +292,10 @@ int fgOSMainLoop() int fgGetKeyModifiers() { + if (!globals->get_renderer()) { // happens during shutdown + return 0; + } + return globals->get_renderer()->getEventHandler()->getCurrentModifiers(); } diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 93755ced7..a5eb32563 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -150,8 +150,8 @@ FGGlobals::FGGlobals() : tacanlist( NULL ), carrierlist( NULL ), channellist( NULL ), - airwaynet( NULL ), - multiplayer_mgr( NULL ) + airwaynet( NULL ) + { simgear::ResourceManager::instance()->addProvider(new AircraftResourceProvider()); } @@ -161,6 +161,8 @@ FGGlobals::FGGlobals() : FGGlobals::~FGGlobals() { delete renderer; + renderer = NULL; + // The AIModels manager performs a number of actions upon // Shutdown that implicitly assume that other subsystems // are still operational (Due to the dynamic allocation and @@ -168,16 +170,11 @@ FGGlobals::~FGGlobals() // shut down all subsystems, make sure we take down the // AIModels system first. subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model"); - // FGInput (FGInputEvent) and FGDialog calls get_subsystem() in their destructors, - // which is not safe since some subsystem are already deleted but can be referred. - // So these subsystems must be deleted prior to deleting subsystem_mgr unless - // ~SGSubsystemGroup and SGSubsystemMgr::get_subsystem are changed not to refer to - // deleted subsystems. - subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("input"); - subsystem_mgr->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("gui"); + subsystem_mgr->unbind(); delete subsystem_mgr; delete event_mgr; + delete time_params; delete mag; delete matlib; @@ -203,7 +200,6 @@ FGGlobals::~FGGlobals() delete carrierlist; delete channellist; delete airwaynet; - delete multiplayer_mgr; soundmgr->unbind(); delete soundmgr; diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index fccee8c51..20f1a6de4 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -66,7 +66,6 @@ class FGLight; class FGModelMgr; class FGRouteMgr; class FGScenery; -class FGMultiplayMgr; class FGPanel; class FGTileMgr; class FGViewMgr; @@ -175,9 +174,6 @@ private: FGTACANList *channellist; FGAirwayNetwork *airwaynet; - //Mulitplayer managers - FGMultiplayMgr *multiplayer_mgr; - /// roots of Aircraft trees string_list fg_aircraft_dirs; public: @@ -289,13 +285,6 @@ public: model_mgr = mgr; } - inline FGMultiplayMgr *get_multiplayer_mgr () { return multiplayer_mgr; } - - inline void set_multiplayer_mgr (FGMultiplayMgr * mgr) - { - multiplayer_mgr = mgr; - } - inline string_list *get_channel_options_list () { return channel_options_list; } diff --git a/src/Main/main.cxx b/src/Main/main.cxx index 1ed54dfe0..4e15fea75 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -146,11 +146,6 @@ static void fgMainLoop( void ) { altitude->getDoubleValue() * SG_FEET_TO_METER, globals->get_time_params()->getJD() ); - - // Update any multiplayer's network queues, the AIMultiplayer - // implementation is an AI model and depends on that - globals->get_multiplayer_mgr()->Update(); - #if ENABLE_ATCDCL // Run ATC subsystem if (fgGetBool("/sim/atc/enabled")) diff --git a/src/MultiPlayer/multiplaymgr.cxx b/src/MultiPlayer/multiplaymgr.cxx index 7574332b2..6ac9aada5 100644 --- a/src/MultiPlayer/multiplaymgr.cxx +++ b/src/MultiPlayer/multiplaymgr.cxx @@ -366,7 +366,7 @@ FGMultiplayMgr::~FGMultiplayMgr() // Initialise object // ////////////////////////////////////////////////////////////////////// -bool +void FGMultiplayMgr::init (void) { ////////////////////////////////////////////////// @@ -374,7 +374,7 @@ FGMultiplayMgr::init (void) ////////////////////////////////////////////////// if (mInitialised) { SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised"); - return false; + return; } ////////////////////////////////////////////////// // Set members from property values @@ -400,7 +400,7 @@ FGMultiplayMgr::init (void) if (rxPort <= 0) { SG_LOG(SG_NETWORK, SG_DEBUG, "FGMultiplayMgr - No receiver port, Multiplayermode disabled"); - return (false); + return; } if (mCallsign.empty()) mCallsign = "JohnDoe"; // FIXME: use getpwuid @@ -415,17 +415,17 @@ FGMultiplayMgr::init (void) if (!mSocket->open(false)) { SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::init - Failed to create data socket" ); - return false; + return; } mSocket->setBlocking(false); if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) { perror("bind"); SG_LOG( SG_NETWORK, SG_DEBUG, "FGMultiplayMgr::Open - Failed to bind receive socket" ); - return false; + return; } + mInitialised = true; - return true; } // FGMultiplayMgr::init() ////////////////////////////////////////////////////////////////////// @@ -710,7 +710,7 @@ FGMultiplayMgr::SendTextMessage(const string &MsgText) // ////////////////////////////////////////////////////////////////////// void -FGMultiplayMgr::Update(void) +FGMultiplayMgr::update(double) { if (!mInitialised) return; diff --git a/src/MultiPlayer/multiplaymgr.hxx b/src/MultiPlayer/multiplaymgr.hxx index eb5fc1edf..b2417f8dd 100644 --- a/src/MultiPlayer/multiplaymgr.hxx +++ b/src/MultiPlayer/multiplaymgr.hxx @@ -33,25 +33,20 @@ #include "mpmessages.hxx" -#ifdef HAVE_CONFIG_H -# include -#endif - #include -using std::string; #include -using std::vector; #include #include #include #include
+#include #include struct FGExternalMotionInfo; -class FGMultiplayMgr +class FGMultiplayMgr : public SGSubsystem { public: @@ -67,13 +62,15 @@ public: FGMultiplayMgr(); ~FGMultiplayMgr(); - bool init(void); + + virtual void init(void); + virtual void update(double dt); + void Close(void); // transmitter void SendMyPosition(const FGExternalMotionData& motionInfo); void SendTextMessage(const string &sMsgText); // receiver - void Update(void); private: union MsgBuf; @@ -93,7 +90,7 @@ private: netAddress mServer; bool mHaveServer; bool mInitialised; - string mCallsign; + std::string mCallsign; }; #endif diff --git a/src/Network/multiplay.cxx b/src/Network/multiplay.cxx index d37c42fdf..eb8a52c08 100644 --- a/src/Network/multiplay.cxx +++ b/src/Network/multiplay.cxx @@ -243,7 +243,7 @@ bool FGMultiplay::process() { motionInfo.properties.push_back(pData); } - FGMultiplayMgr* mpmgr = globals->get_multiplayer_mgr(); + FGMultiplayMgr* mpmgr = (FGMultiplayMgr*) globals->get_subsystem("mp"); mpmgr->SendMyPosition(motionInfo); // Now remove the data @@ -272,7 +272,7 @@ bool FGMultiplay::process() { ******************************************************************/ bool FGMultiplay::close() { - FGMultiplayMgr *mgr = globals->get_multiplayer_mgr(); + FGMultiplayMgr* mgr = (FGMultiplayMgr*) globals->get_subsystem("mp"); if (mgr == 0) { return false;