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
12
namespace
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}
18
struct
Entity
{
19
u32
index
;
20
u32
generation
;
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
29
template
<>
30
struct
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
};
sd
Definition
Application.hpp:28
sd::Entity
Definition
Entity.hpp:18
sd::Entity::operator==
bool operator==(Entity other) const
Definition
Entity.hpp:22
sd::Entity::index
u32 index
Definition
Entity.hpp:19
sd::Entity::operator!=
bool operator!=(Entity other) const
Definition
Entity.hpp:25
sd::Entity::generation
u32 generation
Definition
Entity.hpp:20
std::hash< sd::Entity >::operator()
std::size_t operator()(sd::Entity e) const noexcept
Definition
Entity.hpp:31
types.hpp
u32
std::uint32_t u32
Definition
types.hpp:15
g_type_max
constexpr T g_type_max
Definition
types.hpp:21
SD
include
SD
core
ecs
Entity.hpp
Generated by
1.9.8