TEntityHandleMap
Per-entity data kept by the entity's World slot instead of by hashing its 64-bit id: a lookup is the world's slot index plus one array read, and a walk is a linear pass over a dense vector. A cell remembers the id it was written for, so a slot the world recycled for a new entity never answers for the old one; Prune drops the cells of entities that no longer exist.
- Module
- ECS
- Header
#include "ECS/EntityHandleMap.h"- Namespace
Mowo- Template
template<typename V, bool StableAddresses = false>
The slot comes from World::GetSlotHint, which is one hash probe in the world's own table — it is still cheaper than std::unordered_map's node chase, and a caller that already holds a hint passes it to skip the probe. StableAddresses keeps the cells in a deque, whose growth never moves a cell already stored: an API that hands out a pointer into per-entity state (a perceiver's known-actor list, a resident's search points) stays valid while later entities add their own cells. The default vector storage reallocates on growth, so a pointer into it dies the moment another entity is first seen.
Public functions
| Returns | Name | Description |
|---|---|---|
V* | Find | |
const V* | Find | |
V* | FindAt | |
V* | FindOrAdd | The value for id, default-constructed when absent. |
bool | Erase | A destroyed entity has no slot to look up, so its cell is found by a scan: callers erase an id that may already be dead (a claim being cleaned up after its owner), and that must not leave the cell behind. |
size_t | Prune | Drops every cell whose entity is gone, or whose slot now holds another. |
void | ForEachErase | Calls fn(EntityID, V&) for every live cell; fn returns true to erase it. |
void | ForEach | |
void | ForEach | |
size_t | Size | |
void | Clear |
Function details
Find
V* Find(const World& world, EntityID id)Find
const V* Find(const World& world, EntityID id) constFindAt
V* FindAt(uint32_t slot, EntityID id)FindOrAdd
V* FindOrAdd(const World& world, EntityID id)The value for id, default-constructed when absent. False from the entity not existing in world is reported as a null result.
Erase
bool Erase(const World& world, EntityID id)A destroyed entity has no slot to look up, so its cell is found by a scan: callers erase an id that may already be dead (a claim being cleaned up after its owner), and that must not leave the cell behind.
Prune
size_t Prune(const World& world)Drops every cell whose entity is gone, or whose slot now holds another.
ForEachErase
template<typename Fn> void ForEachErase(Fn&& fn)Calls fn(EntityID, V&) for every live cell; fn returns true to erase it.
ForEach
template<typename Fn> void ForEach(Fn&& fn)ForEach
template<typename Fn> void ForEach(Fn&& fn) constSize
size_t Size() constClear
void Clear()