Replace vector with set in timeline

selection
NaiJi ✨ 3 years ago
parent 00273ab2fd
commit 841e042477

@ -23,6 +23,29 @@ public:
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:
microsec _perfect_offset;
};
struct NotePtrCompt
{
bool operator()(const Note* lhs, const Note* rhs) const
{
return lhs->offset() < rhs->offset();
}
};

@ -1,6 +1,6 @@
#pragma once
#include <vector>
#include <set>
#include <memory>
#include <algorithm>
@ -12,12 +12,13 @@ class Timeline
{
public:
explicit Timeline() :
_visibility_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;
_timeline = std::move(notes);
@ -30,6 +31,18 @@ public:
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()
{
for (auto& note : _timeline)
@ -116,8 +129,7 @@ public:
}
private:
std::vector<microsec> _input_intervals;
std::vector<TNote*> _timeline;
std::set<TNote*, NotePtrCompt> _timeline;
microsec _visibility_offset;
microsec _current_offset;

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

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

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

Loading…
Cancel
Save