Gaia-ECS v1.0.0
A simple and powerful entity component system
Loading...
Searching...
No Matches
component_setter.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#include "gaia/ecs/component_getter.h"
9
10namespace gaia {
11 namespace ecs {
12 struct ComponentRawMutView;
13
23
28 template <typename T>
29 decltype(auto) mut() {
30 GAIA_ASSERT(m_pWorld != nullptr);
31 GAIA_ASSERT(m_entity != EntityBad);
32 GAIA_ASSERT(m_pChunk != nullptr);
33 const auto row = (uint16_t)(m_row * (actual_type_t<T>::Kind == EntityKind::EK_Gen));
34 return const_cast<Chunk*>(m_pChunk)->template sset<T>(row);
35 }
36
41 template <typename T, typename U = typename actual_type_t<T>::Type>
42 ComponentSetter& set(U&& value) {
43 GAIA_ASSERT(m_pWorld != nullptr);
44 GAIA_ASSERT(m_entity != EntityBad);
45 GAIA_ASSERT(m_pChunk != nullptr);
46 smut<T>() = GAIA_FWD(value);
47 auto& chunk = *const_cast<Chunk*>(m_pChunk);
48 chunk.template modify<T, true>();
49 world_notify_on_set(chunk.world(), chunk.template comp_entity<T>(), chunk, m_row, (uint16_t)(m_row + 1));
50 return *this;
51 }
52
58 template <typename T>
59 decltype(auto) mut(Entity type);
60
66 template <typename T>
67 ComponentSetter& set(Entity type, T&& value);
68
72 template <typename T>
73 decltype(auto) smut() {
74 GAIA_ASSERT(m_pWorld != nullptr);
75 GAIA_ASSERT(m_entity != EntityBad);
76 GAIA_ASSERT(m_pChunk != nullptr);
77 const auto row = (uint16_t)(m_row * (actual_type_t<T>::Kind == EntityKind::EK_Gen));
78 return const_cast<Chunk*>(m_pChunk)->template sset<T>(row);
79 }
80
85 template <typename T, typename U = typename actual_type_t<T>::Type>
86 ComponentSetter& sset(U&& value) {
87 GAIA_ASSERT(m_pWorld != nullptr);
88 GAIA_ASSERT(m_entity != EntityBad);
89 GAIA_ASSERT(m_pChunk != nullptr);
90 smut<T>() = GAIA_FWD(value);
91 return *this;
92 }
93
98 template <typename T>
99 decltype(auto) smut(Entity type);
100
106 template <typename T>
107 ComponentSetter& sset(Entity type, T&& value);
108
113 GAIA_NODISCARD ComponentRawMutView mut_raw(Entity component);
114
120 GAIA_NODISCARD ComponentRawMutView mut_raw_field(Entity component, uint32_t fieldIdx);
121
127 ComponentSetter& set_raw(Entity component, const void* data, uint32_t size);
128
133 };
134 } // namespace ecs
135} // namespace gaia
Fixed-capacity archetype storage unit holding entities and their component columns.
Definition chunk.h:36
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
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
ComponentGetter(const World &world, const Chunk *pChunk, Entity entity, uint16_t row)
Creates an accessor for one entity row.
Definition component_getter.h:31
uint16_t m_row
Entity row within the chunk.
Definition component_getter.h:24
Non-owning mutable view over raw component bytes on an entity.
Definition component_cursor.h:64
Entity-scoped mutable component accessor bound to a specific world, chunk and row....
Definition component_setter.h:16
decltype(auto) mut()
Returns a mutable reference to component without triggering hooks, observers or world-version updates...
Definition component_setter.h:29
GAIA_NODISCARD ComponentRawMutView mut_raw(Entity component)
Returns a mutable raw byte view for a runtime component without finishing the write....
Definition world.h:15209
GAIA_NODISCARD ComponentRawMutView mut_raw_field(Entity component, uint32_t fieldIdx)
Returns one mutable SoA field value without finishing the component write. Pair with modify_raw(compo...
Definition world.h:15215
ComponentSetter & set(U &&value)
Sets the value of the component.
Definition component_setter.h:42
decltype(auto) smut()
Returns a mutable reference to component without triggering a world version update.
Definition component_setter.h:73
ComponentSetter & modify_raw(Entity component)
Marks a raw payload or SoA field returned by a mutable raw view as modified.
Definition world.h:15230
ComponentSetter & sset(U &&value)
Sets the value of the component without triggering a world version update.
Definition component_setter.h:86
ComponentSetter & set_raw(Entity component, const void *data, uint32_t size)
Replaces a runtime component payload and emits normal post-write set notifications.
Definition world.h:15221
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:296