|
@@ -11,39 +11,43 @@
|
|
|
|
|
|
#ifndef YAPF_COSTCACHE_HPP
|
|
|
#define YAPF_COSTCACHE_HPP
|
|
|
|
|
|
#include "../../date_func.h"
|
|
|
|
|
|
/** CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
|
|
|
/**
|
|
|
* CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements
|
|
|
* PfNodeCacheFetch() and PfNodeCacheFlush() callbacks. Used when nodes don't have CachedData
|
|
|
* defined (they don't count with any segment cost caching).
|
|
|
*/
|
|
|
template <class Types>
|
|
|
class CYapfSegmentCostCacheNoneT
|
|
|
{
|
|
|
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
|
|
|
|
|
|
/** 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.
|
|
|
* @return true if globally cached data were used or false if local data was used */
|
|
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
|
|
{
|
|
|
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. */
|
|
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
|
|
{
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
/** CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment
|
|
|
/**
|
|
|
* CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment
|
|
|
* cost caching functionality for yapf. Used when node needs caching, but you don't want to
|
|
|
* cache the segment costs.
|
|
|
*/
|
|
|
template <class Types>
|
|
|
class CYapfSegmentCostCacheLocalT
|
|
|
{
|
|
@@ -62,30 +66,33 @@ protected:
|
|
|
FORCEINLINE Tpf& Yapf()
|
|
|
{
|
|
|
return *static_cast<Tpf*>(this);
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
* @return true if globally cached data were used or false if local data was used */
|
|
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
|
|
{
|
|
|
CacheKey key(n.GetKey());
|
|
|
Yapf().ConnectNodeToCachedData(n, *new (m_local_cache.Append()) CachedData(key));
|
|
|
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. */
|
|
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
|
|
{
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
/** Base class for segment cost cache providers. Contains global counter
|
|
|
/**
|
|
|
* 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
|
|
|
{
|
|
@@ -95,13 +102,14 @@ struct CSegmentCostCacheBase
|
|
|
{
|
|
|
s_rail_change_counter++;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
|
|
|
/** CSegmentCostCacheT - template class providing hash-map and storage (heap)
|
|
|
/**
|
|
|
* CSegmentCostCacheT - template class providing hash-map and storage (heap)
|
|
|
* of Tsegment structures. Each rail node contains pointer to the segment
|
|
|
* that contains cached (or non-cached) segment cost information. Nodes can
|
|
|
* differ by key type, but they use the same segment type. Segment key should
|
|
|
* be always the same (TileIndex + DiagDirection) that represent the beginning
|
|
|
* of the segment (origin tile and exit-dir from this tile).
|
|
|
* Different CYapfCachedCostT types can share the same type of CSegmentCostCacheT.
|
|
@@ -139,13 +147,14 @@ struct CSegmentCostCacheT
|
|
|
*found = true;
|
|
|
}
|
|
|
return *item;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/** CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost
|
|
|
/**
|
|
|
* CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost
|
|
|
* caching functionality to yapf. Using this class as base of your will provide the global
|
|
|
* segment cost caching services for your Nodes.
|
|
|
*/
|
|
|
template <class Types>
|
|
|
class CYapfSegmentCostCacheGlobalT
|
|
|
: public CYapfSegmentCostCacheLocalT<Types>
|
|
@@ -189,13 +198,14 @@ protected:
|
|
|
C.Flush();
|
|
|
}
|
|
|
return C;
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
* @return true if globally cached data were used or false if local data was used */
|
|
|
FORCEINLINE bool PfNodeCacheFetch(Node& n)
|
|
|
{
|
|
|
if (!Yapf().CanUseGlobalCache(n)) {
|
|
|
return Tlocal::PfNodeCacheFetch(n);
|
|
|
}
|
|
@@ -203,13 +213,14 @@ public:
|
|
|
bool found;
|
|
|
CachedData& item = m_global_cache.Get(key, &found);
|
|
|
Yapf().ConnectNodeToCachedData(n, item);
|
|
|
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. */
|
|
|
FORCEINLINE void PfNodeCacheFlush(Node& n)
|
|
|
{
|
|
|
}
|
|
|
};
|
|
|
|