Flecs v4.0
A fast entity component system (ECS) for C & C++
|
Meta addon. More...
Go to the source code of this file.
Classes | |
struct | EcsType |
Component that is automatically added to every type with the right kind. More... | |
struct | EcsPrimitive |
Component added to primitive types. More... | |
struct | EcsMember |
Component added to member entities. More... | |
struct | ecs_member_value_range_t |
Type expressing a range for a member value. More... | |
struct | EcsMemberRanges |
Component added to member entities to express valid value ranges. More... | |
struct | ecs_member_t |
Element type of members vector in EcsStruct. More... | |
struct | EcsStruct |
Component added to struct type entities. More... | |
struct | ecs_enum_constant_t |
Type that describes an enum constant. More... | |
struct | EcsEnum |
Component added to enum type entities. More... | |
struct | ecs_bitmask_constant_t |
Type that describes an bitmask constant. More... | |
struct | EcsBitmask |
Component added to bitmask type entities. More... | |
struct | EcsArray |
Component added to array type entities. More... | |
struct | EcsVector |
Component added to vector type entities. More... | |
struct | ecs_serializer_t |
Serializer interface. More... | |
struct | EcsOpaque |
Opaque type reflection data. More... | |
struct | ecs_unit_translation_t |
Helper type to describe translation between two units. More... | |
struct | EcsUnit |
Component that stores unit data. More... | |
struct | EcsUnitPrefix |
Component that stores unit prefix data. More... | |
struct | ecs_meta_type_op_t |
Meta type serializer instruction data. More... | |
struct | EcsTypeSerializer |
Component that stores the type serializer. More... | |
struct | ecs_meta_scope_t |
Type with information about currently serialized scope. More... | |
struct | ecs_meta_cursor_t |
Type that enables iterating/populating a value using reflection data. More... | |
struct | ecs_primitive_desc_t |
Used with ecs_primitive_init(). More... | |
struct | ecs_enum_desc_t |
Used with ecs_enum_init(). More... | |
struct | ecs_bitmask_desc_t |
Used with ecs_bitmask_init(). More... | |
struct | ecs_array_desc_t |
Used with ecs_array_init(). More... | |
struct | ecs_vector_desc_t |
Used with ecs_vector_init(). More... | |
struct | ecs_struct_desc_t |
Used with ecs_struct_init(). More... | |
struct | ecs_opaque_desc_t |
Used with ecs_opaque_init(). More... | |
struct | ecs_unit_desc_t |
Used with ecs_unit_init(). More... | |
struct | ecs_unit_prefix_desc_t |
Used with ecs_unit_prefix_init(). More... | |
Macros | |
#define | FLECS_META_H |
#define | ECS_MEMBER_DESC_CACHE_SIZE (32) |
Max number of constants/members that can be specified in desc structs. | |
#define | ECS_META_MAX_SCOPE_DEPTH (32) |
Maximum level of type nesting. | |
#define | ecs_primitive(world, ...) ecs_primitive_init(world, &(ecs_primitive_desc_t) __VA_ARGS__ ) |
Create a primitive type. | |
#define | ecs_enum(world, ...) ecs_enum_init(world, &(ecs_enum_desc_t) __VA_ARGS__ ) |
Create an enum type. | |
#define | ecs_bitmask(world, ...) ecs_bitmask_init(world, &(ecs_bitmask_desc_t) __VA_ARGS__ ) |
Create a bitmask type. | |
#define | ecs_array(world, ...) ecs_array_init(world, &(ecs_array_desc_t) __VA_ARGS__ ) |
Create an array type. | |
#define | ecs_vector(world, ...) ecs_vector_init(world, &(ecs_vector_desc_t) __VA_ARGS__ ) |
Create a vector type. | |
#define | ecs_opaque(world, ...) ecs_opaque_init(world, &(ecs_opaque_desc_t) __VA_ARGS__ ) |
Create an opaque type. | |
#define | ecs_struct(world, ...) ecs_struct_init(world, &(ecs_struct_desc_t) __VA_ARGS__ ) |
Create a struct type. | |
#define | ecs_unit(world, ...) ecs_unit_init(world, &(ecs_unit_desc_t) __VA_ARGS__ ) |
Create a unit. | |
#define | ecs_unit_prefix(world, ...) ecs_unit_prefix_init(world, &(ecs_unit_prefix_desc_t) __VA_ARGS__ ) |
Create a unit prefix. | |
#define | ecs_quantity(world, ...) ecs_quantity_init(world, &(ecs_entity_desc_t) __VA_ARGS__ ) |
Create a unit quantity. | |
Typedefs | |
typedef bool | ecs_bool_t |
Primitive type definitions. | |
typedef char | ecs_char_t |
Builtin char type. | |
typedef unsigned char | ecs_byte_t |
Builtin ecs_byte type. | |
typedef uint8_t | ecs_u8_t |
Builtin u8 type. | |
typedef uint16_t | ecs_u16_t |
Builtin u16 type. | |
typedef uint32_t | ecs_u32_t |
Builtin u32 type. | |
typedef uint64_t | ecs_u64_t |
Builtin u64 type. | |
typedef uintptr_t | ecs_uptr_t |
Builtin uptr type. | |
typedef int8_t | ecs_i8_t |
Builtin i8 type. | |
typedef int16_t | ecs_i16_t |
Builtin i16 type. | |
typedef int32_t | ecs_i32_t |
Builtin i32 type. | |
typedef int64_t | ecs_i64_t |
Builtin i64 type. | |
typedef intptr_t | ecs_iptr_t |
Builtin iptr type. | |
typedef float | ecs_f32_t |
Builtin f32 type. | |
typedef double | ecs_f64_t |
Builtin f64 type. | |
typedef char * | ecs_string_t |
Builtin string type. | |
typedef enum ecs_type_kind_t | ecs_type_kind_t |
Type kinds supported by meta addon. | |
typedef struct EcsType | EcsType |
Component that is automatically added to every type with the right kind. | |
typedef enum ecs_primitive_kind_t | ecs_primitive_kind_t |
Primitive type kinds supported by meta addon. | |
typedef struct EcsPrimitive | EcsPrimitive |
Component added to primitive types. | |
typedef struct EcsMember | EcsMember |
Component added to member entities. | |
typedef struct ecs_member_value_range_t | ecs_member_value_range_t |
Type expressing a range for a member value. | |
typedef struct EcsMemberRanges | EcsMemberRanges |
Component added to member entities to express valid value ranges. | |
typedef struct ecs_member_t | ecs_member_t |
Element type of members vector in EcsStruct. | |
typedef struct EcsStruct | EcsStruct |
Component added to struct type entities. | |
typedef struct ecs_enum_constant_t | ecs_enum_constant_t |
Type that describes an enum constant. | |
typedef struct EcsEnum | EcsEnum |
Component added to enum type entities. | |
typedef struct ecs_bitmask_constant_t | ecs_bitmask_constant_t |
Type that describes an bitmask constant. | |
typedef struct EcsBitmask | EcsBitmask |
Component added to bitmask type entities. | |
typedef struct EcsArray | EcsArray |
Component added to array type entities. | |
typedef struct EcsVector | EcsVector |
Component added to vector type entities. | |
typedef struct ecs_serializer_t | ecs_serializer_t |
Serializer interface. | |
typedef int(* | ecs_meta_serialize_t) (const ecs_serializer_t *ser, const void *src) |
Callback invoked serializing an opaque type. | |
typedef struct EcsOpaque | EcsOpaque |
Opaque type reflection data. | |
typedef struct ecs_unit_translation_t | ecs_unit_translation_t |
Helper type to describe translation between two units. | |
typedef struct EcsUnit | EcsUnit |
Component that stores unit data. | |
typedef struct EcsUnitPrefix | EcsUnitPrefix |
Component that stores unit prefix data. | |
typedef enum ecs_meta_type_op_kind_t | ecs_meta_type_op_kind_t |
Serializer instruction opcodes. | |
typedef struct ecs_meta_type_op_t | ecs_meta_type_op_t |
Meta type serializer instruction data. | |
typedef struct EcsTypeSerializer | EcsTypeSerializer |
Component that stores the type serializer. | |
typedef struct ecs_meta_scope_t | ecs_meta_scope_t |
Type with information about currently serialized scope. | |
typedef struct ecs_meta_cursor_t | ecs_meta_cursor_t |
Type that enables iterating/populating a value using reflection data. | |
typedef struct ecs_primitive_desc_t | ecs_primitive_desc_t |
Used with ecs_primitive_init(). | |
typedef struct ecs_enum_desc_t | ecs_enum_desc_t |
Used with ecs_enum_init(). | |
typedef struct ecs_bitmask_desc_t | ecs_bitmask_desc_t |
Used with ecs_bitmask_init(). | |
typedef struct ecs_array_desc_t | ecs_array_desc_t |
Used with ecs_array_init(). | |
typedef struct ecs_vector_desc_t | ecs_vector_desc_t |
Used with ecs_vector_init(). | |
typedef struct ecs_struct_desc_t | ecs_struct_desc_t |
Used with ecs_struct_init(). | |
typedef struct ecs_opaque_desc_t | ecs_opaque_desc_t |
Used with ecs_opaque_init(). | |
typedef struct ecs_unit_desc_t | ecs_unit_desc_t |
Used with ecs_unit_init(). | |
typedef struct ecs_unit_prefix_desc_t | ecs_unit_prefix_desc_t |
Used with ecs_unit_prefix_init(). | |
Enumerations | |
enum | ecs_type_kind_t { EcsPrimitiveType , EcsBitmaskType , EcsEnumType , EcsStructType , EcsArrayType , EcsVectorType , EcsOpaqueType , EcsTypeKindLast = EcsOpaqueType } |
Type kinds supported by meta addon. More... | |
enum | ecs_primitive_kind_t { EcsBool = 1 , EcsChar , EcsByte , EcsU8 , EcsU16 , EcsU32 , EcsU64 , EcsI8 , EcsI16 , EcsI32 , EcsI64 , EcsF32 , EcsF64 , EcsUPtr , EcsIPtr , EcsString , EcsEntity , EcsId , EcsPrimitiveKindLast = EcsId } |
Primitive type kinds supported by meta addon. More... | |
enum | ecs_meta_type_op_kind_t { EcsOpArray , EcsOpVector , EcsOpOpaque , EcsOpPush , EcsOpPop , EcsOpScope , EcsOpEnum , EcsOpBitmask , EcsOpPrimitive , EcsOpBool , EcsOpChar , EcsOpByte , EcsOpU8 , EcsOpU16 , EcsOpU32 , EcsOpU64 , EcsOpI8 , EcsOpI16 , EcsOpI32 , EcsOpI64 , EcsOpF32 , EcsOpF64 , EcsOpUPtr , EcsOpIPtr , EcsOpString , EcsOpEntity , EcsOpId , EcsMetaTypeOpKindLast = EcsOpId } |
Serializer instruction opcodes. More... | |
Functions | |
FLECS_API const ecs_entity_t | ecs_id (EcsType) |
Id for component added to all types with reflection data. | |
FLECS_API const ecs_entity_t | ecs_id (EcsTypeSerializer) |
Id for component that stores a type specific serializer. | |
FLECS_API const ecs_entity_t | ecs_id (EcsPrimitive) |
Id for component that stores reflection data for a primitive type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsEnum) |
Id for component that stores reflection data for an enum type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsBitmask) |
Id for component that stores reflection data for a bitmask type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsMember) |
Id for component that stores reflection data for struct members. | |
FLECS_API const ecs_entity_t | ecs_id (EcsMemberRanges) |
Id for component that stores min/max ranges for member values. | |
FLECS_API const ecs_entity_t | ecs_id (EcsStruct) |
Id for component that stores reflection data for a struct type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsArray) |
Id for component that stores reflection data for an array type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsVector) |
Id for component that stores reflection data for a vector type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsOpaque) |
Id for component that stores reflection data for an opaque type. | |
FLECS_API const ecs_entity_t | ecs_id (EcsUnit) |
Id for component that stores unit data. | |
FLECS_API const ecs_entity_t | ecs_id (EcsUnitPrefix) |
Id for component that stores unit prefix data. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_bool_t) |
Builtin boolean type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_char_t) |
Builtin char type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_byte_t) |
Builtin byte type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_u8_t) |
Builtin 8 bit unsigned int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_u16_t) |
Builtin 16 bit unsigned int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_u32_t) |
Builtin 32 bit unsigned int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_u64_t) |
Builtin 64 bit unsigned int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_uptr_t) |
Builtin pointer sized unsigned int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_i8_t) |
Builtin 8 bit signed int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_i16_t) |
Builtin 16 bit signed int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_i32_t) |
Builtin 32 bit signed int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_i64_t) |
Builtin 64 bit signed int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_iptr_t) |
Builtin pointer sized signed int type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_f32_t) |
Builtin 32 bit floating point type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_f64_t) |
Builtin 64 bit floating point type. | |
FLECS_API const ecs_entity_t | ecs_id (ecs_string_t) |
Builtin string type. | |
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 void * | ecs_meta_get_ptr (ecs_meta_cursor_t *cursor) |
Get pointer to current field. | |
FLECS_API int | ecs_meta_next (ecs_meta_cursor_t *cursor) |
Move cursor to next field. | |
FLECS_API int | ecs_meta_elem (ecs_meta_cursor_t *cursor, int32_t elem) |
Move cursor to a field. | |
FLECS_API int | ecs_meta_member (ecs_meta_cursor_t *cursor, const char *name) |
Move cursor to member. | |
FLECS_API int | ecs_meta_dotmember (ecs_meta_cursor_t *cursor, const char *name) |
Move cursor to member. | |
FLECS_API int | ecs_meta_push (ecs_meta_cursor_t *cursor) |
Push a scope (required/only valid for structs & collections). | |
FLECS_API int | ecs_meta_pop (ecs_meta_cursor_t *cursor) |
Pop a struct or collection scope (must follow a push). | |
FLECS_API bool | ecs_meta_is_collection (const ecs_meta_cursor_t *cursor) |
Is the current scope a collection?. | |
FLECS_API ecs_entity_t | ecs_meta_get_type (const ecs_meta_cursor_t *cursor) |
Get type of current field. | |
FLECS_API ecs_entity_t | ecs_meta_get_unit (const ecs_meta_cursor_t *cursor) |
Get unit of current field. | |
FLECS_API const char * | ecs_meta_get_member (const ecs_meta_cursor_t *cursor) |
Get member name of current field. | |
FLECS_API ecs_entity_t | ecs_meta_get_member_id (const ecs_meta_cursor_t *cursor) |
Get member entity of current field. | |
FLECS_API int | ecs_meta_set_bool (ecs_meta_cursor_t *cursor, bool value) |
Set field with boolean value. | |
FLECS_API int | ecs_meta_set_char (ecs_meta_cursor_t *cursor, char value) |
Set field with char value. | |
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_set_uint (ecs_meta_cursor_t *cursor, uint64_t value) |
Set field with uint value. | |
FLECS_API int | ecs_meta_set_float (ecs_meta_cursor_t *cursor, double value) |
Set field with float value. | |
FLECS_API int | ecs_meta_set_string (ecs_meta_cursor_t *cursor, const char *value) |
Set field with string value. | |
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 int | ecs_meta_set_entity (ecs_meta_cursor_t *cursor, ecs_entity_t value) |
Set field with entity value. | |
FLECS_API int | ecs_meta_set_id (ecs_meta_cursor_t *cursor, ecs_id_t value) |
Set field with (component) id value. | |
FLECS_API int | ecs_meta_set_null (ecs_meta_cursor_t *cursor) |
Set field with null 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 bool | ecs_meta_get_bool (const ecs_meta_cursor_t *cursor) |
Get field value as boolean. | |
FLECS_API char | ecs_meta_get_char (const ecs_meta_cursor_t *cursor) |
Get field value as char. | |
FLECS_API int64_t | ecs_meta_get_int (const ecs_meta_cursor_t *cursor) |
Get field value as signed integer. | |
FLECS_API uint64_t | ecs_meta_get_uint (const ecs_meta_cursor_t *cursor) |
Get field value as unsigned integer. | |
FLECS_API double | ecs_meta_get_float (const ecs_meta_cursor_t *cursor) |
Get field value as float. | |
FLECS_API const char * | ecs_meta_get_string (const ecs_meta_cursor_t *cursor) |
Get field value as string. | |
FLECS_API ecs_entity_t | ecs_meta_get_entity (const ecs_meta_cursor_t *cursor) |
Get field value as entity. | |
ecs_id_t | ecs_meta_get_id (const ecs_meta_cursor_t *cursor) |
Get field value as (component) id. | |
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 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_enum_init (ecs_world_t *world, const ecs_enum_desc_t *desc) |
Create a new enum type. | |
FLECS_API ecs_entity_t | ecs_bitmask_init (ecs_world_t *world, const ecs_bitmask_desc_t *desc) |
Create a new bitmask type. | |
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 ecs_entity_t | ecs_vector_init (ecs_world_t *world, const ecs_vector_desc_t *desc) |
Create a new vector 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 ecs_entity_t | ecs_opaque_init (ecs_world_t *world, const ecs_opaque_desc_t *desc) |
Create a new opaque type. | |
FLECS_API ecs_entity_t | ecs_unit_init (ecs_world_t *world, const ecs_unit_desc_t *desc) |
Create a new unit. | |
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 ecs_entity_t | ecs_quantity_init (ecs_world_t *world, const ecs_entity_desc_t *desc) |
Create a new quantity. | |
FLECS_API void | FlecsMetaImport (ecs_world_t *world) |
Meta module import function. | |
Variables | |
FLECS_API const ecs_entity_t | EcsConstant |
Tag added to enum/bitmask constants. | |
FLECS_API const ecs_entity_t | EcsQuantity |
Tag added to unit quantities. | |
Meta addon.
The meta addon enables reflecting on component data. Types are stored as entities, with components that store the reflection data. A type has at least two components:
Additionally the type may have an additional component that contains the reflection data for the type. For example, structs have these components:
Structs can be populated by adding child entities with the EcsMember component. Adding a child with a Member component to an entity will automatically add the EcsStruct component to the parent.
Enums/bitmasks can be populated by adding child entities with the Constant tag. By default constants are automatically assigned values when they are added to the enum/bitmask. The parent entity must have the EcsEnum or EcsBitmask component before adding the constants.
To create enum constants with a manual value, set (Constant, i32) to the desired value. To create bitmask constants with a manual value, set (Constant, u32) to the desired value. Constants with manual values should not conflict with other constants.
The _init APIs are convenience wrappers around creating the entities and components for the types.
When a type is created it automatically receives the EcsComponent and EcsType components. The former means that the resulting type can be used as a regular component:
Type entities do not have to be named.
Definition in file meta.h.