ECS improved to make it less annoying to use
AddComponent<Components::Transform>(entity, "Transform") is now AddComponent<Components::Transform>(entity) etc.
This commit is contained in:
+22
-2
@@ -10,12 +10,18 @@ template <typename T>
|
||||
class Factory
|
||||
{
|
||||
public:
|
||||
void Register(std::string name, std::function<T(void)> factoryFunction)
|
||||
/*void Register(std::string name, std::function<T(void)> factoryFunction)
|
||||
{
|
||||
m_FactoryFunctions[name] = factoryFunction;
|
||||
}*/
|
||||
|
||||
template <typename T2>
|
||||
void Register(std::function<T(void)> factoryFunction)
|
||||
{
|
||||
m_FactoryFunctions[typeid(T2).name()] = factoryFunction;
|
||||
}
|
||||
|
||||
T Create(std::string name)
|
||||
/*T Create(std::string name)
|
||||
{
|
||||
auto it = m_FactoryFunctions.find(name);
|
||||
if (it != m_FactoryFunctions.end())
|
||||
@@ -26,6 +32,20 @@ public:
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}*/
|
||||
|
||||
template <typename T2>
|
||||
T Create()
|
||||
{
|
||||
auto it = m_FactoryFunctions.find(typeid(T2).name());
|
||||
if (it != m_FactoryFunctions.end())
|
||||
{
|
||||
return it->second();
|
||||
}
|
||||
else
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user