Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
Infinity::Procedural::Registry Namespace Reference

Global registry for ProceduralComponent types and their factory functions. More...

Functions

INFINITY_API_PUBLIC ComponentID registerComponentWithString (const std::string &description, const std::filesystem::path &packagePath="")
 Registers a component from a YAML description string.
 
INFINITY_API_PUBLIC std::vector< ComponentIDregisterComponentLibrary (const std::filesystem::path &path)
 Registers all components from a shared library plugin.
 
INFINITY_API_PUBLIC std::vector< ComponentIDregisterComponentsInDirectory (const std::filesystem::path &path)
 Registers all components found in a directory.
 
INFINITY_API_PUBLIC ComponentID registerComponentWithFilepath (const std::filesystem::path &descriptorFile)
 Registers a component from a descriptor file.
 
INFINITY_API_PUBLIC ComponentID registerComponentWithDescriptor (const ProceduralComponentDescription &description)
 Registers a component from a ProceduralComponentDescription object.
 
INFINITY_API_PUBLIC ComponentID registerComponentWithFactory (const ProceduralComponentDescription &description, CreateComponentFunction *createComponent, DeleteComponentFunction *deleteComponent)
 Registers a component with custom factory functions.
 
template<typename T >
ComponentID registerComponent (const ProceduralComponentDescription &description)
 Registers a component type with automatic factory function generation.
 
INFINITY_API_PUBLIC ProceduralComponentcreateComponent (const std::string &group, const std::string &name)
 Creates a component instance by group and name.
 
INFINITY_API_PUBLIC ProceduralComponentcreateComponent (const ComponentID &id)
 Creates a component instance by ComponentID.
 
INFINITY_API_PUBLIC bool hasComponent (const ComponentID &id)
 Checks if a component type is registered.
 
INFINITY_API_PUBLIC std::filesystem::path pathToComponent (const ComponentID &id)
 Gets the package path for a registered component.
 
INFINITY_API_PUBLIC const ProceduralComponentDescriptiondescriptionForComponent (const ComponentID &id)
 Gets the description for a registered component.
 
INFINITY_API_PUBLIC std::vector< ComponentIDgetAvailableComponents ()
 Gets all registered component IDs.
 

Detailed Description

Global registry for ProceduralComponent types and their factory functions.

The Registry namespace provides functions for registering and creating ProceduralComponent instances. Components must be registered before they can be instantiated by the engine. Registration can occur through multiple mechanisms:

  • Loading component libraries (shared libraries/DLLs containing plugins)
  • Registering individual component descriptors
  • Scanning directories for component files
  • Direct registration with factory functions

Once registered, components are identified by their ComponentID (group and name) and can be instantiated on demand throughout the application lifecycle.

Function Documentation

◆ createComponent() [1/2]

INFINITY_API_PUBLIC ProceduralComponent * Infinity::Procedural::Registry::createComponent ( const ComponentID id)

Creates a component instance by ComponentID.

Instantiates a registered component using its ComponentID.

Parameters
idThe ComponentID of the component type to instantiate.
Returns
Pointer to the newly created ProceduralComponent instance.
Exceptions
std::runtime_errorif the component type is not registered.
Note
The caller is responsible for destroying the component using the registered delete function, not directly via delete.

◆ createComponent() [2/2]

INFINITY_API_PUBLIC ProceduralComponent * Infinity::Procedural::Registry::createComponent ( const std::string &  group,
const std::string &  name 
)

Creates a component instance by group and name.

Instantiates a registered component using its group and name identifiers.

Parameters
groupThe component's group identifier.
nameThe component's name within the group.
Returns
Pointer to the newly created ProceduralComponent instance.
Exceptions
std::runtime_errorif the component type is not registered.
Note
The caller is responsible for destroying the component using the registered delete function, not directly via delete.

◆ descriptionForComponent()

INFINITY_API_PUBLIC const ProceduralComponentDescription & Infinity::Procedural::Registry::descriptionForComponent ( const ComponentID id)

Gets the description for a registered component.

Returns the ProceduralComponentDescription that was used to register the component type.

Parameters
idThe ComponentID to query.
Returns
Const reference to the component's description.
Exceptions
std::runtime_errorif the component type is not registered.

◆ getAvailableComponents()

INFINITY_API_PUBLIC std::vector< ComponentID > Infinity::Procedural::Registry::getAvailableComponents ( )

Gets all registered component IDs.

Returns a list of all component types currently registered in the global registry.

Returns
Vector of all registered ComponentIDs.

◆ hasComponent()

INFINITY_API_PUBLIC bool Infinity::Procedural::Registry::hasComponent ( const ComponentID id)

Checks if a component type is registered.

Parameters
idThe ComponentID to check.
Returns
True if the component type is registered, false otherwise.

◆ pathToComponent()

INFINITY_API_PUBLIC std::filesystem::path Infinity::Procedural::Registry::pathToComponent ( const ComponentID id)

Gets the package path for a registered component.

Returns the base directory containing the component's files, including the shared library (if applicable) and any component-specific assets.

Parameters
idThe ComponentID to query.
Returns
The filesystem path to the component's package directory.
Exceptions
std::runtime_errorif the component type is not registered.

◆ registerComponent()

template<typename T >
ComponentID Infinity::Procedural::Registry::registerComponent ( const ProceduralComponentDescription description)

Registers a component type with automatic factory function generation.

Template function that registers a component type and automatically generates appropriate factory functions for creating and destroying instances. The component type T must inherit from ProceduralComponent and have a constructor accepting ProceduralComponentDescription.

Template Parameters
TThe component type to register. Must inherit from ProceduralComponent.
Parameters
descriptionThe component description containing metadata and configuration.
Returns
The ComponentID of the registered component.
Exceptions
std::runtime_errorif registration fails.

Example usage:

ProceduralComponentDescription desc("my_component.pcd");
ComponentID id = registerComponent<MyCustomComponent>(desc);
Description and configuration data for a ProceduralComponent instance.
Definition ProceduralComponentDescription.hpp:48
Unique identifier for a procedural component.
Definition ComponentID.hpp:35

◆ registerComponentLibrary()

INFINITY_API_PUBLIC std::vector< ComponentID > Infinity::Procedural::Registry::registerComponentLibrary ( const std::filesystem::path &  path)

Registers all components from a shared library plugin.

Loads a component library (shared library/DLL) and registers all component types provided by the plugin. The library must implement the plugin API defined in Infinity::Plugin::ComponentLibrary.

Parameters
pathPath to the shared library file (.dll, .so, or .dylib).
Returns
Vector of ComponentIDs for all components registered from this library.
Exceptions
std::runtime_errorif the library cannot be loaded or doesn't implement the required plugin interface.

◆ registerComponentsInDirectory()

INFINITY_API_PUBLIC std::vector< ComponentID > Infinity::Procedural::Registry::registerComponentsInDirectory ( const std::filesystem::path &  path)

Registers all components found in a directory.

Recursively scans the specified directory for component descriptor files (.pcd) and component libraries, registering all discovered components.

Parameters
pathPath to the directory to scan.
Returns
Vector of ComponentIDs for all components registered from this directory.
Exceptions
std::runtime_errorif the directory cannot be accessed or if any component registration fails.

◆ registerComponentWithDescriptor()

INFINITY_API_PUBLIC ComponentID Infinity::Procedural::Registry::registerComponentWithDescriptor ( const ProceduralComponentDescription description)

Registers a component from a ProceduralComponentDescription object.

Registers a component using an already-constructed component description. This is useful when building component descriptions programmatically.

Parameters
descriptionThe component description to register.
Returns
The ComponentID of the registered component.
Exceptions
std::runtime_errorif registration fails.

◆ registerComponentWithFactory()

INFINITY_API_PUBLIC ComponentID Infinity::Procedural::Registry::registerComponentWithFactory ( const ProceduralComponentDescription description,
CreateComponentFunction *  createComponent,
DeleteComponentFunction *  deleteComponent 
)

Registers a component with custom factory functions.

Registers a component type with explicit create and delete functions. This provides maximum control over component instantiation and destruction, which is essential for plugin systems and cross-DLL memory management.

Parameters
descriptionThe component description containing metadata and configuration.
createComponentFunction pointer for creating component instances.
deleteComponentFunction pointer for destroying component instances.
Returns
The ComponentID of the registered component.
Exceptions
std::runtime_errorif registration fails.

◆ registerComponentWithFilepath()

INFINITY_API_PUBLIC ComponentID Infinity::Procedural::Registry::registerComponentWithFilepath ( const std::filesystem::path &  descriptorFile)

Registers a component from a descriptor file.

Loads a component descriptor file (.pcd) and registers the component type. The descriptor file can be in YAML or FlatBuffer format.

Parameters
descriptorFilePath to the component descriptor file.
Returns
The ComponentID of the registered component.
Exceptions
std::runtime_errorif the file cannot be read, parsed, or registration fails.

◆ registerComponentWithString()

INFINITY_API_PUBLIC ComponentID Infinity::Procedural::Registry::registerComponentWithString ( const std::string &  description,
const std::filesystem::path &  packagePath = "" 
)

Registers a component from a YAML description string.

Parses the provided YAML string as a component description and registers the component type in the global registry.

Parameters
descriptionYAML-formatted string containing the component description.
packagePathOptional package path for resolving component files (default: empty).
Returns
The ComponentID of the registered component.
Exceptions
std::runtime_errorif the YAML cannot be parsed or registration fails.