Skip to content

Commit

Permalink
Add tick burst mechanic
Browse files Browse the repository at this point in the history
Clone Hero has a burst of ticks approximately 0.25 beats away from the
end of a sustain. This is now understood by chopt.
  • Loading branch information
GenericMadScientist committed Apr 30, 2020
1 parent 01db7b5 commit 43ba7c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
13 changes: 11 additions & 2 deletions src/points.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static void append_note_points(InputIt first, InputIt last, OutputIt points,
int resolution, bool is_note_sp_ender,
const TimeConverter& converter, double squeeze)
{
constexpr double HALF_RES_OFFSET = 0.5;
constexpr int NOTE_VALUE = 50;
const auto EARLY_WINDOW = Second(0.07 * squeeze);
const auto LATE_WINDOW = Second(0.07 * squeeze);
Expand Down Expand Up @@ -60,14 +61,22 @@ static void append_note_points(InputIt first, InputIt last, OutputIt points,
NOTE_VALUE * chord_size,
false,
is_note_sp_ender};
while (chord_length > 0) {
auto sust_ticks = (chord_length + tick_gap - 1) / tick_gap;
while (chord_length > (resolution / 4)) {
pos += tick_gap;
chord_length -= tick_gap;
beat = Beat(pos / float_res);
beat = Beat((pos - HALF_RES_OFFSET) / float_res);
meas = converter.beats_to_measures(beat);
--sust_ticks;
*points++
= {{beat, meas}, {beat, meas}, {beat, meas}, 1, 1, true, false};
}
if (sust_ticks > 0) {
beat = Beat((pos + HALF_RES_OFFSET) / float_res);
meas = converter.beats_to_measures(beat);
*points++ = {{beat, meas}, {beat, meas}, {beat, meas}, sust_ticks,
sust_ticks, true, false};
}
}

PointSet::PointSet(const NoteTrack& track, int resolution,
Expand Down
23 changes: 10 additions & 13 deletions tests/points_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ TEST_CASE("Hold notes")
NoteTrack track {{{768, 15}}, {}, {}};
TimeConverter converter {{}, 192};
PointSet first_points {track, 192, converter, 1.0};
std::vector<int> first_expected_values {50, 1, 1, 1};
std::vector<Beat> first_expected_beats {Beat(4.0), Beat(4.03646),
Beat(4.07292), Beat(4.10938)};
std::vector<int> first_expected_values {50, 3};
std::vector<Beat> first_expected_beats {Beat(4.0), Beat(4.0026)};
TimeConverter second_converter {{}, 200};
PointSet second_points {track, 200, second_converter, 1.0};
std::vector<int> second_expected_values {50, 1, 1};
std::vector<Beat> second_expected_beats {Beat(3.84), Beat(3.88),
Beat(3.92)};
std::vector<int> second_expected_values {50, 2};
std::vector<Beat> second_expected_beats {Beat(3.84), Beat(3.8425)};

REQUIRE(set_values(first_points) == first_expected_values);
REQUIRE(set_position_beats(first_points) == first_expected_beats);
Expand All @@ -112,9 +110,8 @@ TEST_CASE("Hold notes")
{{768, 7, NoteColour::Green}, {768, 8, NoteColour::Red}}, {}, {}};
TimeConverter converter {{}, 192};
PointSet points {track, 192, converter, 1.0};
std::vector<int> expected_values {100, 1, 1};
std::vector<Beat> expected_beats {Beat(4.0), Beat(4.03646),
Beat(4.07292)};
std::vector<int> expected_values {100, 2};
std::vector<Beat> expected_beats {Beat(4.0), Beat(4.0026)};

REQUIRE(set_values(points) == expected_values);
REQUIRE(set_position_beats(points) == expected_beats);
Expand Down Expand Up @@ -191,8 +188,8 @@ TEST_CASE("Combo multiplier is taken into account")
TimeConverter converter {{}, 192};
PointSet points {track, 192, converter, 1.0};

REQUIRE(std::prev(points.cend())->value == 4);
REQUIRE(std::prev(points.cend())->base_value == 1);
REQUIRE(std::prev(points.cend(), 2)->value == 4);
REQUIRE(std::prev(points.cend(), 2)->base_value == 1);
}

SECTION("Later hold points in extended sustains are multiplied")
Expand All @@ -208,8 +205,8 @@ TEST_CASE("Combo multiplier is taken into account")
TimeConverter converter {{}, 192};
PointSet points {track, 192, converter, 1.0};

REQUIRE(std::prev(points.cend())->value == 2);
REQUIRE(std::prev(points.cend())->base_value == 1);
REQUIRE(std::prev(points.cend(), 2)->value == 2);
REQUIRE(std::prev(points.cend(), 2)->base_value == 1);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/processed_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ TEST_CASE("total_available_sp counts SP correctly", "Available SP")
auto result = song.total_available_sp(Beat(4.0), points.cbegin() + 4,
points.cbegin() + 5);
REQUIRE(result.min() == Approx(0.0));
REQUIRE(result.max() == Approx(0.00121528));
REQUIRE(result.max() == Approx(0.00112847));
}

SECTION("Whammy is counted correctly even started mid hold")
Expand Down

0 comments on commit 43ba7c2

Please sign in to comment.