Make everything work as before redesign
This commit is contained in:
parent
ed300edcf6
commit
7dc4ef2bb8
|
@ -65,5 +65,7 @@ void Application::update()
|
|||
|
||||
void Application::draw()
|
||||
{
|
||||
_game_window.clear();
|
||||
_game->draw(_game_window);
|
||||
_game_window.display();
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ ClassicGame::ClassicGame() :
|
|||
_timeline(std::make_unique<ClassicTimeline>()),
|
||||
_view_manager(std::make_unique<ClassicViewManager>())
|
||||
{
|
||||
_timeline->fetchVisibleNotes(_view_manager);
|
||||
_timeline->init();
|
||||
|
||||
_keys_to_buttons =
|
||||
{
|
||||
{sf::Keyboard::Up, Button::UP}, // Load from settings
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "classicnote.h"
|
||||
#include "classicsprite.h"
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
#include <iostream>
|
||||
|
||||
ClassicNote::ClassicNote(const std::vector<microsec>& intervals, microsec perfect_offset,
|
||||
Action action, const Coordinates& coord) :
|
||||
|
@ -22,12 +23,16 @@ void ClassicNote::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|||
|
||||
ClassicNote::GRADE ClassicNote::input(ClassicInputType&& input_data)
|
||||
{
|
||||
auto grade = ClassicNote::GRADE::BAD;
|
||||
|
||||
if (input_data == _action)
|
||||
{
|
||||
return _evaluator.calculatePrecision(input_data.timestamp());
|
||||
grade = _evaluator.calculatePrecision(input_data.timestamp());
|
||||
}
|
||||
|
||||
return ClassicNote::GRADE::BAD;
|
||||
std::cout << "User input: " << static_cast<int>(grade) << "\n";
|
||||
|
||||
return grade;
|
||||
}
|
||||
|
||||
Action ClassicNote::action() const
|
||||
|
@ -43,6 +48,7 @@ std::shared_ptr<ClassicSprite> ClassicNote::sprite() const noexcept
|
|||
void ClassicNote::setSprite(const std::shared_ptr<ClassicSprite>& sprite) noexcept
|
||||
{
|
||||
_sprite = sprite;
|
||||
if (_sprite)
|
||||
_sprite->setCoordinates(_coordinates.x, _coordinates.y);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ ClassicTimeline::ClassicTimeline()
|
|||
std::string song_filename = "/home/naiji/METEOR.flac";
|
||||
|
||||
_music.openFromFile(song_filename);
|
||||
_music.play();
|
||||
_music.setVolume(10);
|
||||
|
||||
_timeline.reserve(1000);
|
||||
|
@ -25,7 +24,7 @@ ClassicTimeline::ClassicTimeline()
|
|||
microsec note_input_offset = 412162;
|
||||
microsec bpm_iterator = starting_beat_offset;
|
||||
microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
||||
_visibility_offset = note_input_offset * 12;
|
||||
_visibility_offset = note_input_offset * 6;
|
||||
|
||||
_timeline.emplace_back(new ClassicNote({note_input_offset}, bpm_iterator, Action::PRESS_DOWN, {90, 90}));
|
||||
bpm_iterator += interval;
|
||||
|
@ -42,14 +41,14 @@ ClassicTimeline::ClassicTimeline()
|
|||
bpm_iterator += interval;
|
||||
}
|
||||
|
||||
expire(_last_visible_note);
|
||||
expire(_active_note);
|
||||
_top_note = _timeline.begin();
|
||||
_last_visible_note = _top_note;
|
||||
}
|
||||
|
||||
void ClassicTimeline::init()
|
||||
{
|
||||
|
||||
_music.play();
|
||||
}
|
||||
|
||||
ClassicTimeline::~ClassicTimeline()
|
||||
|
@ -70,8 +69,7 @@ void ClassicTimeline::clear()
|
|||
|
||||
void ClassicTimeline::update()
|
||||
{
|
||||
const auto& offset = currentMusicOffset();
|
||||
std::cout << "Upadting at: " << offset << '\n';
|
||||
const microsec& offset = currentMusicOffset();
|
||||
checkCurrentActiveNote(offset);
|
||||
checkForNextActiveNote(offset);
|
||||
}
|
||||
|
@ -100,7 +98,7 @@ ClassicTimeline::Iterator ClassicTimeline::getActiveNote() noexcept
|
|||
return _active_note;
|
||||
}
|
||||
|
||||
bool ClassicTimeline::isExpired(const Iterator &iterator)
|
||||
bool ClassicTimeline::isExpired(const Iterator &iterator) const
|
||||
{
|
||||
return iterator == _timeline.end();
|
||||
}
|
||||
|
@ -115,15 +113,40 @@ microsec ClassicTimeline::currentMusicOffset() const
|
|||
return _music.getPlayingOffset().asMicroseconds();
|
||||
}
|
||||
|
||||
void ClassicTimeline::discardExpiredNotes(const std::unique_ptr<ClassicViewManager> &view_manager, const microsec &music_offset)
|
||||
{
|
||||
if (_top_note == _timeline.begin())
|
||||
return;
|
||||
|
||||
Iterator past_note = _top_note - 1;
|
||||
std::shared_ptr<ClassicSprite> sprite = (*past_note)->sprite();
|
||||
while (sprite)
|
||||
{ // CAREFULLY REWRITE
|
||||
view_manager->resetNoteSprite(*past_note);
|
||||
if (past_note == _timeline.begin())
|
||||
return;
|
||||
--past_note;
|
||||
sprite = (*past_note)->sprite();
|
||||
}
|
||||
}
|
||||
|
||||
bool ClassicTimeline::isVisiblyClose(const Iterator &iterator, const microsec &music_offset) const
|
||||
{
|
||||
return ((*iterator)->offset() - _visibility_offset) <= music_offset;
|
||||
}
|
||||
|
||||
void ClassicTimeline::fetchVisibleNotes(const std::unique_ptr<ClassicViewManager>& view_manager)
|
||||
{
|
||||
Iterator note_iterator = _top_note;
|
||||
auto music_offset = currentMusicOffset();
|
||||
microsec music_offset = currentMusicOffset();
|
||||
discardExpiredNotes(view_manager, music_offset);
|
||||
|
||||
while (((*note_iterator)->offset() - _visibility_offset) <= music_offset)
|
||||
Iterator note_iterator = _top_note;
|
||||
while (isVisiblyClose(note_iterator, music_offset))
|
||||
{
|
||||
if (note_iterator > _last_visible_note)
|
||||
view_manager->initNoteSprite(*note_iterator);
|
||||
ClassicNote* note = *note_iterator;
|
||||
if (!note->sprite())
|
||||
view_manager->initNoteSprite(note);
|
||||
|
||||
++note_iterator;
|
||||
}
|
||||
|
||||
|
@ -132,7 +155,9 @@ void ClassicTimeline::fetchVisibleNotes(const std::unique_ptr<ClassicViewManager
|
|||
|
||||
void ClassicTimeline::drawVisibleNotes(sf::RenderWindow &window) const
|
||||
{
|
||||
if (_last_visible_note == _timeline.end() || _top_note > _last_visible_note)
|
||||
bool no_visible_notes = isExpired(_last_visible_note)
|
||||
|| _top_note > _last_visible_note;
|
||||
if (no_visible_notes)
|
||||
return;
|
||||
|
||||
Iterator note_to_draw = _top_note;
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
Iterator getActiveNote() noexcept;
|
||||
|
||||
bool isExpired(const Iterator& iterator);
|
||||
bool isExpired(const Iterator& iterator) const;
|
||||
void expire(Iterator& iterator);
|
||||
|
||||
private:
|
||||
|
@ -41,6 +41,8 @@ private:
|
|||
|
||||
void checkCurrentActiveNote(const microsec &music_offset);
|
||||
void checkForNextActiveNote(const microsec &music_offset);
|
||||
void discardExpiredNotes(const std::unique_ptr<ClassicViewManager>& view_manager, const microsec &music_offset);
|
||||
bool isVisiblyClose(const Iterator& iterator, const microsec& music_offset) const;
|
||||
|
||||
/* Difference between top and active note is that
|
||||
* top note is the note handling input right now
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "classicsprite.h"
|
||||
#include "classicnote.h"
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <iostream>
|
||||
|
||||
static constexpr std::size_t RESERVED_SIZE = 20;
|
||||
|
||||
|
@ -62,10 +63,12 @@ void ClassicViewManager::initNoteSprite(ClassicNote* note)
|
|||
|
||||
note->setSprite(poll.top());
|
||||
poll.pop();
|
||||
std::cout << "Taking a sprite from poll.\n";
|
||||
}
|
||||
|
||||
void ClassicViewManager::resetNoteSprite(ClassicNote* note)
|
||||
{
|
||||
_sprite_dispatcher[note->action()].push(note->sprite());
|
||||
note->setSprite(nullptr);
|
||||
std::cout << "Returning a sprite to poll.\n";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue