Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
meta_c.h
Go to the documentation of this file.
1
6#ifdef FLECS_META_C
7
16#ifndef FLECS_META
17#define FLECS_META
18#endif
19
20#ifndef FLECS_PARSER
21#define FLECS_PARSER
22#endif
23
24#ifndef FLECS_META_C_H
25#define FLECS_META_C_H
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/* Macro that controls behavior of API. Usually set in module header. When the
32 * macro is not defined, it defaults to IMPL. */
33
34/* Define variables used by reflection utilities. This should only be defined
35 * by the module itself, not by the code importing the module */
36/* #define ECS_META_IMPL IMPL */
37
38/* Don't define variables used by reflection utilities but still declare the
39 * variable for the component id. This enables the reflection utilities to be
40 * used for global component variables, even if no reflection is used. */
41/* #define ECS_META_IMPL DECLARE */
42
43/* Don't define variables used by reflection utilities. This generates an extern
44 * variable for the component identifier. */
45/* #define ECS_META_IMPL EXTERN */
46
48#define ECS_META_COMPONENT(world, name)\
49 ECS_COMPONENT_DEFINE(world, name);\
50 ecs_meta_from_desc(world, ecs_id(name),\
51 FLECS__##name##_kind, FLECS__##name##_desc)
52
54#define ECS_STRUCT(name, ...)\
55 ECS_META_IMPL_CALL(ECS_STRUCT_, ECS_META_IMPL, name, #__VA_ARGS__);\
56 ECS_STRUCT_TYPE(name, __VA_ARGS__)
57
59#define ECS_ENUM(name, ...)\
60 ECS_META_IMPL_CALL(ECS_ENUM_, ECS_META_IMPL, name, #__VA_ARGS__);\
61 ECS_ENUM_TYPE(name, __VA_ARGS__)
62
64#define ECS_BITMASK(name, ...)\
65 ECS_META_IMPL_CALL(ECS_BITMASK_, ECS_META_IMPL, name, #__VA_ARGS__);\
66 ECS_ENUM_TYPE(name, __VA_ARGS__)
67
69#define ECS_PRIVATE
70
72FLECS_API
74 ecs_world_t *world,
75 ecs_entity_t component,
76 ecs_type_kind_t kind,
77 const char *desc);
78
79
80/* Private API */
81
82/* Utilities to switch between IMPL, DECLARE and EXTERN variants */
83#define ECS_META_IMPL_CALL_INNER(base, impl, name, type_desc)\
84 base ## impl(name, type_desc)
85
86#define ECS_META_IMPL_CALL(base, impl, name, type_desc)\
87 ECS_META_IMPL_CALL_INNER(base, impl, name, type_desc)
88
89/* ECS_STRUCT implementation */
90#define ECS_STRUCT_TYPE(name, ...)\
91 typedef struct __VA_ARGS__ name
92
93#define ECS_STRUCT_ECS_META_IMPL ECS_STRUCT_IMPL
94
95#define ECS_STRUCT_IMPL(name, type_desc)\
96 extern ECS_COMPONENT_DECLARE(name);\
97 static const char *FLECS__##name##_desc = type_desc;\
98 static ecs_type_kind_t FLECS__##name##_kind = EcsStructType;\
99 ECS_COMPONENT_DECLARE(name) = 0
100
101#define ECS_STRUCT_DECLARE(name, type_desc)\
102 extern ECS_COMPONENT_DECLARE(name);\
103 ECS_COMPONENT_DECLARE(name) = 0
104
105#define ECS_STRUCT_EXTERN(name, type_desc)\
106 extern ECS_COMPONENT_DECLARE(name)
107
108
109/* ECS_ENUM implementation */
110#define ECS_ENUM_TYPE(name, ...)\
111 typedef enum __VA_ARGS__ name
112
113#define ECS_ENUM_ECS_META_IMPL ECS_ENUM_IMPL
114
115#define ECS_ENUM_IMPL(name, type_desc)\
116 extern ECS_COMPONENT_DECLARE(name);\
117 static const char *FLECS__##name##_desc = type_desc;\
118 static ecs_type_kind_t FLECS__##name##_kind = EcsEnumType;\
119 ECS_COMPONENT_DECLARE(name) = 0
120
121#define ECS_ENUM_DECLARE(name, type_desc)\
122 extern ECS_COMPONENT_DECLARE(name);\
123 ECS_COMPONENT_DECLARE(name) = 0
124
125#define ECS_ENUM_EXTERN(name, type_desc)\
126 extern ECS_COMPONENT_DECLARE(name)
127
128
129/* ECS_BITMASK implementation */
130#define ECS_BITMASK_TYPE(name, ...)\
131 typedef enum __VA_ARGS__ name
132
133#define ECS_BITMASK_ECS_META_IMPL ECS_BITMASK_IMPL
134
135#define ECS_BITMASK_IMPL(name, type_desc)\
136 extern ECS_COMPONENT_DECLARE(name);\
137 static const char *FLECS__##name##_desc = type_desc;\
138 static ecs_type_kind_t FLECS__##name##_kind = EcsBitmaskType;\
139 ECS_COMPONENT_DECLARE(name) = 0
140
141#define ECS_BITMASK_DECLARE(name, type_desc)\
142 extern ECS_COMPONENT_DECLARE(name);\
143 ECS_COMPONENT_DECLARE(name) = 0
144
145#define ECS_BITMASK_EXTERN(name, type_desc)\
146 extern ECS_COMPONENT_DECLARE(name)
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif // FLECS_META_C_H
153
156#endif // FLECS_META_C
FLECS_API int ecs_meta_from_desc(ecs_world_t *world, ecs_entity_t component, ecs_type_kind_t kind, const char *desc)
Populate meta information from type descriptor.
ecs_type_kind_t
Type kinds supported by meta addon.
Definition meta.h:150
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:318
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:362