Replace vector with set in timeline

This commit is contained in:
NaiJi ✨ 2021-10-03 18:23:28 +03:00
parent 00273ab2fd
commit 841e042477
5 changed files with 49 additions and 12 deletions

View File

@ -23,6 +23,29 @@ public:
return _perfect_offset; return _perfect_offset;
} }
bool operator<(const Note& note) const
{
return (_perfect_offset < note._perfect_offset);
}
bool operator==(const Note& note) const
{
return (_perfect_offset == note._perfect_offset);
}
bool operator>(const Note& note) const
{
return (_perfect_offset > note._perfect_offset);
}
protected: protected:
microsec _perfect_offset; microsec _perfect_offset;
}; };
struct NotePtrCompt
{
bool operator()(const Note* lhs, const Note* rhs) const
{
return lhs->offset() < rhs->offset();
}
};

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include <vector> #include <set>
#include <memory> #include <memory>
#include <algorithm> #include <algorithm>
@ -12,12 +12,13 @@ class Timeline
{ {
public: public:
explicit Timeline() : explicit Timeline() :
_visibility_offset(0),
_current_offset(0) _current_offset(0)
{} {}
typedef typename std::vector<TNote*>::const_iterator Iterator; typedef typename std::set<TNote*>::const_iterator Iterator;
void setNotes(const std::vector<TNote*>& notes, const microsec& visibility) void setNotes(const std::set<TNote*, NotePtrCompt>& notes, const microsec& visibility)
{ {
_visibility_offset = visibility; _visibility_offset = visibility;
_timeline = std::move(notes); _timeline = std::move(notes);
@ -30,6 +31,18 @@ public:
fetchVisibleNotes(); fetchVisibleNotes();
} }
void insertNote(TNote* note)
{
_timeline.insert(_top_note, note);
update(_current_offset);
}
void insertNotes(const std::set<TNote*, NotePtrCompt>& notes)
{
_timeline.insert(notes.begin(), notes.end());
update(_current_offset);
}
inline void clear() inline void clear()
{ {
for (auto& note : _timeline) for (auto& note : _timeline)
@ -116,8 +129,7 @@ public:
} }
private: private:
std::vector<microsec> _input_intervals; std::set<TNote*, NotePtrCompt> _timeline;
std::vector<TNote*> _timeline;
microsec _visibility_offset; microsec _visibility_offset;
microsec _current_offset; microsec _current_offset;

View File

@ -94,8 +94,10 @@ void ClassicArrowNote::update(const microsec& music_offset)
break; break;
case State::FLYING: case State::FLYING:
if (_evaluator.isActive(music_offset)) if (_evaluator.isActive(music_offset)) {
_state = State::ACTIVE; _state = State::ACTIVE;
}
break; break;
case State::DYING: case State::DYING:

View File

@ -17,14 +17,14 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
microsec starting_beat_offset = 362162; microsec starting_beat_offset = 362162;
int amount_of_beats = 209; int amount_of_beats = 209;
microsec interval = 1412162; microsec interval = 1412162;
microsec tempo_interval = interval / 2; microsec tempo_interval = interval / 4;
microsec note_input_offset = 412162 / 2; microsec note_input_offset = 412162 / 2;
//microsec note_input_offset_fast = 412162 / 6; //microsec note_input_offset_fast = 412162 / 6;
microsec bpm_iterator = starting_beat_offset; microsec bpm_iterator = starting_beat_offset;
microsec bpm_end = starting_beat_offset + (interval * amount_of_beats); microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
std::vector<microsec> input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; std::vector<microsec> input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset};
std::vector<ClassicNote*> notes; std::set<ClassicNote*, NotePtrCompt> notes;
input_intervals.shrink_to_fit(); input_intervals.shrink_to_fit();
bpm_iterator += tempo_interval; bpm_iterator += tempo_interval;
@ -60,7 +60,7 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
init.elements = {element}; init.elements = {element};
notes.emplace_back(new ClassicArrowNote(std::move(init))); notes.insert(new ClassicArrowNote(std::move(init)));
bpm_iterator += tempo_interval; bpm_iterator += tempo_interval;
x += 70; x += 70;
@ -69,6 +69,6 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
x = 90.; x = 90.;
} }
return {std::move(notes), note_input_offset * 12}; return {std::move(notes), note_input_offset * 8};
} }

View File

@ -1,7 +1,7 @@
#ifndef CLASSICMAPCREATOR_H #ifndef CLASSICMAPCREATOR_H
#define CLASSICMAPCREATOR_H #define CLASSICMAPCREATOR_H
#include <vector> #include <set>
#include "tools/mathutils.h" #include "tools/mathutils.h"
#include "core/note.h" #include "core/note.h"
@ -10,7 +10,7 @@
struct Beatmap struct Beatmap
{ {
std::vector<ClassicNote*> notes; std::set<ClassicNote*, NotePtrCompt> notes;
microsec visibility_offset; microsec visibility_offset;
}; };