From 8b69b8cb28f0ef43d1039b7616ca893344e236cd Mon Sep 17 00:00:00 2001 From: Max-001 <80035972+Max-001@users.noreply.github.com> Date: Wed, 2 Oct 2024 17:01:47 +0200 Subject: Added DeleteAllComponentsOfId methode --- mwe/ecs-homemade/src/ComponentManager.cpp | 6 +++++- mwe/ecs-homemade/src/main.cpp | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'mwe') diff --git a/mwe/ecs-homemade/src/ComponentManager.cpp b/mwe/ecs-homemade/src/ComponentManager.cpp index def50be..16cc2b6 100644 --- a/mwe/ecs-homemade/src/ComponentManager.cpp +++ b/mwe/ecs-homemade/src/ComponentManager.cpp @@ -9,7 +9,11 @@ ComponentManager& ComponentManager::GetInstance() { ComponentManager::ComponentManager() {} void ComponentManager::DeleteAllComponentsOfId(std::uint32_t id) { - + for(auto& [type, componentArray] : mComponents) { //Loop through all the types (in the unordered_map<>) + if (id < componentArray.size()) { //Make sure that the id (that we are looking for) is within the boundaries of the vector<> + componentArray[id].clear(); //Clear the components at this specific id + } + } } void ComponentManager::DeleteAllComponents() { diff --git a/mwe/ecs-homemade/src/main.cpp b/mwe/ecs-homemade/src/main.cpp index f0b94f0..2ee6edd 100644 --- a/mwe/ecs-homemade/src/main.cpp +++ b/mwe/ecs-homemade/src/main.cpp @@ -69,8 +69,8 @@ int main() { } std::cout << std::endl; - ComponentManager::GetInstance().DeleteComponentsById(gameObect2.mId); - gameObect2.AddComponent(); + ComponentManager::GetInstance().DeleteAllComponentsOfId(gameObect0.mId); + gameObect0.AddComponent(-10, -120, -564); std::cout << "Finding all rigidbodies of entity 3" << std::endl; std::vector> rigidbodyOfEntity3 = ComponentManager::GetInstance().GetComponentsByID(gameObect3.mId); -- cgit v1.2.3