33 lines
825 B
C++
33 lines
825 B
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <unordered_map>
|
|
#include <vector>
|
|
|
|
namespace XCEngine {
|
|
namespace Components {
|
|
|
|
class Component;
|
|
class GameObject;
|
|
|
|
class ComponentFactoryRegistry {
|
|
public:
|
|
using CreateComponentFn = Component* (*)(GameObject* gameObject);
|
|
|
|
static ComponentFactoryRegistry& Get();
|
|
|
|
void RegisterFactory(const std::string& typeName, CreateComponentFn createFn);
|
|
Component* CreateComponent(GameObject* gameObject, const std::string& typeName) const;
|
|
bool IsRegistered(const std::string& typeName) const;
|
|
const std::vector<std::string>& GetRegisteredTypes() const;
|
|
|
|
private:
|
|
ComponentFactoryRegistry();
|
|
|
|
std::unordered_map<std::string, CreateComponentFn> m_factories;
|
|
std::vector<std::string> m_registrationOrder;
|
|
};
|
|
|
|
} // namespace Components
|
|
} // namespace XCEngine
|