Made string passing in World a little more effective

This commit is contained in:
2016-01-14 15:42:55 +01:00
parent 71d936f8d1
commit 28392def79
2 changed files with 10 additions and 10 deletions
+5 -5
View File
@@ -21,15 +21,15 @@ public:
// Register a component type and allocate space for it // Register a component type and allocate space for it
void RegisterComponent(ComponentInfo& ci); void RegisterComponent(ComponentInfo& ci);
// Attach a component to an entity and fill it with default values // Attach a component to an entity and fill it with default values
ComponentWrapper AttachComponent(EntityID entity, std::string componentType); ComponentWrapper AttachComponent(EntityID entity, const std::string& componentType);
// Check if an entity has a component // Check if an entity has a component
bool HasComponent(EntityID entity, std::string componentType) const; bool HasComponent(EntityID entity, const std::string& componentType) const;
// Get a component of an entity // Get a component of an entity
ComponentWrapper GetComponent(EntityID entity, std::string componentType); ComponentWrapper GetComponent(EntityID entity, const std::string& componentType);
// Delete a component off an entity // Delete a component off an entity
void DeleteComponent(EntityID entity, std::string componentType); void DeleteComponent(EntityID entity, const std::string& componentType);
// Get all components of the specified type // Get all components of the specified type
const ComponentPool* GetComponents(std::string componentType); const ComponentPool* GetComponents(const std::string& componentType);
// Get entity parent // Get entity parent
EntityID GetParent(EntityID entity); EntityID GetParent(EntityID entity);
// Change the parent of an entity // Change the parent of an entity
+5 -5
View File
@@ -66,7 +66,7 @@ void World::RegisterComponent(ComponentInfo& ci)
} }
} }
ComponentWrapper World::AttachComponent(EntityID entity, std::string componentType) ComponentWrapper World::AttachComponent(EntityID entity, const std::string& componentType)
{ {
// TODO: Allocate dynamic pool if component isn't registered // TODO: Allocate dynamic pool if component isn't registered
ComponentPool* pool = m_ComponentPools.at(componentType); ComponentPool* pool = m_ComponentPools.at(componentType);
@@ -80,26 +80,26 @@ ComponentWrapper World::AttachComponent(EntityID entity, std::string componentTy
return c; return c;
} }
bool World::HasComponent(EntityID entity, std::string componentType) const bool World::HasComponent(EntityID entity, const std::string& componentType) const
{ {
ComponentPool* pool = m_ComponentPools.at(componentType); ComponentPool* pool = m_ComponentPools.at(componentType);
return pool->KnowsEntity(entity); return pool->KnowsEntity(entity);
} }
ComponentWrapper World::GetComponent(EntityID entity, std::string componentType) ComponentWrapper World::GetComponent(EntityID entity, const std::string& componentType)
{ {
ComponentPool* pool = m_ComponentPools.at(componentType); ComponentPool* pool = m_ComponentPools.at(componentType);
return pool->GetByEntity(entity); return pool->GetByEntity(entity);
} }
void World::DeleteComponent(EntityID entity, std::string componentType) void World::DeleteComponent(EntityID entity, const std::string& componentType)
{ {
ComponentPool* pool = m_ComponentPools.at(componentType); ComponentPool* pool = m_ComponentPools.at(componentType);
ComponentWrapper c = pool->GetByEntity(entity); ComponentWrapper c = pool->GetByEntity(entity);
return pool->Delete(c); return pool->Delete(c);
} }
const ComponentPool* World::GetComponents(std::string componentType) const ComponentPool* World::GetComponents(const std::string& componentType)
{ {
auto it = m_ComponentPools.find(componentType); auto it = m_ComponentPools.find(componentType);
return (it != m_ComponentPools.end()) ? it->second : nullptr; return (it != m_ComponentPools.end()) ? it->second : nullptr;