]> git.mxchange.org Git - flightgear.git/blobdiff - src/AIModel/AIMultiplayer.cxx
James Turner: Improved runway management code:
[flightgear.git] / src / AIModel / AIMultiplayer.cxx
index 9a0e80e6f5de8005e3891128e373c20a80cf5e8c..a34a92775635f1bbd2353b9ce71a528e56d74f6b 100755 (executable)
@@ -43,12 +43,13 @@ FGAIMultiplayer::FGAIMultiplayer() : FGAIBase(otMultiplayer) {
 FGAIMultiplayer::~FGAIMultiplayer() {
 }
 
-bool FGAIMultiplayer::init() {
+bool FGAIMultiplayer::init(bool search_in_AI_path) {
+    props->setStringValue("sim/model/path", model_path.c_str());
     //refuel_node = fgGetNode("systems/refuel/contact", true);
     isTanker = false; // do this until this property is
                       // passed over the net
 
-    string str1 = mCallSign;
+    string str1 = _getCallsign();
     string str2 = "MOBIL";
 
     string::size_type loc1= str1.find( str2, 0 );
@@ -57,7 +58,7 @@ bool FGAIMultiplayer::init() {
         isTanker = true;
         //        cout << "isTanker " << isTanker << " " << mCallSign <<endl;
     }
-   return FGAIBase::init();
+   return FGAIBase::init(search_in_AI_path);
 }
 
 void FGAIMultiplayer::bind() {
@@ -73,7 +74,7 @@ SGRawValueMethods<FGAIMultiplayer, type>(*this, &FGAIMultiplayer::get##name)
 SGRawValueMethods<FGAIMultiplayer, type>(*this, \
       &FGAIMultiplayer::get##name, &FGAIMultiplayer::set##name)
 
-    props->tie("callsign", AIMPROProp(const char *, CallSign));
+    //props->tie("callsign", AIMPROProp(const char *, CallSign));
 
     props->tie("controls/allow-extrapolation",
                AIMPRWProp(bool, AllowExtrapolation));
@@ -88,7 +89,7 @@ SGRawValueMethods<FGAIMultiplayer, type>(*this, \
 void FGAIMultiplayer::unbind() {
     FGAIBase::unbind();
 
-    props->untie("callsign");
+    //props->untie("callsign");
     props->untie("controls/allow-extrapolation");
     props->untie("controls/lag-adjust-system-speed");
     props->untie("refuel/contact");
@@ -276,8 +277,8 @@ void FGAIMultiplayer::update(double dt)
               case SGPropertyNode::INT:   
               case SGPropertyNode::BOOL:
               case SGPropertyNode::LONG:        
-                ival = (int) (1-tau)*((double) (*prevPropIt)->int_value) +
-                  tau*((double) (*nextPropIt)->int_value);
+                ival = (int) (0.5+(1-tau)*((double) (*prevPropIt)->int_value) +
+                  tau*((double) (*nextPropIt)->int_value));
                 pIt->second->setIntValue(ival);
                 //cout << "Int: " << ival << "\n";
                 break;
@@ -469,9 +470,18 @@ FGAIMultiplayer::addMotionInfo(const FGExternalMotionData& motionInfo,
                                long stamp)
 {
   mLastTimestamp = stamp;
-  // Drop packets arriving out of order
-  if (!mMotionInfo.empty() && motionInfo.time < mMotionInfo.rbegin()->first)
-    return;
+
+  if (!mMotionInfo.empty()) {
+    double diff = motionInfo.time - mMotionInfo.rbegin()->first;
+
+    // packet is very old -- MP has probably reset (incl. his timebase)
+    if (diff < -10.0)
+      mMotionInfo.clear();
+
+    // drop packets arriving out of order
+    else if (diff < 0.0)
+      return;
+  }
   mMotionInfo[motionInfo.time] = motionInfo;
 }