return PerformanceAttributes instead of PpResult

This commit is contained in:
MaxOhn
2021-11-03 16:53:17 +01:00
parent b7caf35bb4
commit 5780559b70
16 changed files with 233 additions and 56 deletions
+23 -4
View File
@@ -18,8 +18,6 @@ use crate::{
Beatmap, Mods, StarResult, Strains,
};
use std::convert::identity;
const SECTION_LENGTH: f32 = 750.0;
const STAR_SCALING_FACTOR: f32 = 0.153;
@@ -159,7 +157,7 @@ pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> S
}
HitObjectKind::Spinner { .. } | HitObjectKind::Hold { .. } => Some(None),
})
.filter_map(identity)
.flatten()
.flatten()
.take(take);
@@ -384,7 +382,7 @@ pub fn strains(map: &Beatmap, mods: impl Mods) -> Strains {
}
HitObjectKind::Spinner { .. } | HitObjectKind::Hold { .. } => Some(None),
})
.filter_map(identity)
.flatten()
.flatten();
// Hyper dash business
@@ -602,3 +600,24 @@ pub struct DifficultyAttributes {
pub n_droplets: usize,
pub n_tiny_droplets: usize,
}
/// Various data created through the pp calculation.
#[derive(Clone, Debug, Default)]
pub struct PerformanceAttributes {
pub attributes: DifficultyAttributes,
pub pp: f32,
}
impl PerformanceAttributes {
/// Return the star value.
#[inline]
pub fn stars(&self) -> f32 {
self.attributes.stars
}
/// Return the performance point value.
#[inline]
pub fn pp(&self) -> f32 {
self.pp
}
}
+1 -1
View File
@@ -57,7 +57,7 @@ impl Movement {
pub(crate) fn process(&mut self, current: &DifficultyObject) {
self.current_strain *= strain_decay(current.delta);
self.current_strain += self.strain_value_of(&current) * SKILL_MULTIPLIER;
self.current_strain += self.strain_value_of(current) * SKILL_MULTIPLIER;
self.current_section_peak = self.current_strain.max(self.current_section_peak);
self.prev_time.replace(current.start_time);
}
+16 -7
View File
@@ -1,4 +1,4 @@
use super::{stars, DifficultyAttributes};
use super::{stars, DifficultyAttributes, PerformanceAttributes};
use crate::{Beatmap, Mods, PpResult, StarResult};
/// Calculator for pp on osu!ctb maps.
@@ -241,7 +241,7 @@ impl<'m> FruitsPP<'m> {
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::fruits::DifficultyAttributes)
/// containing stars and other attributes.
pub fn calculate(mut self) -> PpResult {
pub fn calculate(mut self) -> PerformanceAttributes {
let attributes = self.attributes.take().unwrap_or_else(|| {
stars(self.map, self.mods, self.passed_objects)
.attributes()
@@ -310,10 +310,7 @@ impl<'m> FruitsPP<'m> {
pp *= 0.9;
}
PpResult {
pp,
attributes: StarResult::Fruits(attributes),
}
PerformanceAttributes { attributes, pp }
}
#[inline]
@@ -358,6 +355,13 @@ impl FruitsAttributeProvider for DifficultyAttributes {
}
}
impl FruitsAttributeProvider for PerformanceAttributes {
#[inline]
fn attributes(self) -> Option<DifficultyAttributes> {
Some(self.attributes)
}
}
impl FruitsAttributeProvider for StarResult {
#[inline]
fn attributes(self) -> Option<DifficultyAttributes> {
@@ -373,7 +377,12 @@ impl FruitsAttributeProvider for StarResult {
impl FruitsAttributeProvider for PpResult {
#[inline]
fn attributes(self) -> Option<DifficultyAttributes> {
self.attributes.attributes()
#[allow(irrefutable_let_patterns)]
if let Self::Fruits(attributes) = self {
Some(attributes.attributes)
} else {
None
}
}
}