mirror of https://github.com/OpenTTD/OpenTTD
(svn r5018) [YAPF] Added some comments to YAPF implementation.
parent
301f4ac856
commit
ed48b38619
|
@ -132,9 +132,9 @@ typedef CTestYapfNodeT<CNodeKey2> CYapfNode2;
|
||||||
template <class Types>
|
template <class Types>
|
||||||
struct CYapfTestBaseT
|
struct CYapfTestBaseT
|
||||||
{
|
{
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
typedef typename Types::Map Map;
|
typedef typename Types::Map Map;
|
||||||
|
|
||||||
int m_x1, m_y1;
|
int m_x1, m_y1;
|
||||||
|
@ -155,9 +155,13 @@ struct CYapfTestBaseT
|
||||||
m_td1 = td1;
|
m_td1 = td1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
FORCEINLINE char TransportTypeChar() const {return 'T';}
|
FORCEINLINE char TransportTypeChar() const {return 'T';}
|
||||||
|
|
||||||
|
/** Called by YAPF to move from the given node to the next tile. For each
|
||||||
|
* reachable trackdir on the new tile creates new node, initializes it
|
||||||
|
* and adds it to the open list by calling Yapf().AddNewNode(n) */
|
||||||
FORCEINLINE void PfFollowNode(Node& org)
|
FORCEINLINE void PfFollowNode(Node& org)
|
||||||
{
|
{
|
||||||
int x_org = org.m_key.m_x;
|
int x_org = org.m_key.m_x;
|
||||||
|
@ -191,6 +195,7 @@ struct CYapfTestBaseT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called when YAPF needs to place origin nodes into open list
|
||||||
FORCEINLINE void PfSetStartupNodes()
|
FORCEINLINE void PfSetStartupNodes()
|
||||||
{
|
{
|
||||||
Node& n1 = Yapf().CreateNewNode();
|
Node& n1 = Yapf().CreateNewNode();
|
||||||
|
@ -201,6 +206,9 @@ struct CYapfTestBaseT
|
||||||
Yapf().AddStartupNode(n1);
|
Yapf().AddStartupNode(n1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate the cost from the origin to the given node.
|
||||||
|
* Calculates only the cost of given node, adds it to the parent node cost
|
||||||
|
* and stores the result into Node::m_cost member */
|
||||||
FORCEINLINE bool PfCalcCost(Node& n)
|
FORCEINLINE bool PfCalcCost(Node& n)
|
||||||
{
|
{
|
||||||
// base tile cost depending on distance
|
// base tile cost depending on distance
|
||||||
|
@ -216,6 +224,8 @@ struct CYapfTestBaseT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
FORCEINLINE bool PfCalcEstimate(Node& n)
|
FORCEINLINE bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
int dx = abs(n.m_key.m_x - m_x2);
|
int dx = abs(n.m_key.m_x - m_x2);
|
||||||
|
@ -227,6 +237,7 @@ struct CYapfTestBaseT
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
|
bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
|
||||||
|
|
|
@ -45,34 +45,34 @@ extern int _total_pf_time_us;
|
||||||
template <class Types>
|
template <class Types>
|
||||||
class CYapfBaseT {
|
class CYapfBaseT {
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList NodeList; ///< our node list
|
typedef typename Types::NodeList NodeList; ///< our node list
|
||||||
typedef typename NodeList::Titem Node; ///< this will be our node type
|
typedef typename NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
|
|
||||||
NodeList m_nodes; ///< node list multi-container
|
NodeList m_nodes; ///< node list multi-container
|
||||||
protected:
|
protected:
|
||||||
Node* m_pBestDestNode; ///< pointer to the destination node found at last round
|
Node* m_pBestDestNode; ///< pointer to the destination node found at last round
|
||||||
Node* m_pBestIntermediateNode;
|
Node* m_pBestIntermediateNode; ///< here should be node closest to the destination if path not found
|
||||||
const YapfSettings *m_settings;
|
const YapfSettings *m_settings; ///< current settings (_patches.yapf)
|
||||||
int m_max_search_nodes;
|
int m_max_search_nodes; ///< maximum number of nodes we are allowed to visit before we give up
|
||||||
Vehicle* m_veh;
|
Vehicle* m_veh; ///< vehicle that we are trying to drive
|
||||||
|
|
||||||
int m_stats_cost_calcs;
|
int m_stats_cost_calcs; ///< stats - how many node's costs were calculated
|
||||||
int m_stats_cache_hits;
|
int m_stats_cache_hits; ///< stats - how many node's costs were reused from cache
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CPerformanceTimer m_perf_cost;
|
CPerformanceTimer m_perf_cost; ///< stats - total CPU time of this run
|
||||||
CPerformanceTimer m_perf_slope_cost;
|
CPerformanceTimer m_perf_slope_cost; ///< stats - slope calculation CPU time
|
||||||
CPerformanceTimer m_perf_ts_cost;
|
CPerformanceTimer m_perf_ts_cost; ///< stats - GetTrackStatus() CPU time
|
||||||
CPerformanceTimer m_perf_other_cost;
|
CPerformanceTimer m_perf_other_cost; ///< stats - other CPU time
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int m_num_steps; ///< this is there for debugging purposes (hope it doesn't hurt)
|
int m_num_steps; ///< this is there for debugging purposes (hope it doesn't hurt)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// default constructor
|
/// default constructor
|
||||||
FORCEINLINE CYapfBaseT()
|
FORCEINLINE CYapfBaseT()
|
||||||
: m_pBestDestNode(NULL)
|
: m_pBestDestNode(NULL)
|
||||||
, m_pBestIntermediateNode(NULL)
|
, m_pBestIntermediateNode(NULL)
|
||||||
|
@ -90,12 +90,15 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// default destructor
|
||||||
~CYapfBaseT() {}
|
~CYapfBaseT() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// return current settings (can be custom - player based - but later)
|
||||||
FORCEINLINE const YapfSettings& PfGetSettings() const
|
FORCEINLINE const YapfSettings& PfGetSettings() const
|
||||||
{
|
{
|
||||||
return *m_settings;
|
return *m_settings;
|
||||||
|
|
|
@ -3,28 +3,31 @@
|
||||||
#ifndef YAPF_COMMON_HPP
|
#ifndef YAPF_COMMON_HPP
|
||||||
#define YAPF_COMMON_HPP
|
#define YAPF_COMMON_HPP
|
||||||
|
|
||||||
|
/** YAPF origin provider base class - used when origin is one tile / multiple trackdirs */
|
||||||
template <class Types>
|
template <class Types>
|
||||||
class CYapfOriginTileT
|
class CYapfOriginTileT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TileIndex m_orgTile;
|
TileIndex m_orgTile; ///< origin tile
|
||||||
TrackdirBits m_orgTrackdirs;
|
TrackdirBits m_orgTrackdirs; ///< origin trackdir mask
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// Set origin tile / trackdir mask
|
||||||
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
|
void SetOrigin(TileIndex tile, TrackdirBits trackdirs)
|
||||||
{
|
{
|
||||||
m_orgTile = tile;
|
m_orgTile = tile;
|
||||||
m_orgTrackdirs = trackdirs;
|
m_orgTrackdirs = trackdirs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called when YAPF needs to place origin nodes into open list
|
||||||
void PfSetStartupNodes()
|
void PfSetStartupNodes()
|
||||||
{
|
{
|
||||||
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = (TrackdirBits)KillFirstBit2x64(tdb)) {
|
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = (TrackdirBits)KillFirstBit2x64(tdb)) {
|
||||||
|
@ -36,25 +39,28 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** YAPF origin provider base class - used when there are two tile/trackdir origins */
|
||||||
template <class Types>
|
template <class Types>
|
||||||
class CYapfOriginTileTwoWayT
|
class CYapfOriginTileTwoWayT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TileIndex m_orgTile;
|
TileIndex m_orgTile; ///< first origin tile
|
||||||
Trackdir m_orgTd;
|
Trackdir m_orgTd; ///< first origin trackdir
|
||||||
TileIndex m_revTile;
|
TileIndex m_revTile; ///< second (reversed) origin tile
|
||||||
Trackdir m_revTd;
|
Trackdir m_revTd; ///< second (reversed) origin trackdir
|
||||||
int m_reverse_penalty;
|
int m_reverse_penalty; ///< penalty to be added for using the reversed origin
|
||||||
bool m_treat_first_red_two_way_signal_as_eol;
|
bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// set origin (tiles, trackdirs, etc.)
|
||||||
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)
|
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)
|
||||||
{
|
{
|
||||||
m_orgTile = tile;
|
m_orgTile = tile;
|
||||||
|
@ -65,6 +71,7 @@ public:
|
||||||
m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol;
|
m_treat_first_red_two_way_signal_as_eol = treat_first_red_two_way_signal_as_eol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called when YAPF needs to place origin nodes into open list
|
||||||
void PfSetStartupNodes()
|
void PfSetStartupNodes()
|
||||||
{
|
{
|
||||||
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
|
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
|
||||||
|
@ -80,25 +87,28 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return true if first two-way signal should be treated as dead end
|
||||||
FORCEINLINE bool TreatFirstRedTwoWaySignalAsEOL()
|
FORCEINLINE bool TreatFirstRedTwoWaySignalAsEOL()
|
||||||
{
|
{
|
||||||
return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol;
|
return Yapf().PfGetSettings().rail_firstred_twoway_eol && m_treat_first_red_two_way_signal_as_eol;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** YAPF destination provider base class - used when destination is single tile / multiple trackdirs */
|
||||||
template <class Types>
|
template <class Types>
|
||||||
class CYapfDestinationTileT
|
class CYapfDestinationTileT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TileIndex m_destTile;
|
TileIndex m_destTile; ///< destination tile
|
||||||
TrackdirBits m_destTrackdirs;
|
TrackdirBits m_destTrackdirs; ///< destination trackdir mask
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// set the destination tile / more trackdirs
|
||||||
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
|
void SetDestination(TileIndex tile, TrackdirBits trackdirs)
|
||||||
{
|
{
|
||||||
m_destTile = tile;
|
m_destTile = tile;
|
||||||
|
@ -106,15 +116,19 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
|
bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
|
||||||
return bDest;
|
return bDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
inline bool PfCalcEstimate(Node& n)
|
inline bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
int dx = abs(TileX(n.GetTile()) - TileX(m_destTile));
|
int dx = abs(TileX(n.GetTile()) - TileX(m_destTile));
|
||||||
|
@ -128,14 +142,18 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** YAPF template that uses Ttypes template argument to determine all YAPF
|
||||||
|
* components (base classes) from which the actual YAPF is composed.
|
||||||
|
* For example classes consult: CYapfRail_TypesT template and its instantiations:
|
||||||
|
* CYapfRail1, CYapfRail2, CYapfRail3, CYapfAnyDepotRail1, CYapfAnyDepotRail2, CYapfAnyDepotRail3 */
|
||||||
template <class Ttypes>
|
template <class Ttypes>
|
||||||
class CYapfT
|
class CYapfT
|
||||||
: public Ttypes::PfBase
|
: public Ttypes::PfBase ///< Instance of CYapfBaseT - main YAPF loop and support base class
|
||||||
, public Ttypes::PfCost
|
, public Ttypes::PfCost ///< Cost calculation provider base class
|
||||||
, public Ttypes::PfCache
|
, public Ttypes::PfCache ///< Segment cost cache provider
|
||||||
, public Ttypes::PfOrigin
|
, public Ttypes::PfOrigin ///< Origin (tile or two-tile origin)
|
||||||
, public Ttypes::PfDestination
|
, public Ttypes::PfDestination ///< Destination detector and distance (estimate) calculation provider
|
||||||
, public Ttypes::PfFollow
|
, public Ttypes::PfFollow ///< Node follower (stepping provider)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,18 @@ template <class Types>
|
||||||
class CYapfSegmentCostCacheNoneT
|
class CYapfSegmentCostCacheNoneT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
|
|
||||||
|
/** Called by YAPF to attach cached or local segment cost data to the given node.
|
||||||
|
* @return true if globally cached data were used or false if local data was used */
|
||||||
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||||
|
* Current cache implementation doesn't use that. */
|
||||||
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
@ -33,9 +37,9 @@ template <class Types>
|
||||||
class CYapfSegmentCostCacheLocalT
|
class CYapfSegmentCostCacheLocalT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
typedef typename Node::CachedData CachedData;
|
typedef typename Node::CachedData CachedData;
|
||||||
typedef typename CachedData::Key CacheKey;
|
typedef typename CachedData::Key CacheKey;
|
||||||
typedef CArrayT<CachedData> LocalCache;
|
typedef CArrayT<CachedData> LocalCache;
|
||||||
|
@ -43,9 +47,12 @@ public:
|
||||||
protected:
|
protected:
|
||||||
LocalCache m_local_cache;
|
LocalCache m_local_cache;
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to attach cached or local segment cost data to the given node.
|
||||||
|
* @return true if globally cached data were used or false if local data was used */
|
||||||
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
||||||
{
|
{
|
||||||
CacheKey key(n.GetKey());
|
CacheKey key(n.GetKey());
|
||||||
|
@ -53,13 +60,19 @@ public:
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||||
|
* Current cache implementation doesn't use that. */
|
||||||
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/** Base class for segment cost cache providers. Contains global counter
|
||||||
|
* of track layout changes and static notification function called whenever
|
||||||
|
* the track layout changes. It is implemented as base class because it needs
|
||||||
|
* to be shared between all rail YAPF types (one shared counter, one notification
|
||||||
|
* function. */
|
||||||
struct CSegmentCostCacheBase
|
struct CSegmentCostCacheBase
|
||||||
{
|
{
|
||||||
static int s_rail_change_counter;
|
static int s_rail_change_counter;
|
||||||
|
@ -76,7 +89,6 @@ struct CSegmentCostCacheBase
|
||||||
of the segment (origin tile and exit-dir from this tile).
|
of the segment (origin tile and exit-dir from this tile).
|
||||||
Different CYapfCachedCostT types can share the same type of CSegmentCostCacheT.
|
Different CYapfCachedCostT types can share the same type of CSegmentCostCacheT.
|
||||||
Look at CYapfRailSegment (yapf_node_rail.hpp) for the segment example */
|
Look at CYapfRailSegment (yapf_node_rail.hpp) for the segment example */
|
||||||
|
|
||||||
template <class Tsegment>
|
template <class Tsegment>
|
||||||
struct CSegmentCostCacheT
|
struct CSegmentCostCacheT
|
||||||
: public CSegmentCostCacheBase
|
: public CSegmentCostCacheBase
|
||||||
|
@ -116,7 +128,7 @@ class CYapfSegmentCostCacheGlobalT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef CYapfSegmentCostCacheLocalT<Types> Tlocal;
|
typedef CYapfSegmentCostCacheLocalT<Types> Tlocal;
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
typedef typename Node::CachedData CachedData;
|
typedef typename Node::CachedData CachedData;
|
||||||
|
@ -128,6 +140,7 @@ protected:
|
||||||
|
|
||||||
FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
|
FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
FORCEINLINE static Cache*& stGlobalCachePtr() {static Cache* pC = NULL; return pC;}
|
FORCEINLINE static Cache*& stGlobalCachePtr() {static Cache* pC = NULL; return pC;}
|
||||||
|
@ -159,6 +172,8 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to attach cached or local segment cost data to the given node.
|
||||||
|
* @return true if globally cached data were used or false if local data was used */
|
||||||
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
||||||
{
|
{
|
||||||
if (!Yapf().CanUseGlobalCache(n)) {
|
if (!Yapf().CanUseGlobalCache(n)) {
|
||||||
|
@ -171,6 +186,8 @@ public:
|
||||||
return found;
|
return found;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||||
|
* Current cache implementation doesn't use that. */
|
||||||
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,10 +10,10 @@ class CYapfCostRailT
|
||||||
, public CostRailSettings
|
, public CostRailSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
typedef typename Node::CachedData CachedData;
|
typedef typename Node::CachedData CachedData;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -33,6 +33,7 @@ protected:
|
||||||
pen[i] = p0 + i * (p1 + i * p2);
|
pen[i] = p0 + i * (p1 + i * p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -140,6 +141,9 @@ public:
|
||||||
public:
|
public:
|
||||||
FORCEINLINE void SetMaxCost(int max_cost) {m_max_cost = max_cost;}
|
FORCEINLINE void SetMaxCost(int max_cost) {m_max_cost = max_cost;}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate the cost from the origin to the given node.
|
||||||
|
* Calculates only the cost of given node, adds it to the parent node cost
|
||||||
|
* and stores the result into Node::m_cost member */
|
||||||
FORCEINLINE bool PfCalcCost(Node& n)
|
FORCEINLINE bool PfCalcCost(Node& n)
|
||||||
{
|
{
|
||||||
assert(!n.flags_u.flags_s.m_targed_seen);
|
assert(!n.flags_u.flags_s.m_targed_seen);
|
||||||
|
|
|
@ -25,18 +25,22 @@ class CYapfDestinationAnyDepotRailT
|
||||||
: public CYapfDestinationRailBase
|
: public CYapfDestinationRailBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest = IsTileDepotType(n.GetLastTile(), TRANSPORT_RAIL);
|
bool bDest = IsTileDepotType(n.GetLastTile(), TRANSPORT_RAIL);
|
||||||
return bDest;
|
return bDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
FORCEINLINE bool PfCalcEstimate(Node& n)
|
FORCEINLINE bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
n.m_estimate = n.m_cost;
|
n.m_estimate = n.m_cost;
|
||||||
|
@ -49,15 +53,16 @@ class CYapfDestinationTileOrStationRailT
|
||||||
: public CYapfDestinationRailBase
|
: public CYapfDestinationRailBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TileIndex m_destTile;
|
TileIndex m_destTile;
|
||||||
TrackdirBits m_destTrackdirs;
|
TrackdirBits m_destTrackdirs;
|
||||||
StationID m_dest_station_id;
|
StationID m_dest_station_id;
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
static TileIndex CalcStationCenterTile(StationID station)
|
static TileIndex CalcStationCenterTile(StationID station)
|
||||||
|
@ -85,6 +90,7 @@ public:
|
||||||
CYapfDestinationRailBase::SetDestination(v);
|
CYapfDestinationRailBase::SetDestination(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest;
|
bool bDest;
|
||||||
|
@ -99,6 +105,8 @@ public:
|
||||||
return bDest;
|
return bDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
FORCEINLINE bool PfCalcEstimate(Node& n)
|
FORCEINLINE bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||||
|
|
|
@ -17,15 +17,19 @@ template <class Types>
|
||||||
class CYapfFollowAnyDepotRailT
|
class CYapfFollowAnyDepotRailT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to move from the given node to the next tile. For each
|
||||||
|
* reachable trackdir on the new tile creates new node, initializes it
|
||||||
|
* and adds it to the open list by calling Yapf().AddNewNode(n) */
|
||||||
inline void PfFollowNode(Node& old_node)
|
inline void PfFollowNode(Node& old_node)
|
||||||
{
|
{
|
||||||
TrackFollower F(Yapf().GetVehicle());
|
TrackFollower F(Yapf().GetVehicle());
|
||||||
|
@ -33,6 +37,7 @@ public:
|
||||||
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 't';}
|
FORCEINLINE char TransportTypeChar() const {return 't';}
|
||||||
|
|
||||||
static bool stFindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed)
|
static bool stFindNearestDepotTwoWay(Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex* depot_tile, bool* reversed)
|
||||||
|
@ -75,15 +80,19 @@ template <class Types>
|
||||||
class CYapfFollowRailT
|
class CYapfFollowRailT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to move from the given node to the next tile. For each
|
||||||
|
* reachable trackdir on the new tile creates new node, initializes it
|
||||||
|
* and adds it to the open list by calling Yapf().AddNewNode(n) */
|
||||||
inline void PfFollowNode(Node& old_node)
|
inline void PfFollowNode(Node& old_node)
|
||||||
{
|
{
|
||||||
TrackFollower F(Yapf().GetVehicle());
|
TrackFollower F(Yapf().GetVehicle());
|
||||||
|
@ -91,6 +100,7 @@ public:
|
||||||
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 't';}
|
FORCEINLINE char TransportTypeChar() const {return 't';}
|
||||||
|
|
||||||
static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs)
|
static Trackdir stChooseRailTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackdirBits trackdirs)
|
||||||
|
|
|
@ -10,12 +10,13 @@ template <class Types>
|
||||||
class CYapfCostRoadT
|
class CYapfCostRoadT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< pathfinder (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower; ///< track follower helper
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
|
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
|
||||||
|
@ -62,6 +63,9 @@ protected:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to calculate the cost from the origin to the given node.
|
||||||
|
* Calculates only the cost of given node, adds it to the parent node cost
|
||||||
|
* and stores the result into Node::m_cost member */
|
||||||
FORCEINLINE bool PfCalcCost(Node& n)
|
FORCEINLINE bool PfCalcCost(Node& n)
|
||||||
{
|
{
|
||||||
int segment_cost = 0;
|
int segment_cost = 0;
|
||||||
|
@ -118,19 +122,23 @@ template <class Types>
|
||||||
class CYapfDestinationAnyDepotRoadT
|
class CYapfDestinationAnyDepotRoadT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD);
|
bool bDest = IsTileDepotType(n.m_segment_last_tile, TRANSPORT_ROAD);
|
||||||
return bDest;
|
return bDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
FORCEINLINE bool PfCalcEstimate(Node& n)
|
FORCEINLINE bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
n.m_estimate = n.m_cost;
|
n.m_estimate = n.m_cost;
|
||||||
|
@ -143,10 +151,10 @@ template <class Types>
|
||||||
class CYapfDestinationTileRoadT
|
class CYapfDestinationTileRoadT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TileIndex m_destTile;
|
TileIndex m_destTile;
|
||||||
|
@ -160,15 +168,19 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/// Called by YAPF to detect if node ends in the desired destination
|
||||||
FORCEINLINE bool PfDetectDestination(Node& n)
|
FORCEINLINE bool PfDetectDestination(Node& n)
|
||||||
{
|
{
|
||||||
bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
|
bool bDest = (n.m_segment_last_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.m_segment_last_td)) != TRACKDIR_BIT_NONE);
|
||||||
return bDest;
|
return bDest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called by YAPF to calculate cost estimate. Calculates distance to the destination
|
||||||
|
* adds it to the actual cost from origin and stores the sum to the Node::m_estimate */
|
||||||
inline bool PfCalcEstimate(Node& n)
|
inline bool PfCalcEstimate(Node& n)
|
||||||
{
|
{
|
||||||
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
static int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||||
|
@ -201,16 +213,20 @@ template <class Types>
|
||||||
class CYapfFollowRoadT
|
class CYapfFollowRoadT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
/** Called by YAPF to move from the given node to the next tile. For each
|
||||||
|
* reachable trackdir on the new tile creates new node, initializes it
|
||||||
|
* and adds it to the open list by calling Yapf().AddNewNode(n) */
|
||||||
inline void PfFollowNode(Node& old_node)
|
inline void PfFollowNode(Node& old_node)
|
||||||
{
|
{
|
||||||
TrackFollower F;
|
TrackFollower F;
|
||||||
|
@ -218,6 +234,7 @@ public:
|
||||||
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 'r';}
|
FORCEINLINE char TransportTypeChar() const {return 'r';}
|
||||||
|
|
||||||
static Trackdir stChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
static Trackdir stChooseRoadTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir)
|
||||||
|
|
|
@ -9,15 +9,19 @@ template <class Types>
|
||||||
class CYapfFollowShipT
|
class CYapfFollowShipT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::TrackFollower TrackFollower;
|
typedef typename Types::TrackFollower TrackFollower;
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to move from the given node to the next tile. For each
|
||||||
|
* reachable trackdir on the new tile creates new node, initializes it
|
||||||
|
* and adds it to the open list by calling Yapf().AddNewNode(n) */
|
||||||
inline void PfFollowNode(Node& old_node)
|
inline void PfFollowNode(Node& old_node)
|
||||||
{
|
{
|
||||||
TrackFollower F;
|
TrackFollower F;
|
||||||
|
@ -25,6 +29,7 @@ public:
|
||||||
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
Yapf().AddMultipleNodes(&old_node, F.m_new_tile, F.m_new_td_bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// return debug report character to identify the transportation type
|
||||||
FORCEINLINE char TransportTypeChar() const {return 'w';}
|
FORCEINLINE char TransportTypeChar() const {return 'w';}
|
||||||
|
|
||||||
static Trackdir ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
|
static Trackdir ChooseShipTrack(Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
|
||||||
|
@ -80,14 +85,18 @@ template <class Types>
|
||||||
class CYapfCostShipT
|
class CYapfCostShipT
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef typename Types::Tpf Tpf;
|
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||||
typedef typename Node::Key Key; ///< key to hash tables
|
typedef typename Node::Key Key; ///< key to hash tables
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
/// to access inherited path finder
|
||||||
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
Tpf& Yapf() {return *static_cast<Tpf*>(this);}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/** Called by YAPF to calculate the cost from the origin to the given node.
|
||||||
|
* Calculates only the cost of given node, adds it to the parent node cost
|
||||||
|
* and stores the result into Node::m_cost member */
|
||||||
FORCEINLINE bool PfCalcCost(Node& n)
|
FORCEINLINE bool PfCalcCost(Node& n)
|
||||||
{
|
{
|
||||||
// base tile cost depending on distance
|
// base tile cost depending on distance
|
||||||
|
|
Loading…
Reference in New Issue