Deki 1.3.0
Modular C++ 2D engine for embedded displays and desktop
Loading...
Searching...
No Matches
ComponentFactory.h File Reference

Simple component factory using a single hash map. More...

Classes

class  SceneFormat::ComponentFactory
 Creates components by type id (see the file comment above). More...

Namespaces

namespace  SceneFormat

Macros

#define COMPONENT_FACTORY_API
#define REGISTER_RUNTIME_COMPONENT(ClassName)
 Register a component type for runtime creation.

Typedefs

using SceneFormat::ComponentCreator = DekiComponent* (*)()
 Function pointer type for component creators.

Detailed Description

Simple component factory using a single hash map.

All components (engine and plugins) register into one hash map. Engine components auto-register via generated code. Plugin/game components register at startup using REGISTER_RUNTIME_COMPONENT.

Usage: // Register a component (plugins/games do this at startup) REGISTER_RUNTIME_COMPONENT(MyComponent);

// Create any component by type ID auto* comp = ComponentFactory::Instance().Create(DekiHashString("MyComponent"));

Macro Definition Documentation

◆ COMPONENT_FACTORY_API

#define COMPONENT_FACTORY_API

◆ REGISTER_RUNTIME_COMPONENT

#define REGISTER_RUNTIME_COMPONENT ( ClassName)
Value:
static struct ClassName##_FactoryRegistrar \
{ \
ClassName##_FactoryRegistrar() \
{ \
SceneFormat::ComponentFactory::Instance().Register( \
ClassName::StaticType, \
[]() -> DekiComponent* { return new ClassName(); }); \
} \
} s_##ClassName##_FactoryRegistrar
Base class for all components (data-only).
Definition DekiComponent.h:51

Register a component type for runtime creation.

Uses static initialization to register the component. Engine components use this in package-specific registration files (e.g. 2DRegistration.gen.cpp). Plugins/games use this at startup for their components.

Usage: REGISTER_RUNTIME_COMPONENT(SkyComponent);