Flecs v4.0
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
7
16#ifndef FLECS_META_C_H
17#define FLECS_META_C_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/* Macro that controls behavior of API. Usually set in module header. When the
24 * macro is not defined, it defaults to IMPL. */
25
26/* Define variables used by reflection utilities. This should only be defined
27 * by the module itself, not by the code importing the module */
28/* #define ECS_META_IMPL IMPL */
29
30/* Don't define variables used by reflection utilities but still declare the
31 * variable for the component id. This enables the reflection utilities to be
32 * used for global component variables, even if no reflection is used. */
33/* #define ECS_META_IMPL DECLARE */
34
35/* Don't define variables used by reflection utilities. This generates an extern
36 * variable for the component identifier. */
37/* #define ECS_META_IMPL EXTERN */
38
40#define ECS_META_COMPONENT(world, name)\
41 ECS_COMPONENT_DEFINE(world, name);\
42 ecs_meta_from_desc(world, ecs_id(name),\
43 FLECS__##name##_kind, FLECS__##name##_desc)
44
46#define ECS_STRUCT(name, ...)\
47 ECS_META_IMPL_CALL(ECS_STRUCT_, ECS_META_IMPL, name, #__VA_ARGS__);\
48 ECS_STRUCT_TYPE(name, __VA_ARGS__)
49
51#define ECS_ENUM(name, ...)\
52 ECS_META_IMPL_CALL(ECS_ENUM_, ECS_META_IMPL, name, #__VA_ARGS__);\
53 ECS_ENUM_TYPE(name, __VA_ARGS__)
54
56#define ECS_BITMASK(name, ...)\
57 ECS_META_IMPL_CALL(ECS_BITMASK_, ECS_META_IMPL, name, #__VA_ARGS__);\
58 ECS_ENUM_TYPE(name, __VA_ARGS__)
59
61#define ECS_PRIVATE
62
64FLECS_API
66 ecs_world_t *world,
67 ecs_entity_t component,
68 ecs_type_kind_t kind,
69 const char *desc);
70
71
76#define ECS_META_IMPL_CALL_INNER(base, impl, name, type_desc)\
77 base ## impl(name, type_desc)
78
79#define ECS_META_IMPL_CALL(base, impl, name, type_desc)\
80 ECS_META_IMPL_CALL_INNER(base, impl, name, type_desc)
81
82/* ECS_STRUCT implementation */
83#define ECS_STRUCT_TYPE(name, ...)\
84 typedef struct __VA_ARGS__ name
85
86#define ECS_STRUCT_ECS_META_IMPL ECS_STRUCT_IMPL
87
88#define ECS_STRUCT_IMPL(name, type_desc)\
89 extern ECS_COMPONENT_DECLARE(name);\
90 static const char *FLECS__##name##_desc = type_desc;\
91 static ecs_type_kind_t FLECS__##name##_kind = EcsStructType;\
92 ECS_COMPONENT_DECLARE(name) = 0
93
94#define ECS_STRUCT_DECLARE(name, type_desc)\
95 extern ECS_COMPONENT_DECLARE(name);\
96 ECS_COMPONENT_DECLARE(name) = 0
97
98#define ECS_STRUCT_EXTERN(name, type_desc)\
99 extern ECS_COMPONENT_DECLARE(name)
100
101
102/* ECS_ENUM implementation */
103#define ECS_ENUM_TYPE(name, ...)\
104 typedef enum __VA_ARGS__ name
105
106#define ECS_ENUM_ECS_META_IMPL ECS_ENUM_IMPL
107
108#define ECS_ENUM_IMPL(name, type_desc)\
109 extern ECS_COMPONENT_DECLARE(name);\
110 static const char *FLECS__##name##_desc = type_desc;\
111 static ecs_type_kind_t FLECS__##name##_kind = EcsEnumType;\
112 ECS_COMPONENT_DECLARE(name) = 0
113
114#define ECS_ENUM_DECLARE(name, type_desc)\
115 extern ECS_COMPONENT_DECLARE(name);\
116 ECS_COMPONENT_DECLARE(name) = 0
117
118#define ECS_ENUM_EXTERN(name, type_desc)\
119 extern ECS_COMPONENT_DECLARE(name)
120
121
122/* ECS_BITMASK implementation */
123#define ECS_BITMASK_TYPE(name, ...)\
124 typedef enum __VA_ARGS__ name
125
126#define ECS_BITMASK_ECS_META_IMPL ECS_BITMASK_IMPL
127
128#define ECS_BITMASK_IMPL(name, type_desc)\
129 extern ECS_COMPONENT_DECLARE(name);\
130 static const char *FLECS__##name##_desc = type_desc;\
131 static ecs_type_kind_t FLECS__##name##_kind = EcsBitmaskType;\
132 ECS_COMPONENT_DECLARE(name) = 0
133
134#define ECS_BITMASK_DECLARE(name, type_desc)\
135 extern ECS_COMPONENT_DECLARE(name);\
136 ECS_COMPONENT_DECLARE(name) = 0
137
138#define ECS_BITMASK_EXTERN(name, type_desc)\
139 extern ECS_COMPONENT_DECLARE(name)
140
143#ifdef __cplusplus
144}
145#endif
146
147#endif // FLECS_META_H
148
151#endif // FLECS_META
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:153
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:347
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:391