Yume Project
3.0
Touhou-inspired Danmaku game made in C only
Chargement...
Recherche...
Aucune correspondance
component.h
Aller à la documentation de ce fichier.
1
6
#pragma once
7
8
#include "
ecs.h
"
9
10
#include <stdint.h>
11
#include <string.h>
12
13
62
#define DEFINE_COMPONENT_MANAGER(Type, Number) \
63
typedef struct { \
64
Type dense[Number]; \
65
Entity entity_lookup[Number]; \
66
uint32_t sparse[MAX_ENTITIES]; \
67
int count; \
68
} Type##Manager; \
69
\
70
static inline void Type##_init(Type##Manager *mgr) { \
71
mgr->count = 0; \
72
memset(mgr->sparse, NULL_INDEX, sizeof(mgr->sparse)); \
73
} \
74
\
75
static inline void Type##_add(Type##Manager *mgr, Entity e, Type data) { \
76
if (mgr->sparse[e] != NULL_INDEX) { \
77
mgr->dense[mgr->sparse[e]] = data; \
78
return; \
79
} \
80
int id = mgr->count++; \
81
if (id >= Number) \
82
return; \
83
mgr->dense[id] = data; \
84
mgr->sparse[e] = id; \
85
mgr->entity_lookup[id] = e; \
86
} \
87
\
88
static inline Type *Type##_get(Type##Manager *mgr, Entity e) { \
89
uint32_t id = mgr->sparse[e]; \
90
if (id == NULL_INDEX) \
91
return NULL; \
92
return &mgr->dense[id]; \
93
} \
94
\
95
static inline void Type##_remove(Type##Manager *mgr, Entity e) { \
96
uint32_t id = mgr->sparse[e]; \
97
if (id == NULL_INDEX) \
98
return; \
99
int last_id = --mgr->count; \
100
Entity last_e = mgr->entity_lookup[last_id]; \
101
mgr->dense[id] = mgr->dense[last_id]; \
102
mgr->entity_lookup[id] = last_e; \
103
mgr->sparse[last_e] = id; \
104
mgr->sparse[e] = NULL_INDEX; \
105
} \
106
\
107
static inline Entity Type##_get_entity(Type##Manager *mgr, int dense_id) { \
108
return mgr->entity_lookup[dense_id]; \
109
}
110
111
#define DECLARE_GETTER(Component, type, champ) \
112
static inline type Component##_get_##champ(Component *p) { return p->champ; }
113
// Sprite_get_textureID();
114
115
#define DECLARE_SETTER(Component, type, champ) \
116
static inline void Component##_set_##champ(Component *p, type champ) { \
117
p->champ = champ; \
118
}
119
// Sprite_set_textureID(&textureID);
120
121
#define DECLARE_SETTER_GETTER(Component, type, champ) \
122
DECLARE_SETTER(Component, type, champ) \
123
DECLARE_GETTER(Component, type, champ)
ecs.h
Types et déclarations utilisés dans l'ECS.
lib
internal
ecs
component.h
Généré par
1.16.1