SDEngine
Game Engine
Loading...
Searching...
No Matches
Entity.hpp
Go to the documentation of this file.
1// TODO(docs): Add file-level Doxygen header
2// - @file Entity.hpp
3// - @brief Brief description of Entity concept
4// - Overview of the entity-identifier system (index + generation)
5// - Example usage in context of ECS
6#pragma once
7#include <functional>
8
9#include "SD/core/types.hpp"
10
11
12namespace sd {
13// TODO(docs): Document Entity struct
14// - Explain index vs generation semantics
15// - Describe entity lifecycle (created -> alive -> destroyed -> recycled)
16// - Note about generation preventing use-after-free
17// - Example: Entity e = manager.Create(); // e = {index: 0, generation: 0}
18struct Entity {
21
22 bool operator==(Entity other) const {
23 return index == other.index && generation == other.generation;
24 }
25 bool operator!=(Entity other) const { return !(*this == other); }
26};
27} // namespace sd
28
29template<>
30struct std::hash<sd::Entity> {
31 inline std::size_t operator()(sd::Entity e) const noexcept {
32 return std::hash<uint32_t>{}(e.index) ^ (std::hash<uint32_t>{}(e.generation) << 1);
33 }
34};
Definition Application.hpp:28
Definition Entity.hpp:18
bool operator==(Entity other) const
Definition Entity.hpp:22
u32 index
Definition Entity.hpp:19
bool operator!=(Entity other) const
Definition Entity.hpp:25
u32 generation
Definition Entity.hpp:20
std::size_t operator()(sd::Entity e) const noexcept
Definition Entity.hpp:31
std::uint32_t u32
Definition types.hpp:15
constexpr T g_type_max
Definition types.hpp:21