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:
2014-05-17 17:46:17 +02:00
parent add27aa8f4
commit 542ad075ea
13 changed files with 268 additions and 256 deletions
+22 -2
View File
@@ -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: