use the same StarResult type for all modes

This commit is contained in:
MaxOhn
2021-01-18 12:55:46 +01:00
parent aae601a91e
commit 44538a7022
11 changed files with 170 additions and 120 deletions
+6 -4
View File
@@ -4,7 +4,7 @@ mod strain;
pub use pp::*;
use strain::Strain;
use crate::{Beatmap, HitObject, Mods};
use crate::{Beatmap, HitObject, Mods, StarResult};
const SECTION_LEN: f32 = 400.0;
const STAR_SCALING_FACTOR: f32 = 0.018;
@@ -12,11 +12,11 @@ const STAR_SCALING_FACTOR: f32 = 0.018;
/// Star calculation for osu!mania maps
///
/// In case of a partial play, e.g. a fail, one can specify the amount of passed objects.
pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> f32 {
pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> StarResult {
let take = passed_objects.unwrap_or_else(|| map.hit_objects.len());
if take < 2 {
return 0.0;
return StarResult::Mania { stars: 0.0 };
}
let clock_rate = mods.speed();
@@ -58,7 +58,9 @@ pub fn stars(map: &Beatmap, mods: impl Mods, passed_objects: Option<usize>) -> f
strain.save_current_peak();
strain.difficulty_value() * STAR_SCALING_FACTOR
let stars = strain.difficulty_value() * STAR_SCALING_FACTOR;
StarResult::Mania { stars }
}
#[derive(Debug)]
+15 -6
View File
@@ -1,5 +1,5 @@
use super::stars;
use crate::{Beatmap, Mods, PpResult};
use crate::{Beatmap, Mods, PpResult, StarResult};
pub trait ManiaStarProvider {
fn attributes(self) -> Option<f32>;
@@ -11,9 +11,9 @@ impl ManiaStarProvider for f32 {
}
}
impl ManiaStarProvider for PpResult {
impl ManiaStarProvider for StarResult {
fn attributes(self) -> Option<f32> {
if let PpResult::Mania { stars, .. } = self {
if let Self::Mania { stars } = self {
Some(stars)
} else {
None
@@ -21,6 +21,12 @@ impl ManiaStarProvider for PpResult {
}
}
impl ManiaStarProvider for PpResult {
fn attributes(self) -> Option<f32> {
self.attributes.attributes()
}
}
/// Calculator for pp on osu!mania maps.
pub struct ManiaPP<'m> {
map: &'m Beatmap,
@@ -42,7 +48,7 @@ impl<'m> ManiaPP<'m> {
}
}
/// [`ManiaStarsProvider`] is implemented by `f32`
/// [`ManiaStarsProvider`] is implemented by `f32`, [`StarResult`](crate::StarResult),
/// and by [`PpResult`](crate::PpResult) meaning you can give the
/// result of a star calculation or a pp calculation.
/// If you already calculated the attributes for the current map-mod combination,
@@ -87,7 +93,7 @@ impl<'m> ManiaPP<'m> {
pub fn calculate(self) -> PpResult {
let stars = self
.stars
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects));
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects).stars());
let ez = self.mods.ez();
let nf = self.mods.nf();
@@ -133,7 +139,10 @@ impl<'m> ManiaPP<'m> {
let pp = (strain_value.powf(1.1) + acc_value.powf(1.1)).powf(1.0 / 1.1) * multiplier;
PpResult::Mania { pp, stars }
PpResult {
pp,
attributes: StarResult::Mania { stars },
}
}
fn compute_strain(&self, score: f32, stars: f32) -> f32 {