diff --git a/CopiumEngine/CopiumEngine.vcxproj b/CopiumEngine/CopiumEngine.vcxproj
index 47cb8f3..9ff3538 100644
--- a/CopiumEngine/CopiumEngine.vcxproj
+++ b/CopiumEngine/CopiumEngine.vcxproj
@@ -178,6 +178,10 @@
+
+
+
+
@@ -236,6 +240,12 @@
+
+
+
+
+
+
diff --git a/CopiumEngine/CopiumEngine.vcxproj.filters b/CopiumEngine/CopiumEngine.vcxproj.filters
index 8dbac8d..9558e2a 100644
--- a/CopiumEngine/CopiumEngine.vcxproj.filters
+++ b/CopiumEngine/CopiumEngine.vcxproj.filters
@@ -186,6 +186,18 @@
Source Files
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
@@ -380,5 +392,23 @@
Header Files
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
\ No newline at end of file
diff --git a/CopiumEngine/src/copium/ecs/ComponentPool.h b/CopiumEngine/src/copium/ecs/ComponentPool.h
new file mode 100644
index 0000000..2f0efdc
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/ComponentPool.h
@@ -0,0 +1,90 @@
+#pragma once
+
+#include "copium/ecs/Config.h"
+#include "copium/ecs/EntitySet.h"
+#include "copium/ecs/ComponentPoolBase.h"
+
+#include
+
+namespace Copium
+{
+ template
+ class ComponentPool : public ComponentPoolBase
+ {
+ using Iterator = typename std::vector::iterator;
+ private:
+ std::vector components;
+
+ public:
+ ComponentPool(EntityID entity, const Component& component)
+ {
+ Emplace(entity, component);
+ }
+
+ Component& Emplace(EntityID entity, const Component& component)
+ {
+ components.push_back(component);
+ entities.Emplace(entity);
+ return components.back();
+ }
+
+ void Pop()
+ {
+ components.pop_back();
+ entities.Pop();
+ }
+
+ bool Erase(EntityID entity)
+ {
+ size_t index = entities.Find(entity);
+ if (!entities.Erase(entity))
+ return false;
+ components.erase(components.begin() + index);
+ return true;
+ }
+
+ Component& At(size_t index)
+ {
+ return operator[](index);
+ }
+
+ size_t Find(EntityID entity)
+ {
+ return entities.Find(entity);
+ }
+
+ Component* FindComponent(EntityID entity)
+ {
+ size_t index = Find(entity);
+ if (index < Size())
+ return &components[index];
+ return nullptr;
+ }
+
+ Component& operator[](size_t index)
+ {
+ CP_ASSERT(index < components.size(), "Index Out of Bound Exception");
+ return components[index];
+ }
+
+ size_t Size()
+ {
+ return components.size();
+ }
+
+ Iterator Back()
+ {
+ return components.back();
+ }
+
+ Iterator begin()
+ {
+ return components.begin();
+ }
+
+ Iterator end()
+ {
+ return components.end();
+ }
+ };
+}
diff --git a/CopiumEngine/src/copium/ecs/ComponentPoolBase.cpp b/CopiumEngine/src/copium/ecs/ComponentPoolBase.cpp
new file mode 100644
index 0000000..067e1bb
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/ComponentPoolBase.cpp
@@ -0,0 +1,14 @@
+#include "copium/ecs/ComponentPoolBase.h"
+
+namespace Copium
+{
+ std::vector& ComponentPoolBase::GetEntities()
+ {
+ return entities.GetList();
+ }
+
+ const std::vector& ComponentPoolBase::GetEntities() const
+ {
+ return entities.GetList();
+ }
+}
diff --git a/CopiumEngine/src/copium/ecs/ComponentPoolBase.h b/CopiumEngine/src/copium/ecs/ComponentPoolBase.h
new file mode 100644
index 0000000..7ef4312
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/ComponentPoolBase.h
@@ -0,0 +1,23 @@
+#pragma once
+
+#include "copium/ecs/Config.h"
+#include "copium/ecs/EntitySet.h"
+
+#include
+
+namespace Copium
+{
+ class ComponentPoolBase
+ {
+ protected:
+ EntitySet entities;
+ public:
+ virtual ~ComponentPoolBase() = default;
+
+ virtual size_t Size() = 0;
+ virtual void Pop() = 0;
+ virtual bool Erase(EntityID entity) = 0;
+ std::vector& GetEntities();
+ const std::vector& GetEntities() const;
+ };
+}
diff --git a/CopiumEngine/src/copium/ecs/Config.h b/CopiumEngine/src/copium/ecs/Config.h
new file mode 100644
index 0000000..21ccf20
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/Config.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include
+#include
+
+namespace Copium
+{
+ using EntityID = uint32_t;
+ const static uint32_t MAX_NUM_ENTITIES = std::numeric_limits::max();
+ const static uint32_t INVALID_ENTITY = 0;
+}
diff --git a/CopiumEngine/src/copium/ecs/ECSManager.cpp b/CopiumEngine/src/copium/ecs/ECSManager.cpp
new file mode 100644
index 0000000..0ddccb2
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/ECSManager.cpp
@@ -0,0 +1,50 @@
+#include "copium/ecs/ECSManager.h"
+
+#include "copium/util/Common.h"
+
+namespace Copium
+{
+ ECSManager::~ECSManager()
+ {
+ for (auto&& components : componentPool)
+ {
+ delete components.second;
+ }
+ componentPool.clear();
+ }
+
+ size_t ECSManager::GetEntityCount() const
+ {
+ return entities.size();
+ }
+
+ EntityID ECSManager::CreateEntity()
+ {
+ CP_ASSERT(currentEntityId != MAX_NUM_ENTITIES, "No more entities available");
+ entities.emplace(currentEntityId);
+ currentEntityId++;
+ return currentEntityId - 1;
+ }
+
+ void ECSManager::DestroyEntity(EntityID entity)
+ {
+ auto it = entities.find(entity);
+ CP_ASSERT(it != entities.end(), "Entity does not exist in ECSManager (entity=%u)", entity);
+ entities.erase(it);
+ for (auto&& pool : componentPool)
+ {
+ pool.second->Erase(entity);
+ }
+ }
+
+ bool ECSManager::ValidEntity(EntityID entity)
+ {
+ return entities.find(entity) != entities.end();
+ }
+
+ void ECSManager::Each(std::function function)
+ {
+ for (auto e : entities)
+ function(e);
+ }
+}
diff --git a/CopiumEngine/src/copium/ecs/ECSManager.h b/CopiumEngine/src/copium/ecs/ECSManager.h
new file mode 100644
index 0000000..ecc69c1
--- /dev/null
+++ b/CopiumEngine/src/copium/ecs/ECSManager.h
@@ -0,0 +1,196 @@
+#pragma once
+
+
+#include "copium/ecs/ComponentPool.h"
+#include "copium/ecs/Config.h"
+#include "copium/util/Common.h"
+
+#include
+#include