2#include "gaia/config/config.h"
6#include "gaia/cnt/bitset.h"
7#include "gaia/core/utility.h"
8#include "gaia/ecs/archetype_common.h"
9#include "gaia/ecs/chunk_allocator.h"
10#include "gaia/ecs/component.h"
11#include "gaia/ecs/id.h"
18 struct ComponentCacheItem;
20 struct GAIA_API ChunkDataOffsets {
22 ChunkDataVersionOffset firstByte_Versions{};
24 ChunkDataOffset firstByte_CompEntities{};
26 ChunkDataOffset firstByte_Records{};
28 ChunkDataOffset firstByte_EntityData{};
31 struct GAIA_API ComponentRecord {
37 const ComponentCacheItem* pItem;
40 struct GAIA_API ChunkRecords {
42 ComponentVersion* pVersions{};
44 Entity* pCompEntities{};
46 ComponentRecord* pRecords{};
51 struct GAIA_API ChunkHeader final {
52 static constexpr uint32_t MAX_COMPONENTS_BITS = 5U;
54 static constexpr uint32_t MAX_COMPONENTS = 1U << MAX_COMPONENTS_BITS;
58 static constexpr uint16_t MAX_CHUNK_ENTITIES = (mem_block_size(2) - 64) /
sizeof(Entity);
59 static constexpr uint16_t MAX_CHUNK_ENTITIES_BITS = (uint16_t)core::count_bits(MAX_CHUNK_ENTITIES);
61 static constexpr uint16_t CHUNK_LIFESPAN_BITS = 4;
63 static constexpr uint16_t MAX_CHUNK_LIFESPAN = (1 << CHUNK_LIFESPAN_BITS) - 1;
68 const ComponentCache* cc;
72 uint32_t deleteQueueIndex;
76 uint16_t countEnabled;
81 uint16_t rowFirstEnabledEntity : MAX_CHUNK_ENTITIES_BITS;
83 uint16_t hasAnyCustomGenCtor : 1;
85 uint16_t hasAnyCustomUniCtor : 1;
87 uint16_t hasAnyCustomGenDtor : 1;
89 uint16_t hasAnyCustomUniDtor : 1;
91 uint16_t lifespanCountdown : CHUNK_LIFESPAN_BITS;
102 uint32_t& worldVersion;
105 uint32_t entityOrderVersion;
107 static inline uint32_t s_worldVersionDummy = 0;
108 ChunkHeader(): worldVersion(s_worldVersionDummy), entityOrderVersion(0) {}
111 const World& wld,
const ComponentCache& compCache, uint32_t chunkIndex, uint16_t cap, uint8_t genEntitiesCnt,
113 world(&wld), cc(&compCache), index(chunkIndex), deleteQueueIndex(BadIndex), count(0), countEnabled(0),
116 rowFirstEnabledEntity(0), hasAnyCustomGenCtor(0), hasAnyCustomUniCtor(0), hasAnyCustomGenDtor(0),
117 hasAnyCustomUniDtor(0), lifespanCountdown(0), dead(0), unused(0),
119 genEntities(genEntitiesCnt), cntEntities(0), worldVersion(version), entityOrderVersion(0) {
121 GAIA_ASSERT(uintptr_t(
this) % (
sizeof(
size_t)) == 0);
124 bool has_disabled_entities()
const {
125 return rowFirstEnabledEntity > 0;
128 bool has_enabled_entities()
const {
129 return countEnabled > 0;