diff --git a/src/ecs/component.cpp b/src/ecs/component.cpp index 3dfddb73..62e698db 100644 --- a/src/ecs/component.cpp +++ b/src/ecs/component.cpp @@ -2,16 +2,17 @@ namespace sp::ecs { -static std::vector all_component_storage; +static ComponentStorageBase* all_component_storage = nullptr; ComponentStorageBase::ComponentStorageBase() { - all_component_storage.push_back(this); + this->next = all_component_storage; + all_component_storage = this; } void ComponentStorageBase::destroyAll(uint32_t index) { - for(auto storage : all_component_storage) + for(auto storage = all_component_storage; storage; storage = storage->next) storage->destroy(index); } diff --git a/src/ecs/component.h b/src/ecs/component.h index 93f40c01..06b8dbed 100644 --- a/src/ecs/component.h +++ b/src/ecs/component.h @@ -8,6 +8,8 @@ class ComponentStorageBase { public: ComponentStorageBase(); +private: + ComponentStorageBase* next = nullptr; protected: static void destroyAll(uint32_t index); virtual void destroy(uint32_t index) = 0;