Skip to main content

engine/ecs/EntityHandle.ixx File

Versioned handle for referencing entities in an EntityPool. More...

Included Headers

#include <functional> #include <helios.engine.common.types.VersionId> #include <helios.engine.ecs.types>

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespaceecs

Core Entity-Component-System architecture. More...

Classes Index

structEntityHandle

A versioned handle for referencing entities in an EntityPool. More...

structhash<helios::engine::ecs::EntityHandle>

Hash specialization for EntityHandle. More...

Description

Versioned handle for referencing entities in an EntityPool.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file EntityHandle.ixx
3 * @brief Versioned handle for referencing entities in an EntityPool.
4 */
5module;
6
7
8#include <functional>
9
10export module helios.engine.ecs.EntityHandle;
11
12import helios.engine.ecs.types;
13import helios.engine.common.types.VersionId;
14
15
16export namespace helios::engine::ecs {
17
18 /**
19 * @brief A versioned handle for referencing entities in an EntityPool.
20 *
21 * `EntityHandle` combines an entity ID with a version number to provide
22 * safe references to pooled entities. The version ensures that handles
23 * to removed entities are detected as stale.
24 *
25 * @see EntityPool
26 */
27 struct EntityHandle {
28
29 /**
30 * @brief The unique identifier for the entity within the pool.
31 */
33
34 /**
35 * @brief The version number for stale handle detection.
36 *
37 * Incremented when an entity is removed from the pool.
38 */
40
41 /**
42 * @brief Compares two handles for equality.
43 */
44 bool operator==(const EntityHandle&) const = default;
45
46 /**
47 * @brief Compares two handles by entity ID (less-than).
48 *
49 * @param entityHandle The handle to compare against.
50 *
51 * @return True if this handle's entity ID is less than the other.
52 */
53 constexpr bool operator<(const EntityHandle& entityHandle) const noexcept {
54 return entityId < entityHandle.entityId;
55 }
56
57 /**
58 * @brief Compares two handles by entity ID (greater-than).
59 *
60 * @param entityHandle The handle to compare against.
61 *
62 * @return True if this handle's entity ID is greater than the other.
63 */
64 constexpr bool operator>(const EntityHandle& entityHandle) const noexcept {
65 return entityId > entityHandle.entityId;
66 }
67
68 /**
69 * @brief Checks if this handle is potentially valid.
70 *
71 * @return True if the version is at least 1 (initial version).
72 */
73 [[nodiscard]] bool isValid() const noexcept {
74 return versionId >= 1;
75 }
76
77 };
78
79}
80
81/**
82 * @brief Hash specialization for EntityHandle.
83 *
84 * Packs entityId and versionId into a 64-bit value for hashing.
85 */
86template<>
87struct std::hash<helios::engine::ecs::EntityHandle> {
88 std::size_t operator()(const helios::engine::ecs::EntityHandle& handle) const noexcept {
89
90 const uint64_t packed = (static_cast<uint64_t>(handle.entityId) << 32) |
91 static_cast<uint64_t>(handle.versionId);
92
93 return std::hash<uint64_t>{}(packed);
94 }
95};
96

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.