summary refs log tree commit diff stats
path: root/src/systems/pondering.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2018-05-08 18:38:28 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2018-05-09 17:59:13 -0400
commit96e6f3231aed9919d660a06944f1d96dc8241f8e (patch)
treeb2e633e7df6e0251afeec8a84a69be7b5944b175 /src/systems/pondering.h
parent296a1c3aa0bdb27e7ee9b53f0382938d0fe6d1a0 (diff)
downloadtherapy-96e6f3231aed9919d660a06944f1d96dc8241f8e.tar.gz
therapy-96e6f3231aed9919d660a06944f1d96dc8241f8e.tar.bz2
therapy-96e6f3231aed9919d660a06944f1d96dc8241f8e.zip
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.
Diffstat (limited to 'src/systems/pondering.h')
-rw-r--r--src/systems/pondering.h40
1 files changed, 29 insertions, 11 deletions
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 @@
5#include "components/ponderable.h" 5#include "components/ponderable.h"
6#include "direction.h" 6#include "direction.h"
7 7
8struct CollisionResult
9{
10 double newX;
11 double newY;
12 bool stopProcessing = false;
13 bool touchedWall = false;
14 bool adjacentlyWarping = false;
15 Direction adjWarpDir;
16 size_t adjWarpMapId;
17 bool grounded = false;
18 EntityManager::id_type groundEntity;
19};
20
8class PonderingSystem : public System { 21class PonderingSystem : public System {
9public: 22public:
10 23
@@ -34,23 +47,28 @@ public:
34 47
35private: 48private:
36 49
37 struct CollisionResult 50
38 {
39 double newX;
40 double newY;
41 bool stopProcessing = false;
42 bool touchedWall = false;
43 bool adjacentlyWarping = false;
44 Direction adjWarpDir;
45 size_t adjWarpMapId;
46 id_type groundEntity;
47 };
48 51
49 void tickBody( 52 void tickBody(
50 id_type entity, 53 id_type entity,
51 double dt, 54 double dt,
52 const std::set<id_type>& entities); 55 const std::set<id_type>& entities);
53 56
57 CollisionResult moveBody(
58 id_type entity,
59 double x,
60 double y);
61
62 CollisionResult detectCollisions(
63 id_type entity,
64 double x,
65 double y);
66
67 template <typename Param>
68 void detectCollisionsInDirection(
69 id_type entity,
70 CollisionResult& result);
71
54 void processCollision( 72 void processCollision(
55 id_type entity, 73 id_type entity,
56 id_type collider, 74 id_type collider,