Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
component_getter.h
1#pragma once
2#include "gaia/config/config.h"
3
4#include <cstdint>
5
6#include "gaia/ecs/chunk.h"
7#include "gaia/ecs/component.h"
8
9namespace gaia {
10 namespace ecs {
11 class World;
12 struct ComponentRawView;
13
24 uint16_t m_row;
25
31 ComponentGetter(const World& world, const Chunk* pChunk, Entity entity, uint16_t row):
32 m_pWorld(&world), m_pChunk(pChunk), m_entity(entity), m_row(row) {}
33
37 template <typename T>
38 GAIA_NODISCARD decltype(auto) get() const {
39 GAIA_ASSERT(m_pWorld != nullptr);
40 GAIA_ASSERT(m_entity != EntityBad);
41 GAIA_ASSERT(m_pChunk != nullptr);
42 verify_comp<T>();
43
44 if constexpr (actual_type_t<T>::Kind == EntityKind::EK_Gen)
45 return m_pChunk->template get<T>(m_row);
46 else
47 return m_pChunk->template get<T>();
48 }
49
54 template <typename T>
55 GAIA_NODISCARD decltype(auto) get(Entity type) const;
56
60 GAIA_NODISCARD ComponentRawView get_raw(Entity component) const;
61
66 GAIA_NODISCARD ComponentRawView get_raw_field(Entity component, uint32_t fieldIdx) const;
67 };
68 } // namespace ecs
69} // namespace gaia
Fixed-capacity archetype storage unit holding entities and their component columns.
Definition chunk.h:36
Owns entities, components, archetypes, queries, observers, and systems.
Definition world.h:80
Entity-scoped component accessor bound to a specific world, chunk and row. It is not a standalone chu...
Definition component_getter.h:16
const Chunk * m_pChunk
Chunk containing the entity's table-backed data.
Definition component_getter.h:20
GAIA_NODISCARD decltype(auto) get() const
Returns the value stored in the component T on entity.
Definition component_getter.h:38
Entity m_entity
Entity whose components are accessed.
Definition component_getter.h:22
const World * m_pWorld
World used to resolve inherited and sparse component data.
Definition component_getter.h:18
GAIA_NODISCARD decltype(auto) get(Entity type) const
Returns the value stored in the component associated with type on entity.
GAIA_NODISCARD ComponentRawView get_raw(Entity component) const
Returns a raw byte view for a runtime component on this entity.
Definition world.h:15197
ComponentGetter(const World &world, const Chunk *pChunk, Entity entity, uint16_t row)
Creates an accessor for one entity row.
Definition component_getter.h:31
GAIA_NODISCARD ComponentRawView get_raw_field(Entity component, uint32_t fieldIdx) const
Returns one read-only SoA field value for a runtime component on this entity.
Definition world.h:15203
uint16_t m_row
Entity row within the chunk.
Definition component_getter.h:24
Non-owning read-only view over raw component bytes on an entity.
Definition component_cursor.h:38
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:296