vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
Vkm::Engine::BehaviorRegistry Class Reference

Name -> factory registry for Behavior subclasses. More...

#include <behavior_registry.h>

Public Member Functions

void registerBehavior (std::string name, Factory factory)
 Register name -> factory.
template<typename T>
void registerBehavior ()
 Register T under the name its reflect block records.
template<typename... Ts>
void registerBehaviors ()
 Register every type in Ts, in order, as registerBehavior<T>() does.
std::unique_ptr< Behavior > create (const std::string &name) const
 Create a fresh instance by name.
bool contains (const std::string &name) const
 Report whether name has a registered factory.
std::vector< std::string > names () const
 List every registered behavior name, sorted.
void clear ()
 Drop every registered factory; call before unloading the module whose code they hold.

Detailed Description

Name -> factory registry for Behavior subclasses.

A gameplay module registers its types from vkmRegisterBehaviors. One per process, since game-DLL code must reach it.

Member Function Documentation

◆ registerBehavior() [1/2]

void Vkm::Engine::BehaviorRegistry::registerBehavior ( std::string name,
Factory factory )

Register name -> factory.

A duplicate name logs a warning and overwrites the existing factory.

Parameters
nameKey the type is registered and created under.
factoryConstructs a fresh instance.

◆ registerBehavior() [2/2]

template<typename T>
void Vkm::Engine::BehaviorRegistry::registerBehavior ( )
inline

Register T under the name its reflect block records.

The same string typeName() returns, so the save and load keys cannot differ.

Template Parameters
TBehavior subclass with a VKM_REFLECT block, default-constructible.

◆ registerBehaviors()

template<typename... Ts>
void Vkm::Engine::BehaviorRegistry::registerBehaviors ( )
inline

Register every type in Ts, in order, as registerBehavior<T>() does.

BehaviorRegistry::get().registerBehaviors<Spinner, Health, Door>();
Template Parameters
TsBehavior subclasses with VKM_REFLECT blocks.

◆ create()

std::unique_ptr< Behavior > Vkm::Engine::BehaviorRegistry::create ( const std::string & name) const

Create a fresh instance by name.

Parameters
nameRegistered type name.
Returns
The new instance, or nullptr, logged, when the name is unknown.

◆ contains()

bool Vkm::Engine::BehaviorRegistry::contains ( const std::string & name) const

Report whether name has a registered factory.

Parameters
nameBehavior type name.
Returns
True if a factory is registered under name.

◆ names()

std::vector< std::string > Vkm::Engine::BehaviorRegistry::names ( ) const

List every registered behavior name, sorted.

Returns
Sorted copy of the names.

The documentation for this class was generated from the following file: