Force update active note on tap

selection
NaiJi ✨ 3 years ago
parent 367316b327
commit a4d7d26e98

@ -1,5 +1,5 @@
#include "application.h"
#include "note.h"
#include <SFML/Graphics/Color.hpp>
#include <SFML/Window/Event.hpp>
@ -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);
}
}

@ -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

@ -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);

@ -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;
}

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

Loading…
Cancel
Save