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
+24 -1
View File
@@ -167,7 +167,30 @@ impl<'o> DifficultyHitObject<'o> {
/// Various data created through the star calculation.
/// This data is necessary to calculate PP.
#[derive(Clone, Debug, Default)]
#[derive(Copy, Clone, Debug, Default)]
pub struct DifficultyAttributes {
pub stars: f32,
}
/// Various data created through the pp calculation.
#[derive(Copy, Clone, Debug, Default)]
pub struct PerformanceAttributes {
pub attributes: DifficultyAttributes,
pub pp_acc: f32,
pub pp_strain: f32,
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
}
}
+19 -5
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!mania maps.
@@ -90,7 +90,7 @@ impl<'m> ManiaPP<'m> {
}
/// Returns an object which contains the pp and stars.
pub fn calculate(self) -> PpResult {
pub fn calculate(self) -> PerformanceAttributes {
let stars = self
.stars
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects).stars());
@@ -131,9 +131,11 @@ impl<'m> ManiaPP<'m> {
let pp = (strain_value.powf(1.1) + acc_value.powf(1.1)).powf(1.0 / 1.1) * multiplier;
PpResult {
PerformanceAttributes {
attributes: DifficultyAttributes { stars },
pp_acc: acc_value,
pp_strain: strain_value,
pp,
attributes: StarResult::Mania(DifficultyAttributes { stars }),
}
}
@@ -185,6 +187,13 @@ impl ManiaAttributeProvider for DifficultyAttributes {
}
}
impl ManiaAttributeProvider for PerformanceAttributes {
#[inline]
fn attributes(self) -> Option<f32> {
Some(self.attributes.stars)
}
}
impl ManiaAttributeProvider for StarResult {
#[inline]
fn attributes(self) -> Option<f32> {
@@ -200,6 +209,11 @@ impl ManiaAttributeProvider for StarResult {
impl ManiaAttributeProvider for PpResult {
#[inline]
fn attributes(self) -> Option<f32> {
self.attributes.attributes()
#[allow(irrefutable_let_patterns)]
if let Self::Mania(attributes) = self {
Some(attributes.attributes.stars)
} else {
None
}
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ impl Strain {
#[inline]
pub(crate) fn process(&mut self, current: &DifficultyHitObject) {
self.current_strain *= self.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);
}