From fa78991795640df31e108c9e3e1667b96f72e9fd Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Fri, 26 Feb 2016 11:08:39 +0100 Subject: [PATCH] World::MemoryUsage returns approximate value of component pool memory usage --- include/Engine/Core/ComponentPool.h | 2 ++ include/Engine/Core/MemoryPool.h | 5 +++++ include/Engine/Core/World.h | 3 +++ src/Engine/Core/ComponentPool.cpp | 5 +++++ src/Engine/Core/World.cpp | 11 +++++++++++ 5 files changed, 26 insertions(+) diff --git a/include/Engine/Core/ComponentPool.h b/include/Engine/Core/ComponentPool.h index aedfd06b..68c937d3 100644 --- a/include/Engine/Core/ComponentPool.h +++ b/include/Engine/Core/ComponentPool.h @@ -65,6 +65,8 @@ public: iterator end() const; size_t size() const; + std::size_t MemoryUsage() const; + //Dumps information about what the pool memory looks like right now //into an output stream (e.g. file/std::cout, anything that has an operator<<) //Interpret the data in the memory as InterpretType. diff --git a/include/Engine/Core/MemoryPool.h b/include/Engine/Core/MemoryPool.h index 053e75aa..324b0086 100644 --- a/include/Engine/Core/MemoryPool.h +++ b/include/Engine/Core/MemoryPool.h @@ -194,6 +194,11 @@ public: return m_ExtraMemory.size(); } + std::size_t MemoryUsage() const + { + return size() * m_Stride; + } + //Dumps information about what the pool memory looks like right now //into an output stream (e.g. file/std::cout, anything that has an operator<<) //Interpret the data in the memory as InterpretType. diff --git a/include/Engine/Core/World.h b/include/Engine/Core/World.h index c9f738ce..05cd3f41 100644 --- a/include/Engine/Core/World.h +++ b/include/Engine/Core/World.h @@ -50,6 +50,9 @@ public: // Get the textual name of an entity std::string GetName(EntityID entity) const; + // Get an approximate number for component pool memory usage + std::size_t MemoryUsage() const; + private: EventBroker* m_EventBroker = nullptr; EntityID m_CurrentEntityID = 0; diff --git a/src/Engine/Core/ComponentPool.cpp b/src/Engine/Core/ComponentPool.cpp index 059b2e38..69878ed3 100644 --- a/src/Engine/Core/ComponentPool.cpp +++ b/src/Engine/Core/ComponentPool.cpp @@ -112,6 +112,11 @@ size_t ComponentPool::size() const return m_Pool.size(); } +std::size_t ComponentPool::MemoryUsage() const +{ + return m_Pool.MemoryUsage(); +} + template void ComponentPool::Dump() const { diff --git a/src/Engine/Core/World.cpp b/src/Engine/Core/World.cpp index 9b323ff4..191fe164 100644 --- a/src/Engine/Core/World.cpp +++ b/src/Engine/Core/World.cpp @@ -151,6 +151,17 @@ std::string World::GetName(EntityID entity) const } } +std::size_t World::MemoryUsage() const +{ + std::size_t mem = 0; + + for (auto& kv : m_ComponentPools) { + mem += kv.second->MemoryUsage(); + } + + return mem; +} + EntityID World::generateEntityID() { // TODO: Make EntityID generation smarter