From 76fd6c803d9c50a3ad677218dad249f596efe760 Mon Sep 17 00:00:00 2001 From: Natsu Kagami Date: Sat, 14 Sep 2024 18:08:15 +0200 Subject: [PATCH] Update rosu_pp to 1.1, pass full mods to it --- Cargo.lock | 5 ++-- youmubot-osu/Cargo.toml | 2 +- youmubot-osu/src/discord/oppai_cache.rs | 39 ++++++++++++------------- youmubot-osu/src/models/mod.rs | 8 +++-- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 951c42b..1f2ab06 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1818,11 +1818,12 @@ dependencies = [ [[package]] name = "rosu-pp" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26f146c66bed5900ee1fa2b55ef5cc5dd2dbd45e6cac0f7bee5cae535980afbc" +checksum = "002a6b12cedcb185f4051f0b3d0466e0b61ff414a9ca8375f09be581c0e70f06" dependencies = [ "rosu-map", + "rosu-mods", ] [[package]] diff --git a/youmubot-osu/Cargo.toml b/youmubot-osu/Cargo.toml index c0228a9..8d8b430 100644 --- a/youmubot-osu/Cargo.toml +++ b/youmubot-osu/Cargo.toml @@ -14,7 +14,7 @@ dashmap = "5.3.4" lazy_static = "1.4.0" regex = "1.5.6" reqwest = "0.11.10" -rosu-pp = "1.0" +rosu-pp = "1.1" rosu-v2 = { git = "https://github.com/MaxOhn/rosu-v2", branch = "lazer" } rosu-map = "0.1" time = "0.3" diff --git a/youmubot-osu/src/discord/oppai_cache.rs b/youmubot-osu/src/discord/oppai_cache.rs index d93b518..640a704 100644 --- a/youmubot-osu/src/discord/oppai_cache.rs +++ b/youmubot-osu/src/discord/oppai_cache.rs @@ -3,7 +3,7 @@ use std::io::Read; use std::sync::Arc; use rosu_map::Beatmap as BeatmapMetadata; -use rosu_pp::Beatmap; +use rosu_pp::{Beatmap, GameMods}; use youmubot_db_sql::{models::osu as models, Pool}; use youmubot_prelude::*; @@ -67,6 +67,19 @@ impl Accuracy { /// Beatmap Info with attached 95/98/99/100% FC pp. pub type BeatmapInfoWithPP = (BeatmapInfo, [f64; 4]); +fn apply_mods( + perf: rosu_pp::Performance<'_>, + mods: impl Into, +) -> rosu_pp::Performance<'_> { + use rosu_pp::Performance::*; + match perf { + Osu(o) => Osu(o.mods(mods)), + Taiko(t) => Taiko(t.mods(mods)), + Catch(f) => Catch(f.mods(mods)), + Mania(m) => Mania(m.mods(mods)), + } +} + impl BeatmapContent { /// Get pp given the combo and accuracy. pub fn get_pp_from( @@ -76,18 +89,13 @@ impl BeatmapContent { accuracy: Accuracy, mods: &Mods, ) -> Result { - let clock = match mods.inner.clock_rate() { - None => bail!("cannot calculate pp for mods: {}", mods), - Some(clock) => clock as f64, - }; - let mut perf = self + let perf = self .content .performance() .mode_or_ignore(mode.into()) .accuracy(accuracy.into()) - .misses(accuracy.misses() as u32) - .mods(mods.bits()) - .clock_rate(clock); + .misses(accuracy.misses() as u32); + let mut perf = apply_mods(perf, mods.inner.clone()); if let Some(combo) = combo { perf = perf.combo(combo as u32); } @@ -97,17 +105,8 @@ impl BeatmapContent { /// Get info given mods. pub fn get_info_with(&self, mode: Mode, mods: &Mods) -> Result { - let clock = match mods.inner.clock_rate() { - None => bail!("cannot calculate info for mods: {}", mods), - Some(clock) => clock as f64, - }; - let attrs = self - .content - .performance() - .mode_or_ignore(mode.into()) - .mods(mods.bits()) - .clock_rate(clock) - .calculate(); + let perf = self.content.performance().mode_or_ignore(mode.into()); + let attrs = apply_mods(perf, mods.inner.clone()).calculate(); Ok(BeatmapInfo { objects: self.content.hit_objects.len(), max_combo: attrs.max_combo() as usize, diff --git a/youmubot-osu/src/models/mod.rs b/youmubot-osu/src/models/mod.rs index 52a62eb..656648e 100644 --- a/youmubot-osu/src/models/mod.rs +++ b/youmubot-osu/src/models/mod.rs @@ -110,9 +110,11 @@ impl Difficulty { diff.cs = old_cs * 1.3; } if let Some(ratio) = mods.inner.clock_rate() { - diff.apply_length_by_ratio(1.0 / ratio as f64); - diff.apply_ar_by_time_ratio(1.0 / ratio as f64); - diff.apply_od_by_time_ratio(1.0 / ratio as f64); + if ratio != 1.0 { + diff.apply_length_by_ratio(1.0 / ratio as f64); + diff.apply_ar_by_time_ratio(1.0 / ratio as f64); + diff.apply_od_by_time_ratio(1.0 / ratio as f64); + } } // if mods.contains(Mods::HT) { // diff.apply_ar_by_time_ratio(4.0 / 3.0);