Flecs v4.0
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
285typedef struct EcsEnum {
286 ecs_entity_t underlying_type;
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 {
336 /* Serialize value */
337 int (*value)(
338 const struct ecs_serializer_t *ser,
339 ecs_entity_t type,
340 const void *value);
342 /* Serialize member */
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);
407typedef struct EcsOpaque {
413 /* Deserializer interface
414 * Only override the callbacks that are valid for the opaque type. If a
415 * deserializer attempts to assign a value type that is not supported by the
416 * interface, a conversion error is thrown.
417 */
418
420 void (*assign_bool)(
421 void *dst,
422 bool value);
423
425 void (*assign_char)(
426 void *dst,
427 char value);
428
430 void (*assign_int)(
431 void *dst,
432 int64_t value);
433
435 void (*assign_uint)(
436 void *dst,
437 uint64_t value);
438
441 void *dst,
442 double value);
443
446 void *dst,
447 const char *value);
448
451 void *dst,
452 ecs_world_t *world,
453 ecs_entity_t entity);
454
456 void (*assign_id)(
457 void *dst,
458 ecs_world_t *world,
459 ecs_id_t id);
460
462 void (*assign_null)(
463 void *dst);
464
466 void (*clear)(
467 void *dst);
468
470 void* (*ensure_element)(
471 void *dst,
472 size_t elem);
473
475 void* (*ensure_member)(
476 void *dst,
477 const char *member);
478
480 size_t (*count)(
481 const void *dst);
482
484 void (*resize)(
485 void *dst,
486 size_t count);
488
489
490/* Units */
491
503
512
518
519
520/* Serializer utilities */
521
527typedef enum ecs_meta_op_kind_t {
541 EcsOpEnum,
542 EcsOpBitmask,
543
546 EcsOpBool,
547 EcsOpChar,
548 EcsOpByte,
549 EcsOpU8,
550 EcsOpU16,
551 EcsOpU32,
552 EcsOpU64,
553 EcsOpI8,
554 EcsOpI16,
555 EcsOpI32,
556 EcsOpI64,
557 EcsOpF32,
558 EcsOpF64,
559 EcsOpUPtr,
560 EcsOpIPtr,
561 EcsOpString,
562 EcsOpEntity,
563 EcsOpId,
564 EcsMetaTypeOpKindLast = EcsOpId
566
584
591
592
593/* Deserializer utilities */
594
598#define ECS_META_MAX_SCOPE_DEPTH (32)
599
615
628
630FLECS_API
632 ecs_world_t *world,
633 ecs_entity_t type);
634
649FLECS_API
651 const ecs_world_t *world,
652 ecs_entity_t type,
653 void *ptr);
654
660FLECS_API
662 ecs_meta_cursor_t *cursor);
663
669FLECS_API
671 ecs_meta_cursor_t *cursor);
672
678FLECS_API
680 ecs_meta_cursor_t *cursor,
681 int32_t elem);
682
689FLECS_API
691 ecs_meta_cursor_t *cursor,
692 const char *name);
693
701FLECS_API
703 ecs_meta_cursor_t *cursor,
704 const char *name);
705
714FLECS_API
716 ecs_meta_cursor_t *cursor,
717 const char *name);
718
726FLECS_API
728 ecs_meta_cursor_t *cursor,
729 const char *name);
730
736FLECS_API
738 ecs_meta_cursor_t *cursor);
739
745FLECS_API
747 ecs_meta_cursor_t *cursor);
748
754FLECS_API
756 const ecs_meta_cursor_t *cursor);
757
763FLECS_API
765 const ecs_meta_cursor_t *cursor);
766
772FLECS_API
774 const ecs_meta_cursor_t *cursor);
775
781FLECS_API
783 const ecs_meta_cursor_t *cursor);
784
790FLECS_API
792 const ecs_meta_cursor_t *cursor);
793
794/* The set functions assign the field with the specified value. If the value
795 * does not have the same type as the field, it will be cased to the field type.
796 * If no valid conversion is available, the operation will fail. */
797
804FLECS_API
806 ecs_meta_cursor_t *cursor,
807 bool value);
808
815FLECS_API
817 ecs_meta_cursor_t *cursor,
818 char value);
819
826FLECS_API
828 ecs_meta_cursor_t *cursor,
829 int64_t value);
830
837FLECS_API
839 ecs_meta_cursor_t *cursor,
840 uint64_t value);
841
848FLECS_API
850 ecs_meta_cursor_t *cursor,
851 double value);
852
859FLECS_API
861 ecs_meta_cursor_t *cursor,
862 const char *value);
863
870FLECS_API
872 ecs_meta_cursor_t *cursor,
873 const char *value);
874
881FLECS_API
883 ecs_meta_cursor_t *cursor,
884 ecs_entity_t value);
885
892FLECS_API
894 ecs_meta_cursor_t *cursor,
895 ecs_id_t value);
896
902FLECS_API
904 ecs_meta_cursor_t *cursor);
905
912FLECS_API
914 ecs_meta_cursor_t *cursor,
915 const ecs_value_t *value);
916
917/* Functions for getting members. */
918
924FLECS_API
926 const ecs_meta_cursor_t *cursor);
927
933FLECS_API
935 const ecs_meta_cursor_t *cursor);
936
942FLECS_API
944 const ecs_meta_cursor_t *cursor);
945
951FLECS_API
953 const ecs_meta_cursor_t *cursor);
954
960FLECS_API
962 const ecs_meta_cursor_t *cursor);
963
971FLECS_API
973 const ecs_meta_cursor_t *cursor);
974
981FLECS_API
983 const ecs_meta_cursor_t *cursor);
984
991FLECS_API
993 const ecs_meta_cursor_t *cursor);
994
1001FLECS_API
1003 ecs_primitive_kind_t type_kind,
1004 const void *ptr);
1005
1014FLECS_API
1016 const ecs_meta_op_t *op,
1017 const void *ptr);
1018
1019/* API functions for creating meta types */
1020
1026
1033FLECS_API
1035 ecs_world_t *world,
1036 const ecs_primitive_desc_t *desc);
1037
1038
1045
1052FLECS_API
1054 ecs_world_t *world,
1055 const ecs_enum_desc_t *desc);
1056
1057
1063
1070FLECS_API
1072 ecs_world_t *world,
1073 const ecs_bitmask_desc_t *desc);
1074
1075
1082
1089FLECS_API
1091 ecs_world_t *world,
1092 const ecs_array_desc_t *desc);
1093
1094
1100
1107FLECS_API
1109 ecs_world_t *world,
1110 const ecs_vector_desc_t *desc);
1111
1112
1118
1125FLECS_API
1127 ecs_world_t *world,
1128 const ecs_struct_desc_t *desc);
1129
1130
1136
1159FLECS_API
1161 ecs_world_t *world,
1162 const ecs_opaque_desc_t *desc);
1163
1164
1193
1200FLECS_API
1202 ecs_world_t *world,
1203 const ecs_unit_desc_t *desc);
1204
1205
1217
1224FLECS_API
1226 ecs_world_t *world,
1227 const ecs_unit_prefix_desc_t *desc);
1228
1229
1236FLECS_API
1238 ecs_world_t *world,
1239 const ecs_entity_desc_t *desc);
1240
1241/* Convenience macros */
1242
1244#define ecs_primitive(world, ...)\
1245 ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )
1246
1248#define ecs_enum(world, ...)\
1249 ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )
1250
1252#define ecs_bitmask(world, ...)\
1253 ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )
1254
1256#define ecs_array(world, ...)\
1257 ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )
1258
1260#define ecs_vector(world, ...)\
1261 ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )
1262
1264#define ecs_opaque(world, ...)\
1265 ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )
1266
1268#define ecs_struct(world, ...)\
1269 ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )
1270
1272#define ecs_unit(world, ...)\
1273 ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )
1274
1276#define ecs_unit_prefix(world, ...)\
1277 ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )
1278
1280#define ecs_quantity(world, ...)\
1281 ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
1282
1283
1292FLECS_API
1294 ecs_world_t *world);
1295
1296#ifdef __cplusplus
1297}
1298#endif
1299
1300#include "meta_c.h"
1301
1302#endif
1303
1306#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
Builtin 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 an bitmask constant.
int16_t ecs_i16_t
Builtin i16 type.
Definition meta.h:104
struct ecs_meta_cursor_t ecs_meta_cursor_t
Type that enables iterating/populating a value using reflection data.
ecs_meta_op_kind_t
Serializer instruction opcodes.
Definition meta.h:527
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
Builtin 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/array element.
Definition meta.h:398
struct EcsVector EcsVector
Component added to vector type entities.
int64_t ecs_i64_t
Builtin 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?.
struct ecs_serializer_t ecs_serializer_t
Serializer interface.
char * ecs_string_t
Builtin 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
Builtin u64 type.
Definition meta.h:101
intptr_t ecs_iptr_t
Builtin 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/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
Builtin 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
Builtin 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.
struct ecs_array_desc_t ecs_array_desc_t
Used with ecs_array_init().
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
Builtin f64 type.
Definition meta.h:109
char ecs_char_t
Builtin 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 datastructures for looking up enum/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
Builtin 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:598
int32_t ecs_i32_t
Builtin 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
Builtin i8 type.
Definition meta.h:103
unsigned char ecs_byte_t
Builtin 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 currently serialized scope.
#define ECS_MEMBER_DESC_CACHE_SIZE
Max number of constants/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/only valid for structs & collections).
@ EcsOpPrimitive
Marks first constant that's a primitive.
Definition meta.h:544
@ EcsOpOpaqueArray
Opaque array.
Definition meta.h:534
@ EcsOpOpaqueStruct
Opaque struct.
Definition meta.h:533
@ EcsOpScope
Marks last constant that can open/close a scope.
Definition meta.h:538
@ EcsOpPop
Pop scope.
Definition meta.h:531
@ EcsOpPushVector
Push vector.
Definition meta.h:530
@ EcsOpOpaqueVector
Opaque vector.
Definition meta.h:535
@ EcsOpPushStruct
Push struct.
Definition meta.h:528
@ EcsOpOpaqueValue
Opaque value.
Definition meta.h:540
@ EcsOpPushArray
Push array.
Definition meta.h:529
@ EcsOpForward
Forward to type.
Definition meta.h:536
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:365
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:409
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:358
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
Component with datastructures for looking up enum/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
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:407
size_t(* count)(const void *dst)
Return number of elements.
Definition meta.h:480
void(* assign_null)(void *dst)
Assign null value.
Definition meta.h:462
ecs_meta_serialize_member_t serialize_member
Serialize member action.
Definition meta.h:410
void(* clear)(void *dst)
Clear collection elements.
Definition meta.h:466
void(* assign_uint)(void *dst, uint64_t value)
Assign unsigned int value.
Definition meta.h:435
ecs_meta_serialize_t serialize
Serialize action.
Definition meta.h:409
void(* assign_char)(void *dst, char value)
Assign char value.
Definition meta.h:425
ecs_entity_t as_type
Type that describes the serialized output.
Definition meta.h:408
void(* assign_bool)(void *dst, bool value)
Assign bool value.
Definition meta.h:420
void(* assign_string)(void *dst, const char *value)
Assign string value.
Definition meta.h:445
void(* resize)(void *dst, size_t count)
Resize to number of elements.
Definition meta.h:484
void(* assign_int)(void *dst, int64_t value)
Assign int value.
Definition meta.h:430
void(* assign_float)(void *dst, double value)
Assign float value.
Definition meta.h:440
void(* assign_entity)(void *dst, ecs_world_t *world, ecs_entity_t entity)
Assign entity value.
Definition meta.h:450
void(* assign_id)(void *dst, ecs_world_t *world, ecs_id_t id)
Assign (component) id value.
Definition meta.h:456
ecs_meta_serialize_element_t serialize_element
Serialize element action.
Definition meta.h:411
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:587
ecs_type_kind_t kind
Quick access to type kind (same as EcsType)
Definition meta.h:588
ecs_vec_t ops
vector<ecs_meta_op_t>
Definition meta.h:589
Component that is automatically added to every type with the right kind.
Definition meta.h:163
bool existing
Did the type exist or is it populated from reflection.
Definition meta.h:165
bool partial
Is the reflection data 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:514
ecs_unit_translation_t translation
Translation of prefix.
Definition meta.h:516
char * symbol
Symbol of prefix (e.g.
Definition meta.h:515
Component that stores unit data.
Definition meta.h:505
ecs_unit_translation_t translation
Translation for derived unit.
Definition meta.h:510
ecs_entity_t prefix
Order of magnitude prefix relative to derived.
Definition meta.h:507
char * symbol
Unit symbol.
Definition meta.h:506
ecs_entity_t base
Base unit (e.g.
Definition meta.h:508
ecs_entity_t over
Over unit (e.g.
Definition meta.h:509
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:1077
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1078
ecs_entity_t type
Element type.
Definition meta.h:1079
int32_t count
Number of elements.
Definition meta.h:1080
Type that describes an 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:1059
ecs_bitmask_constant_t constants[(32)]
Bitmask constants.
Definition meta.h:1061
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1060
Used with ecs_entity_init().
Definition flecs.h:1023
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:1040
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1041
ecs_enum_constant_t constants[(32)]
Enum constants.
Definition meta.h:1042
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 an 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, will be auto-populated if type entity is also a unit.
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/populating a value using reflection data.
Definition meta.h:617
ecs_meta_scope_t scope[(32)]
Cursor scope stack.
Definition meta.h:619
bool valid
Does the cursor point to a valid field.
Definition meta.h:621
const ecs_world_t * world
The world.
Definition meta.h:618
void * lookup_ctx
Context for lookup_action.
Definition meta.h:626
int16_t depth
Current scope depth.
Definition meta.h:620
ecs_entity_t(* lookup_action)(ecs_world_t *, const char *, void *)
Custom entity lookup action for overriding default ecs_lookup.
Definition meta.h:625
bool is_primitive_scope
If in root scope, this allows for a push for primitive types.
Definition meta.h:622
Meta type serializer instruction data.
Definition meta.h:568
const char * name
Name of value (only used for struct members)
Definition meta.h:572
ecs_meta_op_kind_t kind
Instruction opcode.
Definition meta.h:569
ecs_hashmap_t * members
string -> member index (structs)
Definition meta.h:579
ecs_meta_serialize_t opaque
Serialize callback for opaque types.
Definition meta.h:581
const ecs_type_info_t * type_info
Type info.
Definition meta.h:577
ecs_map_t * constants
(u)int -> constant entity (enums/bitmasks)
Definition meta.h:580
int16_t member_index
Index of member in struct.
Definition meta.h:575
ecs_entity_t type
Type entity.
Definition meta.h:576
int16_t op_count
Number of operations until next field or end.
Definition meta.h:574
ecs_meta_op_kind_t underlying_kind
Underlying type kind (for enums).
Definition meta.h:570
ecs_size_t elem_size
Element size (for PushArray/PushVector) and element count (for PopArray)
Definition meta.h:573
ecs_size_t offset
Offset of current field.
Definition meta.h:571
Type with information about currently serialized scope.
Definition meta.h:601
bool is_moved_scope
Was scope moved in (with ecs_meta_elem, for vectors)
Definition meta.h:612
int16_t ops_cur
Current element in ops.
Definition meta.h:605
const EcsOpaque * opaque
Opaque type interface.
Definition meta.h:608
int32_t elem_count
Set for collections.
Definition meta.h:613
void * ptr
Pointer to ops[0].
Definition meta.h:607
bool is_empty_scope
Was scope populated (for vectors)
Definition meta.h:611
int16_t ops_count
Number of elements in ops.
Definition meta.h:604
ecs_meta_op_t * ops
The type operations (see ecs_meta_op_t)
Definition meta.h:603
ecs_hashmap_t * members
string -> member index
Definition meta.h:609
int16_t prev_depth
Depth to restore, in case dotmember was used.
Definition meta.h:606
ecs_entity_t type
The type being iterated.
Definition meta.h:602
bool is_collection
Is the scope iterating elements?
Definition meta.h:610
Used with ecs_opaque_init().
Definition meta.h:1132
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1133
EcsOpaque type
Type that the opaque type maps to.
Definition meta.h:1134
Used with ecs_primitive_init().
Definition meta.h:1022
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1023
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:1024
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)
Pointer to the value to serialize.
Definition meta.h:337
int(* member)(const struct ecs_serializer_t *ser, const char *member)
Member name.
Definition meta.h:343
const ecs_world_t * world
The world.
Definition meta.h:347
Used with ecs_struct_init().
Definition meta.h:1114
ecs_member_t members[(32)]
Struct members.
Definition meta.h:1116
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1115
Type that contains component information (passed to ctors/dtors/...)
Definition flecs.h:1000
Used with ecs_unit_init().
Definition meta.h:1166
ecs_entity_t base
Base unit, e.g.
Definition meta.h:1177
ecs_entity_t over
Over unit, e.g.
Definition meta.h:1180
const char * symbol
Unit symbol, e.g.
Definition meta.h:1171
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1191
ecs_entity_t quantity
Unit quantity, e.g.
Definition meta.h:1174
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1183
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1168
Used with ecs_unit_prefix_init().
Definition meta.h:1207
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1209
const char * symbol
Unit symbol, e.g.
Definition meta.h:1212
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1215
Helper type to describe translation between two units.
Definition meta.h:499
int32_t power
Power to apply to factor (e.g.
Definition meta.h:501
int32_t factor
Factor to apply (e.g.
Definition meta.h:500
Utility to hold a value of a dynamic type.
Definition flecs.h:1014
Used with ecs_vector_init().
Definition meta.h:1096
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1097
ecs_entity_t type
Element type.
Definition meta.h:1098