OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
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;
68 return *
static_cast<Tpf *
>(
this);
78 CacheKey key(n.GetKey());
79 Yapf().ConnectNodeToCachedData(n, *
new (m_local_cache.
Append()) CachedData(key));
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;
210 if (!
Yapf().CanUseGlobalCache(n)) {
213 CacheKey key(n.GetKey());
215 CachedData &item = m_global_cache.Get(key, &found);
216 Yapf().ConnectNodeToCachedData(n, item);
uint32 TileIndex
The index/ID of a Tile.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Types::NodeList::Titem Node
this will be our node type
T * Append()
allocate but not construct new item
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Titem Node
this will be our node type
void Flush()
flush (clear) the cache
const Titem_ * Find(const Tkey &key) const
const item search
void Clear()
Clear (destroy) all items.
Date _date
Current date in days (day counter)
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
#define DEBUG(name, level,...)
Output a line of debugging information.
Tsegment::Key Key
key to hash table
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
int32 Date
The type to store our dates in.
CYapfSegmentCostCacheGlobalT - the yapf cost cache provider that adds the segment cost caching functi...
bool PfNodeCacheFetch(Node &n)
Called by YAPF to attach cached or local segment cost data to the given node.
CSegmentCostCacheT - template class providing hash-map and storage (heap) of Tsegment structures.
void Clear()
simple clear - forget all items - used by CSegmentCostCacheT.Flush()
Node::Key Key
key to hash tables
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
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
Base class for segment cost cache providers.
Node::Key Key
key to hash tables
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
CYapfSegmentCostCacheLocalT - the yapf cost cache provider that implements fake segment cost caching ...
Tpf & Yapf()
to access inherited path finder
Track
These are used to specify a single track.
void PfNodeCacheFlush(Node &n)
Called by YAPF to flush the cached segment cost data back into cache storage.
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
Types::Tpf Tpf
the pathfinder class (derived from THIS class)