mania: fixed attributes on very short maps

This commit is contained in:
MaxOhn
2021-11-23 02:25:44 +01:00
parent 55f0c4bfe3
commit 0b367c59e5
+24 -30
View File
@@ -19,11 +19,10 @@ pub fn stars(
mods: impl Mods, mods: impl Mods,
passed_objects: Option<usize>, passed_objects: Option<usize>,
) -> ManiaDifficultyAttributes { ) -> ManiaDifficultyAttributes {
match calculate_strain(map, mods, passed_objects) { let mut strain = calculate_strain(map, mods, passed_objects);
Some(mut strain) => ManiaDifficultyAttributes {
stars: strain.difficulty_value() * STAR_SCALING_FACTOR, ManiaDifficultyAttributes {
}, stars: strain.difficulty_value() * STAR_SCALING_FACTOR,
None => ManiaDifficultyAttributes::default(),
} }
} }
@@ -32,26 +31,16 @@ pub fn stars(
/// ///
/// Suitable to plot the difficulty of a map over time. /// Suitable to plot the difficulty of a map over time.
pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains { pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
match calculate_strain(map, mods, None) { let strain = calculate_strain(map, mods, None);
Some(strain) => Strains {
section_length: SECTION_LEN * mods.speed(), Strains {
strains: strain.strain_peaks, section_length: SECTION_LEN * mods.speed(),
}, strains: strain.strain_peaks,
None => Strains::default(),
} }
} }
fn calculate_strain( fn calculate_strain(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> Strain {
map: &Beatmap,
mods: impl Mods,
passed_objects: Option<usize>,
) -> Option<Strain> {
let take = passed_objects.unwrap_or_else(|| map.hit_objects.len()); let take = passed_objects.unwrap_or_else(|| map.hit_objects.len());
if take < 2 {
return None;
}
let rounded_cs = map.cs.round(); let rounded_cs = map.cs.round();
let columns = match map.mode { let columns = match map.mode {
@@ -89,25 +78,30 @@ fn calculate_strain(
.map(|(base, prev)| DifficultyHitObject::new(base, prev, columns, clock_rate)); .map(|(base, prev)| DifficultyHitObject::new(base, prev, columns, clock_rate));
// No strain for first object // No strain for first object
let mut current_section_end = let mut curr_section_end = match map.hit_objects.first() {
(map.hit_objects[0].start_time / section_len).ceil() * section_len; Some(h) => (h.start_time / section_len).ceil() * section_len,
None => return strain,
};
// Handle second object separately to remove later if-branching // Handle second object separately to remove later if-branching
let h = hit_objects.next().unwrap(); let h = match hit_objects.next() {
Some(h) => h,
None => return strain,
};
while h.base.start_time > current_section_end { while h.base.start_time > curr_section_end {
current_section_end += section_len; curr_section_end += section_len;
} }
strain.process(&h); strain.process(&h);
// Handle all other objects // Handle all other objects
for h in hit_objects { for h in hit_objects {
while h.base.start_time > current_section_end { while h.base.start_time > curr_section_end {
strain.save_current_peak(); strain.save_current_peak();
strain.start_new_section_from(current_section_end / clock_rate); strain.start_new_section_from(curr_section_end / clock_rate);
current_section_end += section_len; curr_section_end += section_len;
} }
strain.process(&h); strain.process(&h);
@@ -115,7 +109,7 @@ fn calculate_strain(
strain.save_current_peak(); strain.save_current_peak();
Some(strain) strain
} }
#[derive(Debug)] #[derive(Debug)]