Gaia-ECS v0.9.3
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
16 const World* m_pWorld;
17 const Chunk* m_pChunk;
18 Entity m_entity;
19 uint16_t m_row;
20
21 ComponentGetter(const World& world, const Chunk* pChunk, Entity entity, uint16_t row):
22 m_pWorld(&world), m_pChunk(pChunk), m_entity(entity), m_row(row) {}
23
27 template <typename T>
28 GAIA_NODISCARD decltype(auto) get() const {
29 GAIA_ASSERT(m_pWorld != nullptr);
30 GAIA_ASSERT(m_entity != EntityBad);
31 GAIA_ASSERT(m_pChunk != nullptr);
32 verify_comp<T>();
33
34 if constexpr (entity_kind_v<T> == EntityKind::EK_Gen)
35 return m_pChunk->template get<T>(m_row);
36 else
37 return m_pChunk->template get<T>();
38 }
39
43 template <typename T>
44 GAIA_NODISCARD decltype(auto) get(Entity type) const;
45 };
46 } // namespace ecs
47} // namespace gaia
Definition chunk.h:35
Definition world.h:88
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9
Entity-scoped component accessor bound to a specific world, chunk and row. It is not a standalone chu...
Definition component_getter.h:15
GAIA_NODISCARD decltype(auto) get() const
Returns the value stored in the component T on entity.
Definition component_getter.h:28
GAIA_NODISCARD decltype(auto) get(Entity type) const
Returns the value stored in the component associated with type on entity.
Definition id.h:241