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#include <stddef.h>
68
69#ifndef FLECS_MODULE
70#define FLECS_MODULE
71#endif
72
73#ifndef FLECS_META_H
74#define FLECS_META_H
75
76#ifdef __cplusplus
77extern "C" {
78#endif
79
81#define ECS_MEMBER_DESC_CACHE_SIZE (32)
82
97typedef bool ecs_bool_t;
98typedef char ecs_char_t;
99typedef unsigned char ecs_byte_t;
100typedef uint8_t ecs_u8_t;
101typedef uint16_t ecs_u16_t;
102typedef uint32_t ecs_u32_t;
103typedef uint64_t ecs_u64_t;
104typedef uintptr_t ecs_uptr_t;
105typedef int8_t ecs_i8_t;
106typedef int16_t ecs_i16_t;
107typedef int32_t ecs_i32_t;
108typedef int64_t ecs_i64_t;
109typedef intptr_t ecs_iptr_t;
110typedef float ecs_f32_t;
111typedef double ecs_f64_t;
112typedef char* ecs_string_t;
114/* Meta module component ids */
115FLECS_API extern const ecs_entity_t ecs_id(EcsType);
116FLECS_API extern const ecs_entity_t ecs_id(EcsTypeSerializer);
117FLECS_API extern const ecs_entity_t ecs_id(EcsPrimitive);
118FLECS_API extern const ecs_entity_t ecs_id(EcsEnum);
119FLECS_API extern const ecs_entity_t ecs_id(EcsBitmask);
120FLECS_API extern const ecs_entity_t ecs_id(EcsMember);
121FLECS_API extern const ecs_entity_t ecs_id(EcsMemberRanges);
122FLECS_API extern const ecs_entity_t ecs_id(EcsStruct);
123FLECS_API extern const ecs_entity_t ecs_id(EcsArray);
124FLECS_API extern const ecs_entity_t ecs_id(EcsVector);
125FLECS_API extern const ecs_entity_t ecs_id(EcsOpaque);
126FLECS_API extern const ecs_entity_t ecs_id(EcsUnit);
127FLECS_API extern const ecs_entity_t ecs_id(EcsUnitPrefix);
128FLECS_API extern const ecs_entity_t EcsConstant;
129FLECS_API extern const ecs_entity_t EcsQuantity;
131/* Primitive type component ids */
132
133FLECS_API extern const ecs_entity_t ecs_id(ecs_bool_t);
134FLECS_API extern const ecs_entity_t ecs_id(ecs_char_t);
135FLECS_API extern const ecs_entity_t ecs_id(ecs_byte_t);
136FLECS_API extern const ecs_entity_t ecs_id(ecs_u8_t);
137FLECS_API extern const ecs_entity_t ecs_id(ecs_u16_t);
138FLECS_API extern const ecs_entity_t ecs_id(ecs_u32_t);
139FLECS_API extern const ecs_entity_t ecs_id(ecs_u64_t);
140FLECS_API extern const ecs_entity_t ecs_id(ecs_uptr_t);
141FLECS_API extern const ecs_entity_t ecs_id(ecs_i8_t);
142FLECS_API extern const ecs_entity_t ecs_id(ecs_i16_t);
143FLECS_API extern const ecs_entity_t ecs_id(ecs_i32_t);
144FLECS_API extern const ecs_entity_t ecs_id(ecs_i64_t);
145FLECS_API extern const ecs_entity_t ecs_id(ecs_iptr_t);
146FLECS_API extern const ecs_entity_t ecs_id(ecs_f32_t);
147FLECS_API extern const ecs_entity_t ecs_id(ecs_f64_t);
148FLECS_API extern const ecs_entity_t ecs_id(ecs_string_t);
149FLECS_API extern const ecs_entity_t ecs_id(ecs_entity_t);
150FLECS_API extern const ecs_entity_t ecs_id(ecs_id_t);
153typedef enum ecs_type_kind_t {
154 EcsPrimitiveType,
155 EcsBitmaskType,
156 EcsEnumType,
157 EcsStructType,
158 EcsArrayType,
159 EcsVectorType,
160 EcsOpaqueType,
161 EcsTypeKindLast = EcsOpaqueType
163
170
173 EcsBool = 1,
174 EcsChar,
175 EcsByte,
176 EcsU8,
177 EcsU16,
178 EcsU32,
179 EcsU64,
180 EcsI8,
181 EcsI16,
182 EcsI32,
183 EcsI64,
184 EcsF32,
185 EcsF64,
186 EcsUPtr,
187 EcsIPtr,
188 EcsString,
189 EcsEntity,
190 EcsId,
191 EcsPrimitiveKindLast = EcsId
193
198
207
213
220
263
265typedef struct EcsStruct {
267 ecs_vec_t members; /* vector<ecs_member_t> */
269
271typedef struct ecs_enum_constant_t {
273 const char *name;
274
276 int64_t value;
277
280
284
286typedef struct EcsEnum {
287 ecs_entity_t underlying_type;
288
290 ecs_map_t constants;
292
296 const char *name;
297
299 ecs_flags64_t value;
300
302 int64_t _unused;
303
307
309typedef struct EcsBitmask {
310 /* Populated from child entities with Constant component */
311 ecs_map_t constants;
313
319
324
325
326/* Opaque type support */
327
328#if !defined(__cplusplus) || !defined(FLECS_CPP)
329
331typedef struct ecs_serializer_t {
332 /* Serialize value */
333 int (*value)(
334 const struct ecs_serializer_t *ser,
335 ecs_entity_t type,
336 const void *value);
338 /* Serialize member */
339 int (*member)(
340 const struct ecs_serializer_t *ser,
341 const char *member);
344 void *ctx;
346
347#elif defined(__cplusplus)
348
349} /* extern "C" { */
350
352typedef struct ecs_serializer_t {
353 /* Serialize value */
354 int (*value_)(
355 const struct ecs_serializer_t *ser,
356 ecs_entity_t type,
357 const void *value);
358
359 /* Serialize member */
360 int (*member_)(
361 const struct ecs_serializer_t *ser,
362 const char *name);
363
364 /* Serialize value */
365 int value(ecs_entity_t type, const void *value) const;
366
367 /* Serialize value */
368 template <typename T>
369 int value(const T& value) const;
370
371 /* Serialize member */
372 int member(const char *name) const;
373
374 const ecs_world_t *world;
375 void *ctx;
377
378extern "C" {
379#endif
380
382typedef int (*ecs_meta_serialize_t)(
383 const ecs_serializer_t *ser,
384 const void *src);
390typedef struct EcsOpaque {
394 /* Deserializer interface
395 * Only override the callbacks that are valid for the opaque type. If a
396 * deserializer attempts to assign a value type that is not supported by the
397 * interface, a conversion error is thrown.
398 */
399
401 void (*assign_bool)(
402 void *dst,
403 bool value);
404
406 void (*assign_char)(
407 void *dst,
408 char value);
409
411 void (*assign_int)(
412 void *dst,
413 int64_t value);
414
416 void (*assign_uint)(
417 void *dst,
418 uint64_t value);
419
422 void *dst,
423 double value);
424
427 void *dst,
428 const char *value);
429
432 void *dst,
433 ecs_world_t *world,
434 ecs_entity_t entity);
435
437 void (*assign_id)(
438 void *dst,
439 ecs_world_t *world,
440 ecs_id_t id);
441
443 void (*assign_null)(
444 void *dst);
445
447 void (*clear)(
448 void *dst);
449
451 void* (*ensure_element)(
452 void *dst,
453 size_t elem);
454
456 void* (*ensure_member)(
457 void *dst,
458 const char *member);
459
461 size_t (*count)(
462 const void *dst);
463
465 void (*resize)(
466 void *dst,
467 size_t count);
469
470
471/* Units */
472
484
493
499
500
501/* Serializer utilities */
502
509 EcsOpArray,
510 EcsOpVector,
511 EcsOpOpaque,
512 EcsOpPush,
513 EcsOpPop,
514
517 EcsOpEnum,
518 EcsOpBitmask,
519
522 EcsOpBool,
523 EcsOpChar,
524 EcsOpByte,
525 EcsOpU8,
526 EcsOpU16,
527 EcsOpU32,
528 EcsOpU64,
529 EcsOpI8,
530 EcsOpI16,
531 EcsOpI32,
532 EcsOpI64,
533 EcsOpF32,
534 EcsOpF64,
535 EcsOpUPtr,
536 EcsOpIPtr,
537 EcsOpString,
538 EcsOpEntity,
539 EcsOpId,
540 EcsMetaTypeOpKindLast = EcsOpId
542
544typedef struct ecs_meta_type_op_t {
546 ecs_size_t offset;
547 int32_t count;
548 const char *name;
549 int32_t op_count;
550 ecs_size_t size;
552 int32_t member_index;
553 ecs_hashmap_t *members;
555
559typedef struct EcsTypeSerializer {
560 ecs_vec_t ops;
562
563
564/* Deserializer utilities */
565
569#define ECS_META_MAX_SCOPE_DEPTH (32)
570
588
601
616FLECS_API
618 const ecs_world_t *world,
619 ecs_entity_t type,
620 void *ptr);
621
627FLECS_API
629 ecs_meta_cursor_t *cursor);
630
636FLECS_API
638 ecs_meta_cursor_t *cursor);
639
645FLECS_API
647 ecs_meta_cursor_t *cursor,
648 int32_t elem);
649
656FLECS_API
658 ecs_meta_cursor_t *cursor,
659 const char *name);
660
668FLECS_API
670 ecs_meta_cursor_t *cursor,
671 const char *name);
672
678FLECS_API
680 ecs_meta_cursor_t *cursor);
681
687FLECS_API
689 ecs_meta_cursor_t *cursor);
690
696FLECS_API
698 const ecs_meta_cursor_t *cursor);
699
705FLECS_API
707 const ecs_meta_cursor_t *cursor);
708
714FLECS_API
716 const ecs_meta_cursor_t *cursor);
717
723FLECS_API
725 const ecs_meta_cursor_t *cursor);
726
732FLECS_API
734 const ecs_meta_cursor_t *cursor);
735
736/* The set functions assign the field with the specified value. If the value
737 * does not have the same type as the field, it will be cased to the field type.
738 * If no valid conversion is available, the operation will fail. */
739
746FLECS_API
748 ecs_meta_cursor_t *cursor,
749 bool value);
750
757FLECS_API
759 ecs_meta_cursor_t *cursor,
760 char value);
761
768FLECS_API
770 ecs_meta_cursor_t *cursor,
771 int64_t value);
772
779FLECS_API
781 ecs_meta_cursor_t *cursor,
782 uint64_t value);
783
790FLECS_API
792 ecs_meta_cursor_t *cursor,
793 double value);
794
801FLECS_API
803 ecs_meta_cursor_t *cursor,
804 const char *value);
805
812FLECS_API
814 ecs_meta_cursor_t *cursor,
815 const char *value);
816
823FLECS_API
825 ecs_meta_cursor_t *cursor,
826 ecs_entity_t value);
827
834FLECS_API
836 ecs_meta_cursor_t *cursor,
837 ecs_id_t value);
838
844FLECS_API
846 ecs_meta_cursor_t *cursor);
847
854FLECS_API
856 ecs_meta_cursor_t *cursor,
857 const ecs_value_t *value);
858
859/* Functions for getting members. */
860
866FLECS_API
868 const ecs_meta_cursor_t *cursor);
869
875FLECS_API
877 const ecs_meta_cursor_t *cursor);
878
884FLECS_API
886 const ecs_meta_cursor_t *cursor);
887
893FLECS_API
895 const ecs_meta_cursor_t *cursor);
896
902FLECS_API
904 const ecs_meta_cursor_t *cursor);
905
913FLECS_API
915 const ecs_meta_cursor_t *cursor);
916
923FLECS_API
925 const ecs_meta_cursor_t *cursor);
926
934 const ecs_meta_cursor_t *cursor);
935
942FLECS_API
944 ecs_primitive_kind_t type_kind,
945 const void *ptr);
946
947/* API functions for creating meta types */
948
954
961FLECS_API
963 ecs_world_t *world,
964 const ecs_primitive_desc_t *desc);
965
966
973
980FLECS_API
982 ecs_world_t *world,
983 const ecs_enum_desc_t *desc);
984
985
991
998FLECS_API
1000 ecs_world_t *world,
1001 const ecs_bitmask_desc_t *desc);
1002
1003
1010
1017FLECS_API
1019 ecs_world_t *world,
1020 const ecs_array_desc_t *desc);
1021
1022
1028
1035FLECS_API
1037 ecs_world_t *world,
1038 const ecs_vector_desc_t *desc);
1039
1040
1046
1053FLECS_API
1055 ecs_world_t *world,
1056 const ecs_struct_desc_t *desc);
1057
1058
1064
1087FLECS_API
1089 ecs_world_t *world,
1090 const ecs_opaque_desc_t *desc);
1091
1092
1121
1128FLECS_API
1130 ecs_world_t *world,
1131 const ecs_unit_desc_t *desc);
1132
1133
1145
1152FLECS_API
1154 ecs_world_t *world,
1155 const ecs_unit_prefix_desc_t *desc);
1156
1157
1164FLECS_API
1166 ecs_world_t *world,
1167 const ecs_entity_desc_t *desc);
1168
1169/* Convenience macros */
1170
1172#define ecs_primitive(world, ...)\
1173 ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )
1174
1176#define ecs_enum(world, ...)\
1177 ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )
1178
1180#define ecs_bitmask(world, ...)\
1181 ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )
1182
1184#define ecs_array(world, ...)\
1185 ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )
1186
1188#define ecs_vector(world, ...)\
1189 ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )
1190
1192#define ecs_opaque(world, ...)\
1193 ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )
1194
1196#define ecs_struct(world, ...)\
1197 ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )
1198
1200#define ecs_unit(world, ...)\
1201 ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )
1202
1204#define ecs_unit_prefix(world, ...)\
1205 ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )
1206
1208#define ecs_quantity(world, ...)\
1209 ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
1210
1211
1220FLECS_API
1222 ecs_world_t *world);
1223
1224#ifdef __cplusplus
1225}
1226#endif
1227
1228#include "meta_c.h"
1229
1230#endif
1231
1234#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.
ecs_id_t ecs_meta_get_id(const ecs_meta_cursor_t *cursor)
Get field value as (component) id.
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:97
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.
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:102
struct ecs_meta_type_op_t ecs_meta_type_op_t
Meta type serializer instruction data.
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:106
struct ecs_meta_cursor_t ecs_meta_cursor_t
Type that enables iterating/populating a value using reflection data.
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:100
struct ecs_member_t ecs_member_t
Element type of members vector in EcsStruct.
struct EcsVector EcsVector
Component added to vector type entities.
int64_t ecs_i64_t
Builtin i64 type.
Definition meta.h:108
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:112
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.
FLECS_API const ecs_entity_t EcsConstant
Tag added to enum/bitmask constants.
uint64_t ecs_u64_t
Builtin u64 type.
Definition meta.h:103
intptr_t ecs_iptr_t
Builtin iptr type.
Definition meta.h:109
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 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:104
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:110
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:172
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.
ecs_meta_type_op_kind_t
Serializer instruction opcodes.
Definition meta.h:508
double ecs_f64_t
Builtin f64 type.
Definition meta.h:111
char ecs_char_t
Builtin char type.
Definition meta.h:98
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().
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:153
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:101
int(* ecs_meta_serialize_t)(const ecs_serializer_t *ser, const void *src)
Callback invoked serializing an opaque type.
Definition meta.h:382
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:569
int32_t ecs_i32_t
Builtin i32 type.
Definition meta.h:107
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.
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:105
unsigned char ecs_byte_t
Builtin ecs_byte type.
Definition meta.h:99
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:81
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.
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:520
@ EcsOpScope
Marks last constant that can open/close a scope.
Definition meta.h:515
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:346
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:390
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:339
Utility macros for populating reflection data in C.
Component added to array type entities.
Definition meta.h:315
int32_t count
Number of elements.
Definition meta.h:317
ecs_entity_t type
Element type.
Definition meta.h:316
Component added to bitmask type entities.
Definition meta.h:309
ecs_map_t constants
map<u32_t, ecs_bitmask_constant_t>
Definition meta.h:311
Component information.
Definition flecs.h:1488
Component added to enum type entities.
Definition meta.h:286
ecs_map_t constants
Populated from child entities with Constant component.
Definition meta.h:290
Component added to member entities to express valid value ranges.
Definition meta.h:215
ecs_member_value_range_t warning
Member value warning range.
Definition meta.h:217
ecs_member_value_range_t value
Member value range.
Definition meta.h:216
ecs_member_value_range_t error
Member value error range.
Definition meta.h:218
Component added to member entities.
Definition meta.h:200
ecs_entity_t unit
Member unit.
Definition meta.h:203
bool use_offset
If offset should be explicitly used.
Definition meta.h:205
ecs_entity_t type
Member type.
Definition meta.h:201
int32_t offset
Member offset.
Definition meta.h:204
int32_t count
Number of elements (for inline arrays).
Definition meta.h:202
Opaque type reflection data.
Definition meta.h:390
size_t(* count)(const void *dst)
Return number of elements.
Definition meta.h:461
void(* assign_null)(void *dst)
Assign null value.
Definition meta.h:443
void(* clear)(void *dst)
Clear collection elements.
Definition meta.h:447
void(* assign_uint)(void *dst, uint64_t value)
Assign unsigned int value.
Definition meta.h:416
ecs_meta_serialize_t serialize
Serialize action.
Definition meta.h:392
void(* assign_char)(void *dst, char value)
Assign char value.
Definition meta.h:406
ecs_entity_t as_type
Type that describes the serialized output.
Definition meta.h:391
void(* assign_bool)(void *dst, bool value)
Assign bool value.
Definition meta.h:401
void(* assign_string)(void *dst, const char *value)
Assign string value.
Definition meta.h:426
void(* resize)(void *dst, size_t count)
Resize to number of elements.
Definition meta.h:465
void(* assign_int)(void *dst, int64_t value)
Assign int value.
Definition meta.h:411
void(* assign_float)(void *dst, double value)
Assign float value.
Definition meta.h:421
void(* assign_entity)(void *dst, ecs_world_t *world, ecs_entity_t entity)
Assign entity value.
Definition meta.h:431
void(* assign_id)(void *dst, ecs_world_t *world, ecs_id_t id)
Assign (component) id value.
Definition meta.h:437
Component added to primitive types.
Definition meta.h:195
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:196
Component added to struct type entities.
Definition meta.h:265
ecs_vec_t members
Populated from child entities with Member component.
Definition meta.h:267
Component that stores the type serializer.
Definition meta.h:559
ecs_vec_t ops
vector<ecs_meta_type_op_t>
Definition meta.h:560
Component that is automatically added to every type with the right kind.
Definition meta.h:165
bool existing
Did the type exist or is it populated from reflection.
Definition meta.h:167
bool partial
Is the reflection data a partial type description.
Definition meta.h:168
ecs_type_kind_t kind
Type kind.
Definition meta.h:166
Component that stores unit prefix data.
Definition meta.h:495
ecs_unit_translation_t translation
Translation of prefix.
Definition meta.h:497
char * symbol
Symbol of prefix (e.g.
Definition meta.h:496
Component that stores unit data.
Definition meta.h:486
ecs_unit_translation_t translation
Translation for derived unit.
Definition meta.h:491
ecs_entity_t prefix
Order of magnitude prefix relative to derived.
Definition meta.h:488
char * symbol
Unit symbol.
Definition meta.h:487
ecs_entity_t base
Base unit (e.g.
Definition meta.h:489
ecs_entity_t over
Over unit (e.g.
Definition meta.h:490
Component added to vector type entities.
Definition meta.h:321
ecs_entity_t type
Element type.
Definition meta.h:322
Used with ecs_array_init().
Definition meta.h:1005
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1006
ecs_entity_t type
Element type.
Definition meta.h:1007
int32_t count
Number of elements.
Definition meta.h:1008
Type that describes an bitmask constant.
Definition meta.h:294
ecs_flags64_t value
May be set when used with ecs_bitmask_desc_t.
Definition meta.h:299
int64_t _unused
Keep layout the same with ecs_enum_constant_t.
Definition meta.h:302
ecs_entity_t constant
Should not be set by ecs_bitmask_desc_t.
Definition meta.h:305
const char * name
Must be set when used with ecs_bitmask_desc_t.
Definition meta.h:296
Used with ecs_bitmask_init().
Definition meta.h:987
ecs_bitmask_constant_t constants[(32)]
Bitmask constants.
Definition meta.h:989
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:988
Used with ecs_entity_init().
Definition flecs.h:976
Type that describes an enum constant.
Definition meta.h:271
ecs_entity_t constant
Should not be set by ecs_enum_desc_t.
Definition meta.h:282
uint64_t value_unsigned
For when the underlying type is unsigned.
Definition meta.h:279
int64_t value
May be set when used with ecs_enum_desc_t.
Definition meta.h:276
const char * name
Must be set when used with ecs_enum_desc_t.
Definition meta.h:273
Used with ecs_enum_init().
Definition meta.h:968
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:969
ecs_enum_constant_t constants[(32)]
Enum constants.
Definition meta.h:970
Element type of members vector in EcsStruct.
Definition meta.h:222
ecs_member_value_range_t warning_range
Numerical range outside of which the value represents an warning.
Definition meta.h:255
const char * name
Must be set when used with ecs_struct_desc_t.
Definition meta.h:224
ecs_size_t size
Should not be set by ecs_struct_desc_t.
Definition meta.h:258
bool use_offset
Set to true to prevent automatic offset computation.
Definition meta.h:242
ecs_entity_t type
Member type.
Definition meta.h:227
ecs_entity_t member
Should not be set by ecs_struct_desc_t.
Definition meta.h:261
int32_t offset
May be set when used with ecs_struct_desc_t.
Definition meta.h:233
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:237
ecs_member_value_range_t range
Numerical range that specifies which values member can assume.
Definition meta.h:247
int32_t count
Element count (for inline arrays).
Definition meta.h:230
ecs_member_value_range_t error_range
Numerical range outside of which the value represents an error.
Definition meta.h:251
Type expressing a range for a member value.
Definition meta.h:209
double min
Min member value.
Definition meta.h:210
double max
Max member value.
Definition meta.h:211
Type that enables iterating/populating a value using reflection data.
Definition meta.h:590
ecs_meta_scope_t scope[(32)]
Cursor scope stack.
Definition meta.h:592
bool valid
Does the cursor point to a valid field.
Definition meta.h:594
const ecs_world_t * world
The world.
Definition meta.h:591
void * lookup_ctx
Context for lookup_action.
Definition meta.h:599
int32_t depth
Current scope depth.
Definition meta.h:593
bool is_primitive_scope
If in root scope, this allows for a push for primitive types.
Definition meta.h:595
ecs_entity_t(* lookup_action)(const ecs_world_t *, const char *, void *)
Custom entity lookup action for overriding default ecs_lookup.
Definition meta.h:598
Type with information about currently serialized scope.
Definition meta.h:572
const EcsOpaque * opaque
Opaque type interface.
Definition meta.h:581
int32_t prev_depth
Depth to restore, in case dotmember was used.
Definition meta.h:578
const EcsComponent * comp
Pointer to component, in case size/alignment is needed.
Definition meta.h:580
void * ptr
Pointer to the value being iterated.
Definition meta.h:579
bool is_empty_scope
Was scope populated (for collections)
Definition meta.h:586
ecs_vec_t * vector
Current vector, in case a vector is iterated.
Definition meta.h:582
int32_t elem_cur
Current element (for collections)
Definition meta.h:577
int32_t op_cur
Current operation.
Definition meta.h:576
bool is_inline_array
Is the scope iterating an inline array?
Definition meta.h:585
ecs_hashmap_t * members
string -> member index
Definition meta.h:583
ecs_meta_type_op_t * ops
The type operations (see ecs_meta_type_op_t)
Definition meta.h:574
int32_t op_count
Number of operations in ops array to process.
Definition meta.h:575
ecs_entity_t type
The type being iterated.
Definition meta.h:573
bool is_collection
Is the scope iterating elements?
Definition meta.h:584
Meta type serializer instruction data.
Definition meta.h:544
ecs_meta_type_op_kind_t kind
Instruction opcode.
Definition meta.h:545
ecs_entity_t type
Type entity.
Definition meta.h:551
int32_t count
Number of elements (for inline arrays).
Definition meta.h:547
ecs_size_t size
Size of type of operation.
Definition meta.h:550
ecs_size_t offset
Offset of current field.
Definition meta.h:546
const char * name
Name of value (only used for struct members)
Definition meta.h:548
int32_t member_index
Index of member in struct.
Definition meta.h:552
ecs_hashmap_t * members
string -> member index (structs only)
Definition meta.h:553
int32_t op_count
Number of operations until next field or end.
Definition meta.h:549
Used with ecs_opaque_init().
Definition meta.h:1060
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1061
EcsOpaque type
Type that the opaque type maps to.
Definition meta.h:1062
Used with ecs_primitive_init().
Definition meta.h:950
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:951
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:952
Serializer interface.
Definition meta.h:331
void * ctx
Serializer context.
Definition meta.h:344
int(* value)(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Pointer to the value to serialize.
Definition meta.h:333
int(* member)(const struct ecs_serializer_t *ser, const char *member)
Member name.
Definition meta.h:339
const ecs_world_t * world
The world.
Definition meta.h:343
Used with ecs_struct_init().
Definition meta.h:1042
ecs_member_t members[(32)]
Struct members.
Definition meta.h:1044
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1043
Used with ecs_unit_init().
Definition meta.h:1094
ecs_entity_t base
Base unit, e.g.
Definition meta.h:1105
ecs_entity_t over
Over unit, e.g.
Definition meta.h:1108
const char * symbol
Unit symbol, e.g.
Definition meta.h:1099
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1119
ecs_entity_t quantity
Unit quantity, e.g.
Definition meta.h:1102
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1111
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1096
Used with ecs_unit_prefix_init().
Definition meta.h:1135
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1137
const char * symbol
Unit symbol, e.g.
Definition meta.h:1140
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1143
Helper type to describe translation between two units.
Definition meta.h:480
int32_t power
Power to apply to factor (e.g.
Definition meta.h:482
int32_t factor
Factor to apply (e.g.
Definition meta.h:481
Utility to hold a value of a dynamic type.
Definition flecs.h:967
Used with ecs_vector_init().
Definition meta.h:1024
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1025
ecs_entity_t type
Element type.
Definition meta.h:1026