1
0
Fork 0

(svn r15609) -Fix: Code style...

release/0.7
peter1138 2009-03-04 08:02:16 +00:00
parent 0682c1c46c
commit f0de54bc10
13 changed files with 300 additions and 99 deletions

View File

@ -46,28 +46,41 @@ public:
{ {
m_new_node = NULL; m_new_node = NULL;
} }
/** destructor */ /** destructor */
~CNodeList_HashTableT() ~CNodeList_HashTableT()
{ {
} }
/** return number of open nodes */ /** return number of open nodes */
FORCEINLINE int OpenCount() {return m_open.Count();} FORCEINLINE int OpenCount()
{
return m_open.Count();
}
/** return number of closed nodes */ /** return number of closed nodes */
FORCEINLINE int ClosedCount() {return m_closed.Count();} FORCEINLINE int ClosedCount()
{
return m_closed.Count();
}
/** allocate new data item from m_arr */ /** allocate new data item from m_arr */
FORCEINLINE Titem_ *CreateNewNode() FORCEINLINE Titem_ *CreateNewNode()
{ {
if (m_new_node == NULL) m_new_node = &m_arr.Add(); if (m_new_node == NULL) m_new_node = &m_arr.Add();
return m_new_node; return m_new_node;
} }
/** notify the nodelist, that we don't want to discard the given node */ /** notify the nodelist, that we don't want to discard the given node */
FORCEINLINE void FoundBestNode(Titem_& item) FORCEINLINE void FoundBestNode(Titem_& item)
{ {
// for now it is enough to invalidate m_new_node if it is our given node // for now it is enough to invalidate m_new_node if it is our given node
if (&item == m_new_node) if (&item == m_new_node) {
m_new_node = NULL; m_new_node = NULL;
}
// TODO: do we need to store best nodes found in some extra list/array? Probably not now. // TODO: do we need to store best nodes found in some extra list/array? Probably not now.
} }
/** insert given item as open node (into m_open and m_open_queue) */ /** insert given item as open node (into m_open and m_open_queue) */
FORCEINLINE void InsertOpenNode(Titem_& item) FORCEINLINE void InsertOpenNode(Titem_& item)
{ {
@ -76,9 +89,11 @@ public:
// TODO: check if m_open_queue is not full // TODO: check if m_open_queue is not full
assert(!m_open_queue.IsFull()); assert(!m_open_queue.IsFull());
m_open_queue.Push(item); m_open_queue.Push(item);
if (&item == m_new_node) if (&item == m_new_node) {
m_new_node = NULL; m_new_node = NULL;
}
} }
/** return the best open node */ /** return the best open node */
FORCEINLINE Titem_ *GetBestOpenNode() FORCEINLINE Titem_ *GetBestOpenNode()
{ {
@ -88,6 +103,7 @@ public:
} }
return NULL; return NULL;
} }
/** remove and return the best open node */ /** remove and return the best open node */
FORCEINLINE Titem_ *PopBestOpenNode() FORCEINLINE Titem_ *PopBestOpenNode()
{ {
@ -98,12 +114,14 @@ public:
} }
return NULL; return NULL;
} }
/** return the open node specified by a key or NULL if not found */ /** return the open node specified by a key or NULL if not found */
FORCEINLINE Titem_ *FindOpenNode(const Key& key) FORCEINLINE Titem_ *FindOpenNode(const Key& key)
{ {
Titem_ *item = m_open.Find(key); Titem_ *item = m_open.Find(key);
return item; return item;
} }
/** remove and return the open node specified by a key */ /** remove and return the open node specified by a key */
FORCEINLINE Titem_& PopOpenNode(const Key& key) FORCEINLINE Titem_& PopOpenNode(const Key& key)
{ {
@ -112,12 +130,14 @@ public:
m_open_queue.RemoveByIdx(idxPop); m_open_queue.RemoveByIdx(idxPop);
return item; return item;
} }
/** close node */ /** close node */
FORCEINLINE void InsertClosedNode(Titem_& item) FORCEINLINE void InsertClosedNode(Titem_& item)
{ {
assert(m_open.Find(item.GetKey()) == NULL); assert(m_open.Find(item.GetKey()) == NULL);
m_closed.Push(item); m_closed.Push(item);
} }
/** return the closed node specified by a key or NULL if not found */ /** return the closed node specified by a key or NULL if not found */
FORCEINLINE Titem_ *FindClosedNode(const Key& key) FORCEINLINE Titem_ *FindClosedNode(const Key& key)
{ {

View File

@ -41,21 +41,53 @@ struct CPerformanceTimer
CPerformanceTimer() : m_start(0), m_acc(0) {} CPerformanceTimer() : m_start(0), m_acc(0) {}
FORCEINLINE void Start() {m_start = QueryTime();} FORCEINLINE void Start()
FORCEINLINE void Stop() {m_acc += QueryTime() - m_start;} {
FORCEINLINE int Get(int64 coef) {return (int)(m_acc * coef / QueryFrequency());} m_start = QueryTime();
}
FORCEINLINE int64 QueryTime() {return ottd_rdtsc();} FORCEINLINE void Stop()
FORCEINLINE int64 QueryFrequency() {return ((int64)2200 * 1000000);} {
m_acc += QueryTime() - m_start;
}
FORCEINLINE int Get(int64 coef)
{
return (int)(m_acc * coef / QueryFrequency());
}
FORCEINLINE int64 QueryTime()
{
return ottd_rdtsc();
}
FORCEINLINE int64 QueryFrequency()
{
return ((int64)2200 * 1000000);
}
}; };
struct CPerfStartReal struct CPerfStartReal
{ {
CPerformanceTimer *m_pperf; CPerformanceTimer *m_pperf;
FORCEINLINE CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf) {if (m_pperf != NULL) m_pperf->Start();} FORCEINLINE CPerfStartReal(CPerformanceTimer& perf) : m_pperf(&perf)
FORCEINLINE ~CPerfStartReal() {Stop();} {
FORCEINLINE void Stop() {if (m_pperf != NULL) {m_pperf->Stop(); m_pperf = NULL;}} if (m_pperf != NULL) m_pperf->Start();
}
FORCEINLINE ~CPerfStartReal()
{
Stop();
}
FORCEINLINE void Stop()
{
if (m_pperf != NULL) {
m_pperf->Stop();
m_pperf = NULL;
}
}
}; };
struct CPerfStartFake struct CPerfStartFake

View File

@ -88,7 +88,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 - company based - but later) /// return current settings (can be custom - company based - but later)
@ -118,12 +121,14 @@ public:
while (true) { while (true) {
m_num_steps++; m_num_steps++;
Node *n = m_nodes.GetBestOpenNode(); Node *n = m_nodes.GetBestOpenNode();
if (n == NULL) if (n == NULL) {
break; break;
}
// if the best open node was worse than the best path found, we can finish // if the best open node was worse than the best path found, we can finish
if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) if (m_pBestDestNode != NULL && m_pBestDestNode->GetCost() < n->GetCostEstimate()) {
break; break;
}
Yapf().PfFollowNode(*n); Yapf().PfFollowNode(*n);
if (m_max_search_nodes == 0 || m_nodes.ClosedCount() < m_max_search_nodes) { if (m_max_search_nodes == 0 || m_nodes.ClosedCount() < m_max_search_nodes) {
@ -281,7 +286,10 @@ public:
m_nodes.InsertOpenNode(n); m_nodes.InsertOpenNode(n);
} }
const Vehicle * GetVehicle() const {return m_veh;} const Vehicle * GetVehicle() const
{
return m_veh;
}
void DumpBase(DumpTarget &dmp) const void DumpBase(DumpTarget &dmp) const
{ {

View File

@ -19,7 +19,10 @@ protected:
TrackdirBits m_orgTrackdirs; ///< origin trackdir mask TrackdirBits m_orgTrackdirs; ///< origin trackdir mask
/// to access inherited path finder /// 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 /// Set origin tile / trackdir mask
@ -60,7 +63,10 @@ protected:
bool m_treat_first_red_two_way_signal_as_eol; ///< in some cases (leaving station) we need to handle first two-way signal differently 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 /// 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.) /// set origin (tiles, trackdirs, etc.)
@ -120,7 +126,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /// Called by YAPF to detect if node ends in the desired destination

View File

@ -11,7 +11,7 @@ struct CYapfCostBase {
if (IsDiagonalTrackdir(td)) { if (IsDiagonalTrackdir(td)) {
if (IsBridgeTile(tile)) { if (IsBridgeTile(tile)) {
// it is bridge ramp, check if we are entering the bridge // it is bridge ramp, check if we are entering the bridge
if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty if (GetTunnelBridgeDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are leaving it, no penalty
// we are entering the bridge // we are entering the bridge
Slope tile_slope = GetTileSlope(tile, NULL); Slope tile_slope = GetTileSlope(tile, NULL);
Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile)); Axis axis = DiagDirToAxis(GetTunnelBridgeDirection(tile));

View File

@ -23,13 +23,13 @@ public:
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. /** Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. */ * Current cache implementation doesn't use that. */
FORCEINLINE void PfNodeCacheFlush(Node& n) FORCEINLINE void PfNodeCacheFlush(Node& n)
{ {
}; }
}; };
@ -52,7 +52,10 @@ protected:
LocalCache m_local_cache; LocalCache m_local_cache;
/// to access inherited path finder /// 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. /** Called by YAPF to attach cached or local segment cost data to the given node.
@ -62,13 +65,13 @@ public:
CacheKey key(n.GetKey()); CacheKey key(n.GetKey());
Yapf().ConnectNodeToCachedData(n, *new (&m_local_cache.AddNC()) CachedData(key)); Yapf().ConnectNodeToCachedData(n, *new (&m_local_cache.AddNC()) CachedData(key));
return false; return false;
}; }
/** Called by YAPF to flush the cached segment cost data back into cache storage. /** Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. */ * Current cache implementation doesn't use that. */
FORCEINLINE void PfNodeCacheFlush(Node& n) FORCEINLINE void PfNodeCacheFlush(Node& n)
{ {
}; }
}; };
@ -81,7 +84,10 @@ struct CSegmentCostCacheBase
{ {
static int s_rail_change_counter; static int s_rail_change_counter;
static void NotifyTrackLayoutChange(TileIndex tile, Track track) {s_rail_change_counter++;} static void NotifyTrackLayoutChange(TileIndex tile, Track track)
{
s_rail_change_counter++;
}
}; };
@ -109,7 +115,11 @@ struct CSegmentCostCacheT
FORCEINLINE CSegmentCostCacheT() {} FORCEINLINE CSegmentCostCacheT() {}
/** flush (clear) the cache */ /** flush (clear) the cache */
FORCEINLINE void Flush() {m_map.Clear(); m_heap.Clear();}; FORCEINLINE void Flush()
{
m_map.Clear();
m_heap.Clear();
}
FORCEINLINE Tsegment& Get(Key& key, bool *found) FORCEINLINE Tsegment& Get(Key& key, bool *found)
{ {
@ -148,7 +158,10 @@ protected:
FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {}; FORCEINLINE CYapfSegmentCostCacheGlobalT() : m_global_cache(stGetGlobalCache()) {};
/// to access inherited path finder /// to access inherited path finder
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);} FORCEINLINE Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
FORCEINLINE static Cache& stGetGlobalCache() FORCEINLINE static Cache& stGetGlobalCache()
{ {
@ -184,17 +197,13 @@ public:
CachedData& item = m_global_cache.Get(key, &found); CachedData& item = m_global_cache.Get(key, &found);
Yapf().ConnectNodeToCachedData(n, item); Yapf().ConnectNodeToCachedData(n, item);
return found; return found;
}; }
/** Called by YAPF to flush the cached segment cost data back into cache storage. /** Called by YAPF to flush the cached segment cost data back into cache storage.
* Current cache implementation doesn't use that. */ * Current cache implementation doesn't use that. */
FORCEINLINE void PfNodeCacheFlush(Node& n) FORCEINLINE void PfNodeCacheFlush(Node& n)
{ {
}; }
}; };
#endif /* YAPF_COSTCACHE_HPP */ #endif /* YAPF_COSTCACHE_HPP */

View File

@ -74,12 +74,16 @@ protected:
int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1; int p1 = Yapf().PfGetSettings().rail_look_ahead_signal_p1;
int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2; int p2 = Yapf().PfGetSettings().rail_look_ahead_signal_p2;
int *pen = m_sig_look_ahead_costs.GrowSizeNC(Yapf().PfGetSettings().rail_look_ahead_max_signals); int *pen = m_sig_look_ahead_costs.GrowSizeNC(Yapf().PfGetSettings().rail_look_ahead_max_signals);
for (uint i = 0; i < Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) for (uint i = 0; i < Yapf().PfGetSettings().rail_look_ahead_max_signals; i++) {
pen[i] = p0 + i * (p1 + i * p2); pen[i] = p0 + i * (p1 + i * p2);
}
} }
/// to access inherited path finder /// to access inherited path finder
Tpf& Yapf() {return *static_cast<Tpf*>(this);} Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
public: public:
FORCEINLINE int SlopeCost(TileIndex tile, Trackdir td) FORCEINLINE int SlopeCost(TileIndex tile, Trackdir td)
@ -125,8 +129,9 @@ public:
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_ROAD: case MP_ROAD:
/* Increase the cost for level crossings */ /* Increase the cost for level crossings */
if (IsLevelCrossing(tile)) if (IsLevelCrossing(tile)) {
cost += Yapf().PfGetSettings().rail_crossing_penalty; cost += Yapf().PfGetSettings().rail_crossing_penalty;
}
break; break;
default: default:
@ -215,7 +220,7 @@ public:
case SIGTYPE_NORMAL: case SIGTYPE_NORMAL:
case SIGTYPE_ENTRY: cost += Yapf().PfGetSettings().rail_firstred_penalty; break; case SIGTYPE_ENTRY: cost += Yapf().PfGetSettings().rail_firstred_penalty; break;
default: break; default: break;
}; }
} }
} }
@ -251,9 +256,10 @@ 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. /** 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 * Calculates only the cost of given node, adds it to the parent node cost
@ -412,10 +418,12 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
{ {
int min_speed = 0; int min_speed = 0;
int max_speed = tf->GetSpeedLimit(&min_speed); int max_speed = tf->GetSpeedLimit(&min_speed);
if (max_speed < v->max_speed) if (max_speed < v->max_speed) {
extra_cost += YAPF_TILE_LENGTH * (v->max_speed - max_speed) * (4 + tf->m_tiles_skipped) / v->max_speed; extra_cost += YAPF_TILE_LENGTH * (v->max_speed - max_speed) * (4 + tf->m_tiles_skipped) / v->max_speed;
if (min_speed > v->max_speed) }
if (min_speed > v->max_speed) {
extra_cost += YAPF_TILE_LENGTH * (min_speed - v->max_speed); extra_cost += YAPF_TILE_LENGTH * (min_speed - v->max_speed);
}
} }
/* Finish if we already exceeded the maximum path cost (i.e. when /* Finish if we already exceeded the maximum path cost (i.e. when
@ -569,6 +577,4 @@ no_entry_cost: // jump here at the beginning if the node has no parent (it is th
} }
}; };
#endif /* YAPF_COSTRAIL_HPP */ #endif /* YAPF_COSTRAIL_HPP */

View File

@ -38,7 +38,10 @@ public:
typedef typename Node::Key Key; ///< key to hash tables typedef typename Node::Key Key; ///< key to hash tables
/// to access inherited path finder /// 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 /// Called by YAPF to detect if node ends in the desired destination
FORCEINLINE bool PfDetectDestination(Node& n) FORCEINLINE bool PfDetectDestination(Node& n)
@ -73,7 +76,10 @@ public:
typedef typename Types::TrackFollower TrackFollower; ///< TrackFollower. Need to typedef for gcc 2.95 typedef typename Types::TrackFollower TrackFollower; ///< TrackFollower. Need to typedef for gcc 2.95
/// to access inherited path finder /// 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 /// Called by YAPF to detect if node ends in the desired destination
FORCEINLINE bool PfDetectDestination(Node& n) FORCEINLINE bool PfDetectDestination(Node& n)
@ -113,7 +119,10 @@ protected:
StationID m_dest_station_id; StationID m_dest_station_id;
/// to access inherited path finder /// to access inherited path finder
Tpf& Yapf() {return *static_cast<Tpf*>(this);} Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
public: public:
void SetDestination(const Vehicle *v) void SetDestination(const Vehicle *v)
@ -200,5 +209,4 @@ public:
} }
}; };
#endif /* YAPF_DESTRAIL_HPP */ #endif /* YAPF_DESTRAIL_HPP */

View File

@ -11,15 +11,41 @@ struct CYapfRailSegmentKey
uint32 m_value; uint32 m_value;
FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {} FORCEINLINE CYapfRailSegmentKey(const CYapfRailSegmentKey& src) : m_value(src.m_value) {}
FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key) {Set(node_key);}
FORCEINLINE void Set(const CYapfRailSegmentKey& src) {m_value = src.m_value;} FORCEINLINE CYapfRailSegmentKey(const CYapfNodeKeyTrackDir& node_key)
FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key) {m_value = (((int)node_key.m_tile) << 4) | node_key.m_td;} {
Set(node_key);
}
FORCEINLINE int32 CalcHash() const {return m_value;} FORCEINLINE void Set(const CYapfRailSegmentKey& src)
FORCEINLINE TileIndex GetTile() const {return (TileIndex)(m_value >> 4);} {
FORCEINLINE Trackdir GetTrackdir() const {return (Trackdir)(m_value & 0x0F);} m_value = src.m_value;
FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const {return m_value == other.m_value;} }
FORCEINLINE void Set(const CYapfNodeKeyTrackDir& node_key)
{
m_value = (((int)node_key.m_tile) << 4) | node_key.m_td;
}
FORCEINLINE int32 CalcHash() const
{
return m_value;
}
FORCEINLINE TileIndex GetTile() const
{
return (TileIndex)(m_value >> 4);
}
FORCEINLINE Trackdir GetTrackdir() const
{
return (Trackdir)(m_value & 0x0F);
}
FORCEINLINE bool operator == (const CYapfRailSegmentKey& other) const
{
return m_value == other.m_value;
}
void Dump(DumpTarget &dmp) const void Dump(DumpTarget &dmp) const
{ {
@ -122,10 +148,25 @@ struct CYapfRailSegment
, m_hash_next(NULL) , m_hash_next(NULL)
{} {}
FORCEINLINE const Key& GetKey() const {return m_key;} FORCEINLINE const Key& GetKey() const
FORCEINLINE TileIndex GetTile() const {return m_key.GetTile();} {
FORCEINLINE CYapfRailSegment *GetHashNext() {return m_hash_next;} return m_key;
FORCEINLINE void SetHashNext(CYapfRailSegment *next) {m_hash_next = next;} }
FORCEINLINE TileIndex GetTile() const
{
return m_key.GetTile();
}
FORCEINLINE CYapfRailSegment *GetHashNext()
{
return m_hash_next;
}
FORCEINLINE void SetHashNext(CYapfRailSegment *next)
{
m_hash_next = next;
}
void Dump(DumpTarget &dmp) const void Dump(DumpTarget &dmp) const
{ {
@ -175,9 +216,24 @@ struct CYapfRailNodeT
flags_u.flags_s.m_choice_seen |= is_choice; flags_u.flags_s.m_choice_seen |= is_choice;
} }
FORCEINLINE TileIndex GetLastTile() const {assert(m_segment != NULL); return m_segment->m_last_tile;} FORCEINLINE TileIndex GetLastTile() const
FORCEINLINE Trackdir GetLastTrackdir() const {assert(m_segment != NULL); return m_segment->m_last_td;} {
FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td) {assert(m_segment != NULL); m_segment->m_last_tile = tile; m_segment->m_last_td = td;} assert(m_segment != NULL);
return m_segment->m_last_tile;
}
FORCEINLINE Trackdir GetLastTrackdir() const
{
assert(m_segment != NULL);
return m_segment->m_last_td;
}
FORCEINLINE void SetLastTileTrackdir(TileIndex tile, Trackdir td)
{
assert(m_segment != NULL);
m_segment->m_last_tile = tile;
m_segment->m_last_td = td;
}
template <class Tbase, class Tfunc, class Tpf> template <class Tbase, class Tfunc, class Tpf>
bool IterateTiles(const Vehicle *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const bool IterateTiles(const Vehicle *v, Tpf &yapf, Tbase &obj, bool (Tfunc::*func)(TileIndex, Trackdir)) const
@ -218,6 +274,4 @@ typedef CYapfRailNodeT<CYapfNodeKeyTrackDir> CYapfRailNodeTrackDir;
typedef CNodeList_HashTableT<CYapfRailNodeExitDir , 10, 12> CRailNodeListExitDir; typedef CNodeList_HashTableT<CYapfRailNodeExitDir , 10, 12> CRailNodeListExitDir;
typedef CNodeList_HashTableT<CYapfRailNodeTrackDir, 12, 16> CRailNodeListTrackDir; typedef CNodeList_HashTableT<CYapfRailNodeTrackDir, 12, 16> CRailNodeListTrackDir;
#endif /* YAPF_NODE_RAIL_HPP */ #endif /* YAPF_NODE_RAIL_HPP */

View File

@ -5,8 +5,6 @@
#ifndef YAPF_NODE_ROAD_HPP #ifndef YAPF_NODE_ROAD_HPP
#define YAPF_NODE_ROAD_HPP #define YAPF_NODE_ROAD_HPP
/** Yapf Node for road YAPF */ /** Yapf Node for road YAPF */
template <class Tkey_> template <class Tkey_>
struct CYapfRoadNodeT struct CYapfRoadNodeT
@ -33,6 +31,4 @@ typedef CYapfRoadNodeT<CYapfNodeKeyTrackDir> CYapfRoadNodeTrackDir;
typedef CNodeList_HashTableT<CYapfRoadNodeExitDir , 8, 12> CRoadNodeListExitDir; typedef CNodeList_HashTableT<CYapfRoadNodeExitDir , 8, 12> CRoadNodeListExitDir;
typedef CNodeList_HashTableT<CYapfRoadNodeTrackDir, 10, 14> CRoadNodeListTrackDir; typedef CNodeList_HashTableT<CYapfRoadNodeTrackDir, 10, 14> CRoadNodeListTrackDir;
#endif /* YAPF_NODE_ROAD_HPP */ #endif /* YAPF_NODE_ROAD_HPP */

View File

@ -15,8 +15,6 @@
int _total_pf_time_us = 0; int _total_pf_time_us = 0;
template <class Types> template <class Types>
class CYapfReserveTrack class CYapfReserveTrack
{ {
@ -27,7 +25,10 @@ public:
protected: protected:
/// to access inherited pathfinder /// to access inherited pathfinder
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);} FORCEINLINE Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
private: private:
TileIndex m_res_dest; ///< The reservation target tile TileIndex m_res_dest; ///< The reservation target tile
@ -171,7 +172,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /** Called by YAPF to move from the given node to the next tile. For each
@ -180,12 +184,16 @@ public:
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node& old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, F);
}
} }
/// return debug report character to identify the transportation type /// return debug report character to identify the transportation type
FORCEINLINE char TransportTypeChar() const {return 't';} FORCEINLINE char TransportTypeChar() const
{
return 't';
}
static bool stFindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed) static bool stFindNearestDepotTwoWay(const Vehicle *v, TileIndex t1, Trackdir td1, TileIndex t2, Trackdir td2, int max_distance, int reverse_penalty, TileIndex *depot_tile, bool *reversed)
{ {
@ -247,7 +255,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /** Called by YAPF to move from the given node to the next tile. For each
@ -256,12 +267,16 @@ public:
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node& old_node)
{ {
TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes()); TrackFollower F(Yapf().GetVehicle(), Yapf().GetCompatibleRailTypes());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir()) && F.MaskReservedTracks()) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, F);
}
} }
/** Return debug report character to identify the transportation type */ /** Return debug report character to identify the transportation type */
FORCEINLINE char TransportTypeChar() const {return 't';} FORCEINLINE char TransportTypeChar() const
{
return 't';
}
static bool stFindNearestSafeTile(const Vehicle *v, TileIndex t1, Trackdir td, bool override_railtype) static bool stFindNearestSafeTile(const Vehicle *v, TileIndex t1, Trackdir td, bool override_railtype)
{ {
@ -329,7 +344,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /** Called by YAPF to move from the given node to the next tile. For each
@ -338,12 +356,16 @@ public:
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node& old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) if (F.Follow(old_node.GetLastTile(), old_node.GetLastTrackdir())) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, F);
}
} }
/// return debug report character to identify the transportation type /// return debug report character to identify the transportation type
FORCEINLINE char TransportTypeChar() const {return 't';} FORCEINLINE char TransportTypeChar() const
{
return 't';
}
static Trackdir stChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target) static Trackdir stChooseRailTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks, bool *path_not_found, bool reserve_track, PBSTileInfo *target)
{ {
@ -600,4 +622,7 @@ bool YapfRailFindNearestSafeTile(const Vehicle *v, TileIndex tile, Trackdir td,
/** if any track changes, this counter is incremented - that will invalidate segment cost cache */ /** if any track changes, this counter is incremented - that will invalidate segment cost cache */
int CSegmentCostCacheBase::s_rail_change_counter = 0; int CSegmentCostCacheBase::s_rail_change_counter = 0;
void YapfNotifyTrackLayoutChange(TileIndex tile, Track track) {CSegmentCostCacheBase::NotifyTrackLayoutChange(tile, track);} void YapfNotifyTrackLayoutChange(TileIndex tile, Track track)
{
CSegmentCostCacheBase::NotifyTrackLayoutChange(tile, track);
}

View File

@ -20,7 +20,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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)
{ {
@ -51,12 +54,15 @@ protected:
switch (GetTileType(tile)) { switch (GetTileType(tile)) {
case MP_ROAD: case MP_ROAD:
/* Increase the cost for level crossings */ /* Increase the cost for level crossings */
if (IsLevelCrossing(tile)) if (IsLevelCrossing(tile)) {
cost += Yapf().PfGetSettings().road_crossing_penalty; cost += Yapf().PfGetSettings().road_crossing_penalty;
}
break; break;
case MP_STATION: case MP_STATION:
if (IsDriveThroughStopTile(tile)) if (IsDriveThroughStopTile(tile)) {
cost += Yapf().PfGetSettings().road_stop_penalty; cost += Yapf().PfGetSettings().road_stop_penalty;
}
break; break;
default: default:
@ -144,7 +150,10 @@ public:
typedef typename Node::Key Key; ///< key to hash tables typedef typename Node::Key Key; ///< key to hash tables
/// to access inherited path finder /// 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 /// Called by YAPF to detect if node ends in the desired destination
FORCEINLINE bool PfDetectDestination(Node& n) FORCEINLINE bool PfDetectDestination(Node& n)
@ -190,7 +199,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /// Called by YAPF to detect if node ends in the desired destination
@ -246,7 +258,10 @@ public:
protected: protected:
/// to access inherited path finder /// to access inherited path finder
FORCEINLINE Tpf& Yapf() {return *static_cast<Tpf*>(this);} FORCEINLINE Tpf& Yapf()
{
return *static_cast<Tpf*>(this);
}
public: public:
@ -256,12 +271,16 @@ public:
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node& old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) if (F.Follow(old_node.m_segment_last_tile, old_node.m_segment_last_td)) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, F);
}
} }
/// return debug report character to identify the transportation type /// return debug report character to identify the transportation type
FORCEINLINE char TransportTypeChar() const {return 'r';} FORCEINLINE char TransportTypeChar() const
{
return 'r';
}
static Trackdir stChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir) static Trackdir stChooseRoadTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir)
{ {
@ -433,14 +452,17 @@ uint YapfRoadVehDistanceToTile(const Vehicle *v, TileIndex tile)
PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg PfnDistanceToTile pfnDistanceToTile = &CYapfRoad2::stDistanceToTile; // default: ExitDir, allow 90-deg
// check if non-default YAPF type should be used // check if non-default YAPF type should be used
if (_settings_game.pf.yapf.disable_node_optimization) if (_settings_game.pf.yapf.disable_node_optimization) {
pfnDistanceToTile = &CYapfRoad1::stDistanceToTile; // Trackdir, allow 90-deg pfnDistanceToTile = &CYapfRoad1::stDistanceToTile; // Trackdir, allow 90-deg
}
// measure distance in YAPF units // measure distance in YAPF units
uint dist = pfnDistanceToTile(v, tile); uint dist = pfnDistanceToTile(v, tile);
// convert distance to tiles // convert distance to tiles
if (dist != UINT_MAX) if (dist != UINT_MAX) {
dist = (dist + YAPF_TILE_LENGTH - 1) / YAPF_TILE_LENGTH; dist = (dist + YAPF_TILE_LENGTH - 1) / YAPF_TILE_LENGTH;
}
return dist; return dist;
} }
@ -448,8 +470,9 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
{ {
TileIndex tile = v->tile; TileIndex tile = v->tile;
Trackdir trackdir = GetVehicleTrackdir(v); Trackdir trackdir = GetVehicleTrackdir(v);
if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) if ((TrackStatusToTrackdirBits(GetTileTrackStatus(tile, TRANSPORT_ROAD, v->u.road.compatible_roadtypes)) & TrackdirToTrackdirBits(trackdir)) == 0) {
return NULL; return NULL;
}
// handle the case when our vehicle is already in the depot tile // handle the case when our vehicle is already in the depot tile
if (IsRoadDepotTile(tile)) { if (IsRoadDepotTile(tile)) {
@ -462,8 +485,9 @@ Depot *YapfFindNearestRoadDepot(const Vehicle *v)
PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot; PfnFindNearestDepot pfnFindNearestDepot = &CYapfRoadAnyDepot2::stFindNearestDepot;
// check if non-default YAPF type should be used // check if non-default YAPF type should be used
if (_settings_game.pf.yapf.disable_node_optimization) if (_settings_game.pf.yapf.disable_node_optimization) {
pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg pfnFindNearestDepot = &CYapfRoadAnyDepot1::stFindNearestDepot; // Trackdir, allow 90-deg
}
Depot *ret = pfnFindNearestDepot(v, tile, trackdir); Depot *ret = pfnFindNearestDepot(v, tile, trackdir);
return ret; return ret;

View File

@ -18,7 +18,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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 /** Called by YAPF to move from the given node to the next tile. For each
@ -27,12 +30,16 @@ public:
inline void PfFollowNode(Node& old_node) inline void PfFollowNode(Node& old_node)
{ {
TrackFollower F(Yapf().GetVehicle()); TrackFollower F(Yapf().GetVehicle());
if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) if (F.Follow(old_node.m_key.m_tile, old_node.m_key.m_td)) {
Yapf().AddMultipleNodes(&old_node, F); Yapf().AddMultipleNodes(&old_node, F);
}
} }
/// return debug report character to identify the transportation type /// return debug report character to identify the transportation type
FORCEINLINE char TransportTypeChar() const {return 'w';} FORCEINLINE char TransportTypeChar() const
{
return 'w';
}
static Trackdir ChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks) static Trackdir ChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection enterdir, TrackBits tracks)
{ {
@ -94,7 +101,10 @@ public:
protected: protected:
/// to access inherited path finder /// 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. /** Called by YAPF to calculate the cost from the origin to the given node.
@ -168,7 +178,7 @@ Trackdir YapfChooseShipTrack(const Vehicle *v, TileIndex tile, DiagDirection ent
} }
/** performance measurement helper */ /** performance measurement helper */
void * NpfBeginInterval() void *NpfBeginInterval()
{ {
CPerformanceTimer& perf = *new CPerformanceTimer; CPerformanceTimer& perf = *new CPerformanceTimer;
perf.Start(); perf.Start();