From f4f1beba64cdb13c66a08118055933c266bd8a83 Mon Sep 17 00:00:00 2001 From: Kuhnovic <68320206+Kuhnovic@users.noreply.github.com> Date: Fri, 26 Sep 2025 11:37:50 +0200 Subject: [PATCH] Codechange: Moved PruneIntermediateNodeBranch to rail pathfinder. (#14662) --- src/pathfinder/yapf/yapf_base.hpp | 18 ---------------- src/pathfinder/yapf/yapf_rail.cpp | 35 +++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/pathfinder/yapf/yapf_base.hpp b/src/pathfinder/yapf/yapf_base.hpp index f8888e1364..2c8a728953 100644 --- a/src/pathfinder/yapf/yapf_base.hpp +++ b/src/pathfinder/yapf/yapf_base.hpp @@ -185,24 +185,6 @@ public: } } - /** - * In some cases an intermediate node branch should be pruned. - * The most prominent case is when a red EOL signal is encountered, but - * there was a segment change (e.g. a rail type change) before that. If - * the branch would not be pruned, the rail type change location would - * remain the best intermediate node, and thus the vehicle would still - * go towards the red EOL signal. - */ - void PruneIntermediateNodeBranch(Node *n) - { - bool intermediate_on_branch = false; - while (n != nullptr && !n->segment->end_segment_reason.Test(EndSegmentReason::ChoiceFollows)) { - if (n == Yapf().best_intermediate_node) intermediate_on_branch = true; - n = n->parent; - } - if (intermediate_on_branch) Yapf().best_intermediate_node = n; - } - /** * AddNewNode() - called by Tderived::PfFollowNode() for each child node. * Nodes are evaluated here and added into open list diff --git a/src/pathfinder/yapf/yapf_rail.cpp b/src/pathfinder/yapf/yapf_rail.cpp index 208b65b737..4d22118be5 100644 --- a/src/pathfinder/yapf/yapf_rail.cpp +++ b/src/pathfinder/yapf/yapf_rail.cpp @@ -544,14 +544,37 @@ struct CYapfRail_TypesT { typedef CYapfCostRailT PfCost; }; -struct CYapfRail : CYapfT> {}; -struct CYapfRailNo90 : CYapfT> {}; +template +struct CYapfRailBase : CYapfT { + typedef typename Types::NodeList::Item Node; -struct CYapfAnyDepotRail : CYapfT> {}; -struct CYapfAnyDepotRailNo90 : CYapfT> {}; + /** + * In some cases an intermediate node branch should be pruned. + * The most prominent case is when a red EOL signal is encountered, but + * there was a segment change (e.g. a rail type change) before that. If + * the branch would not be pruned, the rail type change location would + * remain the best intermediate node, and thus the vehicle would still + * go towards the red EOL signal. + */ + void PruneIntermediateNodeBranch(Node *n) + { + bool intermediate_on_branch = false; + while (n != nullptr && !n->segment->end_segment_reason.Test(EndSegmentReason::ChoiceFollows)) { + if (n == this->best_intermediate_node) intermediate_on_branch = true; + n = n->parent; + } + if (intermediate_on_branch) this->best_intermediate_node = n; + } +}; -struct CYapfAnySafeTileRail : CYapfT> {}; -struct CYapfAnySafeTileRailNo90 : CYapfT> {}; +struct CYapfRail : CYapfRailBase> {}; +struct CYapfRailNo90 : CYapfRailBase> {}; + +struct CYapfAnyDepotRail : CYapfRailBase> {}; +struct CYapfAnyDepotRailNo90 : CYapfRailBase> {}; + +struct CYapfAnySafeTileRail : CYapfRailBase> {}; +struct CYapfAnySafeTileRailNo90 : CYapfRailBase> {}; Track YapfTrainChooseTrack(const Train *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool &path_found, bool reserve_track, PBSTileInfo *target, TileIndex *dest)