]> git.mxchange.org Git - flightgear.git/blobdiff - src/MultiPlayer/multiplaymgr.cxx
toggle fullscreen: also adapt GUI plane when resizing
[flightgear.git] / src / MultiPlayer / multiplaymgr.cxx
index 123317c63536b25d5d9893f8fd13a41a7e09055c..7d6ce8b33dc8909e2cb0655d88702ace460edaca 100644 (file)
@@ -35,7 +35,6 @@
 #include <algorithm>
 #include <cstring>
 #include <errno.h>
-#include <osg/Math>             // isNaN
 
 #include <simgear/misc/stdint.hxx>
 #include <simgear/timing/timestamp.hxx>
@@ -302,7 +301,7 @@ namespace
         case props::DOUBLE:
           {
             float val = XDR_decode_float(*xdr);
-            if (osg::isNaN(val))
+            if (SGMisc<float>::isNaN(val))
               return false;
             xdr++;
             break;
@@ -403,9 +402,11 @@ FGMultiplayMgr::init (void)
     SG_LOG(SG_NETWORK, SG_WARN, "FGMultiplayMgr::init - already initialised");
     return;
   }
-  
-  fgSetBool("/sim/multiplay/online", false);
-  
+
+  SGPropertyNode* propOnline = fgGetNode("/sim/multiplay/online", true);
+  propOnline->setBoolValue(false);
+  propOnline->setAttribute(SGPropertyNode::PRESERVE, true);
+
   //////////////////////////////////////////////////
   //  Set members from property values
   //////////////////////////////////////////////////
@@ -428,19 +429,23 @@ FGMultiplayMgr::init (void)
     if (strncmp (mServer.getHost(), "0.0.0.0", 8) == 0) {
       mHaveServer = false;
       SG_LOG(SG_NETWORK, SG_ALERT,
-        "FGMultiplayMgr - Could not resolve '"
-        << txAddress << "'. Multiplayer mode disabled.");
+        "Cannot enable multiplayer mode: resolving MP server address '"
+        << txAddress << "' failed.");
       return;
     } else {
-        SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
+      SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - have server");
       mHaveServer = true;
     }
     if (rxPort <= 0)
       rxPort = txPort;
+  } else {
+    SG_LOG(SG_NETWORK, SG_INFO, "FGMultiplayMgr - multiplayer mode disabled (no MP server specificed).");
+    return;
   }
+
   if (rxPort <= 0) {
-    SG_LOG(SG_NETWORK, SG_INFO,
-      "FGMultiplayMgr - No receiver port. Multiplayer mode disabled.");
+    SG_LOG(SG_NETWORK, SG_ALERT,
+      "Cannot enable multiplayer mode: No receiver port specified.");
     return;
   }
   if (mCallsign.empty())
@@ -453,14 +458,14 @@ FGMultiplayMgr::init (void)
   
   mSocket.reset(new simgear::Socket());
   if (!mSocket->open(false)) {
-    SG_LOG( SG_NETWORK, SG_WARN,
-            "FGMultiplayMgr - Failed to create data socket. Multiplayer mode disabled." );
+    SG_LOG( SG_NETWORK, SG_ALERT,
+            "Cannot enable multiplayer mode: creating data socket failed." );
     return;
   }
   mSocket->setBlocking(false);
   if (mSocket->bind(rxAddress.c_str(), rxPort) != 0) {
     SG_LOG( SG_NETWORK, SG_ALERT,
-            "FGMultiplayMgr - Failed to bind receive socket. Multiplayer mode disabled. "
+            "Cannot enable multiplayer mode: binding receive socket failed. "
             << strerror(errno) << "(errno " << errno << ")");
     return;
   }
@@ -473,6 +478,12 @@ FGMultiplayMgr::init (void)
   mInitialised = true;
 
   SG_LOG(SG_NETWORK, SG_ALERT, "Multiplayer mode active!");
+
+  if (!fgGetBool("/sim/ai/enabled"))
+  {
+      // multiplayer depends on AI module
+      fgSetBool("/sim/ai/enabled", true);
+  }
 } // FGMultiplayMgr::init()
 //////////////////////////////////////////////////////////////////////
 
@@ -599,8 +610,8 @@ FGMultiplayMgr::isSane(const FGExternalMotionData& motionInfo)
 {
     // check for corrupted data (NaNs)
     bool isCorrupted = false;
-    isCorrupted |= ((osg::isNaN(motionInfo.time           )) ||
-                    (osg::isNaN(motionInfo.lag            )) ||
+    isCorrupted |= ((SGMisc<double>::isNaN(motionInfo.time           )) ||
+                    (SGMisc<double>::isNaN(motionInfo.lag            )) ||
                     (osg::isNaN(motionInfo.orientation(3) )));
     for (unsigned i = 0; (i < 3)&&(!isCorrupted); ++i)
     {
@@ -965,10 +976,10 @@ FGMultiplayMgr::Send()
     }
 
     double sim_time = globals->get_sim_time_sec();
-    static double lastTime = 0.0;
+//    static double lastTime = 0.0;
     
    // SG_LOG(SG_GENERAL, SG_INFO, "actual dt=" << sim_time - lastTime);
-    lastTime = sim_time;
+//    lastTime = sim_time;
     
     FlightProperties ifce;