-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs.h
61 lines (47 loc) · 2.1 KB
/
ecs.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
#pragma once
#include "stdint.h"
const int ECS_CHUNK_SIZE = 16 * 1024;
const int ECS_ENTITY_MAX_COUNT = 200;
const int ECS_WORLD_ENTITY_COMMAND_BUFFER_CAPACITY = 200;
const int ECS_ARCHETYPE_COMPONENT_MAX_COUNT = 20;
const int ECS_COMPONENT_MAX_COUNT = 20;
const int ECS_ARCHETYPE_MAX_COUNT = 64;
typedef int16_t component_id;
typedef int16_t entity_id;
struct ecs_world;
enum component_request_type
{
REQUEST_Permission_RW = 0,
REQUEST_Permission_R = 1,
REQUEST_Permission_None = 2,
REQUEST_Subtractive = 3,
};
struct component_request
{
component_id ID;
uint8_t Type;
};
struct archetype_request
{
component_request* ComponentRequests;
int32_t ComponentCount;
};
// Job API
#define ECS_JOB_FUNCTION(Name) void Name(void* Components, int32_t Count)
#define ECS_JOB_FUNCTION_PARAMETERS(Name) ECS_JOB_FUNCTION((*Name))
void ExecuteECSJob(const ecs_world* World, const archetype_request* ArchetypeRequest,
ECS_JOB_FUNCTION_PARAMETERS(JobFunc));
// Entity API
bool DoesEntityExist(const ecs_world* World, entity_id EntityID);
entity_id CreateEntity(ecs_world* World);
void DestroyEntity(ecs_world* World, entity_id EntityID);
bool HasComponent(const ecs_world* World, entity_id EntityID, component_id ComponentID);
void AddComponent(ecs_world* World, entity_id EntityID, component_id ComponentID);
void RemoveComponent(ecs_world* World, entity_id EntityID, component_id ComponentID);
void* GetComponent(ecs_world* World, entity_id EntityID, component_id ComponentID);
void SetComponent_(ecs_world* World, entity_id EntityID, const void* ComponentValue,
uint16_t ComponentSize, component_id ComponentID);
#define SetComponent(World, Entity, ComponentName, Value) \
static_assert(sizeof(ComponentName) == sizeof(Value), \
"compile time assertions: SetComponent() ComponentName and Value mismatch"); \
SetComponent_(World, Entity, Value, sizeof(Value), COMPONENT_##ComponentName)