10 #ifndef YAPF_COSTCACHE_HPP 11 #define YAPF_COSTCACHE_HPP 13 #include "../../date_func.h" 20 template <
class Types>
24 typedef typename Types::Tpf
Tpf;
25 typedef typename Types::NodeList::Titem
Node;
51 template <
class Types>
55 typedef typename Types::Tpf
Tpf;
56 typedef typename Types::NodeList::Titem
Node;
57 typedef typename Node::Key
Key;
58 typedef typename Node::CachedData CachedData;
59 typedef typename CachedData::Key CacheKey;
63 LocalCache m_local_cache;
68 return *
static_cast<Tpf *
>(
this);
78 CacheKey key(n.GetKey());
79 Yapf().ConnectNodeToCachedData(n, *
new (m_local_cache.
Append()) CachedData(key));
106 s_rail_change_counter++;
121 template <
class Tsegment>
123 static const int C_HASH_BITS = 14;
127 typedef typename Tsegment::Key
Key;
141 inline Tsegment& Get(Key &key,
bool *found)
143 Tsegment *item = m_map.
Find(key);
144 if (item ==
nullptr) {
146 item =
new (m_heap.
Append()) Tsegment(key);
160 template <
class Types>
164 typedef typename Types::Tpf
Tpf;
165 typedef typename Types::NodeList::Titem
Node;
166 typedef typename Node::Key
Key;
167 typedef typename Node::CachedData CachedData;
168 typedef typename CachedData::Key CacheKey;
172 Cache &m_global_cache;
179 return *
static_cast<Tpf *
>(
this);
182 inline static Cache& stGetGlobalCache()
184 static int last_rail_change_counter = 0;
185 static Date last_date = 0;
189 if (last_date !=
_date) {
191 DEBUG(yapf, 2,
"Pf time today: %5d ms", _total_pf_time_us / 1000);
192 _total_pf_time_us = 0;
196 if (last_rail_change_counter != Cache::s_rail_change_counter) {
197 last_rail_change_counter = Cache::s_rail_change_counter;
210 if (!Yapf().CanUseGlobalCache(n)) {
211 return Tlocal::PfNodeCacheFetch(n);
213 CacheKey key(n.GetKey());
215 CachedData &item = m_global_cache.Get(key, &found);
216 Yapf().ConnectNodeToCachedData(n, item);
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
Types::NodeList::Titem Node
this will be our node type
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
void Push(Titem_ &new_item)
add one item - copy it from the given item
CSegmentCostCacheT - template class providing hash-map and storage (heap) of Tsegment structures...
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Tsegment::Key Key
key to hash table
T * Append()
allocate but not construct new item
void Clear()
Clear (destroy) all items.
Types::NodeList::Titem Node
this will be our node type
static int s_rail_change_counter
if any track changes, this counter is incremented - that will invalidate segment cost cache ...
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
const Titem_ * Find(const Tkey &key) const
const item search
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Types::NodeList::Titem Node
this will be our node type
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
void Clear()
simple clear - forget all items - used by CSegmentCostCacheT.Flush()
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
Tpf & Yapf()
to access inherited path finder
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Tpf & Yapf()
to access inherited path finder
#define DEBUG(name, level,...)
Output a line of debugging information.
CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost caching functi...
Base class for segment cost cache providers.
CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment cost caching ...
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
uint32 TileIndex
The index/ID of a Tile.
Track
These are used to specify a single track.
void Flush()
flush (clear) the cache
Node::Key Key
key to hash tables
int32 Date
The type to store our dates in.
Date _date
Current date in days (day counter)
Node::Key Key
key to hash tables
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.