diff --git a/include/Engine/Collision/CollisionSystem.h b/include/Engine/Collision/CollisionSystem.h index e7a862f7..254a2461 100644 --- a/include/Engine/Collision/CollisionSystem.h +++ b/include/Engine/Collision/CollisionSystem.h @@ -9,18 +9,18 @@ #include "Core/EventBroker.h" #include "Core/EKeyUp.h" -class CollisionSystem : public System +class CollisionSystem : public PureSystem { public: CollisionSystem(EventBroker* eventBroker) - : System(eventBroker, "AABB") + : PureSystem(eventBroker, "AABB") , zPress(false) { //TODO: Debug stuff, remove later. EVENT_SUBSCRIBE_MEMBER(m_EKeyUp, &CollisionSystem::OnKeyUp); } - virtual void Update(World* world, ComponentWrapper& cAABB, double dt) override; + virtual void UpdateComponent(World* world, ComponentWrapper& cAABB, double dt) override; private: bool zPress; diff --git a/src/Engine/Collision/CollisionSystem.cpp b/src/Engine/Collision/CollisionSystem.cpp index e1fcb0a2..ee5d4d29 100644 --- a/src/Engine/Collision/CollisionSystem.cpp +++ b/src/Engine/Collision/CollisionSystem.cpp @@ -2,16 +2,13 @@ #include "Collision/CollisionSystem.h" #include "Core/AABB.h" -void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt) +void CollisionSystem::UpdateComponent(World * world, ComponentWrapper & cAABB, double dt) { //cAABB is any entity that should be collideable. - m_EventBroker->Process(); - //Currently the box is translated according to the models Transform matrix, - //but not scaled (or rotated since it's AABB). This should be fine, if we don't - //want to shrink or scale up an collideable object after creation. - cAABB["BoxCenter"] = (glm::vec3)world->GetComponent(cAABB.EntityID, "Transform")["Position"]; AABB thisBox; - thisBox.CreateFromCenter(cAABB["BoxCenter"], cAABB["BoxSize"]); + if (!Collision::GetEntityBox(world, cAABB, thisBox)) { + return; + } //Here c should be an object that moves, currently only players. if (zPress) { return; @@ -21,8 +18,9 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt) continue; } AABB otherBox; - ComponentWrapper& aabbComp = world->GetComponent(mover.EntityID, "AABB"); - otherBox.CreateFromCenter(aabbComp["BoxCenter"], aabbComp["BoxSize"]); + if (!Collision::GetEntityBox(world, mover.EntityID, otherBox)) { + continue; + } if (Collision::AABBVsAABB(thisBox, otherBox)) { ComponentWrapper& trans = world->GetComponent(mover.EntityID, "Transform"); //TODO: Move entity to correct position on collision instead of this. Special treatment if both are movers. @@ -30,7 +28,6 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt) float moveSpeed = 0.12f; newPos += moveSpeed * glm::normalize(newPos - thisBox.Center()); trans["Position"] = newPos; - aabbComp["BoxCenter"] = newPos; } } } @@ -38,9 +35,7 @@ void CollisionSystem::Update(World * world, ComponentWrapper & cAABB, double dt) bool CollisionSystem::OnKeyUp(const Events::KeyUp & event) { if (event.KeyCode == GLFW_KEY_Z) { - zPress = true; - } else if (event.KeyCode == GLFW_KEY_X) { - zPress = false; + zPress = !zPress; } return false; }