forked from NaiJi/project-kyoku
Add offset adjustment for note insertion
This commit is contained in:
parent
94e3793ec6
commit
0cf711db94
|
@ -7,6 +7,7 @@ struct BPMSection
|
||||||
int bpm = 120; // Hi, osu
|
int bpm = 120; // Hi, osu
|
||||||
int fraction = 2;
|
int fraction = 2;
|
||||||
microsec offset_start = 0;
|
microsec offset_start = 0;
|
||||||
|
microsec interval = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct BPMSectionCompt
|
struct BPMSectionCompt
|
||||||
|
|
|
@ -15,43 +15,68 @@ public:
|
||||||
virtual void draw() const = 0;
|
virtual void draw() const = 0;
|
||||||
virtual void recalculate(const microsec& timestamp) = 0;
|
virtual void recalculate(const microsec& timestamp) = 0;
|
||||||
|
|
||||||
inline void setBPMSections(const std::set<BPMSection, BPMSectionCompt>& sections) noexcept
|
void setBPMSections(const std::set<BPMSection, BPMSectionCompt>& sections) noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections = sections;
|
_bpm_sections = sections;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void setBPMSections(std::set<BPMSection, BPMSectionCompt>&& sections) noexcept
|
void setBPMSections(std::set<BPMSection, BPMSectionCompt>&& sections) noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections = std::move(sections);
|
_bpm_sections = std::move(sections);
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertBPMSection(const BPMSection& section)
|
bool insertBPMSection(const BPMSection& section)
|
||||||
{
|
{
|
||||||
_bpm_sections.insert(section);
|
return _bpm_sections.insert(section).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
void insertBPMSection(BPMSection&& section)
|
bool insertBPMSection(BPMSection&& section)
|
||||||
{
|
{
|
||||||
_bpm_sections.insert(std::move(section));
|
return _bpm_sections.insert(std::move(section)).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void removeBPMSectionAt(const microsec& offset)
|
bool removeBPMSectionAt(const microsec& offset)
|
||||||
{
|
{
|
||||||
const auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
||||||
[offset](const auto& section)
|
[offset](const auto& section)
|
||||||
{
|
{
|
||||||
return section.start_offset < offset;
|
return section.offset_start < offset;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (section_it != _bpm_sections.rend())
|
if (section_it != _bpm_sections.rend())
|
||||||
_bpm_sections.erase((section_it + 1).base());
|
{
|
||||||
}*/
|
++section_it;
|
||||||
|
_bpm_sections.erase(section_it.base());
|
||||||
|
|
||||||
inline void clearBPMSections() noexcept
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BPMSection getBPMSectionAt(const microsec& offset) const
|
||||||
|
{
|
||||||
|
auto section_it = std::find_if(_bpm_sections.rbegin(), _bpm_sections.rend(),
|
||||||
|
[offset](const auto& section)
|
||||||
|
{
|
||||||
|
return section.offset_start < offset;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (section_it != _bpm_sections.rend())
|
||||||
|
{
|
||||||
|
++section_it;
|
||||||
|
return *section_it.base();
|
||||||
|
}
|
||||||
|
|
||||||
|
return BPMSection();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clearBPMSections() noexcept
|
||||||
{
|
{
|
||||||
_bpm_sections.clear();
|
_bpm_sections.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::set<BPMSection, BPMSectionCompt> _bpm_sections;
|
std::set<BPMSection, BPMSectionCompt> _bpm_sections;
|
||||||
|
std::set<microsec> _ticks;
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,6 +30,49 @@ ClassicEditor::ClassicEditor(std::shared_ptr<ClassicGraphicsManager>&& manager)
|
||||||
_timeline.setNotes(_set, 1648648);
|
_timeline.setNotes(_set, 1648648);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
microsec ClassicEditor::adjustOffset(microsec offset) const noexcept
|
||||||
|
{
|
||||||
|
microsec left = -1;
|
||||||
|
microsec right = -1;
|
||||||
|
|
||||||
|
std::set<microsec>::iterator i;
|
||||||
|
|
||||||
|
for (i = _ticks.begin(); i != _ticks.end(); ++i)
|
||||||
|
{
|
||||||
|
if (*i >= offset)
|
||||||
|
{
|
||||||
|
right = *i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i != _ticks.end(); --i)
|
||||||
|
{
|
||||||
|
if (*i <= offset)
|
||||||
|
{
|
||||||
|
left = *i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (right == -1)
|
||||||
|
offset = left;
|
||||||
|
else if (left == -1)
|
||||||
|
offset = right;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const microsec right_distance = right - offset;
|
||||||
|
const microsec left_distance = offset - left;
|
||||||
|
|
||||||
|
offset = (right_distance > left_distance)
|
||||||
|
? left_distance
|
||||||
|
: right_distance;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
void ClassicEditor::input(PlayerInput&& inputdata)
|
void ClassicEditor::input(PlayerInput&& inputdata)
|
||||||
{
|
{
|
||||||
_current_time = inputdata.timestamp;
|
_current_time = inputdata.timestamp;
|
||||||
|
@ -44,12 +87,12 @@ void ClassicEditor::input(PlayerInput&& inputdata)
|
||||||
case sf::Event::MouseButtonPressed:
|
case sf::Event::MouseButtonPressed:
|
||||||
{
|
{
|
||||||
const auto note = _timeline.getNoteBy(_current_time);
|
const auto note = _timeline.getNoteBy(_current_time);
|
||||||
if (_timeline.isExpired(note))
|
if (_timeline.isExpired(note) && !_ticks.empty())
|
||||||
{
|
{
|
||||||
NoteInitializer init;
|
NoteInitializer init;
|
||||||
init.context = &_context;
|
init.context = &_context;
|
||||||
init.intervals = {};
|
init.intervals = {};
|
||||||
init.perfect_offset = _current_time;
|
init.perfect_offset = adjustOffset(_current_time);
|
||||||
|
|
||||||
ElementInitializer elem_init;
|
ElementInitializer elem_init;
|
||||||
elem_init.type = _selected_type;
|
elem_init.type = _selected_type;
|
||||||
|
|
|
@ -22,6 +22,8 @@ public:
|
||||||
void selectNoteType(Type type) noexcept;
|
void selectNoteType(Type type) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
inline microsec adjustOffset(microsec offset) const noexcept;
|
||||||
|
|
||||||
Context _context;
|
Context _context;
|
||||||
|
|
||||||
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "core/game.h"
|
#include "core/game.h"
|
||||||
#include "core/timeline.h"
|
#include "core/timeline.h"
|
||||||
|
|
||||||
#include "context.h"
|
#include "classicmode/context.h"
|
||||||
#include "classicnote.h"
|
#include "classicnote.h"
|
||||||
|
|
||||||
#include "classicmode/classicactions.h"
|
#include "classicmode/classicactions.h"
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "context.h"
|
#include "classicmode/context.h"
|
||||||
#include "core/note.h"
|
#include "core/note.h"
|
||||||
#include "core/precisionevaluator.h"
|
#include "core/precisionevaluator.h"
|
||||||
#include "classicmode/noteinitializer.h"
|
#include "classicmode/noteinitializer.h"
|
||||||
|
|
Loading…
Reference in New Issue