2022-03-16 02:10:18 +01:00
|
|
|
#include "better_song.hpp"
|
2022-03-23 02:20:07 +01:00
|
|
|
#include <SFML/System/Time.hpp>
|
2022-03-16 02:10:18 +01:00
|
|
|
|
|
|
|
namespace better {
|
|
|
|
std::optional<sf::Time> Chart::time_of_last_event() const {
|
|
|
|
if (notes.empty()) {
|
|
|
|
return {};
|
|
|
|
} else {
|
|
|
|
return timing.time_at(notes.crbegin()->second.get_end());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-23 02:20:07 +01:00
|
|
|
bool Chart::is_colliding(const better::Note& note) {
|
|
|
|
const auto [start_beat, end_beat] = note.get_time_bounds();
|
|
|
|
|
|
|
|
/*
|
|
|
|
Two notes collide if they are within ~one second of each other :
|
|
|
|
Approach and burst animations of original jubeat markers last 16 frames
|
|
|
|
at (supposedly) 30 fps, which means a note needs ~half a second both
|
|
|
|
before *and* after itself, so two consecutive notes on the same button
|
|
|
|
cannot be closer than ~one second from each other
|
|
|
|
*/
|
|
|
|
const auto collision_start = timing.beats_at(timing.time_at(start_beat) - sf::seconds(1));
|
|
|
|
const auto collision_end = timing.beats_at(timing.time_at(end_beat) + sf::seconds(1));
|
|
|
|
|
|
|
|
bool found_collision = false;
|
|
|
|
notes.in(
|
|
|
|
{collision_start, collision_end},
|
|
|
|
[&](Notes::const_iterator it){
|
|
|
|
if (it->second.get_position() == note.get_position()) {
|
|
|
|
if (it->second != note) {
|
|
|
|
found_collision = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return found_collision;
|
|
|
|
}
|
|
|
|
|
2022-03-16 02:10:18 +01:00
|
|
|
PreviewLoop::PreviewLoop(Decimal start, Decimal duration) :
|
|
|
|
start(start),
|
|
|
|
duration(duration)
|
|
|
|
{
|
|
|
|
if (start < 0) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Attempted to create a PreviewLoop with negative start ";
|
|
|
|
ss << "position : " << start;
|
|
|
|
throw std::invalid_argument(ss.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (duration < 0) {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << "Attempted to create a PreviewLoop with negative ";
|
|
|
|
ss << "duration : " << duration;
|
|
|
|
throw std::invalid_argument(ss.str());
|
|
|
|
}
|
|
|
|
};
|
2022-03-23 02:20:07 +01:00
|
|
|
|
|
|
|
Decimal PreviewLoop::get_start() const {
|
|
|
|
return start;
|
|
|
|
};
|
|
|
|
|
|
|
|
Decimal PreviewLoop::get_duration() const {
|
|
|
|
return duration;
|
|
|
|
};
|
2022-03-16 02:10:18 +01:00
|
|
|
}
|