From a4d7d26e9854050920afb6eb87ac6bdab473ad12 Mon Sep 17 00:00:00 2001 From: NaiJi Date: Thu, 8 Apr 2021 19:08:01 +0300 Subject: [PATCH] Force update active note on tap --- application.cpp | 41 +++++++++++++++++++++-------------------- application.h | 4 ++++ debughelper.cpp | 2 +- timeline.cpp | 3 ++- timeline.h | 2 +- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/application.cpp b/application.cpp index 355d024..dd9e45d 100644 --- a/application.cpp +++ b/application.cpp @@ -1,5 +1,5 @@ #include "application.h" -#include "note.h" + #include #include @@ -9,11 +9,12 @@ Application::Application() : _game_window({1280, 720}, "Test"), _debug(true) { - _font.loadFromFile("VeraMono.ttf"); + _font.loadFromFile("/usr/share/qtcreator/fonts/SourceCodePro-Regular.ttf"); _grade.setFont(_font); _grade.setPosition(160, 160); - _grade.setFillColor(sf::Color(255, 255, 255, 0)); + _grade.setFillColor(sf::Color(255, 0, 0, 0)); _grade.setCharacterSize(35); + _grade.setString("NOT INIT"); } void Application::run() @@ -22,7 +23,7 @@ void Application::run() _music.openFromFile(song_filename); _music.play(); - _music.setVolume(5); + _music.setVolume(2); _game_window.display(); @@ -141,23 +142,23 @@ void Application::onKeyPressed(const sf::Keyboard::Key &key) return; } - const auto arrow = keyToArrow(key); + onTap(keyToArrow(key)); +} - if (arrow != Note::Arrow::NONE) - { // TODO: SHIT BLOCK. - _debug.spawnGreenPulse(); - const auto note = _timeline.getActiveNote(); - if (note) - { - // This is obscure. Active note on timeline gets received by last ::update() call. - // there can be 100-200 microseconds delay between onKeyPressed and update... - // Also the problem is that we get music offset by CURRENT music time, - // when active note is activated by music time of last ::update call - // anyway gotta think on it, smh smh smh - const auto music_offset = _music.getPlayingOffset().asMicroseconds(); - const auto tap_result = note->onTap(arrow, music_offset); - _grade = makeGradeString(tap_result.rating); - } +void Application::onTap(const Note::Arrow &arrow) +{ + if (arrow == Note::Arrow::NONE) + return; + + _debug.spawnGreenPulse(); + + const auto music_offset = _music.getPlayingOffset().asMicroseconds(); + const auto note = _timeline.fetchActiveNote(music_offset); + + if (note) + { + const auto tap_result = note->onTap(arrow, music_offset); + _grade = makeGradeString(tap_result.rating); } } diff --git a/application.h b/application.h index 91bc93d..a8d2b4d 100644 --- a/application.h +++ b/application.h @@ -7,6 +7,7 @@ #include "debughelper.h" #include "timeline.h" +#include "note.h" class Application { @@ -24,11 +25,14 @@ private: sf::Font _font; sf::Text _grade; + sf::Text _tap_time; + Timeline _timeline; DebugHelper _debug; void startGameLoop(); void onKeyPressed(const sf::Keyboard::Key& key); + void onTap(const Note::Arrow& arrow); }; #endif // APPLICATION_H diff --git a/debughelper.cpp b/debughelper.cpp index 2905979..3bafcbe 100644 --- a/debughelper.cpp +++ b/debughelper.cpp @@ -6,7 +6,7 @@ DebugHelper::DebugHelper(bool init) : _green_pulse({460.f, 0.f}, sf::Color(0, 255, 0)), _blue_pulse({460.f, 360.f}, sf::Color(0, 100, 255)) { - _font.loadFromFile("VeraMono.ttf"); + _font.loadFromFile("/usr/share/qtcreator/fonts/SourceCodePro-Regular.ttf"); _time_print.setFont(_font); _time_print.setPosition(60, 60); diff --git a/timeline.cpp b/timeline.cpp index eb270d0..fd64ba1 100644 --- a/timeline.cpp +++ b/timeline.cpp @@ -60,7 +60,8 @@ void Timeline::checkForNextActiveNote(const microsec µseconds) } } -const Note* Timeline::getActiveNote() const noexcept +const Note* Timeline::fetchActiveNote(const microsec µseconds) noexcept { + update(microseconds); return _active_note; } diff --git a/timeline.h b/timeline.h index f2bda8a..af7c051 100644 --- a/timeline.h +++ b/timeline.h @@ -16,7 +16,7 @@ public: ~Timeline(); void update(const microsec& microseconds); - const Note* getActiveNote() const noexcept; + const Note* fetchActiveNote(const microsec µseconds) noexcept; private: std::vector _timeline;