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 return smut<T>();
31 }
32
37 template <typename T, typename U = typename actual_type_t<T>::Type>
38 ComponentSetter& set(U&& value);
39
45 template <typename T>
46 decltype(auto) mut(Entity type);
47
53 template <typename T>
54 ComponentSetter& set(Entity type, T&& value);
55
59 template <typename T>
60 decltype(auto) smut() {
61 GAIA_ASSERT(m_pWorld != nullptr);
62 GAIA_ASSERT(m_entity != EntityBad);
63 GAIA_ASSERT(m_pChunk != nullptr);
64 if constexpr (uses_ct_sparse_storage_v<T>)
65 return smut<T>(m_pChunk->template comp_entity<T>());
66 else
67 return const_cast<Chunk*>(m_pChunk)->template sset<T>(m_row);
68 }
69
74 template <typename T, typename U = typename actual_type_t<T>::Type>
75 ComponentSetter& sset(U&& value) {
76 GAIA_ASSERT(m_pWorld != nullptr);
77 GAIA_ASSERT(m_entity != EntityBad);
78 GAIA_ASSERT(m_pChunk != nullptr);
79 smut<T>() = GAIA_FWD(value);
80 return *this;
81 }
82
87 template <typename T>
88 decltype(auto) smut(Entity type);
89
95 template <typename T>
96 ComponentSetter& sset(Entity type, T&& value);
97
102 GAIA_NODISCARD ComponentRawMutView mut_raw(Entity component);
103
109 GAIA_NODISCARD ComponentRawMutView mut_raw_field(Entity component, uint32_t fieldIdx);
110
116 ComponentSetter& set_raw(Entity component, const void* data, uint32_t size);
117
122 };
123 } // namespace ecs
124} // 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:17359
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:17365
ComponentSetter & set(U &&value)
Sets the value of the component.
Definition world.h:17435
decltype(auto) smut()
Returns a mutable reference to component without triggering a world version update.
Definition component_setter.h:60
ComponentSetter & modify_raw(Entity component)
Marks a raw payload or SoA field returned by a mutable raw view as modified.
Definition world.h:17380
ComponentSetter & sset(U &&value)
Sets the value of the component without triggering a world version update.
Definition component_setter.h:75
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:17371
Identifier of an entity or component instance in the world. Packs the entity index,...
Definition id.h:231