Traffic performance: cache track length
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.
This commit is contained in:
parent
bb494e52e5
commit
439ad4a7c8
2 changed files with 19 additions and 1 deletions
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue