dont store perf calculator in gradual calc

This commit is contained in:
MaxOhn
2024-02-22 20:04:35 +01:00
parent 1e35e0fcd7
commit 95012c9f48
3 changed files with 27 additions and 34 deletions
+6 -3
View File
@@ -39,8 +39,7 @@ use super::{
/// ///
/// let converted = Beatmap::from_path("./resources/2785319.osu") /// let converted = Beatmap::from_path("./resources/2785319.osu")
/// .unwrap() /// .unwrap()
/// .unchecked_into_converted::<Osu>() /// .unchecked_into_converted::<Osu>();
/// .unwrap();
/// ///
/// let difficulty = ModeDifficulty::new().mods(64); // DT /// let difficulty = ModeDifficulty::new().mods(64); // DT
/// let mut iter = OsuGradualDifficulty::new(&difficulty, &converted); /// let mut iter = OsuGradualDifficulty::new(&difficulty, &converted);
@@ -59,7 +58,8 @@ use super::{
/// [`OsuGradualPerformance`]: crate::osu::OsuGradualPerformance /// [`OsuGradualPerformance`]: crate::osu::OsuGradualPerformance
pub struct OsuGradualDifficulty { pub struct OsuGradualDifficulty {
pub(crate) idx: usize, pub(crate) idx: usize,
mods: u32, pub(crate) mods: u32,
pub(crate) clock_rate: f64,
attrs: OsuDifficultyAttributes, attrs: OsuDifficultyAttributes,
skills: OsuSkills, skills: OsuSkills,
// Lifetimes actually depend on `osu_objects` so this type is // Lifetimes actually depend on `osu_objects` so this type is
@@ -79,6 +79,7 @@ impl Debug for OsuGradualDifficulty {
f.debug_struct("OsuGradualDifficulty") f.debug_struct("OsuGradualDifficulty")
.field("idx", &self.idx) .field("idx", &self.idx)
.field("mods", &self.mods) .field("mods", &self.mods)
.field("clock_rate", &self.clock_rate)
.field("attrs", &self.attrs) .field("attrs", &self.attrs)
.finish() .finish()
} }
@@ -88,6 +89,7 @@ impl OsuGradualDifficulty {
/// Create a new difficulty attributes iterator for osu!standard maps. /// Create a new difficulty attributes iterator for osu!standard maps.
pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self { pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self {
let mods = difficulty.get_mods(); let mods = difficulty.get_mods();
let clock_rate = difficulty.get_clock_rate();
let OsuDifficultySetup { let OsuDifficultySetup {
scaling_factor, scaling_factor,
@@ -128,6 +130,7 @@ impl OsuGradualDifficulty {
Self { Self {
idx: 0, idx: 0,
mods, mods,
clock_rate,
attrs, attrs,
skills, skills,
diff_objects, diff_objects,
+1 -1
View File
@@ -220,7 +220,7 @@ impl DifficultyValues {
pub fn create_difficulty_objects<'a>( pub fn create_difficulty_objects<'a>(
difficulty: &ModeDifficulty, difficulty: &ModeDifficulty,
scaling_factor: &ScalingFactor, scaling_factor: &ScalingFactor,
osu_objects: impl Iterator<Item = Pin<&'a mut OsuObject>>, osu_objects: impl ExactSizeIterator<Item = Pin<&'a mut OsuObject>>,
) -> Vec<OsuDifficultyObject<'a>> { ) -> Vec<OsuDifficultyObject<'a>> {
let take = difficulty.get_passed_objects(); let take = difficulty.get_passed_objects();
let clock_rate = difficulty.get_clock_rate(); let clock_rate = difficulty.get_clock_rate();
+20 -30
View File
@@ -3,7 +3,7 @@ use crate::{
ModeDifficulty, ModeDifficulty,
}; };
use super::{OsuPerformance, OsuPerformanceAttributes, OsuScoreState}; use super::{OsuPerformanceAttributes, OsuScoreState};
/// Gradually calculate the performance attributes of an osu!standard map. /// Gradually calculate the performance attributes of an osu!standard map.
/// ///
@@ -25,8 +25,7 @@ use super::{OsuPerformance, OsuPerformanceAttributes, OsuScoreState};
/// ///
/// let converted = Beatmap::from_path("./resources/2785319.osu") /// let converted = Beatmap::from_path("./resources/2785319.osu")
/// .unwrap() /// .unwrap()
/// .unchecked_into_converted::<Osu>() /// .unchecked_into_converted::<Osu>();
/// .unwrap();
/// ///
/// let difficulty = ModeDifficulty::new().mods(64); // DT /// let difficulty = ModeDifficulty::new().mods(64); // DT
/// let mut gradual_perf = OsuGradualPerformance::new(&difficulty, converted); /// let mut gradual_perf = OsuGradualPerformance::new(&difficulty, converted);
@@ -81,27 +80,16 @@ use super::{OsuPerformance, OsuPerformanceAttributes, OsuScoreState};
/// [`next`]: OsuGradualPerformance::next /// [`next`]: OsuGradualPerformance::next
/// [`nth`]: OsuGradualPerformance::nth /// [`nth`]: OsuGradualPerformance::nth
#[derive(Debug)] #[derive(Debug)]
pub struct OsuGradualPerformance<'map> { pub struct OsuGradualPerformance {
difficulty: OsuGradualDifficulty, difficulty: OsuGradualDifficulty,
performance: OsuPerformance<'map>,
} }
impl<'map> OsuGradualPerformance<'map> { impl OsuGradualPerformance {
/// Create a new gradual performance calculator for osu!standard maps. /// Create a new gradual performance calculator for osu!standard maps.
pub fn new(difficulty: &ModeDifficulty, converted: OsuBeatmap<'map>) -> Self { pub fn new(difficulty: &ModeDifficulty, converted: &OsuBeatmap<'_>) -> Self {
let mods = difficulty.get_mods(); let difficulty = OsuGradualDifficulty::new(difficulty, converted);
let clock_rate = difficulty.get_clock_rate();
let difficulty = OsuGradualDifficulty::new(difficulty, &converted);
let performance = OsuPerformance::new(converted) Self { difficulty }
.mods(mods)
.clock_rate(clock_rate)
.passed_objects(0);
Self {
difficulty,
performance,
}
} }
/// Process the next hit object and calculate the performance attributes /// Process the next hit object and calculate the performance attributes
@@ -122,13 +110,13 @@ impl<'map> OsuGradualPerformance<'map> {
/// Note that the count is zero-indexed, so `n=0` will process 1 object, /// Note that the count is zero-indexed, so `n=0` will process 1 object,
/// `n=1` will process 2, and so on. /// `n=1` will process 2, and so on.
pub fn nth(&mut self, state: OsuScoreState, n: usize) -> Option<OsuPerformanceAttributes> { pub fn nth(&mut self, state: OsuScoreState, n: usize) -> Option<OsuPerformanceAttributes> {
let difficulty = self.difficulty.nth(n)?;
let performance = self let performance = self
.performance .difficulty
.clone() .nth(n)?
.attributes(difficulty) .performance()
.state(state) .state(state)
.mods(self.difficulty.mods)
.clock_rate(self.difficulty.clock_rate)
.passed_objects(self.difficulty.idx as u32) .passed_objects(self.difficulty.idx as u32)
.calculate(); .calculate();
@@ -138,7 +126,10 @@ impl<'map> OsuGradualPerformance<'map> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::{osu::Osu, Beatmap}; use crate::{
osu::{Osu, OsuPerformance},
Beatmap,
};
use super::*; use super::*;
@@ -149,12 +140,11 @@ mod tests {
.unchecked_into_converted::<Osu>(); .unchecked_into_converted::<Osu>();
let mods = 88; // HDHRDT let mods = 88; // HDHRDT
let difficulty = ModeDifficulty::new().mods(88);
let difficulty = ModeDifficulty::new().mods(mods); let mut gradual = OsuGradualPerformance::new(&difficulty, &converted);
let mut gradual_2nd = OsuGradualPerformance::new(&difficulty, &converted);
let mut gradual = OsuGradualPerformance::new(&difficulty, converted.as_owned()); let mut gradual_3rd = OsuGradualPerformance::new(&difficulty, &converted);
let mut gradual_2nd = OsuGradualPerformance::new(&difficulty, converted.as_owned());
let mut gradual_3rd = OsuGradualPerformance::new(&difficulty, converted.as_owned());
let mut state = OsuScoreState::default(); let mut state = OsuScoreState::default();