Skip to content
Flecs v4.1
meta.h
Go to the documentation of this file.
1/**
2 * @file addons/meta.h
3 * @brief Meta addon.
4 *
5 * The meta addon enables reflecting on component data. Types are stored as
6 * entities, with components that store the reflection data. A type has at least
7 * two components:
8 *
9 * - EcsComponent: core component, contains size and alignment
10 * - EcsType: component that indicates what kind of type the entity is
11 *
12 * Additionally, the type may have an additional component that contains the
13 * reflection data for the type. For example, structs have these components:
14 *
15 * - EcsComponent
16 * - EcsType
17 * - EcsStruct
18 *
19 * Structs can be populated by adding child entities with the EcsMember
20 * component. Adding a child with a Member component to an entity will
21 * automatically add the EcsStruct component to the parent.
22 *
23 * Enums and bitmasks can be populated by adding child entities with the Constant
24 * tag. By default, constants are automatically assigned values when they are
25 * added to the enum or bitmask. The parent entity must have the EcsEnum or
26 * EcsBitmask component before adding the constants.
27 *
28 * To create enum constants with a manual value, set (Constant, i32) to the
29 * desired value. To create bitmask constants with a manual value, set
30 * (Constant, u32) to the desired value. Constants with manual values should not
31 * conflict with other constants.
32 *
33 * The _init APIs are convenience wrappers around creating the entities and
34 * components for the types.
35 *
36 * When a type is created, it automatically receives the EcsComponent and
37 * EcsType components. The former means that the resulting type can be
38 * used as a regular component:
39 *
40 * @code
41 * // Create Position type
42 * ecs_entity_t pos = ecs_struct_init(world, &(ecs_struct_desc_t){
43 * .entity.name = "Position",
44 * .members = {
45 * {"x", ecs_id(ecs_f32_t)},
46 * {"y", ecs_id(ecs_f32_t)}
47 * }
48 * });
49 *
50 * // Create entity with Position component
51 * ecs_entity_t e = ecs_new_w_id(world, pos);
52 * @endcode
53 *
54 * Type entities do not have to be named.
55 */
56
57#ifdef FLECS_META
58
59/**
60 * @defgroup c_addons_meta Meta
61 * @ingroup c_addons
62 * Flecs reflection framework.
63 *
64 * @{
65 */
66
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
78/** Max number of constants and members that can be specified in desc structs. */
79#define ECS_MEMBER_DESC_CACHE_SIZE (32)
80
81/** Primitive type definitions.
82 * These typedefs allow the built-in primitives to be used as regular components:
83 *
84 * @code
85 * ecs_set(world, e, ecs_i32_t, {10});
86 * @endcode
87 *
88 * Or a more useful example (create an enum constant with a manual value):
89 *
90 * @code
91 * ecs_set_pair_second(world, e, EcsConstant, ecs_i32_t, {10});
92 * @endcode
93 */
94
95typedef bool ecs_bool_t; /**< Built-in bool type. */
96typedef char ecs_char_t; /**< Built-in char type. */
97typedef unsigned char ecs_byte_t; /**< Built-in ecs_byte type. */
98typedef uint8_t ecs_u8_t; /**< Built-in u8 type. */
99typedef uint16_t ecs_u16_t; /**< Built-in u16 type. */
100typedef uint32_t ecs_u32_t; /**< Built-in u32 type. */
101typedef uint64_t ecs_u64_t; /**< Built-in u64 type. */
102typedef uintptr_t ecs_uptr_t; /**< Built-in uptr type. */
103typedef int8_t ecs_i8_t; /**< Built-in i8 type. */
104typedef int16_t ecs_i16_t; /**< Built-in i16 type. */
105typedef int32_t ecs_i32_t; /**< Built-in i32 type. */
106typedef int64_t ecs_i64_t; /**< Built-in i64 type. */
107typedef intptr_t ecs_iptr_t; /**< Built-in iptr type. */
108typedef float ecs_f32_t; /**< Built-in f32 type. */
109typedef double ecs_f64_t; /**< Built-in f64 type. */
110typedef char* ecs_string_t; /**< Built-in string type. */
111
112/* Meta module */
113FLECS_API extern ecs_entity_t FlecsMeta; /**< Flecs meta module. */
114
115/* Meta module component IDs */
116FLECS_API extern const ecs_entity_t ecs_id(EcsType); /**< ID for component added to all types with reflection data. */
117FLECS_API extern const ecs_entity_t ecs_id(EcsTypeSerializer); /**< ID for component that stores a type-specific serializer. */
118FLECS_API extern const ecs_entity_t ecs_id(EcsPrimitive); /**< ID for component that stores reflection data for a primitive type. */
119FLECS_API extern const ecs_entity_t ecs_id(EcsEnum); /**< ID for component that stores reflection data for an enum type. */
120FLECS_API extern const ecs_entity_t ecs_id(EcsBitmask); /**< ID for component that stores reflection data for a bitmask type. */
121FLECS_API extern const ecs_entity_t ecs_id(EcsConstants); /**< ID for component that stores reflection data for constants. */
122FLECS_API extern const ecs_entity_t ecs_id(EcsMember); /**< ID for component that stores reflection data for struct members. */
123FLECS_API extern const ecs_entity_t ecs_id(EcsMemberRanges); /**< ID for component that stores min and max ranges for member values. */
124FLECS_API extern const ecs_entity_t ecs_id(EcsStruct); /**< ID for component that stores reflection data for a struct type. */
125FLECS_API extern const ecs_entity_t ecs_id(EcsArray); /**< ID for component that stores reflection data for an array type. */
126FLECS_API extern const ecs_entity_t ecs_id(EcsVector); /**< ID for component that stores reflection data for a vector type. */
127FLECS_API extern const ecs_entity_t ecs_id(EcsMap); /**< ID for component that stores reflection data for a map type. */
128FLECS_API extern const ecs_entity_t ecs_id(EcsOpaque); /**< ID for component that stores reflection data for an opaque type. */
129FLECS_API extern const ecs_entity_t ecs_id(EcsUnit); /**< ID for component that stores unit data. */
130FLECS_API extern const ecs_entity_t ecs_id(EcsUnitPrefix); /**< ID for component that stores unit prefix data. */
131FLECS_API extern const ecs_entity_t EcsQuantity; /**< Tag added to unit quantities. */
132
133/* Primitive type component IDs */
134
135FLECS_API extern const ecs_entity_t ecs_id(ecs_bool_t); /**< Built-in boolean type. */
136FLECS_API extern const ecs_entity_t ecs_id(ecs_char_t); /**< Built-in char type. */
137FLECS_API extern const ecs_entity_t ecs_id(ecs_byte_t); /**< Built-in byte type. */
138FLECS_API extern const ecs_entity_t ecs_id(ecs_u8_t); /**< Built-in 8-bit unsigned int type. */
139FLECS_API extern const ecs_entity_t ecs_id(ecs_u16_t); /**< Built-in 16-bit unsigned int type. */
140FLECS_API extern const ecs_entity_t ecs_id(ecs_u32_t); /**< Built-in 32-bit unsigned int type. */
141FLECS_API extern const ecs_entity_t ecs_id(ecs_u64_t); /**< Built-in 64-bit unsigned int type. */
142FLECS_API extern const ecs_entity_t ecs_id(ecs_uptr_t); /**< Built-in pointer-sized unsigned int type. */
143FLECS_API extern const ecs_entity_t ecs_id(ecs_i8_t); /**< Built-in 8-bit signed int type. */
144FLECS_API extern const ecs_entity_t ecs_id(ecs_i16_t); /**< Built-in 16-bit signed int type. */
145FLECS_API extern const ecs_entity_t ecs_id(ecs_i32_t); /**< Built-in 32-bit signed int type. */
146FLECS_API extern const ecs_entity_t ecs_id(ecs_i64_t); /**< Built-in 64-bit signed int type. */
147FLECS_API extern const ecs_entity_t ecs_id(ecs_iptr_t); /**< Built-in pointer-sized signed int type. */
148FLECS_API extern const ecs_entity_t ecs_id(ecs_f32_t); /**< Built-in 32-bit floating-point type. */
149FLECS_API extern const ecs_entity_t ecs_id(ecs_f64_t); /**< Built-in 64-bit floating-point type. */
150FLECS_API extern const ecs_entity_t ecs_id(ecs_string_t); /**< Built-in string type. */
151FLECS_API extern const ecs_entity_t ecs_id(ecs_entity_t); /**< Built-in entity type. */
152FLECS_API extern const ecs_entity_t ecs_id(ecs_id_t); /**< Built-in (component) ID type. */
153FLECS_API extern const ecs_entity_t ecs_id(ecs_value_t); /**< Built-in value type. */
154
155/** Type kinds supported by meta addon. */
156typedef enum ecs_type_kind_t {
157 EcsPrimitiveType,
158 EcsBitmaskType,
159 EcsEnumType,
160 EcsStructType,
161 EcsArrayType,
162 EcsVectorType,
163 EcsOpaqueType,
164 EcsMapType,
165 EcsValueType,
166 EcsTypeKindLast = EcsValueType
168
169/** Component that is automatically added to every type with the right kind. */
170typedef struct EcsType {
171 ecs_type_kind_t kind; /**< Type kind. */
172 bool existing; /**< Whether the type existed or was populated from reflection. */
173 bool partial; /**< Whether the reflection data is a partial type description. */
175
176/** Primitive type kinds supported by meta addon. */
178 EcsBool = 1,
179 EcsChar,
180 EcsByte,
181 EcsU8,
182 EcsU16,
183 EcsU32,
184 EcsU64,
185 EcsI8,
186 EcsI16,
187 EcsI32,
188 EcsI64,
189 EcsF32,
190 EcsF64,
191 EcsUPtr,
192 EcsIPtr,
193 EcsString,
194 EcsEntity,
195 EcsId,
196 EcsPrimitiveKindLast = EcsId
198
199/** Component added to primitive types. */
200typedef struct EcsPrimitive {
201 ecs_primitive_kind_t kind; /**< Primitive type kind. */
203
204/** Component added to member entities. */
205typedef struct EcsMember {
206 ecs_entity_t type; /**< Member type. */
207 int32_t count; /**< Number of elements for inline arrays. Leave to 0 for non-array members. */
208 ecs_entity_t unit; /**< Member unit. */
209 int32_t offset; /**< Member offset. */
210 bool use_offset; /**< If offset should be explicitly used. */
212
213/** Type expressing a range for a member value. */
215 double min; /**< Min member value. */
216 double max; /**< Max member value. */
218
219/** Component added to member entities to express valid value ranges. */
220typedef struct EcsMemberRanges {
221 ecs_member_value_range_t value; /**< Member value range. */
222 ecs_member_value_range_t warning; /**< Member value warning range. */
223 ecs_member_value_range_t error; /**< Member value error range. */
225
226/** Element type of members vector in EcsStruct. */
227typedef struct ecs_member_t {
228 /** Must be set when used with ecs_struct_desc_t. */
229 const char *name;
230
231 /** Member type. */
233
234 /** Element count (for inline arrays). May be set when used with
235 * ecs_struct_desc_t. Leave to 0 for non-array members. */
236 int32_t count;
237
238 /** May be set when used with ecs_struct_desc_t. Member offset. */
239 int32_t offset;
240
241 /** May be set when used with ecs_struct_desc_t. Will be auto-populated if
242 * the type entity is also a unit. */
244
245 /** Set to true to prevent automatic offset computation. This option should
246 * be used when members are registered out of order or where calculation of
247 * member offsets doesn't match C type offsets. */
249
250 /** Numerical range that specifies which values member can assume. This
251 * range may be used by UI elements such as a progress bar or slider. The
252 * value of a member should not exceed this range. */
254
255 /** Numerical range outside of which the value represents an error. This
256 * range may be used by UI elements to style a value. */
258
259 /** Numerical range outside of which the value represents a warning. This
260 * range may be used by UI elements to style a value. */
262
263 /** Should not be set by ecs_struct_desc_t. */
264 ecs_size_t size;
265
266 /** Should not be set by ecs_struct_desc_t. */
269
270/** Component added to struct type entities. */
271typedef struct EcsStruct {
272 /** Populated from child entities with Member component. */
273 ecs_vec_t members; /* vector<ecs_member_t> */
275
276/** Type that describes an enum constant. */
277typedef struct ecs_enum_constant_t {
278 /** Must be set when used with ecs_enum_desc_t. */
279 const char *name;
280
281 /** May be set when used with ecs_enum_desc_t. */
282 int64_t value;
283
284 /** For when the underlying type is unsigned. */
286
287 /** Should not be set by ecs_enum_desc_t. */
290
291/** Component added to enum type entities. */
292typedef struct EcsEnum {
293 ecs_entity_t underlying_type; /**< Underlying type for enum. */
295
296/** Type that describes a bitmask constant. */
298 /** Must be set when used with ecs_bitmask_desc_t. */
299 const char *name;
300
301 /** May be set when used with ecs_bitmask_desc_t. */
302 ecs_flags64_t value;
303
304 /** Keep layout the same with ecs_enum_constant_t. */
305 int64_t _unused;
306
307 /** Should not be set by ecs_bitmask_desc_t. */
310
311/** Component added to bitmask type entities. */
312typedef struct EcsBitmask {
313 int32_t dummy_; /**< Unused. */
315
316/** Component with data structures for looking up enum or bitmask constants. */
317typedef struct EcsConstants {
318 /** Populated from child entities with Constant component. */
319 ecs_map_t *constants; /**< map<i32_t, ecs_enum_constant_t> */
320
321 /** Stores the constants in registration order. */
322 ecs_vec_t ordered_constants; /**< vector<ecs_enum_constants_t> */
324
325/** Component added to array type entities. */
326typedef struct EcsArray {
327 ecs_entity_t type; /**< Element type. */
328 int32_t count; /**< Number of elements. */
330
331/** Component added to vector type entities. */
332typedef struct EcsVector {
333 ecs_entity_t type; /**< Element type. */
335
336/** Component added to map type entities. */
337typedef struct EcsMap {
338 ecs_entity_t key_type; /**< Key type. Must be a primitive (other than string, f32 or f64), enum or bitmask type. */
339 ecs_entity_t type; /**< Value type. */
341
342
343/* Opaque type support */
344
345#if !defined(__cplusplus) || !defined(FLECS_CPP)
346
347/** Serializer interface. */
348typedef struct ecs_serializer_t {
349 /** Serialize value. */
350 int (*value)(
351 const struct ecs_serializer_t *ser, /**< Serializer. */
352 ecs_entity_t type, /**< Type of the value to serialize. */
353 const void *value); /**< Pointer to the value to serialize. */
354
355 /** Serialize member. */
356 int (*member)(
357 const struct ecs_serializer_t *ser, /**< Serializer. */
358 const char *member); /**< Member name. */
359
360 const ecs_world_t *world; /**< The world. */
361 void *ctx; /**< Serializer context. */
363
364#elif defined(__cplusplus)
365
366} /* extern "C" { */
367
368/** Serializer interface (same layout as C, but with convenience methods). */
369typedef struct ecs_serializer_t {
370 /* Serialize value */
371 int (*value_)(
372 const struct ecs_serializer_t *ser,
373 ecs_entity_t type,
374 const void *value);
375
376 /* Serialize member */
377 int (*member_)(
378 const struct ecs_serializer_t *ser,
379 const char *name);
380
381 /* Serialize value */
382 int value(ecs_entity_t type, const void *value) const;
383
384 /* Serialize value */
385 template <typename T>
386 int value(const T& value) const;
387
388 /* Serialize member */
389 int member(const char *name) const;
390
391 const ecs_world_t *world;
392 void *ctx;
394
395extern "C" {
396#endif
397
398/** Callback invoked serializing an opaque type. */
399typedef int (*ecs_meta_serialize_t)(
400 const ecs_serializer_t *ser,
401 const void *src); /**< Pointer to value to serialize. */
402
403
404/** Callback invoked to serialize an opaque struct member. */
406 const ecs_serializer_t *ser,
407 const void *src, /**< Pointer to value to serialize. */
408 const char* name); /**< Name of member to serialize. */
409
410/** Callback invoked to serialize an opaque vector or array element. */
412 const ecs_serializer_t *ser,
413 const void *src, /**< Pointer to value to serialize. */
414 size_t elem); /**< Element index to serialize. */
415
416
417/** Opaque type reflection data.
418 * An opaque type is a type with an unknown layout that can be mapped to a type
419 * known to the reflection framework. See the opaque type reflection examples.
420 */
421typedef struct EcsOpaque {
422 ecs_entity_t as_type; /**< Type that describes the serialized output. */
423 ecs_meta_serialize_t serialize; /**< Serialize action. */
424 ecs_meta_serialize_member_t serialize_member; /**< Serialize member action. */
425 ecs_meta_serialize_element_t serialize_element; /**< Serialize element action. */
426
427 /* Deserializer interface
428 * Only override the callbacks that are valid for the opaque type. If a
429 * deserializer attempts to assign a value type that is not supported by the
430 * interface, a conversion error is thrown.
431 */
432
433 /** Assign bool value. */
434 void (*assign_bool)(
435 void *dst,
436 bool value);
437
438 /** Assign char value. */
439 void (*assign_char)(
440 void *dst,
441 char value);
442
443 /** Assign int value. */
444 void (*assign_int)(
445 void *dst,
446 int64_t value);
447
448 /** Assign unsigned int value. */
449 void (*assign_uint)(
450 void *dst,
451 uint64_t value);
452
453 /** Assign float value. */
455 void *dst,
456 double value);
457
458 /** Assign string value. */
460 void *dst,
461 const char *value);
462
463 /** Assign entity value. */
465 void *dst,
466 ecs_world_t *world,
467 ecs_entity_t entity);
468
469 /** Assign (component) ID value. */
470 void (*assign_id)(
471 void *dst,
472 ecs_world_t *world,
473 ecs_id_t id);
474
475 /** Assign null value. */
476 void (*assign_null)(
477 void *dst);
478
479 /** Clear collection elements. */
480 void (*clear)(
481 void *dst);
482
483 /** Ensure and get collection element. */
484 void* (*ensure_element)(
485 void *dst,
486 size_t elem);
487
488 /** Ensure and get member. */
489 void* (*ensure_member)(
490 void *dst,
491 const char *member);
492
493 /** Return number of elements. */
494 size_t (*count)(
495 const void *dst);
496
497 /** Resize to number of elements. */
498 void (*resize)(
499 void *dst,
500 size_t count);
502
503
504/* Units */
505
506/** Helper type to describe translation between two units. Note that this
507 * is not intended as a generic approach to unit conversions (e.g., from Celsius
508 * to Fahrenheit) but to translate between units that derive from the same base
509 * (e.g., meters to kilometers).
510 *
511 * Note that power is applied to the factor. When describing a translation of
512 * 1000, either use {factor = 1000, power = 1} or {factor = 1, power = 3}. */
514 int32_t factor; /**< Factor to apply (e.g., "1000", "1000000", "1024"). */
515 int32_t power; /**< Power to apply to factor (e.g., "1", "3", "-9"). */
517
518/** Component that stores unit data. */
519typedef struct EcsUnit {
520 char *symbol; /**< Unit symbol. */
521 ecs_entity_t prefix; /**< Order of magnitude prefix relative to derived. */
522 ecs_entity_t base; /**< Base unit (e.g., "meters"). */
523 ecs_entity_t over; /**< Over unit (e.g., "per second"). */
524 ecs_unit_translation_t translation; /**< Translation for derived unit. */
526
527/** Component that stores unit prefix data. */
528typedef struct EcsUnitPrefix {
529 char *symbol; /**< Symbol of prefix (e.g., "K", "M", "Ki"). */
530 ecs_unit_translation_t translation; /**< Translation of prefix. */
532
533
534/* Serializer utilities */
535
536/** Serializer instruction opcodes.
537 * The meta type serializer works by generating a flattened array with
538 * instructions that tell a serializer what kind of fields can be found in a
539 * type at which offsets.
540*/
541typedef enum ecs_meta_op_kind_t {
542 EcsOpPushStruct, /**< Push struct. */
543 EcsOpPushArray, /**< Push array. */
544 EcsOpPushVector, /**< Push vector. */
545 EcsOpPushMap, /**< Push map. */
546 EcsOpPushValue, /**< Push value. */
547 EcsOpPop, /**< Pop scope. */
548
549 EcsOpOpaqueStruct, /**< Opaque struct. */
550 EcsOpOpaqueArray, /**< Opaque array. */
551 EcsOpOpaqueVector, /**< Opaque vector. */
552 EcsOpForward, /**< Forward to type. Allows for recursive types. */
553
554 EcsOpScope, /**< Marks last constant that can open or close a scope. */
555
556 EcsOpOpaqueValue, /**< Opaque value. */
557 EcsOpEnum,
558 EcsOpBitmask,
559
560 EcsOpPrimitive, /**< Marks first constant that's a primitive. */
561
562 EcsOpBool,
563 EcsOpChar,
564 EcsOpByte,
565 EcsOpU8,
566 EcsOpU16,
567 EcsOpU32,
568 EcsOpU64,
569 EcsOpI8,
570 EcsOpI16,
571 EcsOpI32,
572 EcsOpI64,
573 EcsOpF32,
574 EcsOpF64,
575 EcsOpUPtr,
576 EcsOpIPtr,
577 EcsOpString,
578 EcsOpEntity,
579 EcsOpId,
580 EcsMetaTypeOpKindLast = EcsOpId
582
583/** Meta type serializer instruction data. */
584typedef struct ecs_meta_op_t {
585 ecs_meta_op_kind_t kind; /**< Instruction opcode. */
586 ecs_meta_op_kind_t underlying_kind; /**< Underlying type kind (for enums). */
587 ecs_size_t offset; /**< Offset of current field. */
588 const char *name; /**< Name of value (only used for struct members). */
589 ecs_size_t elem_size; /**< Element size (for PushArray or PushVector) and element count (for PopArray). */
590 int16_t op_count; /**< Number of operations until next field or end. */
591 int16_t member_index; /**< Index of member in struct. */
592 ecs_entity_t type; /**< Type entity. */
593 const ecs_type_info_t *type_info; /**< Type info. */
594 union {
595 ecs_hashmap_t *members; /**< string -> member index (structs). */
596 ecs_map_t *constants; /**< (u)int -> constant entity (enums and bitmasks). */
597 ecs_meta_serialize_t opaque; /**< Serialize callback for opaque types. */
598 } is;
600
601/** Component that stores the type serializer.
602 * Added to all types with reflection data. */
603typedef struct EcsTypeSerializer {
604 ecs_type_kind_t kind; /**< Quick access to type kind (same as EcsType). */
605 ecs_vec_t ops; /**< vector<ecs_meta_op_t> */
607
608
609/* Deserializer utilities */
610
611/** Maximum level of type nesting.
612 * >32 levels of nesting are not sane.
613 */
614#define ECS_META_MAX_SCOPE_DEPTH (32)
615
616/** Type with information about the currently iterated scope. */
617typedef struct ecs_meta_scope_t {
618 ecs_entity_t type; /**< The type being iterated. */
619 ecs_meta_op_t *ops; /**< The type operations (see ecs_meta_op_t). */
620 int16_t ops_count; /**< Number of elements in ops. */
621 int16_t ops_cur; /**< Current element in ops. */
622 int16_t prev_depth; /**< Depth to restore, in case dotmember was used. */
623 void *ptr; /**< Pointer to ops[0]. */
624 const EcsOpaque *opaque; /**< Opaque type interface. */
625 ecs_hashmap_t *members; /**< string -> member index. */
626 bool is_collection; /**< Whether the scope is iterating elements. */
627 bool is_map; /**< Whether the scope is a map. */
628 bool is_value; /**< Whether the scope is a value. */
629 bool is_empty_scope; /**< Whether the scope was populated (for vectors). */
630 bool is_moved_scope; /**< Whether the scope was moved in (with ecs_meta_elem(), for vectors). */
631 int32_t elem, elem_count; /**< Set for collections. */
633
634/** Type that enables iterating and populating a value using reflection data. */
635typedef struct ecs_meta_cursor_t {
636 const ecs_world_t *world; /**< The world. */
637 ecs_meta_scope_t scope[ECS_META_MAX_SCOPE_DEPTH]; /**< Cursor scope stack. */
638 int16_t depth; /**< Current scope depth. */
639 bool valid; /**< Whether the cursor points to a valid field. */
640 bool is_primitive_scope; /**< If in root scope, this allows for a push for primitive types. */
641
642 /** Custom entity lookup action for overriding default ecs_lookup(). */
643 ecs_entity_t (*lookup_action)(ecs_world_t*, const char*, void*);
644 void *lookup_ctx; /**< Context for lookup_action. */
646
647/** Convert serializer to string.
648 *
649 * @param world The world.
650 * @param type The type to convert.
651 * @return The serializer string, or NULL if failed.
652 */
653FLECS_API
655 ecs_world_t *world,
656 ecs_entity_t type);
657
658/** Create meta cursor.
659 * A meta cursor allows for walking over, reading, and writing a value without
660 * having to know its type at compile time.
661 *
662 * When a value is assigned through the cursor API, it will get converted to
663 * the actual value of the underlying type. This allows the underlying type to
664 * change without having to update the serialized data. For example, an integer
665 * field can be set by a string, a floating-point value can be set as an integer, etc.
666 *
667 * @param world The world.
668 * @param type The type of the value.
669 * @param ptr Pointer to the value.
670 * @return A meta cursor for the value.
671 */
672FLECS_API
674 const ecs_world_t *world,
675 ecs_entity_t type,
676 void *ptr);
677
678/** Get pointer to current field.
679 *
680 * @param cursor The cursor.
681 * @return A pointer to the current field.
682 */
683FLECS_API
685 ecs_meta_cursor_t *cursor);
686
687/** Move cursor to next field.
688 *
689 * @param cursor The cursor.
690 * @return Zero if success, non-zero if failed.
691 */
692FLECS_API
694 ecs_meta_cursor_t *cursor);
695
696/** Move cursor to a field.
697 *
698 * @param cursor The cursor.
699 * @return Zero if success, non-zero if failed.
700 */
701FLECS_API
703 ecs_meta_cursor_t *cursor,
704 int32_t elem);
705
706/** Move cursor to member.
707 *
708 * @param cursor The cursor.
709 * @param name The name of the member.
710 * @return Zero if success, non-zero if failed.
711 */
712FLECS_API
714 ecs_meta_cursor_t *cursor,
715 const char *name);
716
717/** Move cursor to key (for map scopes).
718 *
719 * @param cursor The cursor.
720 * @param key The key value.
721 * @return Zero if success, non-zero if failed.
722 */
723FLECS_API
725 ecs_meta_cursor_t *cursor,
726 const ecs_value_t *key);
727
728/** Same as ecs_meta_member(), but doesn't throw an error.
729 *
730 * @param cursor The cursor.
731 * @param name The name of the member.
732 * @return Zero if success, non-zero if failed.
733 * @see ecs_meta_member()
734 */
735FLECS_API
737 ecs_meta_cursor_t *cursor,
738 const char *name);
739
740/** Move cursor to member.
741 * Same as ecs_meta_member(), but with support for "foo.bar" syntax.
742 *
743 * @param cursor The cursor.
744 * @param name The name of the member.
745 * @return Zero if success, non-zero if failed.
746 * @see ecs_meta_member()
747 */
748FLECS_API
750 ecs_meta_cursor_t *cursor,
751 const char *name);
752
753/** Same as ecs_meta_dotmember(), but doesn't throw an error.
754 *
755 * @param cursor The cursor.
756 * @param name The name of the member.
757 * @return Zero if success, non-zero if failed.
758 * @see ecs_meta_dotmember()
759 */
760FLECS_API
762 ecs_meta_cursor_t *cursor,
763 const char *name);
764
765/** Push a scope (required and only valid for structs and collections).
766 *
767 * @param cursor The cursor.
768 * @return Zero if success, non-zero if failed.
769 */
770FLECS_API
772 ecs_meta_cursor_t *cursor);
773
774/** Pop a struct or collection scope (must follow a push).
775 *
776 * @param cursor The cursor.
777 * @return Zero if success, non-zero if failed.
778 */
779FLECS_API
781 ecs_meta_cursor_t *cursor);
782
783/** Is the current scope a collection?
784 *
785 * @param cursor The cursor.
786 * @return True if current scope is a collection, false if not.
787 */
788FLECS_API
790 const ecs_meta_cursor_t *cursor);
791
792/** Is the current scope a map?
793 * When the current scope is a map, elements can be selected by moving the
794 * cursor to a key with ecs_meta_member(), where the member name is the string
795 * representation of the key.
796 *
797 * @param cursor The cursor.
798 * @return True if current scope is a map, false if not.
799 */
800FLECS_API
802 const ecs_meta_cursor_t *cursor);
803
804/** Get type of current field.
805 *
806 * @param cursor The cursor.
807 * @return The type of the current field.
808 */
809FLECS_API
811 const ecs_meta_cursor_t *cursor);
812
813/** Get unit of current field.
814 *
815 * @param cursor The cursor.
816 * @return The unit of the current field.
817 */
818FLECS_API
820 const ecs_meta_cursor_t *cursor);
821
822/** Get member name of current field.
823 *
824 * @param cursor The cursor.
825 * @return The member name of the current field.
826 */
827FLECS_API
829 const ecs_meta_cursor_t *cursor);
830
831/** Get member entity of current field.
832 *
833 * @param cursor The cursor.
834 * @return The member entity of the current field.
835 */
836FLECS_API
838 const ecs_meta_cursor_t *cursor);
839
840/* The set functions assign the field with the specified value. If the value
841 * does not have the same type as the field, it will be cast to the field type.
842 * If no valid conversion is available, the operation will fail. */
843
844/** Set field with boolean value.
845 *
846 * @param cursor The cursor.
847 * @param value The value to set.
848 * @return Zero if success, non-zero if failed.
849 */
850FLECS_API
852 ecs_meta_cursor_t *cursor,
853 bool value);
854
855/** Set field with char value.
856 *
857 * @param cursor The cursor.
858 * @param value The value to set.
859 * @return Zero if success, non-zero if failed.
860 */
861FLECS_API
863 ecs_meta_cursor_t *cursor,
864 char value);
865
866/** Set field with int value.
867 *
868 * @param cursor The cursor.
869 * @param value The value to set.
870 * @return Zero if success, non-zero if failed.
871 */
872FLECS_API
874 ecs_meta_cursor_t *cursor,
875 int64_t value);
876
877/** Set field with uint value.
878 *
879 * @param cursor The cursor.
880 * @param value The value to set.
881 * @return Zero if success, non-zero if failed.
882 */
883FLECS_API
885 ecs_meta_cursor_t *cursor,
886 uint64_t value);
887
888/** Set field with float value.
889 *
890 * @param cursor The cursor.
891 * @param value The value to set.
892 * @return Zero if success, non-zero if failed.
893 */
894FLECS_API
896 ecs_meta_cursor_t *cursor,
897 double value);
898
899/** Set field with string value.
900 *
901 * @param cursor The cursor.
902 * @param value The value to set.
903 * @return Zero if success, non-zero if failed.
904 */
905FLECS_API
907 ecs_meta_cursor_t *cursor,
908 const char *value);
909
910/** Set field with string literal value (has enclosing "").
911 *
912 * @param cursor The cursor.
913 * @param value The value to set.
914 * @return Zero if success, non-zero if failed.
915 */
916FLECS_API
918 ecs_meta_cursor_t *cursor,
919 const char *value);
920
921/** Set field with entity value.
922 *
923 * @param cursor The cursor.
924 * @param value The value to set.
925 * @return Zero if success, non-zero if failed.
926 */
927FLECS_API
929 ecs_meta_cursor_t *cursor,
930 ecs_entity_t value);
931
932/** Set field with (component) ID value.
933 *
934 * @param cursor The cursor.
935 * @param value The value to set.
936 * @return Zero if success, non-zero if failed.
937 */
938FLECS_API
940 ecs_meta_cursor_t *cursor,
941 ecs_id_t value);
942
943/** Set field with null value.
944 *
945 * @param cursor The cursor.
946 * @return Zero if success, non-zero if failed.
947 */
948FLECS_API
950 ecs_meta_cursor_t *cursor);
951
952/** Set field with dynamic value.
953 * If the current field is of a value type, the entire value is
954 * overwritten with the provided type and value.
955 *
956 * @param cursor The cursor.
957 * @param value The value to set.
958 * @return Zero if success, non-zero if failed.
959 */
960FLECS_API
962 ecs_meta_cursor_t *cursor,
963 const ecs_value_t *value);
964
965/* Functions for getting members. */
966
967/** Get field value as boolean.
968 *
969 * @param cursor The cursor.
970 * @return The value of the current field.
971 */
972FLECS_API
974 const ecs_meta_cursor_t *cursor);
975
976/** Get field value as char.
977 *
978 * @param cursor The cursor.
979 * @return The value of the current field.
980 */
981FLECS_API
983 const ecs_meta_cursor_t *cursor);
984
985/** Get field value as signed integer.
986 *
987 * @param cursor The cursor.
988 * @return The value of the current field.
989 */
990FLECS_API
992 const ecs_meta_cursor_t *cursor);
993
994/** Get field value as unsigned integer.
995 *
996 * @param cursor The cursor.
997 * @return The value of the current field.
998 */
999FLECS_API
1001 const ecs_meta_cursor_t *cursor);
1002
1003/** Get field value as float.
1004 *
1005 * @param cursor The cursor.
1006 * @return The value of the current field.
1007 */
1008FLECS_API
1010 const ecs_meta_cursor_t *cursor);
1011
1012/** Get field value as string.
1013 * This operation does not perform conversions. If the field is not a string,
1014 * this operation will fail.
1015 *
1016 * @param cursor The cursor.
1017 * @return The value of the current field.
1018 */
1019FLECS_API
1021 const ecs_meta_cursor_t *cursor);
1022
1023/** Get field value as entity.
1024 * This operation does not perform conversions.
1025 *
1026 * @param cursor The cursor.
1027 * @return The value of the current field.
1028 */
1029FLECS_API
1031 const ecs_meta_cursor_t *cursor);
1032
1033/** Get field value as (component) ID.
1034 * This operation can convert from an entity.
1035 *
1036 * @param cursor The cursor.
1037 * @return The value of the current field.
1038 */
1039FLECS_API
1041 const ecs_meta_cursor_t *cursor);
1042
1043/** Convert pointer of primitive kind to float.
1044 *
1045 * @param type_kind The primitive type kind of the value.
1046 * @param ptr Pointer to a value of a primitive type.
1047 * @return The value in floating-point format.
1048 */
1049FLECS_API
1051 ecs_primitive_kind_t type_kind,
1052 const void *ptr);
1053
1054/** Get element count for array, vector or map operations.
1055 * The operation must either be EcsOpPushArray, EcsOpPushVector or
1056 * EcsOpPushMap. If the operation is EcsOpPushArray, the provided pointer may
1057 * be NULL.
1058 *
1059 * @param op The serializer operation.
1060 * @param ptr Pointer to the array or vector value.
1061 * @return The number of elements.
1062 */
1063FLECS_API
1065 const ecs_meta_op_t *op,
1066 const void *ptr);
1067
1068/* Utility functions for working with enum and bitmask types. */
1069
1070/** Find the entity for an enum constant with the provided value.
1071 * The value is interpreted according to the underlying type of the enum. For
1072 * enums with an unsigned underlying type the value is reinterpreted as an
1073 * unsigned integer, which means that a constant with value UINT64_MAX can be
1074 * found by passing -1.
1075 *
1076 * This operation also works for bitmask types.
1077 *
1078 * @param world The world.
1079 * @param type The enum (or bitmask) type.
1080 * @param value The constant value.
1081 * @return The entity for the constant, or 0 if no constant was found.
1082 */
1083FLECS_API
1085 const ecs_world_t *world,
1086 ecs_entity_t type,
1087 int64_t value);
1088
1089/** Find the entity for an enum constant with the provided value.
1090 * Same as ecs_constant_to_entity_id() but with a type instead of a type id.
1091 *
1092 * @param world The world.
1093 * @param T The enum (or bitmask) type.
1094 * @param value The constant value.
1095 * @return The entity for the constant, or 0 if no constant was found.
1096 */
1097#define ecs_constant_to_entity(world, T, value)\
1098 ecs_constant_to_entity_id(world, ecs_id(T), value)
1099
1100/* Utility functions for working with pointers to dynamically created
1101 * values. */
1102
1103/** Construct a value in existing storage.
1104 *
1105 * @param world The world.
1106 * @param type The type of the value to create.
1107 * @param ptr A pointer to a value of type 'type'.
1108 * @return Zero if successful, nonzero if failed.
1109 */
1110FLECS_API
1112 const ecs_world_t *world,
1113 ecs_entity_t type,
1114 void *ptr);
1115
1116/** Construct a value in existing storage.
1117 *
1118 * @param world The world.
1119 * @param ti The type info of the type to create.
1120 * @param ptr A pointer to a value of type 'type'.
1121 * @return Zero if successful, nonzero if failed.
1122 */
1123FLECS_API
1125 const ecs_world_t *world,
1126 const ecs_type_info_t *ti,
1127 void *ptr);
1128
1129/** Construct a value in new storage.
1130 *
1131 * @param world The world.
1132 * @param type The type of the value to create.
1133 * @return A pointer to the value if successful, NULL if failed.
1134 */
1135FLECS_API
1137 ecs_world_t *world,
1138 ecs_entity_t type);
1139
1140/** Construct a value in new storage.
1141 *
1142 * @param world The world.
1143 * @param ti The type info of the type to create.
1144 * @return A pointer to the value if successful, NULL if failed.
1145 */
1147 ecs_world_t *world,
1148 const ecs_type_info_t *ti);
1149
1150/** Destruct a value.
1151 *
1152 * @param world The world.
1153 * @param ti The type info of the value to destruct.
1154 * @param ptr A pointer to a constructed value of type 'type'.
1155 * @return Zero if successful, nonzero if failed.
1156 */
1158 const ecs_world_t *world,
1159 const ecs_type_info_t *ti,
1160 void *ptr);
1161
1162/** Destruct a value.
1163 *
1164 * @param world The world.
1165 * @param type The type of the value to destruct.
1166 * @param ptr A pointer to a constructed value of type 'type'.
1167 * @return Zero if successful, nonzero if failed.
1168 */
1169FLECS_API
1171 const ecs_world_t *world,
1172 ecs_entity_t type,
1173 void* ptr);
1174
1175/** Destruct a value and free storage.
1176 *
1177 * @param world The world.
1178 * @param ti The type info of the value to destruct.
1179 * @param ptr A pointer to the value.
1180 * @return Zero if successful, nonzero if failed.
1181 */
1182FLECS_API
1184 ecs_world_t *world,
1185 const ecs_type_info_t *ti,
1186 void* ptr);
1187
1188/** Destruct a value and free storage.
1189 *
1190 * @param world The world.
1191 * @param type The type of the value to destruct.
1192 * @param ptr A pointer to the value.
1193 * @return Zero if successful, nonzero if failed.
1194 */
1195FLECS_API
1197 ecs_world_t *world,
1198 ecs_entity_t type,
1199 void* ptr);
1200
1201/** Copy a value.
1202 *
1203 * @param world The world.
1204 * @param ti The type info of the value to copy.
1205 * @param dst A pointer to the storage to copy to.
1206 * @param src A pointer to the value to copy.
1207 * @return Zero if successful, nonzero if failed.
1208 */
1209FLECS_API
1211 const ecs_world_t *world,
1212 const ecs_type_info_t *ti,
1213 void* dst,
1214 const void *src);
1215
1216/** Copy a value.
1217 *
1218 * @param world The world.
1219 * @param type The type of the value to copy.
1220 * @param dst A pointer to the storage to copy to.
1221 * @param src A pointer to the value to copy.
1222 * @return Zero if successful, nonzero if failed.
1223 */
1224FLECS_API
1226 const ecs_world_t *world,
1227 ecs_entity_t type,
1228 void* dst,
1229 const void *src);
1230
1231/** Move a value.
1232 *
1233 * @param world The world.
1234 * @param ti The type info of the value to move.
1235 * @param dst A pointer to the storage to move to.
1236 * @param src A pointer to the value to move.
1237 * @return Zero if successful, nonzero if failed.
1238 */
1239FLECS_API
1241 const ecs_world_t *world,
1242 const ecs_type_info_t *ti,
1243 void* dst,
1244 void *src);
1245
1246/** Move a value.
1247 *
1248 * @param world The world.
1249 * @param type The type of the value to move.
1250 * @param dst A pointer to the storage to move to.
1251 * @param src A pointer to the value to move.
1252 * @return Zero if successful, nonzero if failed.
1253 */
1254FLECS_API
1256 const ecs_world_t *world,
1257 ecs_entity_t type,
1258 void* dst,
1259 void *src);
1260
1261/** Move-construct a value.
1262 *
1263 * @param world The world.
1264 * @param ti The type info of the value to move.
1265 * @param dst A pointer to the storage to move to.
1266 * @param src A pointer to the value to move.
1267 * @return Zero if successful, nonzero if failed.
1268 */
1269FLECS_API
1271 const ecs_world_t *world,
1272 const ecs_type_info_t *ti,
1273 void* dst,
1274 void *src);
1275
1276/** Move-construct a value.
1277 *
1278 * @param world The world.
1279 * @param type The type of the value to move.
1280 * @param dst A pointer to the storage to move to.
1281 * @param src A pointer to the value to move.
1282 * @return Zero if successful, nonzero if failed.
1283 */
1284FLECS_API
1286 const ecs_world_t *world,
1287 ecs_entity_t type,
1288 void* dst,
1289 void *src);
1290
1291
1292/* Value utilities. A value is a value that holds a value of a dynamic
1293 * type. Values own the value they point to, and will invoke the correct
1294 * type hooks when a value is assigned, copied, moved or destructed. A value
1295 * must always hold a valid type and value. */
1296
1297/** Assign value of specified type to value.
1298 * If the value already holds a value of a different type, the existing
1299 * value is destructed and storage for the new type is allocated. If the type
1300 * is the same as the current value type, the value is copied into the
1301 * existing storage.
1302 *
1303 * @param world The world.
1304 * @param v The value to assign.
1305 * @param type The type of the value.
1306 * @param ptr Pointer to the value to assign.
1307 */
1308FLECS_API
1310 const ecs_world_t *world,
1311 ecs_value_t *v,
1312 ecs_entity_t type,
1313 const void *ptr);
1314
1315/** Create new value with default constructed value of specified type.
1316 *
1317 * @param world The world.
1318 * @param type The type of the value.
1319 * @return A value holding a default constructed value of the type.
1320 */
1321FLECS_API
1323 const ecs_world_t *world,
1324 ecs_entity_t type);
1325
1326/** Create new value initialized with the provided value.
1327 *
1328 * @param world The world.
1329 * @param type The type of the value.
1330 * @param ptr Pointer to the value to copy into the value.
1331 * @return A value holding a copy of the provided value.
1332 */
1333FLECS_API
1335 const ecs_world_t *world,
1336 ecs_entity_t type,
1337 const void *ptr);
1338
1339/** Destruct value.
1340 * Destructs and frees the value held by the value.
1341 *
1342 * @param world The world.
1343 * @param v The value to destruct.
1344 */
1345FLECS_API
1347 const ecs_world_t *world,
1348 ecs_value_t *v);
1349
1350/** Copy value.
1351 * Copies the value held by src to dst. The dst value must be initialized.
1352 *
1353 * @param world The world.
1354 * @param dst The value to copy to.
1355 * @param src The value to copy from.
1356 */
1357FLECS_API
1359 const ecs_world_t *world,
1360 ecs_value_t *dst,
1361 const ecs_value_t *src);
1362
1363/** Copy construct value.
1364 * Same as ecs_value_copy(), but dst is treated as uninitialized.
1365 *
1366 * @param world The world.
1367 * @param dst The value to copy to.
1368 * @param src The value to copy from.
1369 */
1370FLECS_API
1372 const ecs_world_t *world,
1373 ecs_value_t *dst,
1374 const ecs_value_t *src);
1375
1376/** Move value.
1377 * Moves the value held by src to dst. The dst value must be initialized.
1378 * After this operation src no longer holds a value.
1379 *
1380 * @param world The world.
1381 * @param dst The value to move to.
1382 * @param src The value to move from.
1383 */
1384FLECS_API
1386 const ecs_world_t *world,
1387 ecs_value_t *dst,
1388 ecs_value_t *src);
1389
1390/** Move construct value.
1391 * Same as ecs_value_move(), but dst is treated as uninitialized.
1392 *
1393 * @param world The world.
1394 * @param dst The value to move to.
1395 * @param src The value to move from.
1396 */
1397FLECS_API
1399 const ecs_world_t *world,
1400 ecs_value_t *dst,
1401 ecs_value_t *src);
1402
1403/** Compare two values.
1404 *
1405 * @param world The world.
1406 * @param a The first value.
1407 * @param b The second value.
1408 * @return 0 if equal, <0 if a is less than b, >0 if a is greater than b.
1409 */
1410FLECS_API
1412 const ecs_world_t *world,
1413 const ecs_value_t *a,
1414 const ecs_value_t *b);
1415
1416/** Test if two values are equal.
1417 *
1418 * @param world The world.
1419 * @param a The first value.
1420 * @param b The second value.
1421 * @return true if the values are equal, false otherwise.
1422 */
1423FLECS_API
1425 const ecs_world_t *world,
1426 const ecs_value_t *a,
1427 const ecs_value_t *b);
1428
1429/** Generate a runtime compare hook for a type.
1430 * This generates a compare hook for a type based on its reflection data. This
1431 * can be used to add a compare hook to a compile-time type that does not have
1432 * one.
1433 *
1434 * The operation is recursive: if the type has members, elements or values of a
1435 * type that does not have a compare hook, a compare hook is generated for that
1436 * type as well.
1437 *
1438 * @param world The world.
1439 * @param type The type to generate a compare hook for.
1440 * @return 0 if successful, -1 if the hook could not be generated.
1441 */
1442FLECS_API
1444 ecs_world_t *world,
1445 ecs_entity_t type);
1446
1447/** Generate a runtime equals hook for a type.
1448 * This generates an equals hook for a type based on its reflection data. This
1449 * can be used to add an equals hook to a compile-time type that does not have
1450 * one.
1451 *
1452 * The operation is recursive: if the type has members, elements or values of a
1453 * type that does not have an equals hook, an equals hook is generated for that
1454 * type as well.
1455 *
1456 * @param world The world.
1457 * @param type The type to generate an equals hook for.
1458 * @return 0 if successful, -1 if the hook could not be generated.
1459 */
1460FLECS_API
1462 ecs_world_t *world,
1463 ecs_entity_t type);
1464
1465/* API functions for creating meta types */
1466
1467/** Used with ecs_primitive_init(). */
1468typedef struct ecs_primitive_desc_t {
1469 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1470 ecs_primitive_kind_t kind; /**< Primitive type kind. */
1472
1473/** Create a new primitive type.
1474 *
1475 * @param world The world.
1476 * @param desc The type descriptor.
1477 * @return The new type, 0 if failed.
1478 */
1479FLECS_API
1481 ecs_world_t *world,
1482 const ecs_primitive_desc_t *desc);
1483
1484
1485/** Used with ecs_enum_init(). */
1486typedef struct ecs_enum_desc_t {
1487 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1489 ecs_entity_t underlying_type; /**< Underlying type for enum. */
1491
1492/** Create a new enum type.
1493 *
1494 * @param world The world.
1495 * @param desc The type descriptor.
1496 * @return The new type, 0 if failed.
1497 */
1498FLECS_API
1500 ecs_world_t *world,
1501 const ecs_enum_desc_t *desc);
1502
1503
1504/** Used with ecs_bitmask_init(). */
1505typedef struct ecs_bitmask_desc_t {
1506 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1509
1510/** Create a new bitmask type.
1511 *
1512 * @param world The world.
1513 * @param desc The type descriptor.
1514 * @return The new type, 0 if failed.
1515 */
1516FLECS_API
1518 ecs_world_t *world,
1519 const ecs_bitmask_desc_t *desc);
1520
1521
1522/** Used with ecs_array_init(). */
1523typedef struct ecs_array_desc_t {
1524 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1525 ecs_entity_t type; /**< Element type. */
1526 int32_t count; /**< Number of elements. */
1528
1529/** Create a new array type.
1530 *
1531 * @param world The world.
1532 * @param desc The type descriptor.
1533 * @return The new type, 0 if failed.
1534 */
1535FLECS_API
1537 ecs_world_t *world,
1538 const ecs_array_desc_t *desc);
1539
1540
1541/** Used with ecs_vector_init(). */
1542typedef struct ecs_vector_desc_t {
1543 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1544 ecs_entity_t type; /**< Element type. */
1546
1547/** Create a new vector type.
1548 *
1549 * @param world The world.
1550 * @param desc The type descriptor.
1551 * @return The new type, 0 if failed.
1552 */
1553FLECS_API
1555 ecs_world_t *world,
1556 const ecs_vector_desc_t *desc);
1557
1558
1559/** Used with ecs_map_type_init(). */
1560typedef struct ecs_map_desc_t {
1561 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1562 ecs_entity_t key_type; /**< Key type. Must be a primitive (other than string, f32 or f64), enum or bitmask type. */
1563 ecs_entity_t type; /**< Value type. */
1565
1566/** Create a new map type.
1567 *
1568 * @param world The world.
1569 * @param desc The type descriptor.
1570 * @return The new type, 0 if failed.
1571 */
1572FLECS_API
1574 ecs_world_t *world,
1575 const ecs_map_desc_t *desc);
1576
1577
1578/** Used with ecs_struct_init(). */
1579typedef struct ecs_struct_desc_t {
1580 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1582 bool create_member_entities; /**< Create entities for members. */
1584
1585/** Create a new struct type.
1586 *
1587 * @param world The world.
1588 * @param desc The type descriptor.
1589 * @return The new type, 0 if failed.
1590 */
1591FLECS_API
1593 ecs_world_t *world,
1594 const ecs_struct_desc_t *desc);
1595
1596/** Add member to struct.
1597 * This operation adds a member to a struct type. If the provided entity is not
1598 * a struct type, this operation will add the Struct component.
1599 *
1600 * @param world The world.
1601 * @param type The struct type.
1602 * @param member The member data.
1603 */
1604FLECS_API
1606 ecs_world_t *world,
1607 ecs_entity_t type,
1608 const ecs_member_t *member);
1609
1610/** Get member by name from struct.
1611 *
1612 * @param world The world.
1613 * @param type The struct type.
1614 * @param name The member name.
1615 * @return The member if found, or NULL if no member with the provided name exists.
1616 */
1617FLECS_API
1619 ecs_world_t *world,
1620 ecs_entity_t type,
1621 const char *name);
1622
1623/** Get member by index from struct.
1624 *
1625 * @param world The world.
1626 * @param type The struct type.
1627 * @param i The member index.
1628 * @return The member if found, or NULL if index is larger than the number of members for the struct.
1629 */
1630FLECS_API
1632 ecs_world_t *world,
1633 ecs_entity_t type,
1634 int32_t i);
1635
1636/** Used with ecs_opaque_init(). */
1637typedef struct ecs_opaque_desc_t {
1638 ecs_entity_t entity; /**< Existing entity to use for type (optional). */
1639 EcsOpaque type; /**< Type that the opaque type maps to. */
1641
1642/** Create a new opaque type.
1643 * Opaque types are types of which the layout doesn't match what can be modelled
1644 * with the primitives of the meta framework, but which have a structure
1645 * that can be described with meta primitives. Typical examples are STL types
1646 * such as std::string or std::vector, types with a non-trivial layout, and types
1647 * that only expose getter and setter methods.
1648 *
1649 * An opaque type is a combination of a serialization function, and a handle to
1650 * a meta type which describes the structure of the serialized output. For
1651 * example, an opaque type for std::string would have a serializer function that
1652 * accesses .c_str(), and with type ecs_string_t.
1653 *
1654 * The serializer callback accepts a serializer object and a pointer to the
1655 * value of the opaque type to be serialized. The serializer has two methods:
1656 *
1657 * - value, which serializes a value (such as .c_str())
1658 * - member, which specifies a member to be serialized (in the case of a struct)
1659 *
1660 * @param world The world.
1661 * @param desc The type descriptor.
1662 * @return The new type, 0 if failed.
1663 */
1664FLECS_API
1666 ecs_world_t *world,
1667 const ecs_opaque_desc_t *desc);
1668
1669
1670/** Used with ecs_unit_init(). */
1671typedef struct ecs_unit_desc_t {
1672 /** Existing entity to associate with unit (optional). */
1674
1675 /** Unit symbol, e.g., "m", "%", "g". (optional). */
1676 const char *symbol;
1677
1678 /** Unit quantity, e.g., distance, percentage, weight. (optional). */
1680
1681 /** Base unit, e.g., "meters" (optional). */
1683
1684 /** Over unit, e.g., "per second" (optional). */
1686
1687 /** Translation to apply to derived unit (optional). */
1689
1690 /** Prefix indicating order of magnitude relative to the derived unit. If set
1691 * together with "translation", the values must match. If translation is not
1692 * set, setting prefix will auto-populate it.
1693 * Additionally, setting the prefix will enforce that the symbol (if set)
1694 * is consistent with the prefix symbol + symbol of the derived unit. If the
1695 * symbol is not set, it will be auto-populated. */
1698
1699/** Create a new unit.
1700 *
1701 * @param world The world.
1702 * @param desc The unit descriptor.
1703 * @return The new unit, 0 if failed.
1704 */
1705FLECS_API
1707 ecs_world_t *world,
1708 const ecs_unit_desc_t *desc);
1709
1710
1711/** Used with ecs_unit_prefix_init(). */
1713 /** Existing entity to associate with unit prefix (optional). */
1715
1716 /** Unit prefix symbol, e.g., "K", "M", "Ki". (optional). */
1717 const char *symbol;
1718
1719 /** Translation to apply to derived unit (optional). */
1722
1723/** Create a new unit prefix.
1724 *
1725 * @param world The world.
1726 * @param desc The type descriptor.
1727 * @return The new unit prefix, 0 if failed.
1728 */
1729FLECS_API
1731 ecs_world_t *world,
1732 const ecs_unit_prefix_desc_t *desc);
1733
1734
1735/** Create a new quantity.
1736 *
1737 * @param world The world.
1738 * @param desc The quantity descriptor.
1739 * @return The new quantity, 0 if failed.
1740 */
1741FLECS_API
1743 ecs_world_t *world,
1744 const ecs_entity_desc_t *desc);
1745
1746/* Convenience macros */
1747
1748/** Create a primitive type. */
1749#define ecs_primitive(world, ...)\
1750 ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ )
1751
1752/** Create an enum type. */
1753#define ecs_enum(world, ...)\
1754 ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ )
1755
1756/** Create a bitmask type. */
1757#define ecs_bitmask(world, ...)\
1758 ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ )
1759
1760/** Create an array type. */
1761#define ecs_array(world, ...)\
1762 ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ )
1763
1764/** Create a vector type. */
1765#define ecs_vector(world, ...)\
1766 ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ )
1767
1768/** Create a map type. */
1769#define ecs_map_type(world, ...)\
1770 ecs_map_type_init(world, &(ecs_map_desc_t) __VA_ARGS__ )
1771
1772/** Create an opaque type. */
1773#define ecs_opaque(world, ...)\
1774 ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ )
1775
1776/** Create a struct type. */
1777#define ecs_struct(world, ...)\
1778 ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ )
1779
1780/** Create a unit. */
1781#define ecs_unit(world, ...)\
1782 ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ )
1783
1784/** Create a unit prefix. */
1785#define ecs_unit_prefix(world, ...)\
1786 ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ )
1787
1788/** Create a unit quantity. */
1789#define ecs_quantity(world, ...)\
1790 ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ )
1791
1792
1793/** Meta module import function.
1794 * Usage:
1795 * @code
1796 * ECS_IMPORT(world, FlecsMeta)
1797 * @endcode
1798 *
1799 * @param world The world.
1800 */
1801FLECS_API
1803 ecs_world_t *world);
1804
1805#ifdef __cplusplus
1806}
1807#endif
1808
1809#include "meta_c.h"
1810
1811#endif
1812
1813/** @} */
1814
1815#endif
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
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.
int ecs_ptr_fini_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *ptr)
Destruct a value.
FLECS_API int ecs_ptr_move_ctor_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, void *src)
Move-construct a value.
FLECS_API bool ecs_meta_get_bool(const ecs_meta_cursor_t *cursor)
Get field value as boolean.
FLECS_API ecs_entity_t ecs_constant_to_entity_id(const ecs_world_t *world, ecs_entity_t type, int64_t value)
Find the entity for an enum constant with the provided value.
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:405
FLECS_API int ecs_ptr_free(ecs_world_t *world, ecs_entity_t type, void *ptr)
Destruct a value and free storage.
bool ecs_bool_t
Primitive type definitions.
Definition meta.h:95
FLECS_API ecs_value_t ecs_value_new(const ecs_world_t *world, ecs_entity_t type)
Create new value with default constructed value of specified type.
FLECS_API ecs_entity_t ecs_bitmask_init(ecs_world_t *world, const ecs_bitmask_desc_t *desc)
Create a new bitmask type.
uint32_t ecs_u32_t
Built-in u32 type.
Definition meta.h:100
FLECS_API void ecs_value_copy_ctor(const ecs_world_t *world, ecs_value_t *dst, const ecs_value_t *src)
Copy construct value.
FLECS_API double ecs_meta_ptr_to_float(ecs_primitive_kind_t type_kind, const void *ptr)
Convert pointer of primitive kind to float.
FLECS_API int ecs_set_rtt_equals(ecs_world_t *world, ecs_entity_t type)
Generate a runtime equals hook for a type.
int16_t ecs_i16_t
Built-in i16 type.
Definition meta.h:104
ecs_meta_op_kind_t
Serializer instruction opcodes.
Definition meta.h:541
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.
FLECS_API int ecs_meta_dotmember(ecs_meta_cursor_t *cursor, const char *name)
Move cursor to member.
FLECS_API ecs_entity_t ecs_meta_get_entity(const ecs_meta_cursor_t *cursor)
Get field value as entity.
FLECS_API int ecs_meta_key(ecs_meta_cursor_t *cursor, const ecs_value_t *key)
Move cursor to key (for map scopes).
FLECS_API int ecs_ptr_move_ctor(const ecs_world_t *world, ecs_entity_t type, void *dst, void *src)
Move-construct a value.
uint8_t ecs_u8_t
Built-in u8 type.
Definition meta.h:98
FLECS_API int ecs_ptr_move(const ecs_world_t *world, ecs_entity_t type, void *dst, void *src)
Move a value.
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.
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:411
FLECS_API bool ecs_meta_is_collection(const ecs_meta_cursor_t *cursor)
Is the current scope a collection?
FLECS_API void ecs_value_set(const ecs_world_t *world, ecs_value_t *v, ecs_entity_t type, const void *ptr)
Assign value of specified type to value.
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.
FLECS_API ecs_entity_t ecs_map_type_init(ecs_world_t *world, const ecs_map_desc_t *desc)
Create a new map type.
FLECS_API int ecs_ptr_free_w_type_info(ecs_world_t *world, const ecs_type_info_t *ti, void *ptr)
Destruct a value and free storage.
char * ecs_string_t
Built-in string type.
Definition meta.h:110
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
FLECS_API void ecs_value_move_ctor(const ecs_world_t *world, ecs_value_t *dst, ecs_value_t *src)
Move construct value.
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 or map operations.
FLECS_API int ecs_meta_set_id(ecs_meta_cursor_t *cursor, ecs_id_t value)
Set field with (component) ID value.
FLECS_API void ecs_value_copy(const ecs_world_t *world, ecs_value_t *dst, const ecs_value_t *src)
Copy 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:177
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.
FLECS_API ecs_value_t ecs_value_init(const ecs_world_t *world, ecs_entity_t type, const void *ptr)
Create new value initialized with the provided value.
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.
int(*) ecs_meta_serialize_t(const ecs_serializer_t *ser, const void *src)
Callback invoked serializing an opaque type.
Definition meta.h:399
FLECS_API int ecs_ptr_init(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Construct a value in existing storage.
FLECS_API int ecs_ptr_fini(const ecs_world_t *world, ecs_entity_t type, void *ptr)
Destruct a value.
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.
FLECS_API void * ecs_ptr_new(ecs_world_t *world, ecs_entity_t type)
Construct a value in new storage.
FLECS_API int ecs_meta_elem(ecs_meta_cursor_t *cursor, int32_t elem)
Move cursor to a field.
FLECS_API int64_t ecs_meta_get_int(const ecs_meta_cursor_t *cursor)
Get field value as signed integer.
FLECS_API void ecs_value_fini(const ecs_world_t *world, ecs_value_t *v)
Destruct value.
ecs_type_kind_t
Type kinds supported by meta addon.
Definition meta.h:156
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
FLECS_API int ecs_value_compare(const ecs_world_t *world, const ecs_value_t *a, const ecs_value_t *b)
Compare two values.
FLECS_API int ecs_ptr_init_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *ptr)
Construct a value in existing storage.
FLECS_API int ecs_meta_set_string(ecs_meta_cursor_t *cursor, const char *value)
Set field with string value.
#define ECS_META_MAX_SCOPE_DEPTH
Maximum level of type nesting.
Definition meta.h:614
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 void ecs_value_move(const ecs_world_t *world, ecs_value_t *dst, ecs_value_t *src)
Move value.
FLECS_API int ecs_set_rtt_compare(ecs_world_t *world, ecs_entity_t type)
Generate a runtime compare hook for a type.
void * ecs_ptr_new_w_type_info(ecs_world_t *world, const ecs_type_info_t *ti)
Construct a value in new storage.
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.
FLECS_API ecs_entity_t FlecsMeta
Flecs meta module.
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
FLECS_API int ecs_meta_set_char(ecs_meta_cursor_t *cursor, char value)
Set field with char value.
#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 bool ecs_meta_is_map(const ecs_meta_cursor_t *cursor)
Is the current scope a map?
FLECS_API void * ecs_meta_get_ptr(ecs_meta_cursor_t *cursor)
Get pointer to current field.
FLECS_API int ecs_ptr_copy(const ecs_world_t *world, ecs_entity_t type, void *dst, const void *src)
Copy a value.
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.
FLECS_API int ecs_ptr_copy_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, const void *src)
Copy a value.
FLECS_API bool ecs_value_equals(const ecs_world_t *world, const ecs_value_t *a, const ecs_value_t *b)
Test if two values are equal.
FLECS_API int ecs_meta_push(ecs_meta_cursor_t *cursor)
Push a scope (required and only valid for structs and collections).
FLECS_API int ecs_ptr_move_w_type_info(const ecs_world_t *world, const ecs_type_info_t *ti, void *dst, void *src)
Move a value.
@ EcsOpPrimitive
Marks first constant that's a primitive.
Definition meta.h:560
@ EcsOpPushMap
Push map.
Definition meta.h:545
@ EcsOpOpaqueArray
Opaque array.
Definition meta.h:550
@ EcsOpOpaqueStruct
Opaque struct.
Definition meta.h:549
@ EcsOpScope
Marks last constant that can open or close a scope.
Definition meta.h:554
@ EcsOpPop
Pop scope.
Definition meta.h:547
@ EcsOpPushVector
Push vector.
Definition meta.h:544
@ EcsOpOpaqueVector
Opaque vector.
Definition meta.h:551
@ EcsOpPushStruct
Push struct.
Definition meta.h:542
@ EcsOpPushValue
Push value.
Definition meta.h:546
@ EcsOpOpaqueValue
Opaque value.
Definition meta.h:556
@ EcsOpPushArray
Push array.
Definition meta.h:543
@ EcsOpForward
Forward to type.
Definition meta.h:552
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:395
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:439
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:388
Utility macros for populating reflection data in C.
Component added to array type entities.
Definition meta.h:326
int32_t count
Number of elements.
Definition meta.h:328
ecs_entity_t type
Element type.
Definition meta.h:327
Component added to bitmask type entities.
Definition meta.h:312
int32_t dummy_
Unused.
Definition meta.h:313
Component with data structures for looking up enum or bitmask constants.
Definition meta.h:317
ecs_vec_t ordered_constants
Stores the constants in registration order.
Definition meta.h:322
ecs_map_t * constants
Populated from child entities with Constant component.
Definition meta.h:319
Component added to enum type entities.
Definition meta.h:292
ecs_entity_t underlying_type
Underlying type for enum.
Definition meta.h:293
Component added to map type entities.
Definition meta.h:337
ecs_entity_t type
Value type.
Definition meta.h:339
ecs_entity_t key_type
Key type.
Definition meta.h:338
Component added to member entities to express valid value ranges.
Definition meta.h:220
ecs_member_value_range_t warning
Member value warning range.
Definition meta.h:222
ecs_member_value_range_t value
Member value range.
Definition meta.h:221
ecs_member_value_range_t error
Member value error range.
Definition meta.h:223
Component added to member entities.
Definition meta.h:205
ecs_entity_t unit
Member unit.
Definition meta.h:208
bool use_offset
If offset should be explicitly used.
Definition meta.h:210
ecs_entity_t type
Member type.
Definition meta.h:206
int32_t offset
Member offset.
Definition meta.h:209
int32_t count
Number of elements for inline arrays.
Definition meta.h:207
Opaque type reflection data.
Definition meta.h:421
size_t(*) count(const void *dst)
Return number of elements.
Definition meta.h:494
ecs_meta_serialize_member_t serialize_member
Serialize member action.
Definition meta.h:424
void(*) assign_int(void *dst, int64_t value)
Assign int value.
Definition meta.h:444
ecs_meta_serialize_t serialize
Serialize action.
Definition meta.h:423
void(*) assign_string(void *dst, const char *value)
Assign string value.
Definition meta.h:459
void(*) assign_char(void *dst, char value)
Assign char value.
Definition meta.h:439
ecs_entity_t as_type
Type that describes the serialized output.
Definition meta.h:422
void(*) assign_entity(void *dst, ecs_world_t *world, ecs_entity_t entity)
Assign entity value.
Definition meta.h:464
void(*) assign_float(void *dst, double value)
Assign float value.
Definition meta.h:454
void(*) assign_id(void *dst, ecs_world_t *world, ecs_id_t id)
Assign (component) ID value.
Definition meta.h:470
void(*) assign_uint(void *dst, uint64_t value)
Assign unsigned int value.
Definition meta.h:449
void(*) clear(void *dst)
Clear collection elements.
Definition meta.h:480
void(*) assign_null(void *dst)
Assign null value.
Definition meta.h:476
ecs_meta_serialize_element_t serialize_element
Serialize element action.
Definition meta.h:425
void(*) resize(void *dst, size_t count)
Resize to number of elements.
Definition meta.h:498
void(*) assign_bool(void *dst, bool value)
Assign bool value.
Definition meta.h:434
Component added to primitive types.
Definition meta.h:200
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:201
Component added to struct type entities.
Definition meta.h:271
ecs_vec_t members
Populated from child entities with Member component.
Definition meta.h:273
Component that stores the type serializer.
Definition meta.h:603
ecs_type_kind_t kind
Quick access to type kind (same as EcsType).
Definition meta.h:604
ecs_vec_t ops
vector<ecs_meta_op_t>
Definition meta.h:605
Component that is automatically added to every type with the right kind.
Definition meta.h:170
bool existing
Whether the type existed or was populated from reflection.
Definition meta.h:172
bool partial
Whether the reflection data is a partial type description.
Definition meta.h:173
ecs_type_kind_t kind
Type kind.
Definition meta.h:171
Component that stores unit prefix data.
Definition meta.h:528
ecs_unit_translation_t translation
Translation of prefix.
Definition meta.h:530
char * symbol
Symbol of prefix (e.g., "K", "M", "Ki").
Definition meta.h:529
Component that stores unit data.
Definition meta.h:519
ecs_unit_translation_t translation
Translation for derived unit.
Definition meta.h:524
ecs_entity_t prefix
Order of magnitude prefix relative to derived.
Definition meta.h:521
char * symbol
Unit symbol.
Definition meta.h:520
ecs_entity_t base
Base unit (e.g., "meters").
Definition meta.h:522
ecs_entity_t over
Over unit (e.g., "per second").
Definition meta.h:523
Component added to vector type entities.
Definition meta.h:332
ecs_entity_t type
Element type.
Definition meta.h:333
Used with ecs_array_init().
Definition meta.h:1523
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1524
ecs_entity_t type
Element type.
Definition meta.h:1525
int32_t count
Number of elements.
Definition meta.h:1526
Type that describes a bitmask constant.
Definition meta.h:297
ecs_flags64_t value
May be set when used with ecs_bitmask_desc_t.
Definition meta.h:302
int64_t _unused
Keep layout the same with ecs_enum_constant_t.
Definition meta.h:305
ecs_entity_t constant
Should not be set by ecs_bitmask_desc_t.
Definition meta.h:308
const char * name
Must be set when used with ecs_bitmask_desc_t.
Definition meta.h:299
Used with ecs_bitmask_init().
Definition meta.h:1505
ecs_bitmask_constant_t constants[(32)]
Bitmask constants.
Definition meta.h:1507
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1506
Used with ecs_entity_init().
Definition flecs.h:1077
Type that describes an enum constant.
Definition meta.h:277
ecs_entity_t constant
Should not be set by ecs_enum_desc_t.
Definition meta.h:288
uint64_t value_unsigned
For when the underlying type is unsigned.
Definition meta.h:285
int64_t value
May be set when used with ecs_enum_desc_t.
Definition meta.h:282
const char * name
Must be set when used with ecs_enum_desc_t.
Definition meta.h:279
Used with ecs_enum_init().
Definition meta.h:1486
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1487
ecs_entity_t underlying_type
Underlying type for enum.
Definition meta.h:1489
ecs_enum_constant_t constants[(32)]
Enum constants.
Definition meta.h:1488
Used with ecs_map_type_init().
Definition meta.h:1560
ecs_entity_t key_type
Key type.
Definition meta.h:1562
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1561
ecs_entity_t type
Value type.
Definition meta.h:1563
Element type of members vector in EcsStruct.
Definition meta.h:227
ecs_member_value_range_t warning_range
Numerical range outside of which the value represents a warning.
Definition meta.h:261
const char * name
Must be set when used with ecs_struct_desc_t.
Definition meta.h:229
ecs_size_t size
Should not be set by ecs_struct_desc_t.
Definition meta.h:264
bool use_offset
Set to true to prevent automatic offset computation.
Definition meta.h:248
ecs_entity_t type
Member type.
Definition meta.h:232
ecs_entity_t member
Should not be set by ecs_struct_desc_t.
Definition meta.h:267
int32_t offset
May be set when used with ecs_struct_desc_t.
Definition meta.h:239
ecs_entity_t unit
May be set when used with ecs_struct_desc_t.
Definition meta.h:243
ecs_member_value_range_t range
Numerical range that specifies which values member can assume.
Definition meta.h:253
int32_t count
Element count (for inline arrays).
Definition meta.h:236
ecs_member_value_range_t error_range
Numerical range outside of which the value represents an error.
Definition meta.h:257
Type expressing a range for a member value.
Definition meta.h:214
double min
Min member value.
Definition meta.h:215
double max
Max member value.
Definition meta.h:216
Type that enables iterating and populating a value using reflection data.
Definition meta.h:635
ecs_meta_scope_t scope[(32)]
Cursor scope stack.
Definition meta.h:637
bool valid
Whether the cursor points to a valid field.
Definition meta.h:639
const ecs_world_t * world
The world.
Definition meta.h:636
void * lookup_ctx
Context for lookup_action.
Definition meta.h:644
int16_t depth
Current scope depth.
Definition meta.h:638
bool is_primitive_scope
If in root scope, this allows for a push for primitive types.
Definition meta.h:640
ecs_entity_t(*) lookup_action(ecs_world_t *, const char *, void *)
Custom entity lookup action for overriding default ecs_lookup().
Definition meta.h:643
Meta type serializer instruction data.
Definition meta.h:584
const char * name
Name of value (only used for struct members).
Definition meta.h:588
ecs_meta_op_kind_t kind
Instruction opcode.
Definition meta.h:585
const ecs_type_info_t * type_info
Type info.
Definition meta.h:593
int16_t member_index
Index of member in struct.
Definition meta.h:591
ecs_entity_t type
Type entity.
Definition meta.h:592
int16_t op_count
Number of operations until next field or end.
Definition meta.h:590
ecs_meta_op_kind_t underlying_kind
Underlying type kind (for enums).
Definition meta.h:586
ecs_size_t elem_size
Element size (for PushArray or PushVector) and element count (for PopArray).
Definition meta.h:589
ecs_size_t offset
Offset of current field.
Definition meta.h:587
Type with information about the currently iterated scope.
Definition meta.h:617
bool is_moved_scope
Whether the scope was moved in (with ecs_meta_elem(), for vectors).
Definition meta.h:630
int16_t ops_cur
Current element in ops.
Definition meta.h:621
const EcsOpaque * opaque
Opaque type interface.
Definition meta.h:624
int32_t elem_count
Set for collections.
Definition meta.h:631
void * ptr
Pointer to ops[0].
Definition meta.h:623
bool is_empty_scope
Whether the scope was populated (for vectors).
Definition meta.h:629
bool is_map
Whether the scope is a map.
Definition meta.h:627
int16_t ops_count
Number of elements in ops.
Definition meta.h:620
ecs_meta_op_t * ops
The type operations (see ecs_meta_op_t).
Definition meta.h:619
ecs_hashmap_t * members
string -> member index.
Definition meta.h:625
int16_t prev_depth
Depth to restore, in case dotmember was used.
Definition meta.h:622
ecs_entity_t type
The type being iterated.
Definition meta.h:618
bool is_collection
Whether the scope is iterating elements.
Definition meta.h:626
bool is_value
Whether the scope is a value.
Definition meta.h:628
Used with ecs_opaque_init().
Definition meta.h:1637
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1638
EcsOpaque type
Type that the opaque type maps to.
Definition meta.h:1639
Used with ecs_primitive_init().
Definition meta.h:1468
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1469
ecs_primitive_kind_t kind
Primitive type kind.
Definition meta.h:1470
Serializer interface.
Definition meta.h:348
void * ctx
Serializer context.
Definition meta.h:361
int(*) member(const struct ecs_serializer_t *ser, const char *member)
Serialize member.
Definition meta.h:356
int(*) value(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.
Definition meta.h:350
const ecs_world_t * world
The world.
Definition meta.h:360
Used with ecs_struct_init().
Definition meta.h:1579
ecs_member_t members[(32)]
Struct members.
Definition meta.h:1581
bool create_member_entities
Create entities for members.
Definition meta.h:1582
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1580
Type that contains component information (passed to ctors/dtors/...).
Definition flecs.h:1052
Used with ecs_unit_init().
Definition meta.h:1671
ecs_entity_t base
Base unit, e.g., "meters" (optional).
Definition meta.h:1682
ecs_entity_t over
Over unit, e.g., "per second" (optional).
Definition meta.h:1685
const char * symbol
Unit symbol, e.g., "m", "%", "g".
Definition meta.h:1676
ecs_entity_t prefix
Prefix indicating order of magnitude relative to the derived unit.
Definition meta.h:1696
ecs_entity_t quantity
Unit quantity, e.g., distance, percentage, weight.
Definition meta.h:1679
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1688
ecs_entity_t entity
Existing entity to associate with unit (optional).
Definition meta.h:1673
Used with ecs_unit_prefix_init().
Definition meta.h:1712
ecs_entity_t entity
Existing entity to associate with unit prefix (optional).
Definition meta.h:1714
const char * symbol
Unit prefix symbol, e.g., "K", "M", "Ki".
Definition meta.h:1717
ecs_unit_translation_t translation
Translation to apply to derived unit (optional).
Definition meta.h:1720
Helper type to describe translation between two units.
Definition meta.h:513
int32_t power
Power to apply to factor (e.g., "1", "3", "-9").
Definition meta.h:515
int32_t factor
Factor to apply (e.g., "1000", "1000000", "1024").
Definition meta.h:514
Value of a dynamic type.
Definition flecs.h:1068
Used with ecs_vector_init().
Definition meta.h:1542
ecs_entity_t entity
Existing entity to use for type (optional).
Definition meta.h:1543
ecs_entity_t type
Element type.
Definition meta.h:1544
ecs_map_t * constants
(u)int -> constant entity (enums and bitmasks).
ecs_hashmap_t * members
string -> member index (structs).
ecs_meta_serialize_t opaque
Serialize callback for opaque types.