OpenTTD Source
20240917-master-g9ab0a47812
|
Go to the documentation of this file.
10 #ifndef YAPF_COMMON_HPP
11 #define YAPF_COMMON_HPP
14 template <
class Types>
18 typedef typename Types::Tpf
Tpf;
19 typedef typename Types::NodeList::Titem
Node;
20 typedef typename Node::Key
Key;
29 return *
static_cast<Tpf *
>(
this);
47 n1.Set(
nullptr,
m_orgTile, td, is_choice);
48 Yapf().AddStartupNode(n1);
54 template <
class Types>
58 typedef typename Types::Tpf
Tpf;
59 typedef typename Types::NodeList::Titem
Node;
60 typedef typename Node::Key
Key;
73 return *
static_cast<Tpf *
>(
this);
94 Yapf().AddStartupNode(n1);
100 Yapf().AddStartupNode(n2);
112 template <
class Types>
116 typedef typename Types::Tpf
Tpf;
117 typedef typename Types::NodeList::Titem
Node;
118 typedef typename Node::Key
Key;
136 return *
static_cast<Tpf *
>(
this);
152 static const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
153 static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
155 n.m_estimate = n.m_cost;
161 int x1 = 2 *
TileX(tile) + dg_dir_to_x_offs[(int)exitdir];
162 int y1 = 2 *
TileY(tile) + dg_dir_to_y_offs[(int)exitdir];
165 int dx =
abs(x1 - x2);
166 int dy =
abs(y1 - y2);
167 int dmin = std::min(dx, dy);
168 int dxy =
abs(dx - dy);
170 n.m_estimate = n.m_cost + d;
171 assert(n.m_estimate >= n.m_parent->m_estimate);
182 template <
class Ttypes>
184 :
public Ttypes::PfBase
185 ,
public Ttypes::PfCost
186 ,
public Ttypes::PfCache
187 ,
public Ttypes::PfOrigin
188 ,
public Ttypes::PfDestination
189 ,
public Ttypes::PfFollow
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Tpf & Yapf()
to access inherited path finder
void PfSetStartupNodes()
Called when YAPF needs to place origin nodes into open list.
TileIndex m_revTile
second (reversed) origin tile
DiagDirection TrackdirToExitdir(Trackdir trackdir)
Maps a trackdir to the (4-way) direction the tile is exited when following that trackdir.
bool PfCalcEstimate(Node &n)
Called by YAPF to calculate cost estimate.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
bool PfDetectDestination(Node &n)
Called by YAPF to detect if node ends in the desired destination.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Trackdir m_revTd
second (reversed) origin trackdir
bool TreatFirstRedTwoWaySignalAsEOL()
return true if first two-way signal should be treated as dead end
DiagDirection
Enumeration for diagonal directions.
Trackdir m_orgTd
first origin trackdir
YAPF template that uses Ttypes template argument to determine all YAPF components (base classes) from...
constexpr T KillFirstBit(T value)
Clear the first bit in an integer.
YAPF origin provider base class - used when origin is one tile / multiple trackdirs.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
YAPF origin provider base class - used when there are two tile/trackdir origins.
TileIndex m_orgTile
first origin tile
YAPF destination provider base class - used when destination is single tile / multiple trackdirs.
static const int YAPF_TILE_LENGTH
Length (penalty) of one tile with YAPF.
@ TRACKDIR_BIT_NONE
No track build.
Node::Key Key
key to hash tables
bool m_treat_first_red_two_way_signal_as_eol
in some cases (leaving station) we need to handle first two-way signal differently
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
set the destination tile / more trackdirs
void PfSetStartupNodes()
Called when YAPF needs to place origin nodes into open list.
Types::NodeList::Titem Node
this will be our node type
TrackdirBits m_destTrackdirs
destination trackdir mask
Tpf & Yapf()
to access inherited path finder
TrackdirBits m_orgTrackdirs
origin trackdir mask
TileIndex m_destTile
destination tile
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
Set origin tile / trackdir mask.
Node::Key Key
key to hash tables
Tpf & Yapf()
to access inherited path finder
Trackdir
Enumeration for tracks and directions.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
Node::Key Key
key to hash tables
int m_reverse_penalty
penalty to be added for using the reversed origin
TileIndex m_orgTile
origin tile
static const int YAPF_TILE_CORNER_LENGTH
Length (penalty) of a corner with YAPF.
void SetOrigin(TileIndex tile, Trackdir td, TileIndex tiler=INVALID_TILE, Trackdir tdr=INVALID_TRACKDIR, int reverse_penalty=0, bool treat_first_red_two_way_signal_as_eol=true)
set origin (tiles, trackdirs, etc.)
TrackdirBits
Allow incrementing of Trackdir variables.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
bool HasTrackdir(TrackdirBits trackdirs, Trackdir trackdir)
Checks whether a TrackdirBits has a given Trackdir.
Types::NodeList::Titem Node
this will be our node type
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
@ INVALID_TRACKDIR
Flag for an invalid trackdir.
Types::NodeList::Titem Node
this will be our node type
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.