From ddd703b00b6a3f1bc601e98548b410753fbfc340 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Mon, 11 Mar 2013 02:53:40 -0400 Subject: [PATCH] Use std::list for free list. --- entityx/Entity.h | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/entityx/Entity.h b/entityx/Entity.h index e9c5d3f..644456f 100644 --- a/entityx/Entity.h +++ b/entityx/Entity.h @@ -11,17 +11,18 @@ #pragma once -#include #include #include #include #include #include +#include #include +#include #include #include #include -#include + #include #include #include "entityx/Event.h" @@ -210,9 +211,6 @@ struct ComponentAddedEvent : public Event> { * shared_ptr controllable = player.assign(); */ class EntityManager : boost::noncopyable { - private: - typedef std::vector> EntitiesComponent; - public: EntityManager(EventManager &event_manager) : event_manager_(event_manager) {} @@ -350,9 +348,8 @@ class EntityManager : boost::noncopyable { id = id_counter_++; accomodate_entity(id); } else { - auto it = free_list_.begin(); - id = *it; - free_list_.erase(it); + id = free_list_.front(); + free_list_.pop_front(); } event_manager_.emit(Entity(this, id)); return Entity(this, id); @@ -370,7 +367,7 @@ class EntityManager : boost::noncopyable { components.at(entity).reset(); } entity_component_mask_.at(entity) = 0; - free_list_.insert(entity); + free_list_.push_back(entity); } Entity get(Entity::Id id) { @@ -516,11 +513,11 @@ class EntityManager : boost::noncopyable { EventManager &event_manager_; // A nested array of: components = entity_components_[family][entity] - std::vector entity_components_; + std::vector>> entity_components_; // Bitmask of components associated with each entity. Index into the vector is the Entity::Id. std::vector entity_component_mask_; // List of available Entity::Id IDs. - boost::unordered_set free_list_; + std::list free_list_; }; template -- 2.39.5