Skip to content

Commit

Permalink
refactor!: keep large tick naming more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Nov 25, 2024
1 parent 660f44d commit 48414de
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/any/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl<'map> Performance<'map> {
/// slider heads, ticks, and repeats
pub fn large_tick_hits(self, large_tick_hits: u32) -> Self {
if let Self::Osu(osu) = self {
Self::Osu(osu.large_tick_hits(large_tick_hits))
Self::Osu(osu.n_large_ticks(large_tick_hits))
} else {
self
}
Expand Down
11 changes: 9 additions & 2 deletions src/osu/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,15 @@ pub struct OsuDifficultyAttributes {
pub n_circles: u32,
/// The amount of sliders.
pub n_sliders: u32,
/// The amount of slider ticks and repeat points.
pub n_slider_ticks: u32,
/// The amount of "large ticks".
///
/// The meaning depends on the kind of score:
/// - if set on osu!stable, this value is irrelevant
/// - if set on osu!lazer *without* `CL`, this value is the amount of
/// slider ticks and repeats
/// - if set on osu!lazer *with* `CL`, this value is the amount of slider
/// heads, ticks, and repeats
pub n_large_ticks: u32,
/// The amount of spinners.
pub n_spinners: u32,
/// The final star rating
Expand Down
2 changes: 1 addition & 1 deletion src/osu/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn convert_objects(
OsuObjectKind::Circle => attrs.n_circles += 1,
OsuObjectKind::Slider(ref slider) => {
attrs.n_sliders += 1;
attrs.n_slider_ticks += slider.tick_count() as u32;
attrs.n_large_ticks += slider.large_tick_count() as u32;
attrs.max_combo += slider.nested_objects.len() as u32;
}
OsuObjectKind::Spinner(_) => attrs.n_spinners += 1,
Expand Down
4 changes: 2 additions & 2 deletions src/osu/difficulty/gradual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl OsuGradualDifficulty {

attrs.n_circles = 0;
attrs.n_sliders = 0;
attrs.n_slider_ticks = 0;
attrs.n_large_ticks = 0;
attrs.n_spinners = 0;
attrs.max_combo = 0;

Expand Down Expand Up @@ -130,7 +130,7 @@ impl OsuGradualDifficulty {
OsuObjectKind::Circle => attrs.n_circles += 1,
OsuObjectKind::Slider(slider) => {
attrs.n_sliders += 1;
attrs.n_slider_ticks += slider.tick_count() as u32;
attrs.n_large_ticks += slider.large_tick_count() as u32;
attrs.max_combo += slider.nested_objects.len() as u32;
}
OsuObjectKind::Spinner { .. } => attrs.n_spinners += 1,
Expand Down
2 changes: 1 addition & 1 deletion src/osu/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl OsuSlider {
}

/// Counts both ticks and repeats
pub fn tick_count(&self) -> usize {
pub fn large_tick_count(&self) -> usize {
self.nested_objects
.iter()
.filter(|nested| {
Expand Down
30 changes: 15 additions & 15 deletions src/osu/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl<'map> OsuPerformance<'map> {
/// slider ticks and repeats
/// - if set on osu!lazer *with* `CL`, this value is the amount of hit
/// slider heads, ticks, and repeats
pub const fn large_tick_hits(mut self, large_tick_hits: u32) -> Self {
self.large_tick_hits = Some(large_tick_hits);
pub const fn n_large_ticks(mut self, n_large_ticks: u32) -> Self {
self.large_tick_hits = Some(n_large_ticks);

self
}
Expand Down Expand Up @@ -378,7 +378,7 @@ impl<'map> OsuPerformance<'map> {
(false, _) => (OsuScoreOrigin::Stable, 0, 0),
(true, false) => {
let origin = OsuScoreOrigin::WithSliderAcc {
max_large_ticks: attrs.n_slider_ticks,
max_large_ticks: attrs.n_large_ticks,
max_slider_ends: attrs.n_sliders,
};

Expand All @@ -388,13 +388,13 @@ impl<'map> OsuPerformance<'map> {

let large_tick_hits = self
.large_tick_hits
.map_or(attrs.n_slider_ticks, |n| cmp::min(n, attrs.n_slider_ticks));
.map_or(attrs.n_large_ticks, |n| cmp::min(n, attrs.n_large_ticks));

(origin, slider_end_hits, large_tick_hits)
}
(true, true) => {
let origin = OsuScoreOrigin::WithoutSliderAcc {
max_large_ticks: attrs.n_sliders + attrs.n_slider_ticks,
max_large_ticks: attrs.n_sliders + attrs.n_large_ticks,
max_slider_ends: attrs.n_sliders,
};

Expand All @@ -404,8 +404,8 @@ impl<'map> OsuPerformance<'map> {

let large_tick_hits = self
.large_tick_hits
.map_or(attrs.n_sliders + attrs.n_slider_ticks, |n| {
cmp::min(n, attrs.n_sliders + attrs.n_slider_ticks)
.map_or(attrs.n_sliders + attrs.n_large_ticks, |n| {
cmp::min(n, attrs.n_sliders + attrs.n_large_ticks)
});

(origin, slider_end_hits, large_tick_hits)
Expand Down Expand Up @@ -685,7 +685,7 @@ impl<'map> OsuPerformance<'map> {

// * Combine regular misses with tick misses since tick misses break combo as well
effective_miss_count = effective_miss_count
.min(f64::from(n_slider_tick_miss(&attrs, &state) + state.misses));
.min(f64::from(n_large_tick_miss(&attrs, &state) + state.misses));
}
}

Expand All @@ -695,11 +695,11 @@ impl<'map> OsuPerformance<'map> {
let origin = match (lazer, using_classic_slider_acc) {
(false, _) => OsuScoreOrigin::Stable,
(true, false) => OsuScoreOrigin::WithSliderAcc {
max_large_ticks: attrs.n_slider_ticks,
max_large_ticks: attrs.n_large_ticks,
max_slider_ends: attrs.n_sliders,
},
(true, true) => OsuScoreOrigin::WithoutSliderAcc {
max_large_ticks: attrs.n_sliders + attrs.n_slider_ticks,
max_large_ticks: attrs.n_sliders + attrs.n_large_ticks,
max_slider_ends: attrs.n_sliders,
},
};
Expand Down Expand Up @@ -905,7 +905,7 @@ impl OsuPerformanceInner<'_> {
// * We however aren't adding misses here because missing slider heads has a harsh penalty by itself and doesn't mean that the rest of the slider wasn't followed properly
(f64::from(
n_slider_ends_dropped(&self.attrs, &self.state)
+ n_slider_tick_miss(&self.attrs, &self.state),
+ n_large_tick_miss(&self.attrs, &self.state),
))
.min(estimate_diff_sliders)
};
Expand Down Expand Up @@ -1112,8 +1112,8 @@ const fn n_slider_ends_dropped(attrs: &OsuDifficultyAttributes, state: &OsuScore
attrs.n_sliders - state.slider_end_hits
}

const fn n_slider_tick_miss(attrs: &OsuDifficultyAttributes, state: &OsuScoreState) -> u32 {
attrs.n_slider_ticks - state.large_tick_hits
const fn n_large_tick_miss(attrs: &OsuDifficultyAttributes, state: &OsuScoreState) -> u32 {
attrs.n_large_ticks - state.large_tick_hits
}

struct NoComboState {
Expand Down Expand Up @@ -1202,7 +1202,7 @@ mod test {
N_OBJECTS,
);
assert_eq!(attrs.n_sliders, N_SLIDERS);
assert_eq!(attrs.n_slider_ticks, N_SLIDER_TICKS);
assert_eq!(attrs.n_large_ticks, N_SLIDER_TICKS);

attrs
})
Expand Down Expand Up @@ -1383,7 +1383,7 @@ mod test {
}

if let Some(large_tick_hits) = large_tick_hits {
state = state.large_tick_hits(large_tick_hits);
state = state.n_large_ticks(large_tick_hits);
}

if let Some(n_slider_ends) = slider_end_hits {
Expand Down
28 changes: 14 additions & 14 deletions tests/difficulty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ macro_rules! test_cases {
hp: $hp:literal,
n_circles: $n_circles:literal,
n_sliders: $n_sliders:literal,
n_slider_ticks: $n_slider_ticks:literal,
n_large_ticks: $n_large_ticks:literal,
n_spinners: $n_spinners:literal,
stars: $stars:literal,
max_combo: $max_combo:literal,
Expand All @@ -63,7 +63,7 @@ macro_rules! test_cases {
hp: $hp,
n_circles: $n_circles,
n_sliders: $n_sliders,
n_slider_ticks: $n_slider_ticks,
n_large_ticks: $n_large_ticks,
n_spinners: $n_spinners,
stars: $stars,
max_combo: $max_combo,
Expand Down Expand Up @@ -148,7 +148,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 5.643619989739299,
max_combo: 909,
Expand All @@ -166,7 +166,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 5.643619989739299,
max_combo: 909,
Expand All @@ -184,7 +184,7 @@ fn basic_osu() {
hp: 7.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 6.243301253337941,
max_combo: 909,
Expand All @@ -202,7 +202,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 8.030649319285482,
max_combo: 909,
Expand All @@ -220,7 +220,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 6.858771801534423,
max_combo: 909,
Expand All @@ -238,7 +238,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 7.167932950561898,
max_combo: 909,
Expand All @@ -261,7 +261,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 5.6436199897393005,
max_combo: 909,
Expand All @@ -279,7 +279,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 5.6436199897393005,
max_combo: 909,
Expand All @@ -297,7 +297,7 @@ fn basic_osu() {
hp: 7.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 6.2433012533379415,
max_combo: 909,
Expand All @@ -315,7 +315,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 8.030649319285482,
max_combo: 909,
Expand All @@ -333,7 +333,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 6.858771801534423,
max_combo: 909,
Expand All @@ -351,7 +351,7 @@ fn basic_osu() {
hp: 5.0,
n_circles: 307,
n_sliders: 293,
n_slider_ticks: 15,
n_large_ticks: 15,
n_spinners: 1,
stars: 7.167932950561899,
max_combo: 909,
Expand Down

0 comments on commit 48414de

Please sign in to comment.