-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecs.h
63 lines (48 loc) · 1.58 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
62
63
#ifndef ECS_H
#define ECS_H
#include <inttypes.h>
#include <stddef.h>
#define ENTITY_FLAG_ALIVE 1
/* Identifier for each entity, unique */
typedef struct {
uint32_t id;
} entity_t;
typedef struct {
/* Number of components */
uint32_t count;
/* The query must have enough capacity to hold a query of all avaible
* components */
uint32_t cap;
/* Array of entities that match the data of the query */
uint32_t *list;
} query_result_t;
/* Initialize the ECS module with the component size.
*
* Must pass in the size of each component type in the order you want to store
* them. The maximum number of component types is 32, though this could be
* extended by adding another bitmask and a bit switch */
void
ecs_init(uint32_t component_count, ...);
/* Create an entity. Returns a handle which contains the id */
entity_t
ecs_create();
/* Returns a pointer to the place where the component data for a certain type
* of component for a certain entity should belong */
void*
ecs_get(uint32_t entity_id, uint32_t component_id);
/* Add a component with data to an entity */
void
ecs_add(uint32_t entity_id, uint32_t component_id, void* data);
/* Remove a component from an entity */
void
ecs_remove(uint32_t entity_id, uint32_t component_id);
/* Returns true if entity has component */
uint32_t
ecs_has(uint32_t entity_id, uint32_t component_id);
/* Kill an entity */
void ecs_kill(uint32_t entity_id);
/* Query all components from the entities that match with the component ids
* of the provided ones */
query_result_t*
ecs_query(uint32_t component_count, ...);
#endif