]> git.mxchange.org Git - flightgear.git/commitdiff
Make MultiPlayer a well-behaved subsystem.
authorJames Turner <zakalawe@mac.com>
Sat, 2 Oct 2010 22:40:38 +0000 (23:40 +0100)
committerJames Turner <zakalawe@mac.com>
Tue, 5 Oct 2010 22:17:32 +0000 (23:17 +0100)
src/Main/fg_init.cxx
src/Main/fg_os_osgviewer.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Main/main.cxx
src/MultiPlayer/multiplaymgr.cxx
src/MultiPlayer/multiplaymgr.hxx
src/Network/multiplay.cxx

index f1c542310228cd95025801fb754cc36aec8a1336..1ebff97b1439bdccbaec25b5179966a1701a6b15 100644 (file)
@@ -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
index 26ecbd2669a21dbf131d11b1ec66c4d1da3192d5..483a7f4178387ba10e4e472ed3470277cd14829f 100644 (file)
@@ -292,6 +292,10 @@ int fgOSMainLoop()
 
 int fgGetKeyModifiers()
 {
+    if (!globals->get_renderer()) { // happens during shutdown
+      return 0;
+    }
+    
     return globals->get_renderer()->getEventHandler()->getCurrentModifiers();
 }
 
index 93755ced7198f81f0c9f5ac1709ccd0660b04a26..a5eb32563f3729f09a1aab13ec65c28ad775bf81 100644 (file)
@@ -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;
index fccee8c5159bf6ae209b7c685baa059dd98cc163..20f1a6de42d0168865f4d86c955ad6aafb92891d 100644 (file)
@@ -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;
     }
index 1ed54dfe03a2b3dbd418f3c0a4d1288ba5037d09..4e15fea753f93d3a13d4688db3f8518e33b1b165 100644 (file)
@@ -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"))
index 7574332b26d34064fb8932d778d6dcaf8ac13037..6ac9aada5327cb3cf368bfbdd7d0841655829821 100644 (file)
@@ -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;
index eb5fc1edf004bda1570503d828a03c1ced3c3c94..b2417f8dd5b5c1c6fde9b65548b41e43ecb3cea9 100644 (file)
 
 #include "mpmessages.hxx"
 
-#ifdef HAVE_CONFIG_H
-#  include <config.h>
-#endif
-
 #include <string>
-using std::string;
 #include <vector>
-using std::vector;
 
 #include <simgear/compiler.h>
 #include <simgear/props/props.hxx>
 #include <plib/netSocket.h>
 #include <Main/globals.hxx>
+#include <simgear/structure/subsystem_mgr.hxx>
 
 #include <AIModel/AIMultiplayer.hxx>
 
 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
index d37c42fdf5040cb98cdf7293e091b74f5a83669e..eb8a52c084628730fec8b90ad7fca276a25147dd 100644 (file)
@@ -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;