From 7c88558c55571ca33c10e22d61f1d98e349fab7c Mon Sep 17 00:00:00 2001 From: benkyd Date: Wed, 8 Jun 2022 00:04:25 +0000 Subject: [PATCH] entity component API sorted --- Aeon/Aeon.hpp | 2 + .../CoreComponents/PositionComponent.hpp | 10 ++++ Aeon/Entity/Entity.hpp | 17 ++++++- Aeon/Entity/EntityController.hpp | 49 +++++++++++++++++++ Aeon/Includes.hpp | 2 + CMakeLists.txt | 2 + 6 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Aeon/Entity/CoreComponents/PositionComponent.hpp diff --git a/Aeon/Aeon.hpp b/Aeon/Aeon.hpp index 70664dd..39a96a5 100644 --- a/Aeon/Aeon.hpp +++ b/Aeon/Aeon.hpp @@ -7,6 +7,7 @@ #include #include #include +#include namespace Core { @@ -43,6 +44,7 @@ public: private: Display mDisplay; + EC::EntityController& mEntityController; Input::InputController& mInput; // Game layers from z orderxko285132046 diff --git a/Aeon/Entity/CoreComponents/PositionComponent.hpp b/Aeon/Entity/CoreComponents/PositionComponent.hpp new file mode 100644 index 0000000..639c992 --- /dev/null +++ b/Aeon/Entity/CoreComponents/PositionComponent.hpp @@ -0,0 +1,10 @@ +#ifndef AEON_ENTITY_CORECOMPONENTS_POSITIONCOMPONENT_H_ +#define AEON_ENTITY_CORECOMPONENTS_POSITIONCOMPONENT_H_ + +template +struct Position +{ + // Vector data; +} + +#endif diff --git a/Aeon/Entity/Entity.hpp b/Aeon/Entity/Entity.hpp index 17a2c37..ed1be9e 100644 --- a/Aeon/Entity/Entity.hpp +++ b/Aeon/Entity/Entity.hpp @@ -1,12 +1,27 @@ +#ifndef AEON_ENTITY_ENTITY_H_ +#define AEON_ENTITY_ENTITY_H_ #include namespace EC { +template struct Entity { - uint32_t id; + T id; + + inline bool operator==( const Entity& rhs ) + { + return rhs.id == id; + } + + inline bool operator!=( const Entity& rhs ) + { + return rhs.id != id; + } }; } + +#endif diff --git a/Aeon/Entity/EntityController.hpp b/Aeon/Entity/EntityController.hpp index 464814e..006eea0 100644 --- a/Aeon/Entity/EntityController.hpp +++ b/Aeon/Entity/EntityController.hpp @@ -1,8 +1,57 @@ +#ifndef AEON_ENTITY_ENTITYCONTROLLER_H_ +#define AEON_ENTITY_ENTITYCONTROLLER_H_ + +#include + +struct Entity; +struct Component; namespace EC { +// TODO: Entities space in memory should be pre-allocated +// using the engine's lifecycle bump allocator +class EntityRegistry +{ +public: + EntityRegistry(); + ~EntityRegistry(); + Entity& Create(); + Entity& Copy(const Entity& entity); + Entity& Destroy(Entity& entity); + bool Valid(const Entity& entity); + + // add, replace components + template + TComponent& Add(const Entity& entity); + + template + TComponent& Replace(const Entity& entity); + + // replace inplace + template + TComponent& Patch(const Entity& entity); + + // Get component from entity based on T + template + TComponent& Get(const Entity& entity); + + // Get std::optional from entity based on T + template + std::optional Opt(const Entity& entity); + + // TODO: Sort by component properties, for example list of + // entities with the renderable components, sorted by Y pos + // of position component + // template + // std::vector Sort(std::function<; + +private: + + +}; } +#endif diff --git a/Aeon/Includes.hpp b/Aeon/Includes.hpp index f69b0ef..682000c 100644 --- a/Aeon/Includes.hpp +++ b/Aeon/Includes.hpp @@ -19,5 +19,7 @@ extern "C" { #include #include #include +#include +#include #endif diff --git a/CMakeLists.txt b/CMakeLists.txt index 7848b1d..722d679 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,8 @@ file(GLOB EngineSource Aeon/*.cpp Aeon/Core/*.cpp Aeon/Debug/*.cpp + Aeon/Entity/*.cpp + Aeon/Entity/CoreComponents/*.cpp Aeon/Input/*.cpp Aeon/Maths/*.cpp Aeon/Rendering/*.cpp