From e0da16a63e917de65a40993a9dbc4b1e7b127c71 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 6 Nov 2019 15:47:16 +0900 Subject: [PATCH] Replace vector with deque for Component storage When reallocating more data, vector moves the original data to a new buffer. Deque preserves the location of the original data, preventing invalidated pointers to existing data when additional allocation is required. --- src/EC/Manager.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/EC/Manager.hpp b/src/EC/Manager.hpp index 5f10fd6..bca25fa 100644 --- a/src/EC/Manager.hpp +++ b/src/EC/Manager.hpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -67,14 +68,14 @@ namespace EC template struct Storage { - using type = std::tuple..., std::vector >; + using type = std::tuple..., std::deque >; }; using ComponentsStorage = typename EC::Meta::Morph >::type; // Entity: isAlive, ComponentsTags Info using EntitiesTupleType = std::tuple; - using EntitiesType = std::vector; + using EntitiesType = std::deque; EntitiesType entities; ComponentsStorage componentsStorage; @@ -103,7 +104,7 @@ namespace EC } EC::Meta::forEach([this, newCapacity] (auto t) { - std::get >( + std::get >( this->componentsStorage).resize(newCapacity); }); @@ -410,10 +411,10 @@ namespace EC constexpr auto index = EC::Meta::IndexOf::value; - // Cast required due to compiler thinking that vector at + // Cast required due to compiler thinking that deque at // index = Components::size is being used, even if the previous // if statement will prevent this from ever happening. - (*((std::vector*)(&std::get( + (*((std::deque*)(&std::get( componentsStorage ))))[entityID] = std::move(component); }