use CompactVec for all modes

This commit is contained in:
MaxOhn
2023-02-22 13:12:54 +01:00
parent de342f5c3d
commit bd9623d32b
9 changed files with 45 additions and 30 deletions
+1 -1
View File
@@ -139,7 +139,7 @@ impl<'map> ManiaStars<'map> {
ManiaStrains {
section_len: SECTION_LEN,
strains: strain.strain_peaks,
strains: strain.strain_peaks.to_vec(),
}
}
}
+4 -4
View File
@@ -1,4 +1,4 @@
use crate::mania::difficulty_object::ManiaDifficultyObject;
use crate::{mania::difficulty_object::ManiaDifficultyObject, util::CompactVec};
use super::{previous, Skill, StrainDecaySkill, StrainSkill};
@@ -15,7 +15,7 @@ pub(crate) struct Strain {
curr_section_peak: f64,
curr_section_end: f64,
pub(crate) strain_peaks: Vec<f64>,
pub(crate) strain_peaks: CompactVec,
}
impl Strain {
@@ -33,7 +33,7 @@ impl Strain {
curr_strain: 0.0,
curr_section_peak: 0.0,
curr_section_end: 0.0,
strain_peaks: Vec::new(),
strain_peaks: CompactVec::new(),
}
}
@@ -78,7 +78,7 @@ impl StrainSkill for Strain {
}
#[inline]
fn strain_peaks_mut(&mut self) -> &mut Vec<f64> {
fn strain_peaks_mut(&mut self) -> &mut CompactVec {
&mut self.strain_peaks
}
+8 -4
View File
@@ -1,6 +1,9 @@
use std::{cmp::Ordering, mem};
use crate::mania::{difficulty_object::ManiaDifficultyObject, SECTION_LEN};
use crate::{
mania::{difficulty_object::ManiaDifficultyObject, SECTION_LEN},
util::CompactVec,
};
pub(crate) trait Skill {
fn process(&mut self, curr: &ManiaDifficultyObject, diff_objects: &[ManiaDifficultyObject]);
@@ -16,7 +19,7 @@ pub(crate) trait StrainSkill: Sized + Skill {
fn curr_section_peak(&self) -> f64;
fn curr_section_peak_mut(&mut self) -> &mut f64;
fn strain_peaks_mut(&mut self) -> &mut Vec<f64>;
fn strain_peaks_mut(&mut self) -> &mut CompactVec;
fn strain_value_at(&mut self, curr: &ManiaDifficultyObject) -> f64;
@@ -68,7 +71,7 @@ pub(crate) trait StrainSkill: Sized + Skill {
diff_objects: &[ManiaDifficultyObject],
) -> f64;
fn get_curr_strain_peaks(mut self) -> Vec<f64> {
fn get_curr_strain_peaks(mut self) -> CompactVec {
let mut peaks = mem::take(self.strain_peaks_mut());
peaks.push(self.curr_section_peak());
@@ -82,7 +85,8 @@ pub(crate) trait StrainSkill: Sized + Skill {
// * Sections with 0 strain are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871).
// * These sections will not contribute to the difficulty.
let mut peaks = self.get_curr_strain_peaks();
peaks.retain(|&peak| peak > 0.0);
peaks.retain(|peak| peak > 0.0);
let mut peaks = peaks.to_vec();
peaks.sort_unstable_by(|a, b| b.partial_cmp(a).unwrap_or(Ordering::Equal));
// * Difficulty is the weighted sum of the highest strains from every section.