]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/multiplay.cxx
Fix bug 191, uninitialised HUD color.
[flightgear.git] / src / Network / multiplay.cxx
index eb8a52c084628730fec8b90ad7fca276a25147dd..a9cd32bf3823009c0fb6002270d321b993f35c35 100644 (file)
@@ -28,8 +28,7 @@
 
 #include <simgear/compiler.h>
 
-#include <string>
-
+#include <cstring>
 #include <iostream>
 #include <map>
 #include <string>
@@ -49,6 +48,24 @@ using std::string;
 const char sFG_MULTIPLAY_BID[] = "$Id$";
 const char sFG_MULTIPLAY_HID[] = FG_MULTIPLAY_HID;
 
+typedef std::set<std::string> string_set;
+
+class MPPropertyListener : public SGPropertyChangeListener
+{
+public:
+  MPPropertyListener(FGMultiplay* mp) :
+    _multiplay(mp)
+  {
+  }
+
+  virtual void childAdded(SGPropertyNode*, SGPropertyNode*)
+  {
+    _multiplay->setPropertiesChanged();
+  }
+
+private:
+  FGMultiplay* _multiplay;
+};
 
 /******************************************************************
 * Name: FGMultiplay
@@ -73,6 +90,7 @@ FGMultiplay::FGMultiplay (const string &dir, const int rate, const string &host,
 
   }
 
+  mPropertiesChanged = true;
 }
 
 
@@ -97,19 +115,38 @@ bool FGMultiplay::open() {
     }
 
     set_enabled(true);
-
-    SGPropertyNode* root = globals->get_props();
-
-    /// Build up the id to property map
     
-    for (unsigned i = 0; i < FGMultiplayMgr::numProperties; ++i) {
+    mPropertiesChanged = true;
+    
+    MPPropertyListener* pl = new MPPropertyListener(this);
+    globals->get_props()->addChangeListener(pl, false);
+    return is_enabled();
+}
+
+void FGMultiplay::findProperties()
+{
+  if (!mPropertiesChanged) {
+    return;
+  }
+  
+  mPropertiesChanged = false;
+  
+  for (unsigned i = 0; i < FGMultiplayMgr::numProperties; ++i) {
       const char* name = FGMultiplayMgr::sIdPropertyList[i].name;
-      SGPropertyNode* pNode = root->getNode(name);
-      if (pNode)
-        mPropertyMap[FGMultiplayMgr::sIdPropertyList[i].id] = pNode;
+      SGPropertyNode* pNode = globals->get_props()->getNode(name);
+      if (!pNode) {
+        continue;
+      }
+      
+      int id = FGMultiplayMgr::sIdPropertyList[i].id;
+      if (mPropertyMap.find(id) != mPropertyMap.end()) {
+        continue; // already activated
+      }
+      
+      mPropertyMap[id] = pNode;
+      SG_LOG(SG_NETWORK, SG_INFO, "activating MP property:" << pNode->getPath());
     }
 
-    return is_enabled();
 }
 
 
@@ -121,7 +158,8 @@ bool FGMultiplay::open() {
 bool FGMultiplay::process() {
   using namespace simgear;
   if (get_direction() == SG_IO_OUT) {
-
+    findProperties();
+    
     // check if we have left initialization phase. That will not provide
     // interresting data, also the freeze in simulation time hurts the
     // multiplayer clients
@@ -270,8 +308,10 @@ bool FGMultiplay::process() {
 * Description:  Closes the multiplayer mgrs to stop any further
 * network processing
 ******************************************************************/
-bool FGMultiplay::close() {
-
+bool FGMultiplay::close()
+{
+  mPropertyMap.clear();
+  
   FGMultiplayMgr* mgr = (FGMultiplayMgr*) globals->get_subsystem("mp");
 
   if (mgr == 0) {