OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
13 #include "../../debug.h"
14 #include "../../settings_type.h"
16 extern int _total_pf_time_us;
48 template <
class Types>
51 typedef typename Types::Tpf
Tpf;
52 typedef typename Types::TrackFollower TrackFollower;
55 typedef typename NodeList::Titem
Node;
56 typedef typename Node::Key
Key;
100 return *
static_cast<Tpf *
>(
this);
126 Yapf().PfSetStartupNodes();
127 bool bDestFound =
true;
141 Yapf().PfFollowNode(*n);
143 m_nodes.PopOpenNode(n->GetKey());
154 if (_debug_yapf_level >= 2) {
155 int t = perf.Get(1000000);
156 _total_pf_time_us += t;
158 if (_debug_yapf_level >= 3) {
160 char ttc =
Yapf().TransportTypeChar();
165 DEBUG(yapf, 3,
"[YAPF%c]%c%4d- %d us - %d rounds - %d open - %d closed - CHR %4.1f%% - C %d D %d - c%d(sc%d, ts%d, o%d) -- ",
197 Yapf().PfNodeCacheFetch(n);
199 if (
m_nodes.FindOpenNode(n.m_key) ==
nullptr) {
215 n.Set(parent, tf.m_new_tile, td, is_choice);
216 Yapf().AddNewNode(n, tf);
231 Yapf().m_pBestIntermediateNode =
Yapf().m_pBestIntermediateNode->m_parent;
242 bool bCached =
Yapf().PfNodeCacheFetch(n);
249 bool bValid =
Yapf().PfCalcCost(n, &tf);
252 Yapf().PfNodeCacheFlush(n);
255 if (bValid) bValid =
Yapf().PfCalcEstimate(n);
261 bool bDestination =
Yapf().PfDetectDestination(n);
276 if (openNode !=
nullptr) {
279 if (n.GetCostEstimate() < openNode->GetCostEstimate()) {
281 m_nodes.PopOpenNode(n.GetKey());
284 m_nodes.InsertOpenNode(*openNode);
290 Node *closedNode =
m_nodes.FindClosedNode(n.GetKey());
291 if (closedNode !=
nullptr) {
294 int node_est = n.GetCostEstimate();
295 int closed_est = closedNode->GetCostEstimate();
296 if (node_est < closed_est) {
327 inline void PfSetStartupNodes()
330 Node &n1 = *base::m_nodes.CreateNewNode();
334 base::m_nodes.InsertOpenNode(n1);
338 inline void PfFollowNode(
Node &org)
340 for (each follower of node org) {
341 Node &n = *base::m_nodes.CreateNewNode();
351 inline bool PfCalcCost(
Node &n)
356 n.m_cost = n.m_parent->m_cost + cost;
361 inline bool PfCalcEstimate(
Node &n)
366 n.m_estimate = n.m_cost + distance;
371 inline bool PfDetectDestination(
Node &n)
373 bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
CPerformanceTimer m_perf_ts_cost
stats - GetTrackStatus() CPU time
const YAPFSettings & PfGetSettings() const
return current settings (can be custom - company based - but later)
TrackdirBits
Enumeration of bitmasks for the TrackDirs.
uint16 UnitID
Type for the company global vehicle unit number.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
static T KillFirstBit(T value)
Clear the first bit in an integer.
void CDECL WriteLine(const char *format,...) WARN_FORMAT(2
Write a line with indent at the beginning and <LF> at the end.
Settings related to the yet another pathfinder.
int m_stats_cache_hits
stats - how many node's costs were reused from cache
void AddMultipleNodes(Node *parent, const TrackFollower &tf)
add multiple nodes - direct children of the given node
#define DEBUG(name, level,...)
Output a line of debugging information.
const YAPFSettings * m_settings
current settings (_settings_game.yapf)
CPerformanceTimer m_perf_slope_cost
stats - slope calculation CPU time
CYapfBaseT()
default constructor
static uint8 FindFirstBit2x64(const int value)
Finds the position of the first non-zero bit in an integer.
Tpf & Yapf()
to access inherited path finder
void PruneIntermediateNodeBranch()
In some cases an intermediate node branch should be pruned.
Class that represents the dump-into-string target.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
NodeList m_nodes
node list multi-container
int m_num_steps
this is there for debugging purposes (hope it doesn't hurt)
Types::VehicleType VehicleType
the type of vehicle
CPerformanceTimer m_perf_other_cost
stats - other CPU time
VehicleType
Available vehicle types.
Node * GetBestNode()
If path was found return the best node that has reached the destination.
Node::Key Key
key to hash tables
void AddNewNode(Node &n, const TrackFollower &tf)
AddNewNode() - called by Tderived::PfFollowNode() for each child node.
void WriteStructT(const char *name, const S *s)
Dump nested object (or only its name if this instance is already known).
int m_max_search_nodes
maximum number of nodes we are allowed to visit before we give up
@ TRACKDIR_BIT_NONE
No track build.
Node * m_pBestDestNode
pointer to the destination node found at last round
void AddStartupNode(Node &n)
Add new node (created by CreateNewNode and filled with data) into open list.
int m_stats_cost_calcs
stats - how many node's costs were calculated
bool FindPath(const VehicleType *v)
Main pathfinder routine:
Node & CreateNewNode()
Calls NodeList::CreateNewNode() - allocates new node that can be filled and used as argument for AddS...
Types::NodeList NodeList
our node list
~CYapfBaseT()
default destructor
Node * m_pBestIntermediateNode
here should be node closest to the destination if path not found
const VehicleType * m_veh
vehicle that we are trying to drive
Trackdir
Enumeration for tracks and directions.
CYapfBaseT - A-star type path finder base class.
CPerformanceTimer m_perf_cost
stats - total CPU time of this run
NodeList::Titem Node
this will be our node type