13#include <unordered_map>
43 for (
auto it = entries_.begin(); it != entries_.end();) {
44 it = (frame_ - it->second.stamp >
kKeepFrames) ? entries_.erase(it) : std::next(it);
51 const auto it = entries_.find(key(view, entity));
52 return it == entries_.end() ? 0 : it->second.level;
58 const auto it = entries_.find(key(view, entity));
59 if (it == entries_.end() || frame_ - it->second.stamp > frames)
return false;
60 outLevel = it->second.level;
73 auto& entry = entries_[key(view, entity)];
75 entry.unbiased = unbiased;
76 entry.levels = levels;
85 const auto it = entries_.find(key(view, entity));
86 if (it == entries_.end())
return false;
87 outLevel = it->second.level;
88 outUnbiased = it->second.unbiased;
89 outLevels = it->second.levels;
90 outSize = it->second.size;
103 if (level ==
kNoPreview) previews_.erase(key(view, entity));
104 else previews_[key(view, entity)] = level;
109 const auto it = previews_.find(key(view, entity));
110 return it == previews_.end() ?
kNoPreview : it->second;
123 return held !=
kNoPreview && held <= levels ? held : chosen;
126 void clear() { entries_.clear(); previews_.clear(); }
143 return (
static_cast<u64>(view) << 32) |
static_cast<u64>(entity.
raw);
146 std::unordered_map<u64, Entry> entries_;
147 std::unordered_map<u64, u8> previews_;
Core type definitions and utilities for ESEngine.
Levels remembered per (view, entity) pair.
bool inspect(u32 view, Entity entity, u8 &outLevel, u8 &outUnbiased, u8 &outLevels, f32 &outSize) const
The whole recorded decision, or false when this view has not measured this entity — which is not the ...
static constexpr u64 kKeepFrames
How many frames an untouched pair is kept before it is dropped.
usize previewCount() const
How many (view, entity) pairs are currently held up for inspection.
u8 drawn(u32 view, Entity entity, u8 chosen, u8 levels) const
What to DRAW: the preview if one names a level this group reaches, otherwise chosen.
u8 lastLevel(u32 view, Entity entity) const
The level view last drew entity at; level 0 for a pair it has never seen, which is the unbiased answe...
void beginFrame()
Opens a frame and, now and then, drops what no view still asks about — an entity that died leaves a p...
u8 previewOf(u32 view, Entity entity) const
The level this view was told to show, or kNoPreview.
void remember(u32 view, Entity entity, u8 chosen, u8 unbiased, u8 levels, f32 size)
Record a decision: what was chosen, what the bare thresholds asked for, how many stand-ins were reach...
bool recent(u32 view, Entity entity, u64 frames, u8 &outLevel) const
The level view drew entity at within the last frames frames, or false when it has not drawn it that l...
void preview(u32 view, Entity entity, u8 level)
Hold level up for inspection in this view, or kNoPreview to stop.
constexpr u8 kNoPreview
A preview slot holding no level, so the view's own choice is drawn.
std::uint64_t u64
Unsigned 64-bit integer.
std::size_t usize
Size type for indexing and sizes.
std::uint32_t u32
Unsigned 32-bit integer.
std::uint8_t u8
Unsigned 8-bit integer.
float f32
32-bit floating point
Entity identifier with packed index + generation.