Class responsible for registering and then creating GameObjects eg. Player, CameraObject. It is needed to load GameObjects from scene files but not all GameObjects can be registered. It requires your GameObject to not change constructor parameters. More...
#include <GameObjectFactory.hpp>
Public Types | |
| using | ObjectConstructor = GameObject* (*)(Engine&, const std::string&) |
| using | Creator = std::function<GameObject*(Engine&, const std::string&)> |
Public Member Functions | |
| template<typename T> | |
| void | registerClass (const std::string &name, bool isDynamic=false) |
| Register a GameObject class with the factory. | |
| GameObject * | create (const std::string &type, Engine &engine, const std::string &name) |
| Create a GameObject instance of the specified type string. | |
| std::vector< std::string > | GetAllRegisteredObjectTypes () |
| Get all registered object types. | |
| std::vector< std::string > | GetNonDynamicRegisteredObjectTypes () |
| Get all non-dynamic registered object types. | |
| std::vector< std::string > | GetDynamicRegisteredObjectTypes () |
| Get all dynamic registered object types. | |
| void | clearDynamicGameObjects () |
| Clears all GameObjects registered as dynamic. | |
| void | UnregisterGameObjects () |
| Unregisters all GameObjects and clears internal lists. | |
Static Public Member Functions | |
| static GameObjectFactory & | getInstance () |
| Get the singleton instance of the GameObjectFactory. | |
| template<typename T> | |
| static GameObject * | constructObject (Engine &engine, const std::string &name) |
| constructs registered objects, used internally in scene loading. | |
Private Member Functions | |
| void | registerCreator (const std::string &name, ObjectConstructor ctor, bool isDynamic) |
| Registers a creator function for a specific GameObject type string. | |
Private Attributes | |
| std::unordered_map< std::string, Creator > | creators |
| std::vector< std::string > | dynamicTypes |
| std::vector< std::string > | nonDynamicTypes |
| std::vector< std::string > | allTypes |
Class responsible for registering and then creating GameObjects eg. Player, CameraObject. It is needed to load GameObjects from scene files but not all GameObjects can be registered. It requires your GameObject to not change constructor parameters.
Definition at line 23 of file GameObjectFactory.hpp.
| using vex::GameObjectFactory::Creator = std::function<GameObject*(Engine&, const std::string&)> |
Definition at line 27 of file GameObjectFactory.hpp.
| using vex::GameObjectFactory::ObjectConstructor = GameObject* (*)(Engine&, const std::string&) |
Definition at line 25 of file GameObjectFactory.hpp.
| void vex::GameObjectFactory::clearDynamicGameObjects | ( | ) |
Clears all GameObjects registered as dynamic.
Used during hot-reload. Iterates through dynamicTypes, removes them from the creators map, and resets the allTypes list.
Definition at line 48 of file GameObjectFactory.cpp.
|
inlinestatic |
constructs registered objects, used internally in scene loading.
Definition at line 34 of file GameObjectFactory.hpp.
| GameObject * vex::GameObjectFactory::create | ( | const std::string & | type, |
| Engine & | engine, | ||
| const std::string & | name ) |
Create a GameObject instance of the specified type string.
Looks up the creator in the creators map. If found, invokes it. If not found, logs an error and returns nullptr.
| const | std::string& type - The registered type string. |
| Engine& | engine - The engine instance to pass to the constructor. |
| const | std::string& name - The name for the new GameObject instance. |
Definition at line 27 of file GameObjectFactory.cpp.
| std::vector< std::string > vex::GameObjectFactory::GetAllRegisteredObjectTypes | ( | ) |
Get all registered object types.
Definition at line 36 of file GameObjectFactory.cpp.
| std::vector< std::string > vex::GameObjectFactory::GetDynamicRegisteredObjectTypes | ( | ) |
Get all dynamic registered object types.
Definition at line 44 of file GameObjectFactory.cpp.
|
static |
Get the singleton instance of the GameObjectFactory.
Definition at line 6 of file GameObjectFactory.cpp.
| std::vector< std::string > vex::GameObjectFactory::GetNonDynamicRegisteredObjectTypes | ( | ) |
Get all non-dynamic registered object types.
Definition at line 40 of file GameObjectFactory.cpp.
|
inline |
Register a GameObject class with the factory.
| std::string& | name The name of the GameObject class. |
| bool | isDynamic Whether the GameObject class is dynamic. |
Definition at line 42 of file GameObjectFactory.hpp.
|
private |
Registers a creator function for a specific GameObject type string.
Stores a lambda in the creators map that constructs the object and sets its objectType. Appends the name to allTypes and either dynamicTypes or nonDynamicTypes based on the flag.
| const | std::string& name - The string identifier for the class. |
| ObjectConstructor | ctor - Function pointer to the constructor. |
| bool | isDynamic - True if this class is part of a hot-reloadable module. |
Definition at line 11 of file GameObjectFactory.cpp.
| void vex::GameObjectFactory::UnregisterGameObjects | ( | ) |
Unregisters all GameObjects and clears internal lists.
Clears creators, dynamicTypes, nonDynamicTypes, and allTypes.
Definition at line 59 of file GameObjectFactory.cpp.
|
private |
Definition at line 90 of file GameObjectFactory.hpp.
|
private |
Definition at line 87 of file GameObjectFactory.hpp.
|
private |
Definition at line 88 of file GameObjectFactory.hpp.
|
private |
Definition at line 89 of file GameObjectFactory.hpp.