Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
meta.h
Go to the documentation of this file.
1
57#ifdef FLECS_META
58
67#ifndef FLECS_MODULE
68#define FLECS_MODULE
69#endif
70
71#ifndef FLECS_META_H
72#define FLECS_META_H
73
74#ifdef __cplusplus
75extern "C" {
76#endif
77
79#define ECS_MEMBER_DESC_CACHE_SIZE (32)
80
95typedef bool ecs_bool_t;
96typedef char ecs_char_t;
97typedef unsigned char ecs_byte_t;
98typedef uint8_t ecs_u8_t;
99typedef uint16_t ecs_u16_t;
100typedef uint32_t ecs_u32_t;
101typedef uint64_t ecs_u64_t;
102typedef uintptr_t ecs_uptr_t;
103typedef int8_t ecs_i8_t;
104typedef int16_t ecs_i16_t;
105typedef int32_t ecs_i32_t;
106typedef int64_t ecs_i64_t;
107typedef intptr_t ecs_iptr_t;
108typedef float ecs_f32_t;
109typedef double ecs_f64_t;
110typedef char* ecs_string_t;
112/* Meta module component IDs */
113FLECS_API extern const ecs_entity_t ecs_id(EcsType);
114FLECS_API extern const ecs_entity_t ecs_id(EcsTypeSerializer);
115FLECS_API extern const ecs_entity_t ecs_id(EcsPrimitive);
116FLECS_API extern const ecs_entity_t ecs_id(EcsEnum);
117FLECS_API extern const ecs_entity_t ecs_id(EcsBitmask);
118FLECS_API extern const ecs_entity_t ecs_id(EcsConstants);
119FLECS_API extern const ecs_entity_t ecs_id(EcsMember);
120FLECS_API extern const ecs_entity_t ecs_id(EcsMemberRanges);
121FLECS_API extern const ecs_entity_t ecs_id(EcsStruct);
122FLECS_API extern const ecs_entity_t ecs_id(EcsArray);
123FLECS_API extern const ecs_entity_t ecs_id(EcsVector);
124FLECS_API extern const ecs_entity_t ecs_id(EcsOpaque);
125FLECS_API extern const ecs_entity_t ecs_id(EcsUnit);
126FLECS_API extern const ecs_entity_t ecs_id(EcsUnitPrefix);
127FLECS_API extern const ecs_entity_t EcsQuantity;
129/* Primitive type component IDs */
130
131FLECS_API extern const ecs_entity_t ecs_id(ecs_bool_t);
132FLECS_API extern const ecs_entity_t ecs_id(ecs_char_t);
133FLECS_API extern const ecs_entity_t ecs_id(ecs_byte_t);
134FLECS_API extern const ecs_entity_t ecs_id(ecs_u8_t);
135FLECS_API extern const ecs_entity_t ecs_id(ecs_u16_t);
136FLECS_API extern const ecs_entity_t ecs_id(ecs_u32_t);
137FLECS_API extern const ecs_entity_t ecs_id(ecs_u64_t);
138FLECS_API extern const ecs_entity_t ecs_id(ecs_uptr_t);
139FLECS_API extern const ecs_entity_t ecs_id(ecs_i8_t);
140FLECS_API extern const ecs_entity_t ecs_id(ecs_i16_t);
141FLECS_API extern const ecs_entity_t ecs_id(ecs_i32_t);
142FLECS_API extern const ecs_entity_t ecs_id(ecs_i64_t);
143FLECS_API extern const ecs_entity_t ecs_id(ecs_iptr_t);
144FLECS_API extern const ecs_entity_t ecs_id(ecs_f32_t);
145FLECS_API extern const ecs_entity_t ecs_id(ecs_f64_t);
146FLECS_API extern const ecs_entity_t ecs_id(ecs_string_t);
147FLECS_API extern const ecs_entity_t ecs_id(ecs_entity_t);
148FLECS_API extern const ecs_entity_t ecs_id(ecs_id_t);
151typedef enum ecs_type_kind_t {
152 EcsPrimitiveType,
153 EcsBitmaskType,
154 EcsEnumType,
155 EcsStructType,
156 EcsArrayType,
157 EcsVectorType,
158 EcsOpaqueType,
159 EcsTypeKindLast = EcsOpaqueType
161
168
171 EcsBool = 1,
172 EcsChar,
173 EcsByte,
174 EcsU8,
175 EcsU16,
176 EcsU32,
177 EcsU64,
178 EcsI8,
179 EcsI16,
180 EcsI32,
181 EcsI64,
182 EcsF32,
183 EcsF64,
184 EcsUPtr,
185 EcsIPtr,
186 EcsString,
187 EcsEntity,
188 EcsId,
189 EcsPrimitiveKindLast = EcsId
191
196
205
211
218
262
264typedef struct EcsStruct {
266 ecs_vec_t members; /* vector<ecs_member_t> */
268
270typedef struct ecs_enum_constant_t {
272 const char *name;
273
275 int64_t value;
276
279
283
288
292 const char *name;
293
295 ecs_flags64_t value;
296
298 int64_t _unused;
299
303
305typedef struct EcsBitmask {
306 int32_t dummy_;
308
310typedef struct EcsConstants {
312 ecs_map_t *constants;
317
323
328
329
330/* Opaque type support */
331
332#if !defined(__cplusplus) || !defined(FLECS_CPP)
333
335typedef struct ecs_serializer_t {
337 int (*value)(
338 const struct ecs_serializer_t *ser,
339 ecs_entity_t type,
340 const void *value);
343 int (*member)(
344 const struct ecs_serializer_t *ser,
345 const char *member);
348 void *ctx;
350
351#elif defined(__cplusplus)
352
353} /* extern "C" { */
354
356typedef struct ecs_serializer_t {
357 /* Serialize value */
358 int (*value_)(
359 const struct ecs_serializer_t *ser,
360 ecs_entity_t type,
361 const void *value);
362
363 /* Serialize member */
364 int (*member_)(
365 const struct ecs_serializer_t *ser,
366 const char *name);
367
368 /* Serialize value */
369 int value(ecs_entity_t type, const void *value) const;
370
371 /* Serialize value */
372 template <typename T>
373 int value(const T& value) const;
374
375 /* Serialize member */
376 int member(const char *name) const;
377
378 const ecs_world_t *world;
379 void *ctx;
381
382extern "C" {
383#endif
384
386typedef int (*ecs_meta_serialize_t)(
387 const ecs_serializer_t *ser,
388 const void *src);
393 const ecs_serializer_t *ser,
394 const void *src,
395 const char* name);
399 const ecs_serializer_t *ser,
400 const void *src,
401 size_t elem);
408typedef struct EcsOpaque {
414 /* Deserializer interface
415 * Only override the callbacks that are valid for the opaque type. If a
416 * deserializer attempts to assign a value type that is not supported by the
417 * interface, a conversion error is thrown.
418 */
419
421 void (*assign_bool)(
422 void *dst,
423 bool value);
424
426 void (*assign_char)(
427 void *dst,
428 char value);
429
431 void (*assign_int)(
432 void *dst,
433 int64_t value);
434
436 void (*assign_uint)(
437 void *dst,
438 uint64_t value);
439
442 void *dst,
443 double value);
444
447 void *dst,
448 const char *value);
449
452 void *dst,
453 ecs_world_t *world,
454 ecs_entity_t entity);
455
457 void (*assign_id)(
458 void *dst,
459 ecs_world_t *world,
460 ecs_id_t id);
461
463 void (*assign_null)(
464 void *dst);
465
467 void (*clear)(
468 void *dst);
469
471 void* (*ensure_element)(
472 void *dst,
473 size_t elem);
474
476 void* (*ensure_member)(
477 void *dst,
478 const char *member);
479
481 size_t (*count)(
482 const void *dst);
483
485 void (*resize)(
486 void *dst,
487 size_t count);
489
490
491/* Units */
492
504
513
519
520
521/* Serializer utilities */
522
528typedef enum ecs_meta_op_kind_t {
542 EcsOpEnum,
543 EcsOpBitmask,
544
547 EcsOpBool,
548 EcsOpChar,
549 EcsOpByte,
550 EcsOpU8,
551 EcsOpU16,
552 EcsOpU32,
553 EcsOpU64,
554 EcsOpI8,
555 EcsOpI16,
556 EcsOpI32,
557 EcsOpI64,
558 EcsOpF32,
559 EcsOpF64,
560 EcsOpUPtr,
561 EcsOpIPtr,
562 EcsOpString,
563 EcsOpEntity,
564 EcsOpId,
565 EcsMetaTypeOpKindLast = EcsOpId
567
585
592
593
594/* Deserializer utilities */
595
599#define ECS_META_MAX_SCOPE_DEPTH (32)
600
616
629
636FLECS_API
638 ecs_world_t *world,
639 ecs_entity_t type);
640
655FLECS_API
657 const ecs_world_t *world,
658 ecs_entity_t type,
659 void *ptr);
660
666FLECS_API
668 ecs_meta_cursor_t *cursor);
669
675FLECS_API
677 ecs_meta_cursor_t *cursor);
678
684FLECS_API
686 ecs_meta_cursor_t *cursor,
687 int32_t elem);
688
695FLECS_API
697 ecs_meta_cursor_t *cursor,
698 const char *name);
699
707FLECS_API
709 ecs_meta_cursor_t *cursor,
710 const char *name);
711
720FLECS_API
722 ecs_meta_cursor_t *cursor,
723 const char *name);
724
732FLECS_API
734 ecs_meta_cursor_t *cursor,
735 const char *name);
736
742FLECS_API
744 ecs_meta_cursor_t *cursor);
745
751FLECS_API
753 ecs_meta_cursor_t *cursor);
754
760FLECS_API
762 const ecs_meta_cursor_t *cursor);
763
769FLECS_API
771 const ecs_meta_cursor_t *cursor);
772
778FLECS_API
780 const ecs_meta_cursor_t *cursor);
781
787FLECS_API
789 const ecs_meta_cursor_t *cursor);
790
796FLECS_API
798 const ecs_meta_cursor_t *cursor);
799
800/* The set functions assign the field with the specified value. If the value
801 * does not have the same type as the field, it will be cast to the field type.
802 * If no valid conversion is available, the operation will fail. */
803
810FLECS_API
812 ecs_meta_cursor_t *cursor,
813 bool value);
814
821FLECS_API
823 ecs_meta_cursor_t *cursor,
824 char value);
825
832FLECS_API
834 ecs_meta_cursor_t *cursor,
835 int64_t value);
836
843FLECS_API
845 ecs_meta_cursor_t *cursor,
846 uint64_t value);
847
854FLECS_API
856 ecs_meta_cursor_t *cursor,
857 double value);
858
865FLECS_API
867 ecs_meta_cursor_t *cursor,
868 const char *value);
869
876FLECS_API
878 ecs_meta_cursor_t *cursor,
879 const char *value);
880
887FLECS_API
889 ecs_meta_cursor_t *cursor,
890 ecs_entity_t value);
891
898FLECS_API
900 ecs_meta_cursor_t *cursor,
901 ecs_id_t value);
902
908FLECS_API
910 ecs_meta_cursor_t *cursor);
911
918FLECS_API
920 ecs_meta_cursor_t *cursor,
921 const ecs_value_t *value);
922
923/* Functions for getting members. */
924
930FLECS_API
932 const ecs_meta_cursor_t *cursor);
933
939FLECS_API
941 const ecs_meta_cursor_t *cursor);
942
948FLECS_API
950 const ecs_meta_cursor_t *cursor);
951
957FLECS_API
959 const ecs_meta_cursor_t *cursor);
960
966FLECS_API
968 const ecs_meta_cursor_t *cursor);
969
977FLECS_API
979 const ecs_meta_cursor_t *cursor);
980
987FLECS_API
989 const ecs_meta_cursor_t *cursor);
990
997FLECS_API
999 const ecs_meta_cursor_t *cursor);
1000
1007FLECS_API
1009 ecs_primitive_kind_t type_kind,
1010 const void *ptr);
1011
1020FLECS_API
1022 const ecs_meta_op_t *op,
1023 const void *ptr);
1024
1025/* API functions for creating meta types */
1026
1032
1039FLECS_API
1041 ecs_world_t *world,
1042 const ecs_primitive_desc_t *desc);
1043
1044
1051
1058FLECS_API
1060 ecs_world_t *world,
1061 const ecs_enum_desc_t *desc);
1062
1063
1069
1076FLECS_API
1078 ecs_world_t *world,
1079 const ecs_bitmask_desc_t *desc);
1080
1081
1088
1095FLECS_API
1097 ecs_world_t *world,
1098 const ecs_array_desc_t *desc);
1099
1100
1106
1113FLECS_API
1115 ecs_world_t *world,
1116 const ecs_vector_desc_t *desc);
1117
1118
1125
1132FLECS_API
1134 ecs_world_t *world,
1135 const ecs_struct_desc_t *desc);
1136
1145FLECS_API
1147 ecs_world_t *world,
1148 ecs_entity_t type,
1149 const ecs_member_t *member);
1150
1158FLECS_API
1160 ecs_world_t *world,
1161 ecs_entity_t type,
1162 const char *name);
1163
1171FLECS_API
1173 ecs_world_t *world,
1174 ecs_entity_t type,
1175 int32_t i);
1176
1182
1205FLECS_API
1207 ecs_world_t *world,
1208 const ecs_opaque_desc_t *desc);
1209
1210
1239
1246FLECS_API
1248 ecs_world_t *world,
1249 const ecs_unit_desc_t *desc);
1250
1251
1263
1270FLECS_API
1272 ecs_world_t *world,
1273 const ecs_unit_prefix_desc_t *desc);
1274
1275
1282FLECS_API
1284 ecs_world_t *world,
1285 const ecs_entity_desc_t *desc);
1286
1287/* Convenience macros */
1288
1290#define ecs_primitive(world, ...)\
1291 ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )
1292
1294#define ecs_enum(world, ...)\
1295 ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )
1296
1298#define ecs_bitmask(world, ...)\
1299 ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )
1300
1302#define ecs_array(world, ...)\
1303 ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )
1304
1306#define ecs_vector(world, ...)\
1307 ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )
1308
1310#define ecs_opaque(world, ...)\
1311 ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )
1312
1314#define ecs_struct(world, ...)\
1315 ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )
1316
1318#define ecs_unit(world, ...)\
1319 ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )
1320
1322#define ecs_unit_prefix(world, ...)\
1323 ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )
1324
1326#define ecs_quantity(world, ...)\
1327 ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
1328
1329
1338FLECS_API
1340 ecs_world_t *world);
1341
1342#ifdef __cplusplus
1343}
1344#endif
1345
1346#include "meta_c.h"
1347
1348#endif
1349
1352#endif
FLECS_API int ecs_meta_set_int(ecs_meta_cursor_t *cursor, int64_t value)
Set field with int value.
FLECS_API int ecs_meta_next(ecs_meta_cursor_t *cursor)
Move cursor to next field.
FLECS_API int ecs_meta_set_uint(ecs_meta_cursor_t *cursor, uint64_t value)
Set field with uint value.
struct EcsMember EcsMember
Component added to member entities.
FLECS_API bool ecs_meta_get_bool(const ecs_meta_cursor_t *cursor)
Get field value as boolean.
struct EcsPrimitive EcsPrimitive
Component added to primitive types.
bool ecs_bool_t
Primitive type definitions.
Definition meta.h:95
struct ecs_vector_desc_t ecs_vector_desc_t
Used with ecs_vector_init().
FLECS_API const ecs_entity_t ecs_id(EcsType)
ID for component added to all types with reflection data.
int(* ecs_meta_serialize_member_t)(const ecs_serializer_t *ser, const void *src, const char *name)
Callback invoked to serialize an opaque struct member.
Definition meta.h:392
FLECS_API ecs_entity_t ecs_bitmask_init(ecs_world_t *world, const ecs_bitmask_desc_t *desc)
Create a new bitmask type.
struct EcsEnum EcsEnum
Component added to enum type entities.
uint32_t ecs_u32_t
Built-in u32 type.
Definition meta.h:100
FLECS_API double ecs_meta_ptr_to_float(ecs_primitive_kind_t type_kind, const void *ptr)
Convert pointer of primitive kind to float.
struct ecs_bitmask_constant_t ecs_bitmask_constant_t
Type that describes a bitmask constant.
int16_t ecs_i16_t
Built-in i16 type.
Definition meta.h:104
struct ecs_meta_cursor_t ecs_meta_cursor_t
Type that enables iterating and populating a value using reflection data.
ecs_meta_op_kind_t
Serializer instruction opcodes.
Definition meta.h:528
FLECS_API int ecs_meta_set_string_literal(ecs_meta_cursor_t *cursor, const char *value)
Set field with string literal value (has enclosing "").
FLECS_API ecs_entity_t ecs_opaque_init(ecs_world_t *world, const ecs_opaque_desc_t *desc)
Create a new opaque type.
FLECS_API int ecs_meta_set_float(ecs_meta_cursor_t *cursor, double value)
Set field with float value.
struct ecs_enum_desc_t ecs_enum_desc_t
Used with ecs_enum_init().
FLECS_API int ecs_meta_dotmember(ecs_meta_cursor_t *cursor, const char *name)
Move cursor to member.
struct EcsStruct EcsStruct
Component added to struct type entities.
FLECS_API ecs_entity_t ecs_meta_get_entity(const ecs_meta_cursor_t *cursor)
Get field value as entity.
uint8_t ecs_u8_t
Built-in u8 type.
Definition meta.h:98
struct ecs_member_t ecs_member_t
Element type of members vector in EcsStruct.
int(* ecs_meta_serialize_element_t)(const ecs_serializer_t *ser, const void *src, size_t elem)
Callback invoked to serialize an opaque vector or array element.
Definition meta.h:398
struct EcsVector EcsVector
Component added to vector type entities.
int64_t ecs_i64_t
Built-in i64 type.
Definition meta.h:106
FLECS_API char * ecs_meta_serializer_to_str(ecs_world_t *world, ecs_entity_t type)
Convert serializer to string.
FLECS_API bool ecs_meta_is_collection(const ecs_meta_cursor_t *cursor)
Is the current scope a collection?
FLECS_API int ecs_struct_add_member(ecs_world_t *world, ecs_entity_t type, const ecs_member_t *member)
Add member to struct.
struct ecs_serializer_t ecs_serializer_t
Serializer interface.
char * ecs_string_t
Built-in string type.
Definition meta.h:110
struct EcsBitmask EcsBitmask
Component added to bitmask type entities.
struct ecs_member_value_range_t ecs_member_value_range_t
Type expressing a range for a member value.
uint64_t ecs_u64_t
Built-in u64 type.
Definition meta.h:101
intptr_t ecs_iptr_t
Built-in iptr type.
Definition meta.h:107
struct EcsOpaque EcsOpaque
Opaque type reflection data.
FLECS_API ecs_entity_t ecs_quantity_init(ecs_world_t *world, const ecs_entity_desc_t *desc)
Create a new quantity.
FLECS_API ecs_size_t ecs_meta_op_get_elem_count(const ecs_meta_op_t *op, const void *ptr)
Get element count for array or vector operations.
FLECS_API int ecs_meta_set_id(ecs_meta_cursor_t *cursor, ecs_id_t value)
Set field with (component) ID value.
uintptr_t ecs_uptr_t
Built-in uptr type.
Definition meta.h:102
FLECS_API ecs_meta_cursor_t ecs_meta_cursor(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Create meta cursor.
FLECS_API ecs_entity_t ecs_meta_get_unit(const ecs_meta_cursor_t *cursor)
Get unit of current field.
FLECS_API const ecs_entity_t EcsQuantity
Tag added to unit quantities.
float ecs_f32_t
Built-in f32 type.
Definition meta.h:108
FLECS_API void FlecsMetaImport(ecs_world_t *world)
Meta module import function.
ecs_primitive_kind_t
Primitive type kinds supported by meta addon.
Definition meta.h:170
FLECS_API ecs_entity_t ecs_meta_get_member_id(const ecs_meta_cursor_t *cursor)
Get member entity of current field.
FLECS_API const char * ecs_meta_get_string(const ecs_meta_cursor_t *cursor)
Get field value as string.
FLECS_API const char * ecs_meta_get_member(const ecs_meta_cursor_t *cursor)
Get member name of current field.
struct EcsArray EcsArray
Component added to array type entities.
FLECS_API ecs_member_t * ecs_struct_get_member(ecs_world_t *world, ecs_entity_t type, const char *name)
Get member by name from struct.
struct ecs_array_desc_t ecs_array_desc_t
Used with ecs_array_init().
FLECS_API ecs_member_t * ecs_struct_get_nth_member(ecs_world_t *world, ecs_entity_t type, int32_t i)
Get member by index from struct.
FLECS_API double ecs_meta_get_float(const ecs_meta_cursor_t *cursor)
Get field value as float.
FLECS_API int ecs_meta_pop(ecs_meta_cursor_t *cursor)
Pop a struct or collection scope (must follow a push).
FLECS_API ecs_entity_t ecs_meta_get_type(const ecs_meta_cursor_t *cursor)
Get type of current field.
FLECS_API uint64_t ecs_meta_get_uint(const ecs_meta_cursor_t *cursor)
Get field value as unsigned integer.
FLECS_API ecs_entity_t ecs_vector_init(ecs_world_t *world, const ecs_vector_desc_t *desc)
Create a new vector type.
FLECS_API char ecs_meta_get_char(const ecs_meta_cursor_t *cursor)
Get field value as char.
double ecs_f64_t
Built-in f64 type.
Definition meta.h:109
char ecs_char_t
Built-in char type.
Definition meta.h:96
FLECS_API ecs_entity_t ecs_unit_prefix_init(ecs_world_t *world, const ecs_unit_prefix_desc_t *desc)
Create a new unit prefix.
struct ecs_opaque_desc_t ecs_opaque_desc_t
Used with ecs_opaque_init().
struct EcsConstants EcsConstants
Component with data structures for looking up enum or bitmask constants.
FLECS_API int ecs_meta_elem(ecs_meta_cursor_t *cursor, int32_t elem)
Move cursor to a field.
struct ecs_enum_constant_t ecs_enum_constant_t
Type that describes an enum constant.
FLECS_API int64_t ecs_meta_get_int(const ecs_meta_cursor_t *cursor)
Get field value as signed integer.
struct ecs_primitive_desc_t ecs_primitive_desc_t
Used with ecs_primitive_init().
ecs_type_kind_t
Type kinds supported by meta addon.
Definition meta.h:151
struct ecs_unit_translation_t ecs_unit_translation_t
Helper type to describe translation between two units.
FLECS_API ecs_entity_t ecs_primitive_init(ecs_world_t *world, const ecs_primitive_desc_t *desc)
Create a new primitive type.
FLECS_API ecs_entity_t ecs_unit_init(ecs_world_t *world, const ecs_unit_desc_t *desc)
Create a new unit.
uint16_t ecs_u16_t
Built-in u16 type.
Definition meta.h:99
int(* ecs_meta_serialize_t)(const ecs_serializer_t *ser, const void *src)
Callback invoked serializing an opaque type.
Definition meta.h:386
FLECS_API int ecs_meta_set_string(ecs_meta_cursor_t *cursor, const char *value)
Set field with string value.
struct ecs_struct_desc_t ecs_struct_desc_t
Used with ecs_struct_init().
#define ECS_META_MAX_SCOPE_DEPTH
Maximum level of type nesting.
Definition meta.h:599
int32_t ecs_i32_t
Built-in i32 type.
Definition meta.h:105
FLECS_API int ecs_meta_member(ecs_meta_cursor_t *cursor, const char *name)
Move cursor to member.
FLECS_API ecs_entity_t ecs_enum_init(ecs_world_t *world, const ecs_enum_desc_t *desc)
Create a new enum type.
FLECS_API ecs_entity_t ecs_struct_init(ecs_world_t *world, const ecs_struct_desc_t *desc)
Create a new struct type.
FLECS_API int ecs_meta_try_member(ecs_meta_cursor_t *cursor, const char *name)
Same as ecs_meta_member(), but doesn't throw an error.
struct ecs_meta_op_t ecs_meta_op_t
Meta type serializer instruction data.
struct EcsType EcsType
Component that is automatically added to every type with the right kind.
FLECS_API int ecs_meta_set_bool(ecs_meta_cursor_t *cursor, bool value)
Set field with boolean value.
int8_t ecs_i8_t
Built-in i8 type.
Definition meta.h:103
unsigned char ecs_byte_t
Built-in ecs_byte type.
Definition meta.h:97
struct EcsUnitPrefix EcsUnitPrefix
Component that stores unit prefix data.
FLECS_API int ecs_meta_set_char(ecs_meta_cursor_t *cursor, char value)
Set field with char value.
struct ecs_unit_desc_t ecs_unit_desc_t
Used with ecs_unit_init().
struct ecs_meta_scope_t ecs_meta_scope_t
Type with information about the currently iterated scope.
#define ECS_MEMBER_DESC_CACHE_SIZE
Max number of constants and members that can be specified in desc structs.
Definition meta.h:79
FLECS_API int ecs_meta_try_dotmember(ecs_meta_cursor_t *cursor, const char *name)
Same as ecs_meta_dotmember(), but doesn't throw an error.
FLECS_API void * ecs_meta_get_ptr(ecs_meta_cursor_t *cursor)
Get pointer to current field.
struct EcsMemberRanges EcsMemberRanges
Component added to member entities to express valid value ranges.
struct EcsTypeSerializer EcsTypeSerializer
Component that stores the type serializer.
struct EcsUnit EcsUnit
Component that stores unit data.
FLECS_API int ecs_meta_set_value(ecs_meta_cursor_t *cursor, const ecs_value_t *value)
Set field with dynamic value.
FLECS_API int ecs_meta_set_null(ecs_meta_cursor_t *cursor)
Set field with null value.
FLECS_API ecs_entity_t ecs_array_init(ecs_world_t *world, const ecs_array_desc_t *desc)
Create a new array type.
FLECS_API int ecs_meta_set_entity(ecs_meta_cursor_t *cursor, ecs_entity_t value)
Set field with entity value.
FLECS_API ecs_id_t ecs_meta_get_id(const ecs_meta_cursor_t *cursor)
Get field value as (component) ID.
struct ecs_unit_prefix_desc_t ecs_unit_prefix_desc_t
Used with ecs_unit_prefix_init().
struct ecs_bitmask_desc_t ecs_bitmask_desc_t
Used with ecs_bitmask_init().
FLECS_API int ecs_meta_push(ecs_meta_cursor_t *cursor)
Push a scope (required and only valid for structs and collections).
@ EcsOpPrimitive
Marks first constant that's a primitive.
Definition meta.h:545
@ EcsOpOpaqueArray
Opaque array.
Definition meta.h:535
@ EcsOpOpaqueStruct
Opaque struct.
Definition meta.h:534
@ EcsOpScope
Marks last constant that can open or close a scope.
Definition meta.h:539
@ EcsOpPop
Pop scope.
Definition meta.h:532
@ EcsOpPushVector
Push vector.
Definition meta.h:531
@ EcsOpOpaqueVector
Opaque vector.
Definition meta.h:536
@ EcsOpPushStruct
Push struct.
Definition meta.h:529
@ EcsOpOpaqueValue
Opaque value.
Definition meta.h:541
@ EcsOpPushArray
Push array.
Definition meta.h:530
@ EcsOpForward
Forward to type.
Definition meta.h:537
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:381
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:425
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:374
Utility macros for populating reflection data in C.
Component added to array type entities.
Definition meta.h:319
int32_t count
Number of elements.
Definition meta.h:321
ecs_entity_t type
Element type.
Definition meta.h:320
Component added to bitmask type entities.
Definition meta.h:305
int32_t dummy_
Unused.
Definition meta.h:306
Component with data structures for looking up enum or bitmask constants.
Definition meta.h:310
ecs_vec_t ordered_constants
Stores the constants in registration order.
Definition meta.h:315
ecs_map_t * constants
Populated from child entities with Constant component.
Definition meta.h:312
Component added to enum type entities.
Definition meta.h:285
ecs_entity_t underlying_type
Underlying type for enum.
Definition meta.h:286
Component added to member entities to express valid value ranges.
Definition meta.h:213
ecs_member_value_range_t warning
Member value warning range.
Definition meta.h:215
ecs_member_value_range_t value
Member value range.
Definition meta.h:214
ecs_member_value_range_t error
Member value error range.
Definition meta.h:216
Component added to member entities.
Definition meta.h:198
ecs_entity_t unit
Member unit.
Definition meta.h:201
bool use_offset
If offset should be explicitly used.
Definition meta.h:203
ecs_entity_t type
Member type.
Definition meta.h:199
int32_t offset
Member offset.
Definition meta.h:202
int32_t count
Number of elements for inline arrays.
Definition meta.h:200
Opaque type reflection data.
Definition meta.h:408
size_t(* count)(const void *dst)
Return number of elements.
Definition meta.h:481
void(* assign_null)(void *dst)
Assign null value.
Definition meta.h:463
ecs_meta_serialize_member_t serialize_member
Serialize member action.
Definition meta.h:411
void(* clear)(void *dst)
Clear collection elements.
Definition meta.h:467
void(* assign_uint)(void *dst, uint64_t value)
Assign unsigned int value.
Definition meta.h:436
ecs_meta_serialize_t serialize
Serialize action.
Definition meta.h:410
void(* assign_char)(void *dst, char value)
Assign char value.
Definition meta.h:426
ecs_entity_t as_type
Type that describes the serialized output.
Definition meta.h:409
void(* assign_bool)(void *dst, bool value)
Assign bool value.
Definition meta.h:421
void(* assign_string)(void *dst, const char *value)
Assign string value.
Definition meta.h:446
void(* resize)(void *dst, size_t count)
Resize to number of elements.
Definition meta.h:485
void(* assign_int)(void *dst, int64_t value)
Assign int value.
Definition meta.h:431
void(* assign_float)(void *dst, double value)
Assign float value.
Definition meta.h:441
void(* assign_entity)(void *dst, ecs_world_t *world, ecs_entity_t entity)
Assign entity value.
Definition meta.h:451
void(* assign_id)(void *dst, ecs_world_t *world, ecs_id_t id)
Assign (component) ID value.
Definition meta.h:457
ecs_meta_serialize_element_t serialize_element
Serialize element action.
Definition meta.h:412
Component added to primitive types.
Definition meta.h:193
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:194
Component added to struct type entities.
Definition meta.h:264
ecs_vec_t members
Populated from child entities with Member component.
Definition meta.h:266
Component that stores the type serializer.
Definition meta.h:588
ecs_type_kind_t kind
Quick access to type kind (same as EcsType).
Definition meta.h:589
ecs_vec_t ops
vector<ecs_meta_op_t>
Definition meta.h:590
Component that is automatically added to every type with the right kind.
Definition meta.h:163
bool existing
Whether the type existed or was populated from reflection.
Definition meta.h:165
bool partial
Whether the reflection data is a partial type description.
Definition meta.h:166
ecs_type_kind_t kind
Type kind.
Definition meta.h:164
Component that stores unit prefix data.
Definition meta.h:515
ecs_unit_translation_t translation
Translation of prefix.
Definition meta.h:517
char * symbol
Symbol of prefix (e.g., "K", "M", "Ki").
Definition meta.h:516
Component that stores unit data.
Definition meta.h:506
ecs_unit_translation_t translation
Translation for derived unit.
Definition meta.h:511
ecs_entity_t prefix
Order of magnitude prefix relative to derived.
Definition meta.h:508
char * symbol
Unit symbol.
Definition meta.h:507
ecs_entity_t base
Base unit (e.g., "meters").
Definition meta.h:509
ecs_entity_t over
Over unit (e.g., "per second").
Definition meta.h:510
Component added to vector type entities.
Definition meta.h:325
ecs_entity_t type
Element type.
Definition meta.h:326
Used with ecs_array_init().
Definition meta.h:1083
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1084
ecs_entity_t type
Element type.
Definition meta.h:1085
int32_t count
Number of elements.
Definition meta.h:1086
Type that describes a bitmask constant.
Definition meta.h:290
ecs_flags64_t value
May be set when used with ecs_bitmask_desc_t.
Definition meta.h:295
int64_t _unused
Keep layout the same with ecs_enum_constant_t.
Definition meta.h:298
ecs_entity_t constant
Should not be set by ecs_bitmask_desc_t.
Definition meta.h:301
const char * name
Must be set when used with ecs_bitmask_desc_t.
Definition meta.h:292
Used with ecs_bitmask_init().
Definition meta.h:1065
ecs_bitmask_constant_t constants[(32)]
Bitmask constants.
Definition meta.h:1067
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1066
Used with ecs_entity_init().
Definition flecs.h:1042
Type that describes an enum constant.
Definition meta.h:270
ecs_entity_t constant
Should not be set by ecs_enum_desc_t.
Definition meta.h:281
uint64_t value_unsigned
For when the underlying type is unsigned.
Definition meta.h:278
int64_t value
May be set when used with ecs_enum_desc_t.
Definition meta.h:275
const char * name
Must be set when used with ecs_enum_desc_t.
Definition meta.h:272
Used with ecs_enum_init().
Definition meta.h:1046
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1047
ecs_entity_t underlying_type
Underlying type for enum.
Definition meta.h:1049
ecs_enum_constant_t constants[(32)]
Enum constants.
Definition meta.h:1048
Element type of members vector in EcsStruct.
Definition meta.h:220
ecs_member_value_range_t warning_range
Numerical range outside of which the value represents a warning.
Definition meta.h:254
const char * name
Must be set when used with ecs_struct_desc_t.
Definition meta.h:222
ecs_size_t size
Should not be set by ecs_struct_desc_t.
Definition meta.h:257
bool use_offset
Set to true to prevent automatic offset computation.
Definition meta.h:241
ecs_entity_t type
Member type.
Definition meta.h:225
ecs_entity_t member
Should not be set by ecs_struct_desc_t.
Definition meta.h:260
int32_t offset
May be set when used with ecs_struct_desc_t.
Definition meta.h:232
ecs_entity_t unit
May be set when used with ecs_struct_desc_t.
Definition meta.h:236
ecs_member_value_range_t range
Numerical range that specifies which values member can assume.
Definition meta.h:246
int32_t count
Element count (for inline arrays).
Definition meta.h:229
ecs_member_value_range_t error_range
Numerical range outside of which the value represents an error.
Definition meta.h:250
Type expressing a range for a member value.
Definition meta.h:207
double min
Min member value.
Definition meta.h:208
double max
Max member value.
Definition meta.h:209
Type that enables iterating and populating a value using reflection data.
Definition meta.h:618
ecs_meta_scope_t scope[(32)]
Cursor scope stack.
Definition meta.h:620
bool valid
Whether the cursor points to a valid field.
Definition meta.h:622
const ecs_world_t * world
The world.
Definition meta.h:619
void * lookup_ctx
Context for lookup_action.
Definition meta.h:627
int16_t depth
Current scope depth.
Definition meta.h:621
ecs_entity_t(* lookup_action)(ecs_world_t *, const char *, void *)
Custom entity lookup action for overriding default ecs_lookup().
Definition meta.h:626
bool is_primitive_scope
If in root scope, this allows for a push for primitive types.
Definition meta.h:623
Meta type serializer instruction data.
Definition meta.h:569
const char * name
Name of value (only used for struct members).
Definition meta.h:573
ecs_meta_op_kind_t kind
Instruction opcode.
Definition meta.h:570
ecs_hashmap_t * members
string -> member index (structs).
Definition meta.h:580
ecs_meta_serialize_t opaque
Serialize callback for opaque types.
Definition meta.h:582
const ecs_type_info_t * type_info
Type info.
Definition meta.h:578
ecs_map_t * constants
(u)int -> constant entity (enums and bitmasks).
Definition meta.h:581
int16_t member_index
Index of member in struct.
Definition meta.h:576
ecs_entity_t type
Type entity.
Definition meta.h:577
int16_t op_count
Number of operations until next field or end.
Definition meta.h:575
ecs_meta_op_kind_t underlying_kind
Underlying type kind (for enums).
Definition meta.h:571
ecs_size_t elem_size
Element size (for PushArray or PushVector) and element count (for PopArray).
Definition meta.h:574
ecs_size_t offset
Offset of current field.
Definition meta.h:572
Type with information about the currently iterated scope.
Definition meta.h:602
bool is_moved_scope
Whether the scope was moved in (with ecs_meta_elem(), for vectors).
Definition meta.h:613
int16_t ops_cur
Current element in ops.
Definition meta.h:606
const EcsOpaque * opaque
Opaque type interface.
Definition meta.h:609
int32_t elem_count
Set for collections.
Definition meta.h:614
void * ptr
Pointer to ops[0].
Definition meta.h:608
bool is_empty_scope
Whether the scope was populated (for vectors).
Definition meta.h:612
int16_t ops_count
Number of elements in ops.
Definition meta.h:605
ecs_meta_op_t * ops
The type operations (see ecs_meta_op_t).
Definition meta.h:604
ecs_hashmap_t * members
string -> member index.
Definition meta.h:610
int16_t prev_depth
Depth to restore, in case dotmember was used.
Definition meta.h:607
ecs_entity_t type
The type being iterated.
Definition meta.h:603
bool is_collection
Whether the scope is iterating elements.
Definition meta.h:611
Used with ecs_opaque_init().
Definition meta.h:1178
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1179
EcsOpaque type
Type that the opaque type maps to.
Definition meta.h:1180
Used with ecs_primitive_init().
Definition meta.h:1028
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1029
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:1030
Serializer interface.
Definition meta.h:335
void * ctx
Serializer context.
Definition meta.h:348
int(* value)(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.
Definition meta.h:337
int(* member)(const struct ecs_serializer_t *ser, const char *member)
Serialize member.
Definition meta.h:343
const ecs_world_t * world
The world.
Definition meta.h:347
Used with ecs_struct_init().
Definition meta.h:1120
ecs_member_t members[(32)]
Struct members.
Definition meta.h:1122
bool create_member_entities
Create entities for members.
Definition meta.h:1123
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1121
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1019
Used with ecs_unit_init().
Definition meta.h:1212
ecs_entity_t base
Base unit, e.g., "meters" (optional).
Definition meta.h:1223
ecs_entity_t over
Over unit, e.g., "per second" (optional).
Definition meta.h:1226
const char * symbol
Unit symbol, e.g., "m", "%", "g".
Definition meta.h:1217
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1237
ecs_entity_t quantity
Unit quantity, e.g., distance, percentage, weight.
Definition meta.h:1220
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1229
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1214
Used with ecs_unit_prefix_init().
Definition meta.h:1253
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1255
const char * symbol
Unit prefix symbol, e.g., "K", "M", "Ki".
Definition meta.h:1258
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1261
Helper type to describe translation between two units.
Definition meta.h:500
int32_t power
Power to apply to factor (e.g., "1", "3", "-9").
Definition meta.h:502
int32_t factor
Factor to apply (e.g., "1000", "1000000", "1024").
Definition meta.h:501
Utility to hold a value of a dynamic type.
Definition flecs.h:1033
Used with ecs_vector_init().
Definition meta.h:1102
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1103
ecs_entity_t type
Element type.
Definition meta.h:1104