Helios Engine 0.1.0
A modular ECS based data-oriented C++23 game engine
 
Loading...
Searching...
No Matches
world.cpp
Go to the documentation of this file.
2
5
6#include <array>
7#include <cstddef>
8#include <vector>
9
10namespace helios::ecs {
11
12void World::UpdateEntityArchetype(Entity entity) {
13 const auto component_infos = components_.GetComponentTypes(entity);
14
15 // Use a stack buffer for small counts
16 constexpr size_t kStackSize = 16;
17 if (component_infos.size() <= kStackSize) {
18 std::array<ComponentTypeId, kStackSize> type_ids = {};
19 for (size_t i = 0; i < component_infos.size(); ++i) {
20 type_ids[i] = component_infos[i].TypeId();
21 }
22 archetypes_.UpdateEntityArchetype(entity, std::span(type_ids.data(), component_infos.size()));
23 } else {
24 // Fallback for large counts
25 std::vector<ComponentTypeId> type_ids;
26 type_ids.reserve(component_infos.size());
27 for (const auto& info : component_infos) {
28 type_ids.push_back(info.TypeId());
29 }
30 archetypes_.UpdateEntityArchetype(entity, type_ids);
31 }
32}
33
34} // namespace helios::ecs
void UpdateEntityArchetype(Entity entity, std::span< const ComponentTypeId > component_types)
Updates entity's archetype based on its current components.
Definition archetype.cpp:17
std::vector< ComponentTypeInfo > GetComponentTypes(Entity entity) const
Gets all component types for the specified entity.
BasicQuery< World, Allocator, Components... > Query
Type alias for query with mutable world access.
Definition query.hpp:2481