1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2025-12-21 12:12:43 +01:00

Codechange: Rename TrackFollowers to follower. (#14664)

Replaces use of codestyle breaking `F` in places.
This commit is contained in:
Peter Nelson
2025-09-27 18:10:22 +01:00
committed by GitHub
parent 69ea970d6e
commit 0aaeb6f7e7
5 changed files with 42 additions and 42 deletions

View File

@@ -185,7 +185,7 @@ public:
* AddNewNode() - called by Tderived::PfFollowNode() for each child node. * AddNewNode() - called by Tderived::PfFollowNode() for each child node.
* Nodes are evaluated here and added into open list * Nodes are evaluated here and added into open list
*/ */
void AddNewNode(Node &n, const TrackFollower &tf) void AddNewNode(Node &n, const TrackFollower &follower)
{ {
assert(n.parent != nullptr); assert(n.parent != nullptr);
@@ -197,7 +197,7 @@ public:
this->stats_cache_hits++; this->stats_cache_hits++;
} }
bool valid = Yapf().PfCalcCost(n, &tf); bool valid = Yapf().PfCalcCost(n, &follower);
if (valid) valid = Yapf().PfCalcEstimate(n); if (valid) valid = Yapf().PfCalcEstimate(n);

View File

@@ -271,11 +271,11 @@ public:
* Calculates only the cost of given node, adds it to the parent node cost * Calculates only the cost of given node, adds it to the parent node cost
* and stores the result into Node::cost member * and stores the result into Node::cost member
*/ */
inline bool PfCalcCost(Node &n, const TrackFollower *tf) inline bool PfCalcCost(Node &n, const TrackFollower *follower)
{ {
assert(!n.flags_u.flags_s.target_seen); assert(!n.flags_u.flags_s.target_seen);
assert(tf->new_tile == n.key.tile); assert(follower->new_tile == n.key.tile);
assert((HasTrackdir(tf->new_td_bits, n.key.td))); assert((HasTrackdir(follower->new_td_bits, n.key.td)));
/* Does the node have some parent node? */ /* Does the node have some parent node? */
bool has_parent = (n.parent != nullptr); bool has_parent = (n.parent != nullptr);
@@ -326,7 +326,7 @@ public:
EndSegmentReasons end_segment_reason{}; EndSegmentReasons end_segment_reason{};
TrackFollower tf_local(v, Yapf().GetCompatibleRailTypes()); TrackFollower follower_local{v, Yapf().GetCompatibleRailTypes()};
if (!has_parent) { if (!has_parent) {
/* We will jump to the middle of the cost calculator assuming that segment cache is not used. */ /* We will jump to the middle of the cost calculator assuming that segment cache is not used. */
@@ -378,7 +378,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
segment_cost += Yapf().OneTileCost(cur.tile, cur.td); segment_cost += Yapf().OneTileCost(cur.tile, cur.td);
/* If we skipped some tunnel/bridge/station tiles, add their base cost */ /* If we skipped some tunnel/bridge/station tiles, add their base cost */
segment_cost += YAPF_TILE_LENGTH * tf->tiles_skipped; segment_cost += YAPF_TILE_LENGTH * follower->tiles_skipped;
/* Slope cost. */ /* Slope cost. */
segment_cost += Yapf().SlopeCost(cur.tile, cur.td); segment_cost += Yapf().SlopeCost(cur.tile, cur.td);
@@ -387,7 +387,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
segment_cost += Yapf().SignalCost(n, cur.tile, cur.td); segment_cost += Yapf().SignalCost(n, cur.tile, cur.td);
/* Reserved tiles. */ /* Reserved tiles. */
segment_cost += Yapf().ReservationCost(n, cur.tile, cur.td, tf->tiles_skipped); segment_cost += Yapf().ReservationCost(n, cur.tile, cur.td, follower->tiles_skipped);
end_segment_reason = segment.end_segment_reason; end_segment_reason = segment.end_segment_reason;
@@ -445,9 +445,9 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
/* Waypoint is also a good reason to finish. */ /* Waypoint is also a good reason to finish. */
end_segment_reason.Set(EndSegmentReason::Waypoint); end_segment_reason.Set(EndSegmentReason::Waypoint);
} else if (tf->is_station) { } else if (follower->is_station) {
/* Station penalties. */ /* Station penalties. */
uint platform_length = tf->tiles_skipped + 1; uint platform_length = follower->tiles_skipped + 1;
/* We don't know yet if the station is our target or not. Act like /* We don't know yet if the station is our target or not. Act like
* if it is pass-through station (not our destination). */ * if it is pass-through station (not our destination). */
segment_cost += Yapf().PfGetSettings().rail_station_penalty * platform_length; segment_cost += Yapf().PfGetSettings().rail_station_penalty * platform_length;
@@ -466,10 +466,10 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
if (n.num_signals_passed < this->sig_look_ahead_costs.size()) if (n.num_signals_passed < this->sig_look_ahead_costs.size())
{ {
int min_speed = 0; int min_speed = 0;
int max_speed = tf->GetSpeedLimit(&min_speed); int max_speed = follower->GetSpeedLimit(&min_speed);
int max_veh_speed = std::min<int>(v->GetDisplayMaxSpeed(), v->current_order.GetMaxSpeed()); int max_veh_speed = std::min<int>(v->GetDisplayMaxSpeed(), v->current_order.GetMaxSpeed());
if (max_speed < max_veh_speed) { if (max_speed < max_veh_speed) {
extra_cost += YAPF_TILE_LENGTH * (max_veh_speed - max_speed) * (4 + tf->tiles_skipped) / max_veh_speed; extra_cost += YAPF_TILE_LENGTH * (max_veh_speed - max_speed) * (4 + follower->tiles_skipped) / max_veh_speed;
} }
if (min_speed > max_veh_speed) { if (min_speed > max_veh_speed) {
extra_cost += YAPF_TILE_LENGTH * (min_speed - max_veh_speed); extra_cost += YAPF_TILE_LENGTH * (min_speed - max_veh_speed);
@@ -483,13 +483,13 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
} }
/* Move to the next tile/trackdir. */ /* Move to the next tile/trackdir. */
tf = &tf_local; follower = &follower_local;
tf_local.Init(v, Yapf().GetCompatibleRailTypes()); follower_local.Init(v, Yapf().GetCompatibleRailTypes());
if (!tf_local.Follow(cur.tile, cur.td)) { if (!follower_local.Follow(cur.tile, cur.td)) {
assert(tf_local.err != TrackFollower::EC_NONE); assert(follower_local.err != TrackFollower::EC_NONE);
/* Can't move to the next tile (EOL?). */ /* Can't move to the next tile (EOL?). */
if (tf_local.err == TrackFollower::EC_RAIL_ROAD_TYPE) { if (follower_local.err == TrackFollower::EC_RAIL_ROAD_TYPE) {
end_segment_reason.Set(EndSegmentReason::RailType); end_segment_reason.Set(EndSegmentReason::RailType);
} else { } else {
end_segment_reason.Set(EndSegmentReason::DeadEnd); end_segment_reason.Set(EndSegmentReason::DeadEnd);
@@ -502,14 +502,14 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
} }
/* Check if the next tile is not a choice. */ /* Check if the next tile is not a choice. */
if (KillFirstBit(tf_local.new_td_bits) != TRACKDIR_BIT_NONE) { if (KillFirstBit(follower_local.new_td_bits) != TRACKDIR_BIT_NONE) {
/* More than one segment will follow. Close this one. */ /* More than one segment will follow. Close this one. */
end_segment_reason.Set(EndSegmentReason::ChoiceFollows); end_segment_reason.Set(EndSegmentReason::ChoiceFollows);
break; break;
} }
/* Gather the next tile/trackdir/tile_type/rail_type. */ /* Gather the next tile/trackdir/tile_type/rail_type. */
TILE next(tf_local.new_tile, (Trackdir)FindFirstBit(tf_local.new_td_bits)); TILE next(follower_local.new_tile, (Trackdir)FindFirstBit(follower_local.new_td_bits));
if (TrackFollower::DoTrackMasking() && IsTileType(next.tile, MP_RAILWAY)) { if (TrackFollower::DoTrackMasking() && IsTileType(next.tile, MP_RAILWAY)) {
if (HasSignalOnTrackdir(next.tile, next.td) && IsPbsSignal(GetSignalType(next.tile, TrackdirToTrack(next.td)))) { if (HasSignalOnTrackdir(next.tile, next.td) && IsPbsSignal(GetSignalType(next.tile, TrackdirToTrack(next.td)))) {
@@ -538,7 +538,7 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
if (segment_cost > MAX_SEGMENT_COST) { if (segment_cost > MAX_SEGMENT_COST) {
/* Potentially in the infinite loop (or only very long segment?). We should /* Potentially in the infinite loop (or only very long segment?). We should
* not force it to finish prematurely unless we are on a regular tile. */ * not force it to finish prematurely unless we are on a regular tile. */
if (IsTileType(tf->new_tile, MP_RAILWAY)) { if (IsTileType(follower->new_tile, MP_RAILWAY)) {
end_segment_reason.Set(EndSegmentReason::SegmentTooLong); end_segment_reason.Set(EndSegmentReason::SegmentTooLong);
break; break;
} }

View File

@@ -177,17 +177,17 @@ struct CYapfRailNode : CYapfNodeT<CYapfNodeKeyTrackDir, CYapfRailNode> {
template <class Tbase, class Tfunc, class Tpf> template <class Tbase, class Tfunc, class Tpf>
bool IterateTiles(const Train *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const bool IterateTiles(const Train *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const
{ {
typename Tbase::TrackFollower ft(v, yapf.GetCompatibleRailTypes()); typename Tbase::TrackFollower follower{v, yapf.GetCompatibleRailTypes()};
TileIndex cur = this->base::GetTile(); TileIndex cur = this->base::GetTile();
Trackdir cur_td = this->base::GetTrackdir(); Trackdir cur_td = this->base::GetTrackdir();
while (cur != this->GetLastTile() || cur_td != this->GetLastTrackdir()) { while (cur != this->GetLastTile() || cur_td != this->GetLastTrackdir()) {
if (!((obj.*func)(cur, cur_td))) return false; if (!((obj.*func)(cur, cur_td))) return false;
if (!ft.Follow(cur, cur_td)) break; if (!follower.Follow(cur, cur_td)) break;
cur = ft.new_tile; cur = follower.new_tile;
assert(KillFirstBit(ft.new_td_bits) == TRACKDIR_BIT_NONE); assert(KillFirstBit(follower.new_td_bits) == TRACKDIR_BIT_NONE);
cur_td = FindFirstTrackdir(ft.new_td_bits); cur_td = FindFirstTrackdir(follower.new_td_bits);
} }
return (obj.*func)(cur, cur_td); return (obj.*func)(cur, cur_td);

View File

@@ -229,9 +229,9 @@ public:
*/ */
inline void PfFollowNode(Node &old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower follower{Yapf().GetVehicle()};
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) { if (follower.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, follower);
} }
} }
@@ -320,9 +320,9 @@ public:
*/ */
inline void PfFollowNode(Node &old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes()); TrackFollower follower{Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes()};
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) { if (follower.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && follower.MaskReservedTracks()) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, follower);
} }
} }
@@ -402,9 +402,9 @@ public:
*/ */
inline void PfFollowNode(Node &old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower follower{Yapf().GetVehicle()};
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) { if (follower.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, follower);
} }
} }

View File

@@ -133,11 +133,11 @@ public:
*/ */
inline void PfFollowNode(Node &old_node) inline void PfFollowNode(Node &old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower follower{Yapf().GetVehicle()};
if (F.Follow(old_node.key.tile, old_node.key.td)) { if (follower.Follow(old_node.key.tile, old_node.key.td)) {
if (this->water_region_corridor.empty() if (this->water_region_corridor.empty()
|| std::ranges::find(this->water_region_corridor, GetWaterRegionInfo(F.new_tile)) != this->water_region_corridor.end()) { || std::ranges::find(this->water_region_corridor, GetWaterRegionInfo(follower.new_tile)) != this->water_region_corridor.end()) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, follower);
} }
} }
} }
@@ -166,7 +166,7 @@ public:
/** Returns a random tile/trackdir that can be reached from the current tile/trackdir, or tile/INVALID_TRACK if none is available. */ /** Returns a random tile/trackdir that can be reached from the current tile/trackdir, or tile/INVALID_TRACK if none is available. */
static std::pair<TileIndex, Trackdir> GetRandomFollowUpTileTrackdir(const Ship *v, TileIndex tile, Trackdir dir) static std::pair<TileIndex, Trackdir> GetRandomFollowUpTileTrackdir(const Ship *v, TileIndex tile, Trackdir dir)
{ {
TrackFollower follower(v); TrackFollower follower{v};
if (follower.Follow(tile, dir)) { if (follower.Follow(tile, dir)) {
TrackdirBits dirs = follower.new_td_bits; TrackdirBits dirs = follower.new_td_bits;
const TrackdirBits dirs_without_90_degree = dirs & ~TrackdirCrossesTrackdirs(dir); const TrackdirBits dirs_without_90_degree = dirs & ~TrackdirCrossesTrackdirs(dir);
@@ -361,7 +361,7 @@ public:
* Calculates only the cost of given node, adds it to the parent node cost * Calculates only the cost of given node, adds it to the parent node cost
* and stores the result into Node::cost member. * and stores the result into Node::cost member.
*/ */
inline bool PfCalcCost(Node &n, const TrackFollower *tf) inline bool PfCalcCost(Node &n, const TrackFollower *follower)
{ {
/* Base tile cost depending on distance. */ /* Base tile cost depending on distance. */
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH; int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
@@ -381,12 +381,12 @@ public:
if (!IsPreferredShipDirection(n.GetTile(), n.GetTrackdir())) c += YAPF_TILE_LENGTH; if (!IsPreferredShipDirection(n.GetTile(), n.GetTrackdir())) c += YAPF_TILE_LENGTH;
/* Skipped tile cost for aqueducts. */ /* Skipped tile cost for aqueducts. */
c += YAPF_TILE_LENGTH * tf->tiles_skipped; c += YAPF_TILE_LENGTH * follower->tiles_skipped;
/* Ocean/canal speed penalty. */ /* Ocean/canal speed penalty. */
const ShipVehicleInfo *svi = ShipVehInfo(Yapf().GetVehicle()->engine_type); const ShipVehicleInfo *svi = ShipVehInfo(Yapf().GetVehicle()->engine_type);
uint8_t speed_frac = (GetEffectiveWaterClass(n.GetTile()) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac; uint8_t speed_frac = (GetEffectiveWaterClass(n.GetTile()) == WATER_CLASS_SEA) ? svi->ocean_speed_frac : svi->canal_speed_frac;
if (speed_frac > 0) c += YAPF_TILE_LENGTH * (1 + tf->tiles_skipped) * speed_frac / (256 - speed_frac); if (speed_frac > 0) c += YAPF_TILE_LENGTH * (1 + follower->tiles_skipped) * speed_frac / (256 - speed_frac);
/* Lock penalty. */ /* Lock penalty. */
if (IsTileType(n.GetTile(), MP_WATER) && IsLock(n.GetTile()) && GetLockPart(n.GetTile()) == LOCK_PART_MIDDLE) { if (IsTileType(n.GetTile(), MP_WATER) && IsLock(n.GetTile()) && GetLockPart(n.GetTile()) == LOCK_PART_MIDDLE) {