From 96e6f3231aed9919d660a06944f1d96dc8241f8e Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 8 May 2018 18:38:28 -0400 Subject: Started refactoring collision detection to use directional functor Because there was a lot of code replication with collision detection, this new implementation uses a functor that takes a parameter object describing the things that are different between the four directions. This allows the collision detection code to be writen only once. It's currently very ugly, but should work identically to before. --- src/systems/pondering.h | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/systems/pondering.h') diff --git a/src/systems/pondering.h b/src/systems/pondering.h index eed0d32..abc6db2 100644 --- a/src/systems/pondering.h +++ b/src/systems/pondering.h @@ -5,6 +5,19 @@ #include "components/ponderable.h" #include "direction.h" +struct CollisionResult +{ + double newX; + double newY; + bool stopProcessing = false; + bool touchedWall = false; + bool adjacentlyWarping = false; + Direction adjWarpDir; + size_t adjWarpMapId; + bool grounded = false; + EntityManager::id_type groundEntity; +}; + class PonderingSystem : public System { public: @@ -34,23 +47,28 @@ public: private: - struct CollisionResult - { - double newX; - double newY; - bool stopProcessing = false; - bool touchedWall = false; - bool adjacentlyWarping = false; - Direction adjWarpDir; - size_t adjWarpMapId; - id_type groundEntity; - }; + void tickBody( id_type entity, double dt, const std::set& entities); + CollisionResult moveBody( + id_type entity, + double x, + double y); + + CollisionResult detectCollisions( + id_type entity, + double x, + double y); + + template + void detectCollisionsInDirection( + id_type entity, + CollisionResult& result); + void processCollision( id_type entity, id_type collider, -- cgit 1.4.1