2#include "gaia/config/config.h"
8#include "gaia/ecs/api.h"
9#include "gaia/ecs/archetype.h"
10#include "gaia/ecs/chunk.h"
11#include "gaia/ecs/command_buffer_fwd.h"
12#include "gaia/ecs/component.h"
13#include "gaia/ecs/component_cache_item.h"
14#include "gaia/ecs/id.h"
15#include "gaia/ecs/query_common.h"
16#include "gaia/mem/data_layout_policy.h"
21 void world_finish_write(World& world, Entity term, Entity entity);
23 decltype(
auto) world_query_entity_arg_by_id_raw(World& world, Entity entity, Entity
id);
25 decltype(
auto) world_query_entity_arg_by_id_cached_const(
26 World& world, Entity entity, Entity
id,
const Archetype*& pLastArchetype, Entity& cachedOwner,
29 void world_init_query_entity_arg_by_id_chunk_stable_const(
30 World& world,
const Chunk& chunk,
const Entity* pEntities, Entity
id,
bool& direct, uint32_t& compIdx,
31 const std::remove_cv_t<std::remove_reference_t<T>>*& pDataInherited);
33 const std::remove_cv_t<std::remove_reference_t<T>>*
34 world_query_inherited_arg_data_const(World& world, Entity owner, Entity
id);
35 bool world_term_uses_inherit_policy(
const World& world, Entity term);
37 Entity world_query_arg_id(World& world);
40 enum class Constraints : uint8_t { EnabledOnly, DisabledOnly, AcceptAll };
47 bool isEntity =
false;
48 bool isOutOfLine =
false;
61 static auto view(
const ChunkIterImpl& self, uint32_t termIdx);
69 static auto view_any_mut(
ChunkIterImpl& self, uint32_t termIdx);
77 static auto sview_any_mut(
ChunkIterImpl& self, uint32_t termIdx);
82 Chunk* pChunk =
nullptr;
92 const U* pData =
nullptr;
95 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
96 GAIA_ASSERT(idx < cnt);
100 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
104 GAIA_NODISCARD
const U* data()
const noexcept {
111 template <
typename U>
113 const Entity* pEntities =
nullptr;
114 World* pWorld =
nullptr;
117 mutable const Archetype* pLastArchetype =
nullptr;
118 mutable Entity cachedOwner = EntityBad;
119 mutable bool cachedDirect =
false;
121 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
122 GAIA_ASSERT(idx < cnt);
123 return world_query_entity_arg_by_id_cached_const<const U&>(
124 *pWorld, pEntities[idx],
id, pLastArchetype, cachedOwner, cachedDirect);
127 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
131 GAIA_NODISCARD
const U* data()
const noexcept {
138 template <
typename U>
143 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx) {
144 GAIA_ASSERT(idx < cnt);
148 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
149 GAIA_ASSERT(idx < cnt);
150 return static_cast<const U&
>(pData[idx]);
153 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
157 GAIA_NODISCARD U* data()
noexcept {
161 GAIA_NODISCARD
const U* data()
const noexcept {
168 template <
typename U,
bool WriteIm>
170 const Entity* pEntities =
nullptr;
171 World* pWorld =
nullptr;
175 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx) {
176 GAIA_ASSERT(idx < cnt);
177 if constexpr (WriteIm)
178 return world_query_entity_arg_by_id<U&>(*pWorld, pEntities[idx],
id);
180 return world_query_entity_arg_by_id_raw<U&>(*pWorld, pEntities[idx],
id);
183 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
184 GAIA_ASSERT(idx < cnt);
185 return world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
188 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
192 GAIA_NODISCARD U* data()
noexcept {
196 GAIA_NODISCARD
const U* data()
const noexcept {
203 template <
typename U>
205 const U* pData =
nullptr;
206 const Entity* pEntities =
nullptr;
207 World* pWorld =
nullptr;
210 const U* pDataInherited =
nullptr;
211 mutable const Archetype* pLastArchetype =
nullptr;
212 mutable Entity cachedOwner = EntityBad;
213 mutable bool cachedDirect =
false;
216 return {pData,
nullptr,
nullptr, EntityBad, cnt,
nullptr,
nullptr, EntityBad,
false};
220 return {
nullptr, pEntities, pWorld, id, cnt,
nullptr,
nullptr, EntityBad,
false};
224 return {
nullptr,
nullptr,
nullptr, EntityBad, cnt, pDataInherited,
nullptr, EntityBad,
false};
230 const U* pDataInherited =
nullptr;
232 world_init_query_entity_arg_by_id_chunk_stable_const<U>(
233 *pWorld, *pChunk, pEntities,
id, direct, compIdx, pDataInherited);
234 const U* pData =
nullptr;
236 pData =
reinterpret_cast<const U*
>(pChunk->comp_ptr(compIdx, rowBase));
238 return {pData,
nullptr, pWorld, id, cnt, pDataInherited,
nullptr, EntityBad,
false};
241 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
242 GAIA_ASSERT(idx < cnt);
243 if (pData !=
nullptr)
245 if (pDataInherited !=
nullptr) {
246 GAIA_ASSERT(pDataInherited !=
nullptr);
247 return *pDataInherited;
250 return world_query_entity_arg_by_id_cached_const<const U&>(
251 *pWorld, pEntities[idx],
id, pLastArchetype, cachedOwner, cachedDirect);
254 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
258 GAIA_NODISCARD
const U* data()
const noexcept {
265 template <
typename U>
268 const Entity* pEntities =
nullptr;
269 World* pWorld =
nullptr;
275 return {pData,
nullptr,
nullptr, EntityBad, cnt,
true};
279 entity(
const Entity* pEntities,
World* pWorld,
Entity id, uint32_t cnt,
bool writeIm =
true) {
280 return {
nullptr, pEntities, pWorld, id, cnt, writeIm};
283 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx) {
284 GAIA_ASSERT(idx < cnt);
285 if (pData !=
nullptr)
293 GAIA_NODISCARD
decltype(
auto)
operator[](
size_t idx)
const {
294 GAIA_ASSERT(idx < cnt);
295 if (pData !=
nullptr)
296 return static_cast<const U&
>(pData[idx]);
298 return world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
301 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
305 GAIA_NODISCARD U* data()
noexcept {
309 GAIA_NODISCARD
const U* data()
const noexcept {
316 template <
typename U>
320 uint8_t* pData =
nullptr;
321 uint32_t dataSize = 0;
324 GAIA_NODISCARD
operator U()
const {
336 template <
typename U,
bool WriteIm>
338 const Entity* pEntities =
nullptr;
339 World* pWorld =
nullptr;
343 GAIA_NODISCARD
operator U()
const {
344 return world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
348 if constexpr (WriteIm)
349 world_query_entity_arg_by_id<U&>(*pWorld, pEntities[idx],
id) = value;
351 world_query_entity_arg_by_id_raw<U&>(*pWorld, pEntities[idx],
id) = value;
358 template <
typename U,
size_t Item>
361 using value_type =
typename view_policy::template data_view_policy_idx_info<Item>::const_value_type;
363 const value_type* pData =
nullptr;
366 GAIA_NODISCARD value_type operator[](
size_t idx)
const {
367 GAIA_ASSERT(idx < cnt);
371 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
378 template <
typename U,
size_t Item>
381 using value_type =
typename view_policy::template data_view_policy_idx_info<Item>::const_value_type;
383 const Entity* pEntities =
nullptr;
384 World* pWorld =
nullptr;
388 GAIA_NODISCARD value_type operator[](
size_t idx)
const {
389 GAIA_ASSERT(idx < cnt);
390 const U value = world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
391 return std::get<Item>(meta::struct_to_tuple(value));
394 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
401 template <
typename U,
size_t Item>
404 using value_type =
typename view_policy::template data_view_policy_idx_info<Item>::value_type;
406 value_type* pData =
nullptr;
409 GAIA_NODISCARD value_type& operator[](
size_t idx) {
410 GAIA_ASSERT(idx < cnt);
414 GAIA_NODISCARD
const value_type& operator[](
size_t idx)
const {
415 GAIA_ASSERT(idx < cnt);
419 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
426 template <
typename U,
size_t Item,
bool WriteIm>
429 using value_type =
typename view_policy::template data_view_policy_idx_info<Item>::value_type;
433 const Entity* pEntities =
nullptr;
434 World* pWorld =
nullptr;
438 GAIA_NODISCARD
operator value_type()
const {
439 const U value = world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
440 return std::get<Item>(meta::struct_to_tuple(value));
444 auto data = world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
445 auto tuple = meta::struct_to_tuple(data);
446 std::get<Item>(tuple) = value;
447 if constexpr (WriteIm)
448 world_query_entity_arg_by_id<U&>(*pWorld, pEntities[idx],
id) = meta::tuple_to_struct<U>(GAIA_MOV(tuple));
450 world_query_entity_arg_by_id_raw<U&>(*pWorld, pEntities[idx],
id) =
451 meta::tuple_to_struct<U>(GAIA_MOV(tuple));
455 template <
typename V>
457 const value_type current =
operator value_type();
458 return operator=(current + GAIA_FWD(value));
461 template <
typename V>
463 const value_type current =
operator value_type();
464 return operator=(current - GAIA_FWD(value));
467 template <
typename V>
469 const value_type current =
operator value_type();
470 return operator=(current * GAIA_FWD(value));
473 template <
typename V>
475 const value_type current =
operator value_type();
476 return operator=(current / GAIA_FWD(value));
480 const Entity* pEntities =
nullptr;
481 World* pWorld =
nullptr;
485 GAIA_NODISCARD
ElementProxy operator[](
size_t idx)
const {
486 GAIA_ASSERT(idx < cnt);
487 return ElementProxy{pEntities, pWorld, id, (uint32_t)idx};
490 GAIA_NODISCARD
constexpr size_t size() const noexcept {
497 template <
typename U>
502 const uint8_t* pData =
nullptr;
503 uint32_t dataSize = 0;
504 uint32_t idxBase = 0;
507 GAIA_NODISCARD U operator[](
size_t idx)
const {
508 GAIA_ASSERT(idx < cnt);
512 template <
size_t Item>
513 GAIA_NODISCARD
auto get()
const {
518 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
525 template <
typename U>
527 const Entity* pEntities =
nullptr;
528 World* pWorld =
nullptr;
532 GAIA_NODISCARD U operator[](
size_t idx)
const {
533 GAIA_ASSERT(idx < cnt);
534 return world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
537 template <
size_t Item>
538 GAIA_NODISCARD
auto get()
const {
542 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
549 template <
typename U>
555 uint8_t* pData =
nullptr;
556 uint32_t dataSize = 0;
557 uint32_t idxBase = 0;
560 GAIA_NODISCARD
auto operator[](
size_t idx) {
561 GAIA_ASSERT(idx < cnt);
565 GAIA_NODISCARD U operator[](
size_t idx)
const {
566 GAIA_ASSERT(idx < cnt);
570 template <
size_t Item>
571 GAIA_NODISCARD
auto get()
const {
576 template <
size_t Item>
577 GAIA_NODISCARD
auto set() {
582 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
589 template <
typename U,
bool WriteIm>
591 const Entity* pEntities =
nullptr;
592 World* pWorld =
nullptr;
596 GAIA_NODISCARD
auto operator[](
size_t idx) {
597 GAIA_ASSERT(idx < cnt);
601 GAIA_NODISCARD U operator[](
size_t idx)
const {
602 GAIA_ASSERT(idx < cnt);
603 return world_query_entity_arg_by_id<const U&>(*pWorld, pEntities[idx],
id);
606 template <
size_t Item>
607 GAIA_NODISCARD
auto get()
const {
611 template <
size_t Item>
612 GAIA_NODISCARD
auto set() {
616 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
623 template <
typename U>
625 uint8_t* pData =
nullptr;
626 uint32_t dataSize = 0;
627 const Entity* pEntities =
nullptr;
628 World* pWorld =
nullptr;
633 GAIA_NODISCARD
operator U()
const {
634 if (pData !=
nullptr)
643 if (pData !=
nullptr) {
655 template <
typename U,
size_t Item>
657 using value_type =
typename SoATermFieldReadProxyPointer<U, Item>::value_type;
659 const value_type* pData =
nullptr;
660 const Entity* pEntities =
nullptr;
661 World* pWorld =
nullptr;
665 GAIA_NODISCARD value_type operator[](
size_t idx)
const {
666 GAIA_ASSERT(idx < cnt);
667 if (pData !=
nullptr)
673 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
680 template <
typename U,
size_t Item>
682 using value_type =
typename SoATermFieldWriteProxyPointer<U, Item>::value_type;
684 value_type* pData =
nullptr;
685 const Entity* pEntities =
nullptr;
686 World* pWorld =
nullptr;
694 value_type* pData =
nullptr;
695 const Entity* pEntities =
nullptr;
696 World* pWorld =
nullptr;
701 GAIA_NODISCARD
operator value_type()
const {
702 if (pData !=
nullptr)
711 if (pData !=
nullptr) {
723 template <
typename V>
725 const value_type current =
operator value_type();
726 return operator=(current + GAIA_FWD(value));
729 template <
typename V>
731 const value_type current =
operator value_type();
732 return operator=(current - GAIA_FWD(value));
735 template <
typename V>
737 const value_type current =
operator value_type();
738 return operator=(current * GAIA_FWD(value));
741 template <
typename V>
743 const value_type current =
operator value_type();
744 return operator=(current / GAIA_FWD(value));
748 GAIA_NODISCARD
ElementProxy operator[](
size_t idx)
const {
749 GAIA_ASSERT(idx < cnt);
750 return ElementProxy{pData, pEntities, pWorld, id, (uint32_t)idx, writeIm};
753 GAIA_NODISCARD
constexpr size_t size() const noexcept {
760 template <
typename U>
762 const uint8_t* pData =
nullptr;
763 uint32_t dataSize = 0;
764 const Entity* pEntities =
nullptr;
765 World* pWorld =
nullptr;
767 uint32_t idxBase = 0;
770 GAIA_NODISCARD U operator[](
size_t idx)
const {
771 GAIA_ASSERT(idx < cnt);
772 if (pData !=
nullptr)
778 template <
size_t Item>
779 GAIA_NODISCARD
auto get()
const {
780 if (pData !=
nullptr) {
789 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
796 template <
typename U>
798 uint8_t* pData =
nullptr;
799 uint32_t dataSize = 0;
800 const Entity* pEntities =
nullptr;
801 World* pWorld =
nullptr;
803 uint32_t idxBase = 0;
807 GAIA_NODISCARD
auto operator[](
size_t idx) {
808 GAIA_ASSERT(idx < cnt);
812 GAIA_NODISCARD U operator[](
size_t idx)
const {
813 GAIA_ASSERT(idx < cnt);
814 if (pData !=
nullptr)
820 template <
size_t Item>
821 GAIA_NODISCARD
auto get()
const {
822 if (pData !=
nullptr) {
831 template <
size_t Item>
832 GAIA_NODISCARD
auto set() {
833 if (pData !=
nullptr) {
847 GAIA_NODISCARD
constexpr size_t size()
const noexcept {
876 uint8_t m_touchedCompCnt = 0;
879 uint8_t m_touchedTermCnt = 0;
882 bool m_entitySnapshotValid =
false;
900 void set_world(const
World* pWorld) {
901 GAIA_ASSERT(pWorld !=
nullptr);
905 GAIA_NODISCARD
World* world() {
910 GAIA_NODISCARD
const World* world()
const {
915 void set_archetype(
const Archetype* pArchetype) {
916 GAIA_ASSERT(pArchetype !=
nullptr);
925 GAIA_NODISCARD
const Archetype* archetype()
const {
930 void set_chunk(Chunk* pChunk) {
931 GAIA_ASSERT(pChunk !=
nullptr);
933 m_entitySnapshotValid =
false;
938 void set_chunk(Chunk* pChunk, uint16_t
from, uint16_t
to) {
939 if (
from == 0 &&
to == 0) {
944 GAIA_ASSERT(pChunk !=
nullptr);
946 m_entitySnapshotValid =
false;
951 GAIA_NODISCARD
const Chunk* chunk()
const {
956 void set_comp_indices(
const uint8_t* pCompIndices) {
960 void set_inherited_data(InheritedTermDataView inheritedData) {
964 void set_term_ids(
const Entity* pTermIds) {
968 GAIA_NODISCARD
const uint8_t* comp_indices()
const {
972 GAIA_NODISCARD InheritedTermDataView inherited_data()
const {
976 GAIA_NODISCARD
const Entity* term_ids()
const {
980 void set_write_im(
bool value) {
982 clear_touched_writes();
985 void set_constraints(Constraints constraints) {
990 m_entitySnapshotValid =
false;
1002 clear_touched_writes();
1012 const Archetype* pArchetype,
const uint8_t* pCompIndices,
Chunk* pChunk, uint16_t
from, uint16_t
to) {
1013 GAIA_ASSERT(pArchetype !=
nullptr);
1014 GAIA_ASSERT(pChunk !=
nullptr);
1020 m_entitySnapshotValid =
false;
1025 GAIA_NODISCARD
bool write_im()
const {
1029 GAIA_NODISCARD Constraints constraints()
const {
1033 void clear_touched_writes() {
1034 m_touchedCompCnt = 0;
1035 m_touchedTermCnt = 0;
1038 GAIA_NODISCARD
const Entity* entity_snapshot() {
1039 if (!m_entitySnapshotValid) {
1040 const auto cnt =
size();
1043 const auto entities =
m_pChunk->entity_view();
1048 m_entitySnapshotValid =
true;
1054 GAIA_NODISCARD
auto touched_comp_indices()
const {
1058 GAIA_NODISCARD
auto touched_terms()
const {
1062 GAIA_NODISCARD
auto entity_rows() {
1063 if (m_entitySnapshotValid)
1069 template <
typename U>
1070 GAIA_NODISCARD
auto entity_view_set(Entity termId,
bool writeIm) {
1071 return EntityTermViewSet<U>::entity(entity_snapshot(), world(), termId,
size(), writeIm);
1074 template <
typename U>
1075 GAIA_NODISCARD
auto entity_soa_view_set(Entity termId,
bool writeIm) {
1076 return SoATermViewSet<U>{
nullptr, 0, entity_snapshot(), world(), termId, 0,
size(), writeIm};
1079 void set_group_id(GroupId groupId) {
1083 GAIA_NODISCARD GroupId group_id()
const {
1101 GAIA_NODISCARD
void*
ctx()
const {
1108 return cmd_buffer_st_get(*pWorld);
1113 return cmd_buffer_mt_get(*pWorld);
1116 GAIA_NODISCARD IterTermDesc resolved_term_desc(uint32_t termIdx, IterTermDesc desc)
const {
1119 if (mappedTermId != EntityBad)
1120 desc.termId = mappedTermId;
1123 if (!desc.isEntity && desc.termId != EntityBad)
1124 desc.isOutOfLine = world_is_out_of_line_component(*world(), desc.termId);
1129 void touch_comp_idx(uint8_t compIdx) {
1130 GAIA_ASSERT(compIdx != 0xFF);
1131 GAIA_FOR(m_touchedCompCnt) {
1140 void touch_term(Entity term) {
1141 GAIA_ASSERT(term != EntityBad);
1142 GAIA_FOR(m_touchedTermCnt) {
1151 void touch_term_desc(
const IterTermDesc& desc) {
1154 if (desc.isOutOfLine)
1155 touch_term(desc.termId);
1166 template <
typename T>
1168 return ChunkIterTypedOps::template view_any<T>(*
this);
1178 template <
typename T>
1180 return ChunkIterTypedOps::template view_any<T>(*
this, termIdx);
1191 template <
typename T>
1193 return ChunkIterTypedOps::template view<T>(*
this);
1204 template <
typename T>
1205 GAIA_NODISCARD
auto view(uint32_t termIdx)
const {
1206 return ChunkIterTypedOps::template view<T>(*
this, termIdx);
1215 template <
typename T>
1217 return ChunkIterTypedOps::template view_any_mut<T>(*
this);
1226 template <
typename T>
1228 return ChunkIterTypedOps::template view_mut<T>(*
this);
1239 template <
typename T>
1241 return ChunkIterTypedOps::template view_mut<T>(*
this, termIdx);
1252 template <
typename T>
1254 return ChunkIterTypedOps::template view_any_mut<T>(*
this, termIdx);
1264 template <
typename T>
1266 return ChunkIterTypedOps::template sview_any_mut<T>(*
this);
1275 template <
typename T>
1277 return ChunkIterTypedOps::template sview_mut<T>(*
this);
1288 template <
typename T>
1290 return ChunkIterTypedOps::template sview_mut<T>(*
this, termIdx);
1301 template <
typename T>
1303 return ChunkIterTypedOps::template sview_any_mut<T>(*
this, termIdx);
1309 template <
typename T,
bool TriggerHooks>
1311 m_pChunk->template modify<T, TriggerHooks>();
1321 template <
typename T>
1323 using UOriginal =
typename actual_type_t<T>::TypeOriginal;
1324 if constexpr (core::is_mut_v<UOriginal>)
1325 return view_mut<T>();
1336 template <
typename T>
1338 using UOriginal =
typename actual_type_t<T>::TypeOriginal;
1339 if constexpr (core::is_mut_v<UOriginal>)
1340 return view_any_mut<T>();
1342 return view_any<T>();
1352 template <
typename T>
1354 using UOriginal =
typename actual_type_t<T>::TypeOriginal;
1355 if constexpr (core::is_mut_v<UOriginal>)
1356 return sview_any_mut<T>();
1358 return view_any<T>();
1369 template <
typename T>
1371 using UOriginal =
typename actual_type_t<T>::TypeOriginal;
1372 if constexpr (core::is_mut_v<UOriginal>)
1373 return sview_mut<T>();
1380 GAIA_NODISCARD
bool enabled(uint32_t index)
const {
1381 const auto row = (uint16_t)(
from() + index);
1402 template <
typename T>
1403 GAIA_NODISCARD
bool has()
const {
1404 return m_pChunk->template has<T>();
1407 GAIA_NODISCARD
static uint16_t start_index(
Chunk* pChunk, Constraints constraints)
noexcept {
1408 if (constraints == Constraints::EnabledOnly)
1409 return pChunk->size_disabled();
1413 GAIA_NODISCARD
static uint16_t end_index(
Chunk* pChunk, Constraints constraints)
noexcept {
1414 if (constraints == Constraints::DisabledOnly)
1415 return pChunk->size_disabled();
1416 return pChunk->size();
1419 GAIA_NODISCARD
static uint16_t
size(Chunk* pChunk, Constraints constraints)
noexcept {
1420 if (constraints == Constraints::EnabledOnly)
1421 return pChunk->size_enabled();
1422 if (constraints == Constraints::DisabledOnly)
1423 return pChunk->size_disabled();
1424 return pChunk->size();
1428 GAIA_NODISCARD uint16_t
size() const noexcept {
1429 return (uint16_t)(
to() -
from());
1438 GAIA_NODISCARD uint16_t
row_end() const noexcept {
1445 template <
typename T>
1447 using U =
typename actual_type_t<T>::Type;
1448 if constexpr (mem::is_soa_layout_v<U>)
1449 return idx +
from();
1456 GAIA_NODISCARD uint16_t
from() const noexcept {
1461 GAIA_NODISCARD uint16_t
to() const noexcept {
1471 static constexpr Constraints ConstraintMode = Constraints::EnabledOnly;
1473 using detail::ChunkIterImpl::size;
1476 set_constraints(ConstraintMode);
1479 GAIA_NODISCARD
static uint16_t start_index(
Chunk* pChunk)
noexcept {
1480 return detail::ChunkIterImpl::start_index(pChunk, ConstraintMode);
1483 GAIA_NODISCARD
static uint16_t end_index(
Chunk* pChunk)
noexcept {
1484 return detail::ChunkIterImpl::end_index(pChunk, ConstraintMode);
1487 GAIA_NODISCARD
static uint16_t size(
Chunk* pChunk)
noexcept {
1488 return detail::ChunkIterImpl::size(pChunk, ConstraintMode);
1530 void set_range(uint16_t from, uint16_t cnt) {
1531 GAIA_ASSERT(from < m_pChunk->size());
1532 GAIA_ASSERT(from + cnt <= m_pChunk->size());
1537 void set_world(
const World* pWorld) {
1538 GAIA_ASSERT(pWorld !=
nullptr);
1542 GAIA_NODISCARD World* world() {
1543 GAIA_ASSERT(m_pWorld !=
nullptr);
1544 return const_cast<World*
>(m_pWorld);
1547 GAIA_NODISCARD
const World* world()
const {
1548 GAIA_ASSERT(m_pWorld !=
nullptr);
1552 void set_archetype(
const Archetype* pArchetype) {
1553 GAIA_ASSERT(pArchetype !=
nullptr);
1554 m_pArchetype = pArchetype;
1562 GAIA_NODISCARD
const Archetype* archetype()
const {
1563 GAIA_ASSERT(m_pArchetype !=
nullptr);
1564 return m_pArchetype;
1567 void set_chunk(Chunk* pChunk) {
1568 GAIA_ASSERT(pChunk !=
nullptr);
1572 GAIA_NODISCARD
const Chunk* chunk()
const {
1573 GAIA_ASSERT(m_pChunk !=
nullptr);
1577 GAIA_NODISCARD CommandBufferST& cmd_buffer_st()
const {
1578 auto* pWorld =
const_cast<World*
>(m_pWorld);
1579 return cmd_buffer_st_get(*pWorld);
1582 GAIA_NODISCARD CommandBufferMT& cmd_buffer_mt()
const {
1583 auto* pWorld =
const_cast<World*
>(m_pWorld);
1584 return cmd_buffer_mt_get(*pWorld);
1591 template <
typename T>
1593 return m_pChunk->template view<T>(from(), to());
1600 template <
typename T>
1602 return m_pChunk->template view_mut<T>(from(), to());
1610 template <
typename T>
1612 return m_pChunk->template sview_mut<T>(from(), to());
1618 template <
typename T,
bool TriggerHooks>
1620 m_pChunk->template modify<T, TriggerHooks>();
1628 template <
typename T>
1630 return m_pChunk->template view_auto<T>(from(), to());
1639 template <
typename T>
1641 return m_pChunk->template sview_auto<T>(from(), to());
1646 GAIA_NODISCARD
bool enabled(uint32_t index)
const {
1647 const auto row = (uint16_t)(from() + index);
1648 return m_pChunk->
enabled(row);
1655 return m_pChunk->
has(entity);
1668 template <
typename T>
1669 GAIA_NODISCARD
bool has()
const {
1670 return m_pChunk->template has<T>();
1674 GAIA_NODISCARD uint16_t
size() const noexcept {
1680 GAIA_NODISCARD uint16_t from() const noexcept {
1685 GAIA_NODISCARD uint16_t to() const noexcept {
1686 return m_from + m_cnt;
1692#include "gaia/ecs/chunk_iterator_typed.inl"
Definition span_impl.h:99
Definition archetype.h:83
GAIA_NODISCARD uint16_t size_enabled() const
Return the number of entities in the chunk which are enabled.
Definition chunk.h:1809
bool enabled(uint16_t row) const
Checks if the entity is enabled.
Definition chunk.h:1359
GAIA_NODISCARD uint16_t size_disabled() const
Return the number of entities in the chunk which are enabled.
Definition chunk.h:1814
GAIA_NODISCARD uint32_t comp_idx(Entity entity) const
Returns the internal index of a component based on the provided entity.
Definition chunk.h:1694
GAIA_NODISCARD bool has(Entity entity) const
Checks if a component/entity entity is present in the chunk.
Definition chunk.h:1447
Iterator used when copying entities.
Definition chunk_iterator.h:1504
uint16_t m_from
Row of the first entity we iterate from.
Definition chunk_iterator.h:1515
GAIA_NODISCARD auto view() const
Returns a read-only entity or component view.
Definition chunk_iterator.h:1592
GAIA_NODISCARD auto sview_auto()
Returns either a mutable or immutable entity/component view based on the requested type....
Definition chunk_iterator.h:1640
GAIA_NODISCARD auto sview_mut()
Returns a mutable component view. Doesn't update the world version when the access is acquired.
Definition chunk_iterator.h:1611
GAIA_NODISCARD bool has() const
Checks if component T is present in the chunk.
Definition chunk_iterator.h:1669
GAIA_NODISCARD auto view_mut()
Returns a mutable entity or component view.
Definition chunk_iterator.h:1601
GAIA_NODISCARD bool has(Pair pair) const
Checks if relationship pair pair is present in the chunk.
Definition chunk_iterator.h:1661
uint16_t m_cnt
The number of entities accessible via the iterator.
Definition chunk_iterator.h:1517
GAIA_NODISCARD auto view_auto()
Returns either a mutable or immutable entity/component view based on the requested type....
Definition chunk_iterator.h:1629
GAIA_NODISCARD bool has(Entity entity) const
Checks if entity entity is present in the chunk.
Definition chunk_iterator.h:1654
void modify()
Marks the component T as modified. Best used with sview to manually trigger an update at user's whim....
Definition chunk_iterator.h:1619
GAIA_NODISCARD uint16_t size() const noexcept
Returns the number of entities accessible via the iterator.
Definition chunk_iterator.h:1674
GAIA_NODISCARD bool enabled(uint32_t index) const
Checks if the entity at the current iterator index is enabled.
Definition chunk_iterator.h:1646
Iterator for iterating entity subsets selected by Constraints. Disabled entities always precede enabl...
Definition chunk_iterator.h:1469
GAIA_NODISCARD uint16_t size_disabled() const noexcept
Returns the number of disabled entities accessible via the iterator. Can be read also as "the index o...
Definition chunk_iterator.h:1498
GAIA_NODISCARD uint16_t size_enabled() const noexcept
Returns the number of enabled entities accessible via the iterator.
Definition chunk_iterator.h:1492
Definition chunk_iterator.h:852
GAIA_NODISCARD auto view_mut(uint32_t termIdx)
Returns a mutable entity or component view for a query-term owned chunk-backed term....
Definition chunk_iterator.h:1240
GAIA_NODISCARD auto sview_any_mut()
Returns a mutable component view that can resolve non-direct storage. This is the fallback accessor f...
Definition chunk_iterator.h:1265
GAIA_NODISCARD uint16_t to() const noexcept
Returns the ending index of the iterator (one past the last valid index)
Definition chunk_iterator.h:1461
void init_query_state(const World *pWorld, Constraints constraints, bool writeIm)
Initializes stable query execution state stored by the iterator.
Definition chunk_iterator.h:998
GAIA_NODISCARD auto view_any_mut(uint32_t termIdx)
Returns a mutable entity or component view for a query-term index that can resolve non-direct storage...
Definition chunk_iterator.h:1253
Entity m_entitySnapshot[ChunkHeader::MAX_CHUNK_ENTITIES]
Stable copy of the currently iterated entity rows for mutable entity-backed views.
Definition chunk_iterator.h:881
GAIA_NODISCARD auto sview_mut()
Returns a mutable component view for the owned chunk-backed fast path. Doesn't update the world versi...
Definition chunk_iterator.h:1276
Entity m_touchedTerms[ChunkHeader::MAX_COMPONENTS]
Entity-backed terms that were exposed as mutable during the current callback.
Definition chunk_iterator.h:878
GAIA_NODISCARD uint16_t row_end() const noexcept
Returns one-past-the-end row covered by the iterator in the current chunk.
Definition chunk_iterator.h:1438
void ctx(void *pCtx)
Sets the user-owned context pointer visible through ctx().
Definition chunk_iterator.h:1095
GAIA_NODISCARD uint16_t from() const noexcept
Returns the starting index of the iterator.
Definition chunk_iterator.h:1456
GAIA_NODISCARD void * ctx() const
Returns the user-owned context pointer supplied by the caller driving this iteration.
Definition chunk_iterator.h:1101
GroupId m_groupId
GroupId. 0 if not set.
Definition chunk_iterator.h:888
GAIA_NODISCARD auto view_auto()
Returns either a mutable or immutable entity/component view for the owned chunk-backed fast path....
Definition chunk_iterator.h:1322
GAIA_NODISCARD uint16_t row_begin() const noexcept
Returns the first row covered by the iterator in the current chunk.
Definition chunk_iterator.h:1433
GAIA_NODISCARD auto view() const
Returns a read-only entity or component view for the owned chunk-backed fast path....
Definition chunk_iterator.h:1192
GAIA_NODISCARD auto sview_any_mut(uint32_t termIdx)
Returns a mutable component view for a query-term index that can resolve non-direct storage....
Definition chunk_iterator.h:1302
const Entity * m_pTermIdMapping
Optional per-term ids used by one-row direct iterators when a term resolves semantically.
Definition chunk_iterator.h:869
GAIA_NODISCARD auto sview_auto()
Returns either a mutable or immutable entity/component view for the owned chunk-backed fast path....
Definition chunk_iterator.h:1370
GAIA_NODISCARD auto sview_auto_any()
Returns either a mutable or immutable entity/component view that can resolve non-direct storage....
Definition chunk_iterator.h:1353
const World * m_pWorld
World pointer.
Definition chunk_iterator.h:859
void set_query_chunk(const Archetype *pArchetype, const uint8_t *pCompIndices, Chunk *pChunk, uint16_t from, uint16_t to)
Binds the iterator to the next query chunk and keeps archetype/mapping state on the iterator.
Definition chunk_iterator.h:1011
GAIA_NODISCARD auto view_any_mut()
Returns a mutable entity or component view that can resolve non-direct storage. This is the fallback ...
Definition chunk_iterator.h:1216
uint32_t acc_index(uint32_t idx) const noexcept
Returns the absolute index that should be used to access an item in the chunk. AoS indices map direct...
Definition chunk_iterator.h:1446
void modify()
Marks the component T as modified. Best used with sview to manually trigger an update at user's whim....
Definition chunk_iterator.h:1310
GAIA_NODISCARD auto view_any() const
Returns a read-only entity or component view that can resolve non-direct storage. This is the fallbac...
Definition chunk_iterator.h:1167
uint16_t m_from
Row of the first entity we iterate from.
Definition chunk_iterator.h:884
GAIA_NODISCARD bool has() const
Checks if component T is present in the chunk.
Definition chunk_iterator.h:1403
GAIA_NODISCARD bool has(Entity entity) const
Checks if entity entity is present in the chunk.
Definition chunk_iterator.h:1388
const uint8_t * m_pCompIndices
ChunkHeader::MAX_COMPONENTS values for component indices mapping for the parent archetype.
Definition chunk_iterator.h:865
Constraints m_constraints
Which entity subset the iterator currently exposes from the chunk.
Definition chunk_iterator.h:873
void * m_pCtx
User-owned pointer supplied by the caller driving this iteration.
Definition chunk_iterator.h:890
InheritedTermDataView m_inheritedData
Optional inherited term data view for exact semantic self-source terms.
Definition chunk_iterator.h:867
GAIA_NODISCARD auto view_auto_any()
Returns either a mutable or immutable entity/component view that can resolve non-direct storage....
Definition chunk_iterator.h:1337
GAIA_NODISCARD auto view_mut()
Returns a mutable entity or component view for the owned chunk-backed fast path. Updates world versio...
Definition chunk_iterator.h:1227
const Archetype * m_pArchetype
Currently iterated archetype.
Definition chunk_iterator.h:861
GAIA_NODISCARD auto view(uint32_t termIdx) const
Returns a read-only entity or component view for a query-term owned chunk-backed term....
Definition chunk_iterator.h:1205
uint8_t m_touchedCompIndices[ChunkHeader::MAX_COMPONENTS]
Chunk-backed columns that were exposed as mutable during the current callback.
Definition chunk_iterator.h:875
GAIA_NODISCARD uint16_t size() const noexcept
Returns the number of entities accessible via the iterator.
Definition chunk_iterator.h:1428
GAIA_NODISCARD auto sview_mut(uint32_t termIdx)
Returns a mutable component view for a query-term owned chunk-backed term. Doesn't update the world v...
Definition chunk_iterator.h:1289
GAIA_NODISCARD bool enabled(uint32_t index) const
Checks if the entity at the current iterator index is enabled.
Definition chunk_iterator.h:1380
uint16_t m_to
Row of the last entity we iterate to.
Definition chunk_iterator.h:886
Chunk * m_pChunk
Chunk currently associated with the iterator.
Definition chunk_iterator.h:863
GAIA_NODISCARD auto view_any(uint32_t termIdx)
Returns a read-only entity or component view for a query-term index that can resolve non-direct stora...
Definition chunk_iterator.h:1179
GAIA_NODISCARD bool has(Pair pair) const
Checks if relationship pair pair is present in the chunk.
Definition chunk_iterator.h:1395
bool m_writeIm
Whether mutable access should finish writes immediately or defer them until the callback returns.
Definition chunk_iterator.h:871
Buffer for deferred execution of some operations on entities.
Definition command_buffer.h:45
Wrapper for two Entities forming a relationship pair.
Definition id.h:529
Wrapper for two types forming a relationship pair. Depending on what types are used to form a pair it...
Definition id.h:224
Checks if endianess was detected correctly at compile-time.
Definition bitset.h:9
constexpr uint32_t BadIndex
Sentinel index value returned by helpers when a lookup fails.
Definition utility.h:20
Definition bit_utils.h:11
Definition chunk_iterator.h:80
Definition chunk_iterator.h:51
Read-only term view for entity-backed AoS data resolved through the world store. Used when the querie...
Definition chunk_iterator.h:112
Read-only term view for chunk-backed AoS data. Used by direct iteration paths that can guarantee cont...
Definition chunk_iterator.h:91
Read-only AoS term view fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:204
Mutable term view for entity-backed AoS data resolved through the world store. Used when writes targe...
Definition chunk_iterator.h:169
Mutable term view for chunk-backed AoS data. Exposes direct references to contiguous component storag...
Definition chunk_iterator.h:139
Mutable AoS term view fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:266
Definition chunk_iterator.h:45
Read-only field proxy for a single SoA member in entity-backed storage. Resolves the whole value via ...
Definition chunk_iterator.h:379
Read-only field proxy for a single SoA member in chunk-backed storage. Exposes a contiguous field spa...
Definition chunk_iterator.h:359
Read-only SoA field proxy fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:656
Proxy representing one writable field element in entity-backed storage.
Definition chunk_iterator.h:432
Mutable field proxy for a single SoA member in entity-backed storage. Updates reconstruct the whole v...
Definition chunk_iterator.h:427
Mutable field proxy for a single SoA member in chunk-backed storage. Returns raw references so arithm...
Definition chunk_iterator.h:402
Proxy representing a single writable SoA field element in the runtime fallback path only....
Definition chunk_iterator.h:693
Mutable SoA field proxy fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:681
Writable row proxy for entity-backed SoA data. Reads and writes the full structured value through the...
Definition chunk_iterator.h:337
Writable row proxy for chunk-backed SoA data. Reads and writes the full structured value directly fro...
Definition chunk_iterator.h:317
Writable SoA row proxy fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:624
Read-only SoA term view for entity-backed storage only. Used when the queried SoA payload lives out o...
Definition chunk_iterator.h:526
Read-only SoA term view for chunk-backed storage only. Used by direct iteration paths once the term h...
Definition chunk_iterator.h:498
Read-only SoA term view fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:761
Mutable SoA term view for entity-backed storage only. Reads and writes rows and fields through the wo...
Definition chunk_iterator.h:590
Mutable SoA term view for chunk-backed storage only. Provides direct row and field access without car...
Definition chunk_iterator.h:550
Mutable SoA term view fallback for APIs where storage mode is known only at runtime....
Definition chunk_iterator.h:797
Definition data_layout_policy.h:432
Definition data_layout_policy.h:482
View policy for accessing and storing data in the SoA way. Good for SIMD processing.
Definition data_layout_policy.h:243