Engine → ECS → component_registry.h
component_registry
| Type | Class |
| Namespace | conjure::ecs |
| Include File Path | engine/include/conjure/ecs/component_registry.h |
| Source File Path | engine/src/ecs/component_registry.cpp |
| API ↗ | Entities and components, Entities, components and systems |
Syntax
Constructors
| Access | Signature | Description |
|---|---|---|
| public | component_registry(); |
Important
Copy constructor and assignment has been deleted. Move constructors have been deleted. Move assignment has been deleted.
Destructors
| Access | Signature | Description |
|---|---|---|
| public | ~component_registry(); |
Variables
| Access | Name | Type | Default | Description |
|---|---|---|---|---|
| private | mByName | std:: | {} | |
| private | mCount | std::atomic<u32> | 0 | |
| private | m | std:: | {} | |
| private | m | std:: | {} | |
| private | mMutex | mutable std::mutex | {} | |
| private | m | core:: | {} | |
| private | mSerial | u32 | 0 | |
| private | mTypes | std:: | {} | |
| private | mWorlds | mutable std:: | {} |
Functions
Public
count
count[[nodiscard]] u32 count() const noexcept;Number of registered types, unresolved_components included. Lock-free.
find
find[[nodiscard]] component_id find(
core::string_id name) const noexcept;The id registered under name, or INVALID.
has_instances
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
id_oftemplate <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
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
is_registered[[nodiscard]] bool is_registered(
component_id id) const noexcept;True when id names a registered type. Lock-free.
on_registered
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
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
register_componenttemplate <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
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
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
serial[[nodiscard]] u32 serial() const noexcept;The process-unique serial of this registry (never 0).
types
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
attach_worldvoid attach_world(
world *target) const;build_dynamic_type
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
collect_field_offsets[[nodiscard]] core::result<void> collect_field_offsets(
component_info &info) const;detach_world
detach_worldvoid detach_world(
world *target) const;register_info
register_info[[nodiscard]] core::result<component_id> register_info(
component_info info);validate_layout
validate_layout[[nodiscard]] core::result<void> validate_layout(
const component_info &info) const;