LDK_ENTITY_MAX_COMPONENTS
#define LDK_ENTITY_MAX_COMPONENTS 16
Entity system (handles, lifecycle, component binding)
Defines entity creation, destruction, and component associations.
#define LDK_ENTITY_MAX_COMPONENTS 16
#define LDK_ENTITY_NAME_MAX_LEN 32
#define LDK_ENTITY_INVALID_COMPONENT_INDEX UINT32_MAX
typedef XHandle LDKEntity;
typedef enum LDKEntityInternalFlags{
LDK_ENTITY_INTERNAL_NONE=0,
LDK_ENTITY_INTERNAL_PENDING_DELETE=1<<0,
LDK_ENTITY_INTERNAL_HAS_TRANSFORM=1<<1,
LDK_ENTITY_INTERNAL_HAS_CAMERA=1<<2,
LDK_ENTITY_INTERNAL_HAS_RENDERABLE=1<<3,
LDK_ENTITY_INTERNAL_HAS_LIGHT=1<<4,
LDK_ENTITY_INTERNAL_EDITOR=1<<5
}LDKEntityInternalFlags;
Serialized IDs of engine-owned components. These values are persistent: once assigned, a retired ID must not be reused for another component. User component IDs must stay below the engine-reserved high-ID range.
typedef enum LDKComponentInstanceFlags{
LDK_COMPONENT_INSTANCE_FLAG_NONE=0,
LDK_COMPONENT_INSTANCE_FLAG_HIDE_IN_EDITOR=1<<0,
LDK_COMPONENT_INSTANCE_FLAG_DISABLED=1<<1
}LDKComponentInstanceFlags;
typedef enum LDKBuiltinComponentType{
LDK_COMPONENT_TYPE_TRANSFORM=UINT32_MAX-1,
LDK_COMPONENT_TYPE_CAMERA=UINT32_MAX-2,
LDK_COMPONENT_TYPE_MESH_SOURCE=UINT32_MAX-3,
LDK_COMPONENT_TYPE_POINT_LIGHT=UINT32_MAX-4,
LDK_COMPONENT_TYPE_SPOT_LIGHT=UINT32_MAX-5,
LDK_COMPONENT_TYPE_DIRECTIONAL_LIGHT=UINT32_MAX-6,
LDK_COMPONENT_TYPE_INSTANCED_MESH_SOURCE=UINT32_MAX-7,
LDK_COMPONENT_TYPE_PARTICLE_EMITTER=UINT32_MAX-8,
LDK_COMPONENT_TYPE_POST_PROCESSING=UINT32_MAX-9,
LDK_COMPONENT_TYPE_TEXT3D=UINT32_MAX-10,
LDK_COMPONENT_TYPE_AUDIO_SOURCE=UINT32_MAX-11,
LDK_COMPONENT_TYPE_GRASS_INTERACT=UINT32_MAX-12,
LDK_COMPONENT_TYPE_TERRAIN_FOLLOWER=UINT32_MAX-14,
LDK_COMPONENT_TYPE_KEYFRAME_ANIMATION_SOURCE=UINT32_MAX-15,
LDK_COMPONENT_TYPE_MATERIAL_INSTANCE=UINT32_MAX-16,
}LDKBuiltinComponentType;
A list of all components and component types in an entity.
typedef struct LDKComponentDirectory{
u32 component_type[LDK_ENTITY_MAX_COMPONENTS];
u32 component_index[LDK_ENTITY_MAX_COMPONENTS];
u16 component_flags[LDK_ENTITY_MAX_COMPONENTS];
u16 component_count;
u16 version;
}LDKComponentDirectory;
Stable reference to a component through its owning entity.
typedef struct LDKComponentRef{
LDKEntity entity;
u16 version;
u16 slot_index;
}LDKComponentRef;
Callback visiting an entity during iteration.
typedef bool(*LDKEntityIterFn)(LDKEntity entity, LDKEntityInfo *info, void *user);
entityinfouserTrue if the operation succeeds; false otherwise.
typedef struct LDKEntityRegistry{
XHPool pool;
void(*component_state_changed)(void *user, LDKEntity entity);
void *component_state_user;
}LDKEntityRegistry;
Initialize the entity module.
LDK_API bool ldk_entity_module_initialize(
LDKEntityRegistry *system,
u32 page_capacity,
u32 initial_pages
);
LDKEntityRegistry *systemu32 page_capacityu32 initial_pagesTrue if the operation succeeds; false otherwise.
Shut down the entity module.
LDK_API void ldk_entity_module_terminate(LDKEntityRegistry *system);
LDKEntityRegistry *systemClear the state of the entity module.
LDK_API void ldk_entity_module_clear(LDKEntityRegistry *system);
LDKEntityRegistry *systemCreate the entity.
LDK_API LDKEntity ldk_entity_create(LDKEntityRegistry *system);
LDKEntityRegistry *systemThe requested value.
Destroy the entity.
LDK_API void ldk_entity_destroy(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityCheck whether the entity refers to a live resource.
LDK_API bool ldk_entity_is_alive(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityTrue when the queried condition holds; false otherwise.
Get the entity info.
LDK_API LDKEntityInfo * ldk_entity_info_get(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityPointer to the requested object or data; NULL when unavailable.
Get read-only information about an entity.
LDK_API const LDKEntityInfo * ldk_entity_get_info_const(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityPointer to the requested object or data; NULL when unavailable.
Count the entity alive.
LDK_API u32 ldk_entity_alive_count(LDKEntityRegistry *system);
LDKEntityRegistry *systemNumber of matching entries.
Set the entity flags.
LDK_API void ldk_entity_flags_set(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsGet the entity flags.
LDK_API u16 ldk_entity_flags_get(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityThe requested value.
Add the entity flags.
LDK_API void ldk_entity_flags_add(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsRemove the entity flags.
LDK_API void ldk_entity_flags_remove(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsCheck whether an entity has the requested flags.
LDK_API bool ldk_entity_flags_has(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsTrue when the queried condition holds; false otherwise.
Get the entity internal flags.
LDK_API u16 ldk_entity_internal_flags_get(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityThe requested value.
Check whether an entity has the requested internal flags.
LDK_API bool ldk_entity_internal_flags_has(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsTrue when the queried condition holds; false otherwise.
Set the entity name.
LDK_API bool ldk_entity_name_set(
LDKEntityRegistry *system,
LDKEntity entity,
const char *name
);
LDKEntityRegistry *systemLDKEntity entityconst char *nameTrue if the operation succeeds; false otherwise.
Get the entity name.
LDK_API const char * ldk_entity_name_get(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityPointer to the requested object or data; NULL when unavailable.
Compute an entity name hash.
LDK_API u64 ldk_entity_name_hash(const char *name);
const char *nameComputed identifier or hash.
Set the entity name hash.
LDK_API bool ldk_entity_name_hash_set(
LDKEntityRegistry *registry,
LDKEntity entity,
u64 hash
);
LDKEntityRegistry *registryLDKEntity entityu64 hashTrue if the operation succeeds; false otherwise.
Get the entity name hash.
LDK_API u64 ldk_entity_name_hash_get(
LDKEntityRegistry *registry,
LDKEntity entity
);
LDKEntityRegistry *registryLDKEntity entityComputed identifier or hash.
Count the entity component.
LDK_API u32 ldk_entity_component_count(
LDKEntityRegistry *system,
LDKEntity entity
);
LDKEntityRegistry *systemLDKEntity entityNumber of matching entries.
Get the entity transform.
LDK_API LDKTransform * ldk_entity_transform_get(
LDKEntityRegistry *entity_module,
LDKComponentRegistry *component_module,
LDKEntity entity
);
LDKEntityRegistry *entity_moduleLDKComponentRegistry *component_moduleLDKEntity entityPointer to the requested object or data; NULL when unavailable.
Get read-only access to the entity transform.
LDK_API const LDKTransform * ldk_entity_transform_get_const(
LDKEntityRegistry *entity_module,
LDKComponentRegistry *component_module,
LDKEntity entity
);
LDKEntityRegistry *entity_moduleLDKComponentRegistry *component_moduleLDKEntity entityPointer to the requested object or data; NULL when unavailable.
Check whether an entity owns a specific component.
LDK_API bool ldk_entity_component_has(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeTrue when the queried condition holds; false otherwise.
Get the entity component flags.
LDK_API u16 ldk_entity_component_flags_get(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeThe requested value.
Set the entity component flags.
LDK_API bool ldk_entity_component_flags_set(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeu16 flagsTrue if the operation succeeds; false otherwise.
Add the entity component flags.
LDK_API bool ldk_entity_component_flags_add(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeu16 flagsTrue if the operation succeeds; false otherwise.
Remove the entity component flags.
LDK_API bool ldk_entity_component_flags_remove(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeu16 flagsTrue if the operation succeeds; false otherwise.
Check whether a component instance has requested flags.
LDK_API bool ldk_entity_component_flags_has(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeu16 flagsTrue when the queried condition holds; false otherwise.
Check whether the component ref is valid.
LDK_API bool ldk_component_ref_is_valid(
LDKEntityRegistry *system,
LDKComponentRef ref
);
LDKEntityRegistry *systemLDKComponentRef refTrue when the queried condition holds; false otherwise.
Visit each living entity using a callback.
LDK_API void ldk_entity_foreach(
LDKEntityRegistry *system,
LDKEntityIterFn fn,
void *user
);
LDKEntityRegistry *systemLDKEntityIterFn fnvoid *userGet the entity component ref.
LDK_API bool ldk_entity_component_ref_get(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
LDKComponentRef *out_ref
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeLDKComponentRef *out_refTrue if the operation succeeds; false otherwise.
Find the entity component.
LDK_API bool ldk_entity_component_find(
LDKEntityRegistry *system,
LDKEntity entity,
u32 component_type,
u32 *out_slot,
u32 *out_component_index
);
LDKEntityRegistry *systemLDKEntity entityu32 component_typeu32 *out_slotu32 *out_component_indexTrue if the operation succeeds; false otherwise.
Resolve a component reference to its data.
LDK_API void * ldk_component_ref_get(
LDKEntityRegistry *entity_system,
struct LDKComponentRegistry *component_registry,
LDKComponentRef ref
);
LDKEntityRegistry *entity_systemstruct LDKComponentRegistry *component_registryLDKComponentRef refPointer to the requested object or data; NULL when unavailable.
Resolve a component reference as read-only data.
LDK_API const void * ldk_component_ref_get_const(
LDKEntityRegistry *entity_system,
struct LDKComponentRegistry *component_registry,
LDKComponentRef ref
);
LDKEntityRegistry *entity_systemstruct LDKComponentRegistry *component_registryLDKComponentRef refPointer to the requested object or data; NULL when unavailable.
Add the entity component.
LDK_API void * ldk_entity_component_add(
LDKEntityRegistry *entity_module,
LDKComponentRegistry *component_module,
LDKEntity entity,
u32 component_type,
const void *initial_value
);
LDKEntityRegistry *entity_moduleLDKComponentRegistry *component_moduleLDKEntity entityu32 component_typeconst void *initial_valuePointer to the requested object or data; NULL when unavailable.
Get the entity component.
LDK_API void * ldk_entity_component_get(
LDKEntityRegistry *entity_module,
LDKComponentRegistry *component_module,
LDKEntity entity,
u32 component_type
);
LDKEntityRegistry *entity_moduleLDKComponentRegistry *component_moduleLDKEntity entityu32 component_typePointer to the requested object or data; NULL when unavailable.
Remove the entity component.
LDK_API bool ldk_entity_component_remove(
LDKEntityRegistry *entity_module,
LDKComponentRegistry *component_module,
LDKEntity entity,
u32 component_type
);
LDKEntityRegistry *entity_moduleLDKComponentRegistry *component_moduleLDKEntity entityu32 component_typeTrue if the operation succeeds; false otherwise.
typedef struct LDKEntityIterator{
LDKEntityRegistry *registry;
XHPoolIter iter;
LDKEntity current;
u8 has_current;
}LDKEntityIterator;
Begin the entity iterator.
LDK_API LDKEntityIterator ldk_entity_iterator_begin(LDKEntityRegistry *registry);
LDKEntityRegistry *registryThe requested value.
Advance an entity iterator to the next entity.
LDK_API bool ldk_entity_iterator_next(
LDKEntityIterator *iterator,
LDKEntity *out_entity
);
LDKEntityIterator *iteratorLDKEntity *out_entityTrue if the operation succeeds; false otherwise.
Finish the entity iterator.
LDK_API void ldk_entity_iterator_end(LDKEntityIterator *iterator);
LDKEntityIterator *iteratorSet the entity internal flags.
LDK_API void ldk_entity_internal_flags_set(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsAdd the entity internal flags.
LDK_API void ldk_entity_internal_flags_add(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flagsRemove the entity internal flags.
LDK_API void ldk_entity_internal_flags_remove(
LDKEntityRegistry *system,
LDKEntity entity,
u16 flags
);
LDKEntityRegistry *systemLDKEntity entityu16 flags