You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/classicgame/classictimeline.h

61 lines
1.9 KiB
C++

#pragma once
#include <vector>
#include <memory>
#include "timeline.h"
#include <SFML/Audio/Music.hpp>
class ClassicNote;
class ClassicViewManager;
class ClassicTimeline : public Timeline
{
public:
explicit ClassicTimeline();
virtual ~ClassicTimeline();
virtual void update() override;
virtual void init() override;
virtual void clear() override;
virtual microsec currentMusicOffset() const override;
virtual void drawVisibleNotes(sf::RenderWindow& window) const override;
void fetchVisibleNotes(const std::unique_ptr<ClassicViewManager>& view_manager);
using Iterator = std::vector<ClassicNote*>::const_iterator;
Iterator getActiveNote() noexcept;
bool isExpired(const Iterator& iterator) const;
void expire(Iterator& iterator);
private:
std::vector<ClassicNote*> _timeline;
Iterator _top_note;
Iterator _active_note;
Iterator _last_visible_note;
microsec _visibility_offset;
sf::Music _music;
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
* OR it's the closest note from current music offset
* position, not necessarily active. A note stops being top only
* after dying or being tapped by player, even if it's already
* past her perfect offset.
*
* Meanwhile active note is the note which is currently handling
* player input for grade.
*
* An active note is always top note but a top note
* is not always active note.
* */
};