From 3e99a6fe36e63a1e14ba62f2a6e5a3827484e4e6 Mon Sep 17 00:00:00 2001 From: Max-001 <80035972+Max-001@users.noreply.github.com> Date: Wed, 2 Oct 2024 16:21:01 +0200 Subject: DeleteAllComponents created --- mwe/ecs-homemade/inc/ComponentManager.h | 12 ++++++++---- mwe/ecs-homemade/inc/ComponentManager.hpp | 12 +++++++++++- mwe/ecs-homemade/src/ComponentManager.cpp | 8 ++++++++ mwe/ecs-homemade/src/main.cpp | 2 ++ 4 files changed, 29 insertions(+), 5 deletions(-) (limited to 'mwe') diff --git a/mwe/ecs-homemade/inc/ComponentManager.h b/mwe/ecs-homemade/inc/ComponentManager.h index 763c28e..893aa56 100644 --- a/mwe/ecs-homemade/inc/ComponentManager.h +++ b/mwe/ecs-homemade/inc/ComponentManager.h @@ -18,12 +18,16 @@ public: ComponentManager& operator=(ComponentManager&&) = delete; //Singleton template - void AddComponent(std::uint32_t id, Args&&... args); //Add a component - //TODO: void DeleteAllComponentsOfId(std::uint32_t id); //Deletes all components of a specific id - //TODO: void DeleteAllComponents(); //Deletes all components + void AddComponent(std::uint32_t id, Args&&... args); //Add a component of a specific type + template + void DeleteComponentsById(std::uint32_t id); //Deletes all components of a specific type and id + template + void DeleteComponents(); //Deletes all components of a specific type + void DeleteAllComponentsOfId(std::uint32_t id); //Deletes all components of a specific id + void DeleteAllComponents(); //Deletes all components template - std::vector> GetComponentsByID(std::uint32_t id) const; //Get a vector<> of all components at specific id + std::vector> GetComponentsByID(std::uint32_t id) const; //Get a vector<> of all components at specific type and id template std::vector, std::uint32_t>> GetComponentsByType() const; //Get a vector<> of all components of a specific type diff --git a/mwe/ecs-homemade/inc/ComponentManager.hpp b/mwe/ecs-homemade/inc/ComponentManager.hpp index 03135a8..18bd548 100644 --- a/mwe/ecs-homemade/inc/ComponentManager.hpp +++ b/mwe/ecs-homemade/inc/ComponentManager.hpp @@ -14,6 +14,16 @@ void ComponentManager::AddComponent(std::uint32_t id, Args&&... args) { mComponents[type][id].push_back(std::make_unique(std::forward(args)...)); //Create a new component of type T using perfect forwarding and store its unique_ptr in the vector<> } +template +void ComponentManager::DeleteComponentsById(std::uint32_t id) { + +} + +template +void ComponentManager::DeleteComponents() { + +} + template std::vector> ComponentManager::GetComponentsByID(std::uint32_t id) const { std::type_index type = typeid(T); //Determine the type of T (this is used as the key of the unordered_map<>) @@ -62,5 +72,5 @@ std::vector, std::uint32_t>> ComponentManage } } - return componentVector; + return componentVector; //Return the vector<> } diff --git a/mwe/ecs-homemade/src/ComponentManager.cpp b/mwe/ecs-homemade/src/ComponentManager.cpp index 287da38..cca84bc 100644 --- a/mwe/ecs-homemade/src/ComponentManager.cpp +++ b/mwe/ecs-homemade/src/ComponentManager.cpp @@ -7,3 +7,11 @@ ComponentManager& ComponentManager::GetInstance() { } ComponentManager::ComponentManager() {} + +void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) { + +} + +void ComponentManager::DeleteAllComponents() { + mComponents.clear(); +} diff --git a/mwe/ecs-homemade/src/main.cpp b/mwe/ecs-homemade/src/main.cpp index 9e230e5..df229a2 100644 --- a/mwe/ecs-homemade/src/main.cpp +++ b/mwe/ecs-homemade/src/main.cpp @@ -99,6 +99,8 @@ int main() { } std::cout << std::endl; + ComponentManager::GetInstance().DeleteAllComponents(); + std::cout << "Finding all rigidbodies of all entities for the second time (after changing mMass to -1)" << std::endl; std::vector, std::uint32_t>> rigidBodies2 = ComponentManager::GetInstance().GetComponentsByType(); for(auto& [rigidbody2, id2] : rigidBodies2) { -- cgit v1.2.3