53 std::unique_lock lock(this->_mutex);
55 if (!this->_freeIndices.empty()) {
56 std::size_t idx = this->_freeIndices.front();
57 this->_freeIndices.pop_front();
59 return Entity(idx, this->_generations[idx]);
64 "Registry: Max entities reached, cannot spawn new entity.")};
66 std::size_t idx = this->_generations.size();
68 this->_generations.push_back(0);
75 std::unique_lock lock(this->
_mutex);
77 std::uint32_t idx = entity.
index();
80 this->_generations[idx] != entity.
generation())
83 for (
auto &pair : this->
_arrays)
84 pair.second->erase(entity);
92 std::shared_lock lock(this->_mutex);
94 std::uint32_t idx = entity.index();
96 if (idx >= this->_generations.size())
99 return this->_generations[idx] == entity.generation();
104 std::unique_lock lock(this->_mutex);
106 for (
auto &pair : this->_arrays)
107 pair.second->clear();
109 this->_generations.clear();
110 this->_freeIndices.clear();
115 std::unique_lock lock(this->_mutex);
117 for (
auto &pair : this->_arrays)
118 pair.second->clear();
120 this->_freeIndices.clear();
122 auto idxs = std::views::iota(0uz, this->_generations.size())
123 | std::views::filter([
this](std::size_t i) {
return this->_generations[i] != 0; });
124 std::ranges::copy(idxs, std::back_inserter(this->_freeIndices));
129 std::shared_lock lock(this->_mutex);
130 return this->_generations.size() - this->_freeIndices.size();
Assertion and verification macros for runtime checks.
static auto failure(ErrorCode code, std::format_string< Args... > fmt, Args &&...args) -> Error
Create a failure-level error.
Represents an entity in the ECS (Entity-Component-System) architecture.
constexpr std::uint32_t index(void) const
constexpr std::uint32_t generation(void) const
static constexpr std::uint32_t MAX_INDEX
auto spawn(void) -> std::expected< Entity, rtp::Error >
std::size_t entityCount(void) const noexcept
std::deque< std::size_t > _freeIndices
Recyclable entity indices.
std::unordered_map< std::type_index, std::unique_ptr< ISparseArray > > _arrays
Registered component arrays.
std::vector< std::uint32_t > _generations
Generation counters for entities.
void clear(void) noexcept
std::shared_mutex _mutex
Mutex for thread-safe operations.
bool isAlive(Entity entity) const noexcept
void purge(void) noexcept
File : RenderSystem.hpp License: MIT Author : Elias Josué HAJJAR LLAUQUEN elias-josue....
@ RegistryFull
Entity registry has reached maximum capacity.