10 #ifndef YAPF_COSTCACHE_HPP
11 #define YAPF_COSTCACHE_HPP
13 #include "../../timer/timer_game_calendar.h"
14 #include "../../misc/hashtable.hpp"
15 #include "../../tile_type.h"
16 #include "../../track_type.h"
23 template <
class Types>
27 typedef typename Types::Tpf
Tpf;
28 typedef typename Types::NodeList::Titem
Node;
68 template <
class Tsegment>
70 static constexpr
int HASH_BITS = 14;
72 using Key =
typename Tsegment::Key;
75 std::deque<Tsegment> heap;
86 inline Tsegment &Get(
Key &key,
bool *found)
88 Tsegment *item = this->map.
Find(key);
89 if (item ==
nullptr) {
91 item = &this->heap.emplace_back(key);
92 this->map.
Push(*item);
105 template <
class Types>
108 typedef typename Types::Tpf
Tpf;
109 typedef typename Types::NodeList::Titem
Node;
110 typedef typename Node::Key
Key;
111 typedef typename Node::CachedData CachedData;
112 typedef typename CachedData::Key CacheKey;
114 using LocalCache = std::deque<CachedData>;
118 LocalCache local_cache;
125 return *
static_cast<Tpf *
>(
this);
128 inline static Cache &stGetGlobalCache()
130 static int last_rail_change_counter = 0;
148 CacheKey key(n.GetKey());
150 if (!
Yapf().CanUseGlobalCache(n)) {
151 Yapf().ConnectNodeToCachedData(n, this->local_cache.emplace_back(key));
156 CachedData &item = this->global_cache.Get(key, &found);
157 Yapf().ConnectNodeToCachedData(n, item);
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.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Node::Key Key
key to hash tables
Tpf & Yapf()
to access inherited path finder
Types::NodeList::Titem Node
this will be our node type
CYapfSegmentCostCacheNoneT - the formal only yapf cost cache provider that implements PfNodeCacheFetc...
bool PfNodeCacheFetch(Node &)
Called by YAPF to attach cached or local segment cost data to the given node.
Types::Tpf Tpf
the pathfinder class (derived from THIS class)
Types::NodeList::Titem Node
this will be our node type
const Titem * Find(const Tkey &key) const
const item search
void Push(Titem &new_item)
add one item - copy it from the given item
void Clear()
simple clear - forget all items - used by CSegmentCostCacheT.Flush()
Base class for segment cost cache providers.
static int s_rail_change_counter
if any track changes, this counter is incremented - that will invalidate segment cost cache
CSegmentCostCacheT - template class providing hash-map and storage (heap) of Tsegment structures.
void Flush()
flush (clear) the cache
typename Tsegment::Key Key
key to hash table
Track
These are used to specify a single track.