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/schedule.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/schedule.h (limited to 'src/schedule.h') diff --git a/src/schedule.h b/src/schedule.h new file mode 100644 index 0000000..5d77761 --- /dev/null +++ b/src/schedule.h @@ -0,0 +1,44 @@ +#ifndef SCHEDULE_H_EF7B9D12 +#define SCHEDULE_H_EF7B9D12 + +class Schedule { +public: + + explicit Schedule( + size_t bpm) : + bpm_(bpm), + tick_(60.0 / static_cast(bpm_)) + { + } + + size_t getBPM() const + { + return bpm_; + } + + void accumulate(double dt) + { + accum_ += dt; + } + + bool step() + { + if (accum_ > tick_) + { + accum_ -= tick_; + + return true; + } else { + return false; + } + } + +private: + + size_t bpm_; + double tick_; + double accum_ = 0.0; + +}; + +#endif /* end of include guard: SCHEDULE_H_EF7B9D12 */ -- cgit 1.4.1