-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs_management.h
84 lines (68 loc) · 2.19 KB
/
ecs_management.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#pragma once
#include "ecs.h"
#include "basic_data_structures.h"
#include "heap_alloc.h"
union chunk;
struct chunk_header
{
chunk* NextChunk;
uint16_t ArchetypeIndex;
uint16_t EntityCount;
uint16_t EntityCapacity;
};
union chunk {
chunk_header Header;
uint8_t Memory[ECS_CHUNK_SIZE];
};
struct component_id_and_offset
{
component_id ID;
uint16_t Offset;
};
struct archetype
{
chunk* FirstChunk;
fixed_stack<component_id_and_offset, ECS_ARCHETYPE_COMPONENT_MAX_COUNT> ComponentTypes;
};
struct component_struct_info
{
uint8_t Alignment;
uint16_t Size;
};
struct ecs_runtime
{
fixed_stack<archetype, ECS_ARCHETYPE_MAX_COUNT> Archetypes;
fixed_stack<int32_t, ECS_ARCHETYPE_MAX_COUNT> VacantArchetypeIndices;
fixed_stack<const char*, ECS_COMPONENT_MAX_COUNT, component_id> ComponentNames;
fixed_stack<component_struct_info, ECS_COMPONENT_MAX_COUNT, component_id> ComponentStructInfos;
Memory::heap_allocator ChunkHeap;
};
struct entity_storage_info
{
int16_t ChunkIndex;
int16_t IndexInChunk;
};
struct entity_command
{
uint8_t* Data;
entity_id Index;
uint16_t Size;
uint16_t Flags;
};
struct ecs_world
{
ecs_runtime* Runtime;
fixed_stack<entity_storage_info, ECS_ENTITY_MAX_COUNT, entity_id> Entities;
fixed_stack<entity_id, ECS_ENTITY_MAX_COUNT, entity_id> VacantEntityIndices;
fixed_stack<entity_command, ECS_WORLD_ENTITY_COMMAND_BUFFER_CAPACITY> EntityCommands;
};
// Initialization
void InitializeChunkHeap(ecs_runtime* Runtime, uint8_t* ChunkMemory, int32_t MemorySize);
void InitializeArchetypeAndComponentTables(ecs_runtime* Runtime,
const component_struct_info* ComponentInfos,
const char** ComponentNames, int ComponentCount);
void InitializeWorld(ecs_world* World, const ecs_runtime* Runtime);
void RunWorldCommandBuffer(ecs_runtime* Runtime, ecs_world* World);
// Integrating saved worlds (used importing deserialize'ing)
void AdaptWorldToNewRuntime(ecs_world* World, const ecs_runtime* OldRuntime,
const ecs_runtime* NewRuntime);