From d9c201cbf2fbfe315137e141d886a9bbfa6794ba Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 20 Feb 2019 16:44:09 -0500 Subject: 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. --- src/simulation.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/simulation.h') 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 @@ #include "entity.h" #include "renderer.h" +#include "schedule.h" +#include "grid_cache.h" #include #include #include -#include -#include class Level; @@ -17,7 +17,7 @@ public: using id_type = std::vector::size_type; // Constructor - explicit Simulation(const Level& level) : level_(level) {} + explicit Simulation(const Level& level); void tick( double dt, @@ -47,15 +47,12 @@ public: return level_; } - void setGridPos(id_type id, vec2s pos); - static vec2s posInDir(vec2s orig, Direction dir); private: - const std::unordered_set& getGridEntities(vec2s pos) const; bool moveEntityOnGrid( id_type id, @@ -63,12 +60,14 @@ private: bool validate = false); const Level& level_; + Schedule schedule_ { 120 }; std::vector entities_; std::deque available_; std::set active_; - mutable std::unordered_map> gridCache_; + mutable GridCache posCache_ { level_ }; + mutable GridCache moveToCache_ { level_ }; }; #endif /* end of include guard: SIMULATION_H_7BF6EEA4 */ -- cgit 1.4.1