]> git.mxchange.org Git - flightgear.git/commitdiff
Traffic performance: cache track length
authorThorstenB <brehmt@gmail.com>
Sat, 24 Nov 2012 11:06:20 +0000 (12:06 +0100)
committerThorstenB <brehmt@gmail.com>
Sat, 24 Nov 2012 11:06:20 +0000 (12:06 +0100)
Track length is calculate every iteration/for every aircraft. Since some
tracks have hundreds of waypoints, calculation is slow. Cache the
track length between the waypoints ahead, so it rarely needs to be
recalculated.

src/AIModel/AIAircraft.cxx
src/AIModel/AIAircraft.hxx

index d2aac7502e3aca2490e9ad2d43974b428b70daf2..7622402474324c561b0d2073323e7c82fe9bcc96 100644 (file)
@@ -94,6 +94,8 @@ FGAIAircraft::FGAIAircraft(FGAISchedule *ref) :
     _performance = 0; //TODO initialize to JET_TRANSPORT from PerformanceDB
     dt = 0;
     takeOffStatus = 0;
+
+    trackCache.remainingLength = 0;
 }
 
 
@@ -1347,7 +1349,16 @@ time_t FGAIAircraft::checkForArrivalTime(const string& wptName) {
      FGAIWaypoint* curr = 0;
      curr = fp->getCurrentWaypoint();
 
-     double tracklength = fp->checkTrackLength(wptName);
+     // don't recalculate tracklength unless the start/stop waypoint has changed
+     if (curr &&
+         ((curr->getName() != trackCache.startWptName)||
+          (wptName != trackCache.finalWptName)))
+     {
+         trackCache.remainingLength = fp->checkTrackLength(wptName);
+         trackCache.startWptName = curr->getName();
+         trackCache.finalWptName = wptName;
+     }
+     double tracklength = trackCache.remainingLength;
      if (tracklength > 0.1) {
           tracklength += fp->getDistanceToGo(pos.getLatitudeDeg(), pos.getLongitudeDeg(), curr);
      } else {
index 9d8fc8e5e772a29af30e547734a6095fe91c2790..3ce0d62832aaaf2d8aa8383a62a0f18325c04bcc 100644 (file)
@@ -184,6 +184,13 @@ private:
     PerformanceData* _performance; // the performance data for this aircraft
     
    void assertSpeed(double speed);
+
+   struct
+   {
+       double remainingLength;
+       std::string startWptName;
+       std::string finalWptName;
+   } trackCache;
 };