Merge branch 'master' into tracerestrict
Conflicts: src/pathfinder/yapf/yapf_costrail.hpp
This commit is contained in:
@@ -24,34 +24,23 @@
|
||||
template <class Titem_, int Thash_bits_open_, int Thash_bits_closed_>
|
||||
class CNodeList_HashTableT {
|
||||
public:
|
||||
/** make Titem_ visible from outside of class */
|
||||
typedef Titem_ Titem;
|
||||
/** make Titem_::Key a property of HashTable */
|
||||
typedef typename Titem_::Key Key;
|
||||
/** type that we will use as item container */
|
||||
typedef SmallArray<Titem_, 65536, 256> CItemArray;
|
||||
/** how pointers to open nodes will be stored */
|
||||
typedef CHashTableT<Titem_, Thash_bits_open_ > COpenList;
|
||||
/** how pointers to closed nodes will be stored */
|
||||
typedef CHashTableT<Titem_, Thash_bits_closed_> CClosedList;
|
||||
/** how the priority queue will be managed */
|
||||
typedef CBinaryHeapT<Titem_> CPriorityQueue;
|
||||
typedef Titem_ Titem; ///< Make #Titem_ visible from outside of class.
|
||||
typedef typename Titem_::Key Key; ///< Make Titem_::Key a property of #HashTable.
|
||||
typedef SmallArray<Titem_, 65536, 256> CItemArray; ///< Type that we will use as item container.
|
||||
typedef CHashTableT<Titem_, Thash_bits_open_ > COpenList; ///< How pointers to open nodes will be stored.
|
||||
typedef CHashTableT<Titem_, Thash_bits_closed_> CClosedList; ///< How pointers to closed nodes will be stored.
|
||||
typedef CBinaryHeapT<Titem_> CPriorityQueue; ///< How the priority queue will be managed.
|
||||
|
||||
protected:
|
||||
/** here we store full item data (Titem_) */
|
||||
CItemArray m_arr;
|
||||
/** hash table of pointers to open item data */
|
||||
COpenList m_open;
|
||||
/** hash table of pointers to closed item data */
|
||||
CClosedList m_closed;
|
||||
/** priority queue of pointers to open item data */
|
||||
CPriorityQueue m_open_queue;
|
||||
/** new open node under construction */
|
||||
Titem *m_new_node;
|
||||
CItemArray m_arr; ///< Here we store full item data (Titem_).
|
||||
COpenList m_open; ///< Hash table of pointers to open item data.
|
||||
CClosedList m_closed; ///< Hash table of pointers to closed item data.
|
||||
CPriorityQueue m_open_queue; ///< Priority queue of pointers to open item data.
|
||||
Titem *m_new_node; ///< New open node under construction.
|
||||
|
||||
public:
|
||||
/** default constructor */
|
||||
CNodeList_HashTableT()
|
||||
: m_open_queue(2048)
|
||||
CNodeList_HashTableT() : m_open_queue(2048)
|
||||
{
|
||||
m_new_node = NULL;
|
||||
}
|
||||
@@ -81,7 +70,7 @@ public:
|
||||
}
|
||||
|
||||
/** Notify the nodelist that we don't want to discard the given node. */
|
||||
inline void FoundBestNode(Titem_& item)
|
||||
inline void FoundBestNode(Titem_ &item)
|
||||
{
|
||||
/* for now it is enough to invalidate m_new_node if it is our given node */
|
||||
if (&item == m_new_node) {
|
||||
@@ -91,7 +80,7 @@ public:
|
||||
}
|
||||
|
||||
/** insert given item as open node (into m_open and m_open_queue) */
|
||||
inline void InsertOpenNode(Titem_& item)
|
||||
inline void InsertOpenNode(Titem_ &item)
|
||||
{
|
||||
assert(m_closed.Find(item.GetKey()) == NULL);
|
||||
m_open.Push(item);
|
||||
@@ -122,39 +111,46 @@ public:
|
||||
}
|
||||
|
||||
/** return the open node specified by a key or NULL if not found */
|
||||
inline Titem_ *FindOpenNode(const Key& key)
|
||||
inline Titem_ *FindOpenNode(const Key &key)
|
||||
{
|
||||
Titem_ *item = m_open.Find(key);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** remove and return the open node specified by a key */
|
||||
inline Titem_& PopOpenNode(const Key& key)
|
||||
inline Titem_& PopOpenNode(const Key &key)
|
||||
{
|
||||
Titem_& item = m_open.Pop(key);
|
||||
Titem_ &item = m_open.Pop(key);
|
||||
uint idxPop = m_open_queue.FindIndex(item);
|
||||
m_open_queue.Remove(idxPop);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** close node */
|
||||
inline void InsertClosedNode(Titem_& item)
|
||||
inline void InsertClosedNode(Titem_ &item)
|
||||
{
|
||||
assert(m_open.Find(item.GetKey()) == NULL);
|
||||
m_closed.Push(item);
|
||||
}
|
||||
|
||||
/** return the closed node specified by a key or NULL if not found */
|
||||
inline Titem_ *FindClosedNode(const Key& key)
|
||||
inline Titem_ *FindClosedNode(const Key &key)
|
||||
{
|
||||
Titem_ *item = m_closed.Find(key);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** The number of items. */
|
||||
inline int TotalCount() {return m_arr.Length();}
|
||||
inline int TotalCount()
|
||||
{
|
||||
return m_arr.Length();
|
||||
}
|
||||
|
||||
/** Get a particular item. */
|
||||
inline Titem_& ItemAt(int idx) {return m_arr[idx];}
|
||||
inline Titem_& ItemAt(int idx)
|
||||
{
|
||||
return m_arr[idx];
|
||||
}
|
||||
|
||||
/** Helper for creating output of this array. */
|
||||
template <class D> void Dump(D &dmp) const
|
||||
|
@@ -38,10 +38,10 @@ extern int _total_pf_time_us;
|
||||
* --------------------------------------------------------------
|
||||
* Your pathfinder derived class needs to implement following methods:
|
||||
* inline void PfSetStartupNodes()
|
||||
* inline void PfFollowNode(Node& org)
|
||||
* inline bool PfCalcCost(Node& n)
|
||||
* inline bool PfCalcEstimate(Node& n)
|
||||
* inline bool PfDetectDestination(Node& n)
|
||||
* inline void PfFollowNode(Node &org)
|
||||
* inline bool PfCalcCost(Node &n)
|
||||
* inline bool PfCalcEstimate(Node &n)
|
||||
* inline bool PfDetectDestination(Node &n)
|
||||
*
|
||||
* For more details about those methods, look at the end of CYapfBaseT
|
||||
* declaration. There are some examples. For another example look at
|
||||
@@ -99,7 +99,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -193,12 +193,12 @@ public:
|
||||
*/
|
||||
inline Node& CreateNewNode()
|
||||
{
|
||||
Node& node = *m_nodes.CreateNewNode();
|
||||
Node &node = *m_nodes.CreateNewNode();
|
||||
return node;
|
||||
}
|
||||
|
||||
/** Add new node (created by CreateNewNode and filled with data) into open list */
|
||||
inline void AddStartupNode(Node& n)
|
||||
inline void AddStartupNode(Node &n)
|
||||
{
|
||||
Yapf().PfNodeCacheFetch(n);
|
||||
/* insert the new node only if it is not there */
|
||||
@@ -217,7 +217,7 @@ public:
|
||||
bool is_choice = (KillFirstBit(tf.m_new_td_bits) != TRACKDIR_BIT_NONE);
|
||||
for (TrackdirBits rtds = tf.m_new_td_bits; rtds != TRACKDIR_BIT_NONE; rtds = KillFirstBit(rtds)) {
|
||||
Trackdir td = (Trackdir)FindFirstBit2x64(rtds);
|
||||
Node& n = Yapf().CreateNewNode();
|
||||
Node &n = Yapf().CreateNewNode();
|
||||
n.Set(parent, tf.m_new_tile, td, is_choice);
|
||||
Yapf().AddNewNode(n, tf);
|
||||
}
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
inline void PfSetStartupNodes()
|
||||
{
|
||||
/* example: */
|
||||
Node& n1 = *base::m_nodes.CreateNewNode();
|
||||
Node &n1 = *base::m_nodes.CreateNewNode();
|
||||
.
|
||||
. // setup node members here
|
||||
.
|
||||
@@ -341,10 +341,10 @@ public:
|
||||
}
|
||||
|
||||
/** Example: PfFollowNode() - set following (child) nodes of the given node */
|
||||
inline void PfFollowNode(Node& org)
|
||||
inline void PfFollowNode(Node &org)
|
||||
{
|
||||
for (each follower of node org) {
|
||||
Node& n = *base::m_nodes.CreateNewNode();
|
||||
Node &n = *base::m_nodes.CreateNewNode();
|
||||
.
|
||||
. // setup node members here
|
||||
.
|
||||
@@ -354,7 +354,7 @@ public:
|
||||
}
|
||||
|
||||
/** Example: PfCalcCost() - set path cost from origin to the given node */
|
||||
inline bool PfCalcCost(Node& n)
|
||||
inline bool PfCalcCost(Node &n)
|
||||
{
|
||||
/* evaluate last step cost */
|
||||
int cost = ...;
|
||||
@@ -364,7 +364,7 @@ public:
|
||||
}
|
||||
|
||||
/** Example: PfCalcEstimate() - set path cost estimate from origin to the target through given node */
|
||||
inline bool PfCalcEstimate(Node& n)
|
||||
inline bool PfCalcEstimate(Node &n)
|
||||
{
|
||||
/* evaluate the distance to our destination */
|
||||
int distance = ...;
|
||||
@@ -374,7 +374,7 @@ public:
|
||||
}
|
||||
|
||||
/** Example: PfDetectDestination() - return true if the given node is our destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
bool bDest = (n.m_key.m_x == m_x2) && (n.m_key.m_y == m_y2);
|
||||
return bDest;
|
||||
|
@@ -28,7 +28,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
bool is_choice = (KillFirstBit(m_orgTrackdirs) != TRACKDIR_BIT_NONE);
|
||||
for (TrackdirBits tdb = m_orgTrackdirs; tdb != TRACKDIR_BIT_NONE; tdb = KillFirstBit(tdb)) {
|
||||
Trackdir td = (Trackdir)FindFirstBit2x64(tdb);
|
||||
Node& n1 = Yapf().CreateNewNode();
|
||||
Node &n1 = Yapf().CreateNewNode();
|
||||
n1.Set(NULL, m_orgTile, td, is_choice);
|
||||
Yapf().AddStartupNode(n1);
|
||||
}
|
||||
@@ -72,7 +72,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -91,12 +91,12 @@ public:
|
||||
void PfSetStartupNodes()
|
||||
{
|
||||
if (m_orgTile != INVALID_TILE && m_orgTd != INVALID_TRACKDIR) {
|
||||
Node& n1 = Yapf().CreateNewNode();
|
||||
Node &n1 = Yapf().CreateNewNode();
|
||||
n1.Set(NULL, m_orgTile, m_orgTd, false);
|
||||
Yapf().AddStartupNode(n1);
|
||||
}
|
||||
if (m_revTile != INVALID_TILE && m_revTd != INVALID_TRACKDIR) {
|
||||
Node& n2 = Yapf().CreateNewNode();
|
||||
Node &n2 = Yapf().CreateNewNode();
|
||||
n2.Set(NULL, m_revTile, m_revTd, false);
|
||||
n2.m_cost = m_reverse_penalty;
|
||||
Yapf().AddStartupNode(n2);
|
||||
@@ -135,12 +135,12 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
bool bDest = (n.m_key.m_tile == m_destTile) && ((m_destTrackdirs & TrackdirToTrackdirBits(n.GetTrackdir())) != TRACKDIR_BIT_NONE);
|
||||
return bDest;
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
* 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 const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
|
@@ -30,7 +30,7 @@ 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
|
||||
*/
|
||||
inline bool PfNodeCacheFetch(Node& n)
|
||||
inline bool PfNodeCacheFetch(Node &n)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
* Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||
* Current cache implementation doesn't use that.
|
||||
*/
|
||||
inline void PfNodeCacheFlush(Node& n)
|
||||
inline void PfNodeCacheFlush(Node &n)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -67,7 +67,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -75,7 +75,7 @@ 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
|
||||
*/
|
||||
inline bool PfNodeCacheFetch(Node& n)
|
||||
inline bool PfNodeCacheFetch(Node &n)
|
||||
{
|
||||
CacheKey key(n.GetKey());
|
||||
Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key));
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
* Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||
* Current cache implementation doesn't use that.
|
||||
*/
|
||||
inline void PfNodeCacheFlush(Node& n)
|
||||
inline void PfNodeCacheFlush(Node &n)
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -121,9 +121,7 @@ struct CSegmentCostCacheBase
|
||||
* Look at CYapfRailSegment (yapf_node_rail.hpp) for the segment example
|
||||
*/
|
||||
template <class Tsegment>
|
||||
struct CSegmentCostCacheT
|
||||
: public CSegmentCostCacheBase
|
||||
{
|
||||
struct CSegmentCostCacheT : public CSegmentCostCacheBase {
|
||||
static const int C_HASH_BITS = 14;
|
||||
|
||||
typedef CHashTableT<Tsegment, C_HASH_BITS> HashTable;
|
||||
@@ -142,7 +140,7 @@ struct CSegmentCostCacheT
|
||||
m_heap.Clear();
|
||||
}
|
||||
|
||||
inline Tsegment& Get(Key& key, bool *found)
|
||||
inline Tsegment& Get(Key &key, bool *found)
|
||||
{
|
||||
Tsegment *item = m_map.Find(key);
|
||||
if (item == NULL) {
|
||||
@@ -162,9 +160,7 @@ struct CSegmentCostCacheT
|
||||
* segment cost caching services for your Nodes.
|
||||
*/
|
||||
template <class Types>
|
||||
class CYapfSegmentCostCacheGlobalT
|
||||
: public CYapfSegmentCostCacheLocalT<Types>
|
||||
{
|
||||
class CYapfSegmentCostCacheGlobalT : public CYapfSegmentCostCacheLocalT<Types> {
|
||||
public:
|
||||
typedef CYapfSegmentCostCacheLocalT<Types> Tlocal;
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
@@ -175,14 +171,14 @@ public:
|
||||
typedef CSegmentCostCacheT<CachedData> Cache;
|
||||
|
||||
protected:
|
||||
Cache& m_global_cache;
|
||||
Cache &m_global_cache;
|
||||
|
||||
inline CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
|
||||
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
inline static Cache& stGetGlobalCache()
|
||||
@@ -211,14 +207,14 @@ 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
|
||||
*/
|
||||
inline bool PfNodeCacheFetch(Node& n)
|
||||
inline bool PfNodeCacheFetch(Node &n)
|
||||
{
|
||||
if (!Yapf().CanUseGlobalCache(n)) {
|
||||
return Tlocal::PfNodeCacheFetch(n);
|
||||
}
|
||||
CacheKey key(n.GetKey());
|
||||
bool found;
|
||||
CachedData& item = m_global_cache.Get(key, &found);
|
||||
CachedData &item = m_global_cache.Get(key, &found);
|
||||
Yapf().ConnectNodeToCachedData(n, item);
|
||||
return found;
|
||||
}
|
||||
@@ -227,7 +223,7 @@ public:
|
||||
* Called by YAPF to flush the cached segment cost data back into cache storage.
|
||||
* Current cache implementation doesn't use that.
|
||||
*/
|
||||
inline void PfNodeCacheFlush(Node& n)
|
||||
inline void PfNodeCacheFlush(Node &n)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@@ -16,9 +16,7 @@
|
||||
#include "../../tracerestrict.h"
|
||||
|
||||
template <class Types>
|
||||
class CYapfCostRailT
|
||||
: public CYapfCostBase
|
||||
{
|
||||
class CYapfCostRailT : public CYapfCostBase {
|
||||
public:
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
typedef typename Types::TrackFollower TrackFollower;
|
||||
@@ -75,10 +73,7 @@ protected:
|
||||
|
||||
static const int s_max_segment_cost = 10000;
|
||||
|
||||
CYapfCostRailT()
|
||||
: m_max_cost(0)
|
||||
, m_disable_cache(false)
|
||||
, m_stopped_on_first_two_way_signal(false)
|
||||
CYapfCostRailT() : m_max_cost(0), m_disable_cache(false), m_stopped_on_first_two_way_signal(false)
|
||||
{
|
||||
/* pre-compute look-ahead penalties into array */
|
||||
int p0 = Yapf().PfGetSettings().rail_look_ahead_signal_p0;
|
||||
@@ -93,7 +88,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -131,7 +126,7 @@ public:
|
||||
}
|
||||
|
||||
/** Return one tile cost (base cost + level crossing penalty). */
|
||||
inline int OneTileCost(TileIndex& tile, Trackdir trackdir)
|
||||
inline int OneTileCost(TileIndex &tile, Trackdir trackdir)
|
||||
{
|
||||
int cost = 0;
|
||||
/* set base cost */
|
||||
@@ -166,7 +161,7 @@ public:
|
||||
}
|
||||
|
||||
/** The cost for reserved tiles, including skipped ones. */
|
||||
inline int ReservationCost(Node& n, TileIndex tile, Trackdir trackdir, int skipped)
|
||||
inline int ReservationCost(Node &n, TileIndex tile, Trackdir trackdir, int skipped)
|
||||
{
|
||||
if (n.m_num_signals_passed >= m_sig_look_ahead_costs.Size() / 2) return 0;
|
||||
if (!IsPbsSignal(n.m_last_signal_type)) return 0;
|
||||
@@ -281,7 +276,7 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
int SignalCost(Node& n, TileIndex tile, Trackdir trackdir)
|
||||
int SignalCost(Node &n, TileIndex tile, Trackdir trackdir)
|
||||
{
|
||||
int cost = 0;
|
||||
/* if there is one-way signal in the opposite direction, then it is not our way */
|
||||
@@ -729,14 +724,14 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool CanUseGlobalCache(Node& n) const
|
||||
inline bool CanUseGlobalCache(Node &n) const
|
||||
{
|
||||
return !m_disable_cache
|
||||
&& (n.m_parent != NULL)
|
||||
&& (n.m_parent->m_num_signals_passed >= m_sig_look_ahead_costs.Size());
|
||||
}
|
||||
|
||||
inline void ConnectNodeToCachedData(Node& n, CachedData& ci)
|
||||
inline void ConnectNodeToCachedData(Node &n, CachedData &ci)
|
||||
{
|
||||
n.m_segment = &ci;
|
||||
if (n.m_segment->m_cost < 0) {
|
||||
|
@@ -12,8 +12,7 @@
|
||||
#ifndef YAPF_DESTRAIL_HPP
|
||||
#define YAPF_DESTRAIL_HPP
|
||||
|
||||
class CYapfDestinationRailBase
|
||||
{
|
||||
class CYapfDestinationRailBase {
|
||||
protected:
|
||||
RailTypes m_compatible_railtypes;
|
||||
|
||||
@@ -36,9 +35,7 @@ public:
|
||||
};
|
||||
|
||||
template <class Types>
|
||||
class CYapfDestinationAnyDepotRailT
|
||||
: public CYapfDestinationRailBase
|
||||
{
|
||||
class CYapfDestinationAnyDepotRailT : public CYapfDestinationRailBase {
|
||||
public:
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
@@ -47,11 +44,11 @@ public:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
@@ -67,7 +64,7 @@ public:
|
||||
* 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)
|
||||
{
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
@@ -75,9 +72,7 @@ public:
|
||||
};
|
||||
|
||||
template <class Types>
|
||||
class CYapfDestinationAnySafeTileRailT
|
||||
: public CYapfDestinationRailBase
|
||||
{
|
||||
class CYapfDestinationAnySafeTileRailT : public CYapfDestinationRailBase {
|
||||
public:
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
@@ -87,11 +82,11 @@ public:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
@@ -107,7 +102,7 @@ public:
|
||||
* 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)
|
||||
{
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
@@ -115,9 +110,7 @@ public:
|
||||
};
|
||||
|
||||
template <class Types>
|
||||
class CYapfDestinationTileOrStationRailT
|
||||
: public CYapfDestinationRailBase
|
||||
{
|
||||
class CYapfDestinationTileOrStationRailT : public CYapfDestinationRailBase {
|
||||
public:
|
||||
typedef typename Types::Tpf Tpf; ///< the pathfinder class (derived from THIS class)
|
||||
typedef typename Types::NodeList::Titem Node; ///< this will be our node type
|
||||
@@ -131,7 +124,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -164,7 +157,7 @@ public:
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestination(n.GetLastTile(), n.GetLastTrackdir());
|
||||
}
|
||||
@@ -188,7 +181,7 @@ public:
|
||||
* 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 const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
|
@@ -25,8 +25,15 @@ struct CYapfNodeKeyExitDir {
|
||||
m_exitdir = (m_td == INVALID_TRACKDIR) ? INVALID_DIAGDIR : TrackdirToExitdir(m_td);
|
||||
}
|
||||
|
||||
inline int CalcHash() const {return m_exitdir | (m_tile << 2);}
|
||||
inline bool operator == (const CYapfNodeKeyExitDir& other) const {return (m_tile == other.m_tile) && (m_exitdir == other.m_exitdir);}
|
||||
inline int CalcHash() const
|
||||
{
|
||||
return m_exitdir | (m_tile << 2);
|
||||
}
|
||||
|
||||
inline bool operator==(const CYapfNodeKeyExitDir &other) const
|
||||
{
|
||||
return m_tile == other.m_tile && m_exitdir == other.m_exitdir;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
@@ -38,8 +45,15 @@ struct CYapfNodeKeyExitDir {
|
||||
|
||||
struct CYapfNodeKeyTrackDir : public CYapfNodeKeyExitDir
|
||||
{
|
||||
inline int CalcHash() const {return m_td | (m_tile << 4);}
|
||||
inline bool operator == (const CYapfNodeKeyTrackDir& other) const {return (m_tile == other.m_tile) && (m_td == other.m_td);}
|
||||
inline int CalcHash() const
|
||||
{
|
||||
return m_td | (m_tile << 4);
|
||||
}
|
||||
|
||||
inline bool operator==(const CYapfNodeKeyTrackDir &other) const
|
||||
{
|
||||
return m_tile == other.m_tile && m_td == other.m_td;
|
||||
}
|
||||
};
|
||||
|
||||
/** Yapf Node base */
|
||||
@@ -63,14 +77,45 @@ struct CYapfNodeT {
|
||||
m_estimate = 0;
|
||||
}
|
||||
|
||||
inline Node *GetHashNext() {return m_hash_next;}
|
||||
inline void SetHashNext(Node *pNext) {m_hash_next = pNext;}
|
||||
inline TileIndex GetTile() const {return m_key.m_tile;}
|
||||
inline Trackdir GetTrackdir() const {return m_key.m_td;}
|
||||
inline const Tkey_& GetKey() const {return m_key;}
|
||||
inline int GetCost() const {return m_cost;}
|
||||
inline int GetCostEstimate() const {return m_estimate;}
|
||||
inline bool operator < (const Node& other) const {return m_estimate < other.m_estimate;}
|
||||
inline Node *GetHashNext()
|
||||
{
|
||||
return m_hash_next;
|
||||
}
|
||||
|
||||
inline void SetHashNext(Node *pNext)
|
||||
{
|
||||
m_hash_next = pNext;
|
||||
}
|
||||
|
||||
inline TileIndex GetTile() const
|
||||
{
|
||||
return m_key.m_tile;
|
||||
}
|
||||
|
||||
inline Trackdir GetTrackdir() const
|
||||
{
|
||||
return m_key.m_td;
|
||||
}
|
||||
|
||||
inline const Tkey_& GetKey() const
|
||||
{
|
||||
return m_key;
|
||||
}
|
||||
|
||||
inline int GetCost() const
|
||||
{
|
||||
return m_cost;
|
||||
}
|
||||
|
||||
inline int GetCostEstimate() const
|
||||
{
|
||||
return m_estimate;
|
||||
}
|
||||
|
||||
inline bool operator<(const Node &other) const
|
||||
{
|
||||
return m_estimate < other.m_estimate;
|
||||
}
|
||||
|
||||
void Dump(DumpTarget &dmp) const
|
||||
{
|
||||
|
@@ -17,19 +17,19 @@ struct CYapfRailSegmentKey
|
||||
{
|
||||
uint32 m_value;
|
||||
|
||||
inline CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
|
||||
inline CYapfRailSegmentKey(const CYapfRailSegmentKey &src) : m_value(src.m_value) {}
|
||||
|
||||
inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key)
|
||||
inline CYapfRailSegmentKey(const CYapfNodeKeyTrackDir &node_key)
|
||||
{
|
||||
Set(node_key);
|
||||
}
|
||||
|
||||
inline void Set(const CYapfRailSegmentKey& src)
|
||||
inline void Set(const CYapfRailSegmentKey &src)
|
||||
{
|
||||
m_value = src.m_value;
|
||||
}
|
||||
|
||||
inline void Set(const CYapfNodeKeyTrackDir& node_key)
|
||||
inline void Set(const CYapfNodeKeyTrackDir &node_key)
|
||||
{
|
||||
m_value = (((int)node_key.m_tile) << 4) | node_key.m_td;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ struct CYapfRailSegmentKey
|
||||
return (Trackdir)(m_value & 0x0F);
|
||||
}
|
||||
|
||||
inline bool operator == (const CYapfRailSegmentKey& other) const
|
||||
inline bool operator==(const CYapfRailSegmentKey &other) const
|
||||
{
|
||||
return m_value == other.m_value;
|
||||
}
|
||||
@@ -75,7 +75,7 @@ struct CYapfRailSegment
|
||||
EndSegmentReasonBits m_end_segment_reason;
|
||||
CYapfRailSegment *m_hash_next;
|
||||
|
||||
inline CYapfRailSegment(const CYapfRailSegmentKey& key)
|
||||
inline CYapfRailSegment(const CYapfRailSegmentKey &key)
|
||||
: m_key(key)
|
||||
, m_last_tile(INVALID_TILE)
|
||||
, m_last_td(INVALID_TRACKDIR)
|
||||
|
@@ -14,13 +14,11 @@
|
||||
|
||||
/** Yapf Node for road YAPF */
|
||||
template <class Tkey_>
|
||||
struct CYapfRoadNodeT
|
||||
: CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> >
|
||||
{
|
||||
struct CYapfRoadNodeT : CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > {
|
||||
typedef CYapfNodeT<Tkey_, CYapfRoadNodeT<Tkey_> > base;
|
||||
|
||||
TileIndex m_segment_last_tile;
|
||||
Trackdir m_segment_last_td;
|
||||
TileIndex m_segment_last_tile;
|
||||
Trackdir m_segment_last_td;
|
||||
|
||||
void Set(CYapfRoadNodeT *parent, TileIndex tile, Trackdir td, bool is_choice)
|
||||
{
|
||||
|
@@ -14,11 +14,7 @@
|
||||
|
||||
/** Yapf Node for ships */
|
||||
template <class Tkey_>
|
||||
struct CYapfShipNodeT
|
||||
: CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> >
|
||||
{
|
||||
|
||||
};
|
||||
struct CYapfShipNodeT : CYapfNodeT<Tkey_, CYapfShipNodeT<Tkey_> > { };
|
||||
|
||||
/* now define two major node types (that differ by key type) */
|
||||
typedef CYapfShipNodeT<CYapfNodeKeyExitDir> CYapfShipNodeExitDir;
|
||||
@@ -28,5 +24,4 @@ typedef CYapfShipNodeT<CYapfNodeKeyTrackDir> CYapfShipNodeTrackDir;
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeExitDir , 10, 12> CShipNodeListExitDir;
|
||||
typedef CNodeList_HashTableT<CYapfShipNodeTrackDir, 10, 12> CShipNodeListTrackDir;
|
||||
|
||||
|
||||
#endif /* YAPF_NODE_SHIP_HPP */
|
||||
|
@@ -48,7 +48,7 @@ protected:
|
||||
/** to access inherited pathfinder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -200,7 +200,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -209,7 +209,7 @@ public:
|
||||
* 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());
|
||||
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
|
||||
@@ -296,7 +296,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -305,7 +305,7 @@ public:
|
||||
* 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(), Yapf().GetCompatibleRailTypes());
|
||||
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
|
||||
@@ -379,7 +379,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -388,7 +388,7 @@ public:
|
||||
* 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());
|
||||
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
|
||||
@@ -453,7 +453,7 @@ public:
|
||||
this->FindSafePositionOnNode(pPrev);
|
||||
}
|
||||
/* return trackdir from the best origin node (one of start nodes) */
|
||||
Node& best_next_node = *pPrev;
|
||||
Node &best_next_node = *pPrev;
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
|
||||
if (reserve_track && path_found) this->TryReservePath(target, pNode->GetLastTile());
|
||||
@@ -502,7 +502,7 @@ public:
|
||||
}
|
||||
|
||||
/* check if it was reversed origin */
|
||||
Node& best_org_node = *pNode;
|
||||
Node &best_org_node = *pNode;
|
||||
bool reversed = (best_org_node.m_cost != 0);
|
||||
return reversed;
|
||||
}
|
||||
|
@@ -30,7 +30,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
int SlopeCost(TileIndex tile, TileIndex next_tile, Trackdir trackdir)
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
* Calculates only the cost of given node, adds it to the parent node cost
|
||||
* and stores the result into Node::m_cost member
|
||||
*/
|
||||
inline bool PfCalcCost(Node& n, const TrackFollower *tf)
|
||||
inline bool PfCalcCost(Node &n, const TrackFollower *tf)
|
||||
{
|
||||
int segment_cost = 0;
|
||||
uint tiles = 0;
|
||||
@@ -179,11 +179,11 @@ public:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
bool bDest = IsRoadDepotTile(n.m_segment_last_tile);
|
||||
return bDest;
|
||||
@@ -198,7 +198,7 @@ public:
|
||||
* 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)
|
||||
{
|
||||
n.m_estimate = n.m_cost;
|
||||
return true;
|
||||
@@ -242,12 +242,12 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
/** Called by YAPF to detect if node ends in the desired destination */
|
||||
inline bool PfDetectDestination(Node& n)
|
||||
inline bool PfDetectDestination(Node &n)
|
||||
{
|
||||
return PfDetectDestinationTile(n.m_segment_last_tile, n.m_segment_last_td);
|
||||
}
|
||||
@@ -268,7 +268,7 @@ public:
|
||||
* 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 const int dg_dir_to_x_offs[] = {-1, 0, 1, 0};
|
||||
static const int dg_dir_to_y_offs[] = {0, 1, 0, -1};
|
||||
@@ -309,7 +309,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -319,7 +319,7 @@ public:
|
||||
* 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());
|
||||
if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
|
||||
@@ -373,7 +373,7 @@ public:
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
/* return trackdir from the best origin node (one of start nodes) */
|
||||
Node& best_next_node = *pNode;
|
||||
Node &best_next_node = *pNode;
|
||||
assert(best_next_node.GetTile() == tile);
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
inline Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
* 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());
|
||||
if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
|
||||
@@ -97,7 +97,7 @@ public:
|
||||
pNode = pNode->m_parent;
|
||||
}
|
||||
/* return trackdir from the best next node (direct child of origin) */
|
||||
Node& best_next_node = *pPrevNode;
|
||||
Node &best_next_node = *pPrevNode;
|
||||
assert(best_next_node.GetTile() == tile);
|
||||
next_trackdir = best_next_node.GetTrackdir();
|
||||
}
|
||||
@@ -155,7 +155,7 @@ protected:
|
||||
/** to access inherited path finder */
|
||||
Tpf& Yapf()
|
||||
{
|
||||
return *static_cast<Tpf*>(this);
|
||||
return *static_cast<Tpf *>(this);
|
||||
}
|
||||
|
||||
public:
|
||||
@@ -164,7 +164,7 @@ public:
|
||||
* Calculates only the cost of given node, adds it to the parent node cost
|
||||
* and stores the result into Node::m_cost member
|
||||
*/
|
||||
inline bool PfCalcCost(Node& n, const TrackFollower *tf)
|
||||
inline bool PfCalcCost(Node &n, const TrackFollower *tf)
|
||||
{
|
||||
/* base tile cost depending on distance */
|
||||
int c = IsDiagonalTrackdir(n.GetTrackdir()) ? YAPF_TILE_LENGTH : YAPF_TILE_CORNER_LENGTH;
|
||||
|
Reference in New Issue
Block a user