use CompactVec for all modes
This commit is contained in:
+1
-1
@@ -139,7 +139,7 @@ impl<'map> ManiaStars<'map> {
|
||||
|
||||
ManiaStrains {
|
||||
section_len: SECTION_LEN,
|
||||
strains: strain.strain_peaks,
|
||||
strains: strain.strain_peaks.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
+4
-4
@@ -198,10 +198,10 @@ impl<'map> OsuStars<'map> {
|
||||
|
||||
OsuStrains {
|
||||
section_len: SECTION_LEN,
|
||||
aim: aim.strain_peaks,
|
||||
aim_no_sliders: aim_no_sliders.strain_peaks,
|
||||
speed: speed.strain_peaks,
|
||||
flashlight: flashlight.strain_peaks,
|
||||
aim: aim.strain_peaks.to_vec(),
|
||||
aim_no_sliders: aim_no_sliders.strain_peaks.to_vec(),
|
||||
speed: speed.strain_peaks.to_vec(),
|
||||
flashlight: flashlight.strain_peaks.to_vec(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::f64::consts::{FRAC_PI_2, PI};
|
||||
|
||||
use crate::osu::difficulty_object::OsuDifficultyObject;
|
||||
use crate::{osu::difficulty_object::OsuDifficultyObject, util::CompactVec};
|
||||
|
||||
use super::{previous, previous_start_time, OsuStrainSkill, Skill, StrainSkill};
|
||||
|
||||
@@ -9,7 +9,7 @@ pub(crate) struct Aim {
|
||||
curr_strain: f64,
|
||||
curr_section_peak: f64,
|
||||
curr_section_end: f64,
|
||||
pub(crate) strain_peaks: Vec<f64>,
|
||||
pub(crate) strain_peaks: CompactVec,
|
||||
with_sliders: bool,
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ impl Aim {
|
||||
curr_strain: 0.0,
|
||||
curr_section_peak: 0.0,
|
||||
curr_section_end: 0.0,
|
||||
strain_peaks: Vec::new(),
|
||||
strain_peaks: CompactVec::new(),
|
||||
with_sliders,
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ impl Skill for Aim {
|
||||
|
||||
impl StrainSkill for Aim {
|
||||
#[inline]
|
||||
fn strain_peaks_mut(&mut self) -> &mut Vec<f64> {
|
||||
fn strain_peaks_mut(&mut self) -> &mut CompactVec {
|
||||
&mut self.strain_peaks
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
osu::{difficulty_object::OsuDifficultyObject, osu_object::OsuObjectKind},
|
||||
util::CompactVec,
|
||||
Mods,
|
||||
};
|
||||
|
||||
@@ -10,7 +11,7 @@ pub(crate) struct Flashlight {
|
||||
curr_strain: f64,
|
||||
curr_section_peak: f64,
|
||||
curr_section_end: f64,
|
||||
pub(crate) strain_peaks: Vec<f64>,
|
||||
pub(crate) strain_peaks: CompactVec,
|
||||
has_hidden_mod: bool,
|
||||
scaling_factor: f64,
|
||||
time_preempt: f64,
|
||||
@@ -26,7 +27,7 @@ impl Flashlight {
|
||||
curr_strain: 0.0,
|
||||
curr_section_peak: 0.0,
|
||||
curr_section_end: 0.0,
|
||||
strain_peaks: Vec::new(),
|
||||
strain_peaks: CompactVec::new(),
|
||||
has_hidden_mod: mods.hd(),
|
||||
scaling_factor: 52.0 / radius as f64,
|
||||
time_preempt,
|
||||
@@ -59,7 +60,7 @@ impl StrainSkill for Flashlight {
|
||||
const DECAY_WEIGHT: f64 = 0.9;
|
||||
|
||||
#[inline]
|
||||
fn strain_peaks_mut(&mut self) -> &mut Vec<f64> {
|
||||
fn strain_peaks_mut(&mut self) -> &mut CompactVec {
|
||||
&mut self.strain_peaks
|
||||
}
|
||||
|
||||
@@ -104,7 +105,7 @@ impl StrainSkill for Flashlight {
|
||||
|
||||
#[inline]
|
||||
fn difficulty_value(&mut self) -> f64 {
|
||||
self.get_curr_strain_peaks().into_iter().sum::<f64>() * Self::DIFFICULTY_MULTIPLER
|
||||
self.get_curr_strain_peaks().sum() * Self::DIFFICULTY_MULTIPLER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{cmp::Ordering, f64::consts::PI};
|
||||
|
||||
use crate::osu::difficulty_object::OsuDifficultyObject;
|
||||
use crate::{osu::difficulty_object::OsuDifficultyObject, util::CompactVec};
|
||||
|
||||
use super::{next, previous, previous_start_time, OsuStrainSkill, Skill, StrainSkill};
|
||||
|
||||
@@ -10,7 +10,7 @@ pub(crate) struct Speed {
|
||||
curr_section_peak: f64,
|
||||
curr_section_end: f64,
|
||||
curr_rhythm: f64,
|
||||
pub(crate) strain_peaks: Vec<f64>,
|
||||
pub(crate) strain_peaks: CompactVec,
|
||||
object_strains: Vec<f64>,
|
||||
hit_window: f64,
|
||||
}
|
||||
@@ -25,7 +25,7 @@ impl Speed {
|
||||
curr_section_peak: 0.0,
|
||||
curr_section_end: 0.0,
|
||||
curr_rhythm: 0.0,
|
||||
strain_peaks: Vec::new(),
|
||||
strain_peaks: CompactVec::new(),
|
||||
object_strains: Vec::new(),
|
||||
hit_window,
|
||||
}
|
||||
@@ -67,7 +67,7 @@ impl Skill for Speed {
|
||||
|
||||
impl StrainSkill for Speed {
|
||||
#[inline]
|
||||
fn strain_peaks_mut(&mut self) -> &mut Vec<f64> {
|
||||
fn strain_peaks_mut(&mut self) -> &mut CompactVec {
|
||||
&mut self.strain_peaks
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use std::{cmp::Ordering, mem};
|
||||
|
||||
use crate::osu::{difficulty_object::OsuDifficultyObject, SECTION_LEN};
|
||||
use crate::{
|
||||
osu::{difficulty_object::OsuDifficultyObject, SECTION_LEN},
|
||||
util::CompactVec,
|
||||
};
|
||||
|
||||
pub(crate) trait Skill {
|
||||
fn process(&mut self, curr: &OsuDifficultyObject<'_>, diff_objects: &[OsuDifficultyObject<'_>]);
|
||||
@@ -10,7 +13,7 @@ pub(crate) trait Skill {
|
||||
pub(crate) trait StrainSkill: Skill + Sized {
|
||||
const DECAY_WEIGHT: f64 = 0.9;
|
||||
|
||||
fn strain_peaks_mut(&mut self) -> &mut Vec<f64>;
|
||||
fn strain_peaks_mut(&mut self) -> &mut CompactVec;
|
||||
fn curr_section_peak(&mut self) -> &mut f64;
|
||||
fn curr_section_end(&mut self) -> &mut f64;
|
||||
|
||||
@@ -88,7 +91,7 @@ pub(crate) trait StrainSkill: Skill + Sized {
|
||||
fn difficulty_value(&mut self) -> f64;
|
||||
|
||||
#[inline]
|
||||
fn get_curr_strain_peaks(&mut self) -> Vec<f64> {
|
||||
fn get_curr_strain_peaks(&mut self) -> CompactVec {
|
||||
let curr_peak = *self.curr_section_peak();
|
||||
let mut strain_peaks = mem::take(self.strain_peaks_mut());
|
||||
strain_peaks.push(curr_peak);
|
||||
@@ -109,8 +112,9 @@ pub(crate) trait OsuStrainSkill: StrainSkill + Sized {
|
||||
// * 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));
|
||||
|
||||
let peak_iter = peaks.iter_mut().take(Self::REDUCED_SECTION_COUNT);
|
||||
|
||||
@@ -10,7 +10,7 @@ pub(crate) struct CompactVec {
|
||||
}
|
||||
|
||||
impl CompactVec {
|
||||
const ACCEPTABLE_DIFFERENCE: f64 = 1e-7;
|
||||
const ACCEPTABLE_DIFFERENCE: f64 = 1e-16;
|
||||
|
||||
pub(crate) fn new() -> Self {
|
||||
Self::default()
|
||||
@@ -54,6 +54,12 @@ impl CompactVec {
|
||||
|
||||
nums
|
||||
}
|
||||
|
||||
pub(crate) fn sum(&self) -> f64 {
|
||||
self.inner
|
||||
.iter()
|
||||
.fold(0.0, |sum, entry| sum + entry.value * entry.count as f64)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
|
||||
Reference in New Issue
Block a user