From 35b054744b1e54ba48076ae5601e170baed0bdd3 Mon Sep 17 00:00:00 2001 From: cirdan Date: Sat, 1 Feb 2014 09:05:57 +0100 Subject: [PATCH] Avoid checking for destination twice in CYapfRoadT The check for a destination tile for road vehicles can be somewhat expensive, so record whether the inner segment loop in CYapfRoadT::PfFollowNode is broken out from because a destination is found, to avoid repeating the check later. --- src/pathfinder/yapf/yapf_road.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 9cde1d1d3..e0af66413 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -168,12 +168,16 @@ public: n->m_segment_last = pos; tf.SetPos (pos); + bool is_target = false; for (;;) { /* base tile cost depending on distance between edges */ segment_cost += OneTileCost (&PfGetSettings(), tf.m_new); /* we have reached the vehicle's destination - segment should end here to avoid target skipping */ - if (PfDetectDestinationTile(tf.m_new)) break; + if (PfDetectDestinationTile(tf.m_new)) { + is_target = true; + break; + } /* stop if we have just entered the depot */ if (IsRoadDepotTile(tf.m_new.tile) && tf.m_new.td == DiagDirToDiagTrackdir(ReverseDiagDir(GetGroundDepotDirection(tf.m_new.tile)))) { @@ -214,7 +218,7 @@ public: n->m_cost = old_node.m_cost + segment_cost; /* compute estimated cost */ - if (PfDetectDestination(*n)) { + if (is_target) { n->m_estimate = n->m_cost; TAstar::FoundTarget(n); } else { -- 2.11.4.GIT