Skip to content

Commit db25378

Browse files
authored
fix: updates beatmap attribute calculation (#1111)
* dep: cargo update -p rosu-pp Updates beatmap attribute calculation * chore: cargo clippy
1 parent 755bc1a commit db25378

13 files changed

Lines changed: 130 additions & 97 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bathbot/src/active/impls/leaderboard.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl IActiveMessage for LeaderboardPagination {
5454
let _ = write!(
5555
author_text,
5656
"[{}K] ",
57-
self.map.attributes().build().cs as u32
57+
self.map.attributes().build().cs() as u32
5858
);
5959
}
6060

bathbot/src/active/impls/map.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,8 @@ impl IActiveMessage for MapPagination {
8989

9090
let clock_rate = match (self.attrs.bpm, self.attrs.clock_rate) {
9191
(None, None) => self.mods.legacy_clock_rate(),
92-
(_, Some(clock_rate)) => clock_rate,
93-
(Some(new_bpm), None) => {
94-
let old_bpm = map.bpm;
95-
(new_bpm / old_bpm) as f64
96-
}
92+
(_, Some(clock_rate)) => clock_rate.clamp(0.01, 100.0),
93+
(Some(new_bpm), None) => (new_bpm / map.bpm).clamp(0.01, 100.0) as f64,
9794
};
9895

9996
seconds_total = (seconds_total as f64 / clock_rate) as u32;
@@ -130,7 +127,8 @@ impl IActiveMessage for MapPagination {
130127
.attributes()
131128
.mods(&self.mods)
132129
.clock_rate(clock_rate)
133-
.build();
130+
.build()
131+
.apply_clock_rate();
134132

135133
const ACCS: [f32; 4] = [95.0, 97.0, 99.0, 100.0];
136134
let mut pps = Vec::with_capacity(ACCS.len());
@@ -221,10 +219,10 @@ impl IActiveMessage for MapPagination {
221219
"BPM: `{}` Objects: `{}`\nCS: `{}` AR: `{}` OD: `{}` HP: `{}` Spinners: `{}`",
222220
round(bpm as f32),
223221
map.count_circles + map.count_sliders + map.count_spinners,
224-
round(map_attrs.cs as f32),
222+
round(map_attrs.cs),
225223
round(map_attrs.ar as f32),
226224
round(map_attrs.od as f32),
227-
round(map_attrs.hp as f32),
225+
round(map_attrs.hp),
228226
map.count_spinners,
229227
);
230228

bathbot/src/active/impls/profile/top100_stats.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ pub(super) struct Top100Stats {
1212
pub pp: MinMaxAvg<f32>,
1313
pub stars: MinMaxAvg<f64>,
1414
pub ar: MinMaxAvg<f64>,
15-
pub cs: MinMaxAvg<f64>,
16-
pub hp: MinMaxAvg<f64>,
15+
pub cs: MinMaxAvg<f32>,
16+
pub hp: MinMaxAvg<f32>,
1717
pub od: MinMaxAvg<f64>,
1818
pub bpm: MinMaxAvg<f32>,
1919
pub len: MinMaxAvg<f32>,
@@ -98,14 +98,15 @@ impl Top100Stats {
9898
this.pp.add(pp);
9999

100100
let map_attrs = map.attributes().mods(score.mods.clone()).build();
101-
102-
this.ar.add(map_attrs.ar);
103-
this.cs.add(map_attrs.cs);
104-
this.hp.add(map_attrs.hp);
105-
this.od.add(map_attrs.od);
106-
this.bpm.add(map.bpm() * map_attrs.clock_rate as f32);
107-
this.len
108-
.add(map.seconds_drain() as f32 / map_attrs.clock_rate as f32);
101+
let clock_rate = map_attrs.clock_rate() as f32;
102+
let adjusted_map_attrs = map_attrs.apply_clock_rate();
103+
104+
this.ar.add(adjusted_map_attrs.ar);
105+
this.cs.add(adjusted_map_attrs.cs);
106+
this.hp.add(adjusted_map_attrs.hp);
107+
this.od.add(adjusted_map_attrs.od);
108+
this.bpm.add(map.bpm() * clock_rate);
109+
this.len.add(map.seconds_drain() as f32 / clock_rate);
109110
}
110111

111112
Ok(this)

bathbot/src/active/impls/recent_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl IActiveMessage for RecentListPagination {
7676
let _ = write!(
7777
description,
7878
"\t{}",
79-
KeyFormatter::new(&score.mods, map.attributes().build().cs as f32)
79+
KeyFormatter::new(&score.mods, map.attributes().build().cs())
8080
);
8181
}
8282

bathbot/src/active/impls/simulate/data.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ impl SimulateData {
3939

4040
let mod_bits = mods.bits();
4141

42-
if let Some(new_bpm) = self.bpm.filter(|_| self.clock_rate.is_none()) {
42+
if let Some(ref mut clock_rate) = self.clock_rate {
43+
*clock_rate = clock_rate.clamp(0.01, 100.0)
44+
} else if let Some(new_bpm) = self.bpm {
4345
let old_bpm = map.bpm();
4446

45-
self.clock_rate = Some((new_bpm / old_bpm) as f64);
47+
self.clock_rate = Some((new_bpm / old_bpm).clamp(0.01, 100.0) as f64);
4648
}
4749

4850
macro_rules! simulate {

bathbot/src/active/impls/simulate/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,7 @@ impl SimulateMap {
868868
}
869869

870870
let attrs = builder.mods(bits).build();
871-
872-
let clock_rate = attrs.clock_rate;
871+
let clock_rate = attrs.clock_rate();
873872

874873
let start_time = map.hit_objects.first().map_or(0.0, |h| h.start_time);
875874
let end_time = map.hit_objects.last().map_or(0.0, |h| match &h.kind {
@@ -893,20 +892,22 @@ impl SimulateMap {
893892
}
894893

895894
let (cs_key, cs_value) = if map.mode == Mode::Mania {
896-
("Keys", MapInfo::keys(bits, attrs.cs as f32))
895+
("Keys", MapInfo::keys(bits, attrs.cs()))
897896
} else {
898-
("CS", round(attrs.cs as f32))
897+
("CS", round(attrs.cs()))
899898
};
900899

900+
let adjusted_attrs = attrs.apply_clock_rate();
901+
901902
format!(
902903
"Length: `{len}` BPM: `{bpm}` Objects: `{objs}`\n\
903904
{cs_key}: `{cs_value}` AR: `{ar}` OD: `{od}` HP: `{hp}` Stars: `{stars}`",
904905
len = SecToMinSec::new(sec_drain),
905906
bpm = round(bpm),
906907
objs = self.n_objects(),
907-
ar = round(attrs.ar as f32),
908-
od = round(attrs.od as f32),
909-
hp = round(attrs.hp as f32),
908+
ar = round(adjusted_attrs.ar as f32),
909+
od = round(adjusted_attrs.od as f32),
910+
hp = round(adjusted_attrs.hp),
910911
stars = round(stars),
911912
)
912913
}

bathbot/src/active/impls/single_score.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use bathbot_util::{
1919
numbers::round,
2020
};
2121
use eyre::{Report, Result};
22-
use rosu_pp::model::beatmap::BeatmapAttributes;
22+
use rosu_pp::model::beatmap::{AdjustedBeatmapAttributes, BeatmapAttributes};
2323
use rosu_render::{ClientError as OrdrError, client::error::ApiError as OrdrApiError};
2424
use rosu_v2::{
2525
error::OsuError,
@@ -615,11 +615,13 @@ fn apply_settings(
615615
writer.push('*');
616616
}
617617

618+
let adjusted_map_attrs = map_attrs.apply_clock_rate();
619+
618620
let fmt = match curr.inner {
619-
Value::Ar => MapAttribute::AR.fmt(data, &map_attrs),
620-
Value::Cs => MapAttribute::CS.fmt(data, &map_attrs),
621-
Value::Hp => MapAttribute::HP.fmt(data, &map_attrs),
622-
Value::Od => MapAttribute::OD.fmt(data, &map_attrs),
621+
Value::Ar => MapAttribute::AR.fmt(data, &adjusted_map_attrs),
622+
Value::Cs => MapAttribute::CS.fmt(data, &adjusted_map_attrs),
623+
Value::Hp => MapAttribute::HP.fmt(data, &adjusted_map_attrs),
624+
Value::Od => MapAttribute::OD.fmt(data, &adjusted_map_attrs),
623625
_ => unreachable!(),
624626
};
625627

@@ -642,11 +644,13 @@ fn apply_settings(
642644
writer.push('*');
643645
}
644646

647+
let adjusted_map_attrs = map_attrs.apply_clock_rate();
648+
645649
let fmt = match curr.inner {
646-
Value::Ar => MapAttribute::AR.fmt(data, &map_attrs),
647-
Value::Cs => MapAttribute::CS.fmt(data, &map_attrs),
648-
Value::Hp => MapAttribute::HP.fmt(data, &map_attrs),
649-
Value::Od => MapAttribute::OD.fmt(data, &map_attrs),
650+
Value::Ar => MapAttribute::AR.fmt(data, &adjusted_map_attrs),
651+
Value::Cs => MapAttribute::CS.fmt(data, &adjusted_map_attrs),
652+
Value::Hp => MapAttribute::HP.fmt(data, &adjusted_map_attrs),
653+
Value::Od => MapAttribute::OD.fmt(data, &adjusted_map_attrs),
650654
_ => unreachable!(),
651655
};
652656

@@ -690,11 +694,13 @@ fn apply_settings(
690694
writer.push('*');
691695
}
692696

697+
let adjusted_map_attrs = map_attrs.apply_clock_rate();
698+
693699
let fmt = match curr.inner {
694-
Value::Ar => MapAttribute::AR.fmt(data, &map_attrs),
695-
Value::Cs => MapAttribute::CS.fmt(data, &map_attrs),
696-
Value::Hp => MapAttribute::HP.fmt(data, &map_attrs),
697-
Value::Od => MapAttribute::OD.fmt(data, &map_attrs),
700+
Value::Ar => MapAttribute::AR.fmt(data, &adjusted_map_attrs),
701+
Value::Cs => MapAttribute::CS.fmt(data, &adjusted_map_attrs),
702+
Value::Hp => MapAttribute::HP.fmt(data, &adjusted_map_attrs),
703+
Value::Od => MapAttribute::OD.fmt(data, &adjusted_map_attrs),
698704
_ => unreachable!(),
699705
};
700706

@@ -977,7 +983,7 @@ fn write_value(
977983
let _ = write!(writer, "{}★", round(data.stars));
978984
}
979985
Value::Length => {
980-
let clock_rate = map_attrs.clock_rate as f32;
986+
let clock_rate = map_attrs.clock_rate() as f32;
981987
let seconds_drain = (data.map.seconds_drain() as f32 / clock_rate) as u32;
982988

983989
if value.y < SettingValue::FOOTER_Y {
@@ -995,11 +1001,13 @@ fn write_value(
9951001
writer.push('`');
9961002
}
9971003

1004+
let adjusted_map_attrs = map_attrs.apply_clock_rate();
1005+
9981006
let fmt = match &value.inner {
999-
Value::Ar => MapAttribute::AR.fmt(data, map_attrs),
1000-
Value::Cs => MapAttribute::CS.fmt(data, map_attrs),
1001-
Value::Hp => MapAttribute::HP.fmt(data, map_attrs),
1002-
Value::Od => MapAttribute::OD.fmt(data, map_attrs),
1007+
Value::Ar => MapAttribute::AR.fmt(data, &adjusted_map_attrs),
1008+
Value::Cs => MapAttribute::CS.fmt(data, &adjusted_map_attrs),
1009+
Value::Hp => MapAttribute::HP.fmt(data, &adjusted_map_attrs),
1010+
Value::Od => MapAttribute::OD.fmt(data, &adjusted_map_attrs),
10031011
_ => unreachable!(),
10041012
};
10051013

@@ -1010,7 +1018,7 @@ fn write_value(
10101018
}
10111019
}
10121020
Value::Bpm(emote_text) => {
1013-
let clock_rate = map_attrs.clock_rate as f32;
1021+
let clock_rate = map_attrs.clock_rate() as f32;
10141022
let bpm = round(data.map.bpm() * clock_rate);
10151023

10161024
if value.y < SettingValue::FOOTER_Y {
@@ -1153,7 +1161,14 @@ impl Display for MapAttributeFormatter<'_> {
11531161
})
11541162
.collect();
11551163

1156-
let map_attrs = self.data.map.attributes().mods(alt_mods).build();
1164+
let map_attrs = self
1165+
.data
1166+
.map
1167+
.attributes()
1168+
.mods(alt_mods)
1169+
.build()
1170+
.apply_clock_rate();
1171+
11571172
let alt_value = self.map_attr.get_value(&map_attrs);
11581173

11591174
let symbol = match self.value.partial_cmp(&alt_value) {
@@ -1178,16 +1193,16 @@ impl MapAttribute {
11781193
fn fmt<'a>(
11791194
self,
11801195
data: &'a ScoreEmbedData,
1181-
attrs: &BeatmapAttributes,
1196+
attrs: &AdjustedBeatmapAttributes,
11821197
) -> MapAttributeFormatter<'a> {
11831198
MapAttributeFormatter::new(data, self, self.get_value(attrs))
11841199
}
11851200

1186-
fn get_value(self, attrs: &BeatmapAttributes) -> f64 {
1201+
fn get_value(self, attrs: &AdjustedBeatmapAttributes) -> f64 {
11871202
match self {
11881203
MapAttribute::AR => attrs.ar,
1189-
MapAttribute::CS => attrs.cs,
1190-
MapAttribute::HP => attrs.hp,
1204+
MapAttribute::CS => f64::from(attrs.cs),
1205+
MapAttribute::HP => f64::from(attrs.hp),
11911206
MapAttribute::OD => attrs.od,
11921207
}
11931208
}

bathbot/src/commands/osu/top/if_.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,11 +386,12 @@ impl<'q> Searchable<TopCriteria<'q>> for TopIfEntry {
386386
}
387387

388388
let attrs = self.map.attributes().mods(self.score.mods.clone()).build();
389+
let adjusted_attrs = attrs.apply_clock_rate();
389390

390-
matches &= criteria.ar.contains(attrs.ar as f32);
391-
matches &= criteria.cs.contains(attrs.cs as f32);
392-
matches &= criteria.hp.contains(attrs.hp as f32);
393-
matches &= criteria.od.contains(attrs.od as f32);
391+
matches &= criteria.ar.contains(adjusted_attrs.ar as f32);
392+
matches &= criteria.cs.contains(adjusted_attrs.cs);
393+
matches &= criteria.hp.contains(adjusted_attrs.hp);
394+
matches &= criteria.od.contains(adjusted_attrs.od as f32);
394395

395396
let keys = [
396397
(GameModIntermode::OneKey, 1.0),
@@ -406,7 +407,7 @@ impl<'q> Searchable<TopCriteria<'q>> for TopIfEntry {
406407
]
407408
.into_iter()
408409
.find_map(|(gamemod, keys)| self.score.mods.contains_intermode(gamemod).then_some(keys))
409-
.unwrap_or(attrs.cs as f32);
410+
.unwrap_or(adjusted_attrs.cs);
410411

411412
matches &= self.map.mode() != GameMode::Mania || criteria.keys.contains(keys);
412413

@@ -422,7 +423,7 @@ impl<'q> Searchable<TopCriteria<'q>> for TopIfEntry {
422423
return matches;
423424
}
424425

425-
let clock_rate = attrs.clock_rate as f32;
426+
let clock_rate = attrs.clock_rate() as f32;
426427
matches &= criteria
427428
.length
428429
.contains(self.map.seconds_drain() as f32 / clock_rate);

0 commit comments

Comments
 (0)