Skip to content

Engine → ECS → component_registry.h

component_registry

Syntax

class CONJURE_API component_registry

Constructors

AccessSignatureDescription
publiccomponent_registry();

Important

Copy constructor and assignment has been deleted. Move constructors have been deleted. Move assignment has been deleted.

Destructors

AccessSignatureDescription
public~component_registry();

Variables

AccessNameTypeDefaultDescription
privatemByNamestd::unordered_map<core::string_id, component_id>{}
privatemCountstd::atomic<u32>0
privatemDynamicEnumsstd::vector<std::unique_ptr<core::reflect::enum_info>>{}
privatemDynamicTypesstd::vector<std::unique_ptr<core::reflect::type_info>>{}
privatemMutexmutable std::mutex{}
privatemOnRegisteredcore::event<const component_info &>{}
privatemSerialu320
privatemTypesstd::vector<component_info>{}
privatemWorldsmutable std::vector<world *>{}

Functions

Public

count

[[nodiscard]] u32 count() const noexcept;

Number of registered types, unresolved_components included. Lock-free.

find

[[nodiscard]] component_id find(
    core::string_id name) const noexcept;

The id registered under name, or INVALID.

has_instances

[[nodiscard]] bool has_instances(
    component_id id) const;

True when any live world created on this registry holds an instance of id.

id_of

template <named_component ComponentType> [[nodiscard]] component_id id_of() const noexcept;

The id of a C++ type, INVALID when it is not registered here. Cached per type and registry serial, so the lookup costs one atomic load after the first call.

info

[[nodiscard]] const component_info &info(
    component_id id) const noexcept;

The description of a registered id. Asserts and returns the unresolved_components description for an id that is not registered. Lock-free.

is_registered

[[nodiscard]] bool is_registered(
    component_id id) const noexcept;

True when id names a registered type. Lock-free.

on_registered

[[nodiscard]] core::event<const component_info &> &on_registered() noexcept;

Fires once per new registration, on the registering thread, after the registry lock is released.

redefine_dynamic

[[nodiscard]] core::result<void> redefine_dynamic(
    component_id id,
    const dynamic_component_desc &desc);

Replaces the layout of a dynamic type while keeping its id (hot reload). COMPONENT_IN_USE while any live world holds an instance, UNKNOWN_COMPONENT for an id that is not dynamic, NAME_CONFLICT when the new description carries a different name.

register_component

template <named_component ComponentType> [[nodiscard]] core::result<component_id> register_component(
    component_flags flags = component_flags::NONE);

Registers a C++ type named with CONJURE_COMPONENT. Size, alignment, TAG/TRIVIAL flags and the lifecycle hooks come from the type, the reflection description from core::reflect::type_info_of (required unless the type is TRANSIENT or a tag), the entity and asset-reference field offsets and the default serializer from the description. Re-registering a name with the same layout and flags returns the existing id; NAME_CONFLICT otherwise. COMPONENT_LIMIT_REACHED, COMPONENT_TOO_LARGE, BAD_ALIGNMENT and UNSUPPORTED_FIELD as documented in.

register_described

[[nodiscard]] core::result<component_id> register_described(
    const component_type_desc &desc);

Registers a type from a module extension record (component_type_desc.h). The reflection description is deep-copied into the registry, nested struct and enum descriptions included, so the module may unload. The record's serializer hooks are copied as given: null for a reflected type (describe_component leaves them null and the registry's reflection walker serialises the deep copy, so nothing points into the module), while a type without reflection must supply writeJson and readJson (UNSUPPORTED_FIELD otherwise). A record whose size and TAG flag disagree (size 0 without TAG, or TAG with a non-zero size) is INVALID_ARGUMENT.

register_dynamic

[[nodiscard]] core::result<component_id> register_dynamic(
    const dynamic_component_desc &desc);

Registers a runtime-described type. Builds a reflection description from the fields, forces DYNAMIC | TRIVIAL and accepts an alignment in {1, 2, 4, 8, 16}. Same conflict and limit rules as register_component; for a dynamic type the fields are part of the layout, so re-registering a known name whose fields differ (order, name, type or offset) is NAME_CONFLICT even with the same size and alignment. redefine_dynamic replaces the description of such a type.

serial

[[nodiscard]] u32 serial() const noexcept;

The process-unique serial of this registry (never 0).

types

[[nodiscard]] std::span<const component_info> types() const noexcept;

Every registered type in id order (editor and test enumeration). The view stays valid for the registry's lifetime; it grows with later registrations.

Private

attach_world

void attach_world(
    world *target) const;

build_dynamic_type

[[nodiscard]] core::result<std::unique_ptr<core::reflect::type_info>> build_dynamic_type(
    const dynamic_component_desc &desc) const;

collect_field_offsets

[[nodiscard]] core::result<void> collect_field_offsets(
    component_info &info) const;

detach_world

void detach_world(
    world *target) const;

register_info

[[nodiscard]] core::result<component_id> register_info(
    component_info info);

validate_layout

[[nodiscard]] core::result<void> validate_layout(
    const component_info &info) const;