From 26fbd8c1edaf94513d9750681edbe449b699efe4 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 22 Feb 2019 17:25:59 -0500 Subject: Trains move on tracks to the beat Small implementation changes in various places, biggest thing is now we're using ranges, which is experimental and will be included for real in C++20. --- src/schedule.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/schedule.h') diff --git a/src/schedule.h b/src/schedule.h index 5d77761..f7c5543 100644 --- a/src/schedule.h +++ b/src/schedule.h @@ -5,17 +5,23 @@ class Schedule { public: explicit Schedule( - size_t bpm) : + double bpm) : bpm_(bpm), - tick_(60.0 / static_cast(bpm_)) + bps_(bpm_ / 60.0), + tick_(1.0 / bps_) { } - size_t getBPM() const + double getBPM() const { return bpm_; } + double getBPS() const + { + return bps_; + } + void accumulate(double dt) { accum_ += dt; @@ -26,6 +32,7 @@ public: if (accum_ > tick_) { accum_ -= tick_; + beats_++; return true; } else { @@ -33,11 +40,18 @@ public: } } + size_t getBeat() const + { + return beats_; + } + private: - size_t bpm_; + double bpm_; + double bps_; double tick_; double accum_ = 0.0; + size_t beats_ = 0; }; -- cgit 1.4.1