diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-08 18:38:28 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-05-09 17:59:13 -0400 |
commit | 96e6f3231aed9919d660a06944f1d96dc8241f8e (patch) | |
tree | b2e633e7df6e0251afeec8a84a69be7b5944b175 /src/systems/pondering.h | |
parent | 296a1c3aa0bdb27e7ee9b53f0382938d0fe6d1a0 (diff) | |
download | therapy-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.h | 40 |
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 | ||
8 | struct 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 | |||
8 | class PonderingSystem : public System { | 21 | class PonderingSystem : public System { |
9 | public: | 22 | public: |
10 | 23 | ||
@@ -34,23 +47,28 @@ public: | |||
34 | 47 | ||
35 | private: | 48 | private: |
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, |