Force update active note on tap

selection
NaiJi ✨ 3 years ago
parent 367316b327
commit a4d7d26e98

@ -1,5 +1,5 @@
#include "application.h" #include "application.h"
#include "note.h"
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include <SFML/Window/Event.hpp> #include <SFML/Window/Event.hpp>
@ -9,11 +9,12 @@ Application::Application() :
_game_window({1280, 720}, "Test"), _game_window({1280, 720}, "Test"),
_debug(true) _debug(true)
{ {
_font.loadFromFile("VeraMono.ttf"); _font.loadFromFile("/usr/share/qtcreator/fonts/SourceCodePro-Regular.ttf");
_grade.setFont(_font); _grade.setFont(_font);
_grade.setPosition(160, 160); _grade.setPosition(160, 160);
_grade.setFillColor(sf::Color(255, 255, 255, 0)); _grade.setFillColor(sf::Color(255, 0, 0, 0));
_grade.setCharacterSize(35); _grade.setCharacterSize(35);
_grade.setString("NOT INIT");
} }
void Application::run() void Application::run()
@ -22,7 +23,7 @@ void Application::run()
_music.openFromFile(song_filename); _music.openFromFile(song_filename);
_music.play(); _music.play();
_music.setVolume(5); _music.setVolume(2);
_game_window.display(); _game_window.display();
@ -141,23 +142,23 @@ void Application::onKeyPressed(const sf::Keyboard::Key &key)
return; return;
} }
const auto arrow = keyToArrow(key); onTap(keyToArrow(key));
}
if (arrow != Note::Arrow::NONE) void Application::onTap(const Note::Arrow &arrow)
{ // TODO: SHIT BLOCK. {
_debug.spawnGreenPulse(); if (arrow == Note::Arrow::NONE)
const auto note = _timeline.getActiveNote(); return;
if (note)
{ _debug.spawnGreenPulse();
// This is obscure. Active note on timeline gets received by last ::update() call.
// there can be 100-200 microseconds delay between onKeyPressed and update... const auto music_offset = _music.getPlayingOffset().asMicroseconds();
// Also the problem is that we get music offset by CURRENT music time, const auto note = _timeline.fetchActiveNote(music_offset);
// when active note is activated by music time of last ::update call
// anyway gotta think on it, smh smh smh if (note)
const auto music_offset = _music.getPlayingOffset().asMicroseconds(); {
const auto tap_result = note->onTap(arrow, music_offset); const auto tap_result = note->onTap(arrow, music_offset);
_grade = makeGradeString(tap_result.rating); _grade = makeGradeString(tap_result.rating);
}
} }
} }

@ -7,6 +7,7 @@
#include "debughelper.h" #include "debughelper.h"
#include "timeline.h" #include "timeline.h"
#include "note.h"
class Application class Application
{ {
@ -24,11 +25,14 @@ private:
sf::Font _font; sf::Font _font;
sf::Text _grade; sf::Text _grade;
sf::Text _tap_time;
Timeline _timeline; Timeline _timeline;
DebugHelper _debug; DebugHelper _debug;
void startGameLoop(); void startGameLoop();
void onKeyPressed(const sf::Keyboard::Key& key); void onKeyPressed(const sf::Keyboard::Key& key);
void onTap(const Note::Arrow& arrow);
}; };
#endif // APPLICATION_H #endif // APPLICATION_H

@ -6,7 +6,7 @@ DebugHelper::DebugHelper(bool init) :
_green_pulse({460.f, 0.f}, sf::Color(0, 255, 0)), _green_pulse({460.f, 0.f}, sf::Color(0, 255, 0)),
_blue_pulse({460.f, 360.f}, sf::Color(0, 100, 255)) _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.setFont(_font);
_time_print.setPosition(60, 60); _time_print.setPosition(60, 60);

@ -60,7 +60,8 @@ void Timeline::checkForNextActiveNote(const microsec &microseconds)
} }
} }
const Note* Timeline::getActiveNote() const noexcept const Note* Timeline::fetchActiveNote(const microsec &microseconds) noexcept
{ {
update(microseconds);
return _active_note; return _active_note;
} }

@ -16,7 +16,7 @@ public:
~Timeline(); ~Timeline();
void update(const microsec& microseconds); void update(const microsec& microseconds);
const Note* getActiveNote() const noexcept; const Note* fetchActiveNote(const microsec &microseconds) noexcept;
private: private:
std::vector<Note*> _timeline; std::vector<Note*> _timeline;

Loading…
Cancel
Save