summary refs log tree commit diff stats
path: root/src/simulation.h
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2019-02-20 16:44:09 -0500
committerKelly Rauchenberger <fefferburbia@gmail.com>2019-02-20 16:44:09 -0500
commitd9c201cbf2fbfe315137e141d886a9bbfa6794ba (patch)
tree2dfaf8db9e43e456386796d797884ea18d63befe /src/simulation.h
parent8996810b1356c2224d4f34423fd4211de20da238 (diff)
downloaddispatcher-d9c201cbf2fbfe315137e141d886a9bbfa6794ba.tar.gz
dispatcher-d9c201cbf2fbfe315137e141d886a9bbfa6794ba.tar.bz2
dispatcher-d9c201cbf2fbfe315137e141d886a9bbfa6794ba.zip
Started implementing schedule
Scheduled entities move downward every beat, although they have a speed that is twice the bpm, so essentially they move every other beat?

Broke the simulation loop such that different parts run independently -- made it horizontal rather than vertical.

Encapsulated the grid cache so that more than one position field could be cached. This is used to make sure that an entity can't move into a space that something else is already moving into.

Fixed issue where an entity could move perpendicularly into the space an entity was moving out of.
Diffstat (limited to 'src/simulation.h')
-rw-r--r--src/simulation.h13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/simulation.h b/src/simulation.h index 4d41b49..f86d513 100644 --- a/src/simulation.h +++ b/src/simulation.h
@@ -3,11 +3,11 @@
3 3
4#include "entity.h" 4#include "entity.h"
5#include "renderer.h" 5#include "renderer.h"
6#include "schedule.h"
7#include "grid_cache.h"
6#include <vector> 8#include <vector>
7#include <deque> 9#include <deque>
8#include <set> 10#include <set>
9#include <unordered_map>
10#include <unordered_set>
11 11
12class Level; 12class Level;
13 13
@@ -17,7 +17,7 @@ public:
17 using id_type = std::vector<Entity>::size_type; 17 using id_type = std::vector<Entity>::size_type;
18 18
19 // Constructor 19 // Constructor
20 explicit Simulation(const Level& level) : level_(level) {} 20 explicit Simulation(const Level& level);
21 21
22 void tick( 22 void tick(
23 double dt, 23 double dt,
@@ -47,15 +47,12 @@ public:
47 return level_; 47 return level_;
48 } 48 }
49 49
50 void setGridPos(id_type id, vec2s pos);
51
52 static vec2s posInDir(vec2s orig, Direction dir); 50 static vec2s posInDir(vec2s orig, Direction dir);
53 51
54private: 52private:
55 53
56 54
57 55
58 const std::unordered_set<id_type>& getGridEntities(vec2s pos) const;
59 56
60 bool moveEntityOnGrid( 57 bool moveEntityOnGrid(
61 id_type id, 58 id_type id,
@@ -63,12 +60,14 @@ private:
63 bool validate = false); 60 bool validate = false);
64 61
65 const Level& level_; 62 const Level& level_;
63 Schedule schedule_ { 120 };
66 64
67 std::vector<Entity> entities_; 65 std::vector<Entity> entities_;
68 std::deque<id_type> available_; 66 std::deque<id_type> available_;
69 std::set<id_type> active_; 67 std::set<id_type> active_;
70 68
71 mutable std::unordered_map<size_t, std::unordered_set<id_type>> gridCache_; 69 mutable GridCache<id_type> posCache_ { level_ };
70 mutable GridCache<id_type> moveToCache_ { level_ };
72}; 71};
73 72
74#endif /* end of include guard: SIMULATION_H_7BF6EEA4 */ 73#endif /* end of include guard: SIMULATION_H_7BF6EEA4 */