10#include <source_location>
37 m_parent_stack.reserve(4096);
38 m_static_slots.reserve(4096);
39 m_static_free_list.reserve(4096);
54 public: [[nodiscard]]
inline bool IsInsideFrame()
const {
return !m_parent_stack.empty(); }
84 private:
bool SetGenerationForSlot(uint32_t index, int32_t generation);
94 private: [[nodiscard]]
ID AllocateDynamicID(uint64_t hash);
96#ifdef TACHYON_SUPPORT_CPP20
99 public: [[nodiscard]]
inline ID AllocateDynamicID(
const std::source_location location = std::source_location::current())
101 return AllocateDynamicID(
Hash::Combine(FileHash(location.file_name()),
static_cast<uint64_t
>(location.line())));
123 if (hash == 0) hash = 1;
126 id.value.dynamicParts.hashValue = hash;
134 private: [[nodiscard]]
ID AllocateRangedID(uint32_t size, uint64_t hash);
136#ifdef TACHYON_SUPPORT_CPP20
139 public: [[nodiscard]]
inline ID AllocateRangedID(uint32_t size,
const std::source_location location = std::source_location::current())
141 return AllocateRangedID(size,
Hash::Combine(FileHash(location.file_name()),
static_cast<uint64_t
>(location.line())));
198 std::vector<ParentData> m_parent_stack;
202 uint64_t FileHash(
const char* file)
204 FileHashSlot& slot = m_file_hashes[(
reinterpret_cast<uintptr_t
>(file) >> 4) & (m_file_hashes.size() - 1)];
205 if (slot.file != file)
209 struct FileHashSlot {
const char* file =
nullptr; uint64_t hash = 0; };
210 std::array<FileHashSlot, 64> m_file_hashes {};
216 struct SiteSlot { uint64_t site = 0; uint32_t count = 0; uint32_t frame = 0; };
217 std::vector<SiteSlot> m_site_slots = std::vector<SiteSlot>(1024);
218 uint32_t m_site_used = 0;
219 uint32_t m_frame = 0;
220 uint32_t NextSiteCount(uint64_t site);
223 std::vector<int32_t> m_static_slots;
224 std::vector<uint32_t> m_static_free_list;
225 size_t m_static_id_count = 0;
228 size_t m_dynamic_id_total = 0;
231 size_t m_ranged_count = 0;
233#ifdef TACHYON_ID_DEBUG
234 std::vector<ID> m_debug_dynamic_ids;
235 std::vector<ID> m_debug_ranges;
ID GetSubID(ID ranged_id, uint32_t index) const
The ID of item index (< range size) in a ranged ID, for indexed content such as list rows.
bool IsInsideFrame() const
True between BeginFrame and EndFrame.
Definition gui_id_manager.h:54
ID AllocateRangedID(uint32_t size, std::string_view file, int line)
A ranged ID of size sub-IDs from file and line (FILE, LINE) and the parent stack.
size_t GetDynamicIDCount() const
Live static IDs, and dynamic / ranged IDs made so far this frame.
Definition gui_id_manager.h:185
bool PopParent()
Pops the last PushParent. Never pops the root; false on underflow or outside a frame.
bool IsStaticIDValid(ID id) const
True if the slot is active and the generation matches.
ID GetStackParent() const
The innermost parent; Invalid at the root or outside a frame.
ID AllocateDynamicID(std::string_view file, int line)
A dynamic ID from file and line (FILE, LINE) and the parent stack; different per call site.
void EndFrame()
Clears the parent stack; reports misuse when a PushParent was left unpopped.
size_t GetStaticIDCount() const
Live static IDs, and dynamic / ranged IDs made so far this frame.
Definition gui_id_manager.h:184
friend struct IDManagerTestAccess
Definition gui_id_manager.h:85
IDManager()
Definition gui_id_manager.h:35
void ReleaseStaticIDsNotIn(std::vector< ID > &ids, std::vector< ID > &keep)
Releases each static ID in ids that isn't in keep: what one side of a change holds and the other does...
bool BeginFrame()
Resets the parent stack and dynamic/ranged counters.
ID AllocateRangedID(uint32_t size, std::string_view hint)
A ranged ID of size sub-IDs from hint and the parent stack; different per hint.
static ID ScopedID(ID scope, ID key)
The ID of the item key names (a node's stableID, say) inside scope (the container showing it): the sa...
Definition gui_id_manager.h:120
uint32_t GetRangeSize(ID ranged_id) const
The number of sub-IDs in a ranged ID; 0 (and a misuse report) for other modes.
bool ReleaseStaticID(ID id)
Frees the slot and bumps its generation, invalidating copies of id.
bool IsRangedIDValid(ID id) const
Debug: checks stored ranges (slow). Release: true for any non-Invalid Ranged ID.
bool IsInParentStack(ID id) const
True when id is anywhere on the parent stack. Slow: linear search.
bool IsIDValid(ID id) const
True when id is valid for its mode (see the Is*IDValid functions); slow in debug builds.
bool IsSubRangeIDValid(ID id) const
Debug: checks stored ranges (slow). Release: true for any non-Invalid SubRange ID.
bool PushParent(ID parent_id)
Makes parent_id the parent: dynamic and ranged IDs created under it inherit its hash.
bool IsDynamicIDValid(ID id) const
Debug: checks the tracking list (slow). Release: true for any non-Invalid Dynamic ID.
ID CreateStaticID()
A persistent ID tracked by slot and generation; release it with ReleaseStaticID.
ID AllocateDynamicID(std::string_view hint)
A dynamic ID from hint and the parent stack; different per hint.
size_t GetRangedIDCount() const
Live static IDs, and dynamic / ranged IDs made so far this frame.
Definition gui_id_manager.h:186
@ Dynamic
remade each frame from the call site or a hint and the parent stack
Definition gui_id.h:15
uint64_t Calculate(std::string_view str)
FNV-1a hash of str; same result as CalculateConst.
Definition gui_hash.h:29
constexpr uint64_t Combine(uint64_t a, uint64_t b)
Order-dependent combine; repeated values don't cancel out.
Definition gui_hash.h:65
Definition gui_logging.h:24
A 64-bit element ID whose bit layout depends on its IDMode.
Definition gui_id.h:23
static constexpr ID Invalid()
The "no element" ID (all bits zero); also the default for optional ID parameters.
Definition gui_id.h:66
union tachyon::ID::Value value
uint64_t integer
Definition gui_id.h:40