add: async wrapper for pp calculate

This commit is contained in:
PurePeace
2021-02-23 15:30:57 +08:00
parent a597735513
commit 59f77dfd4b
5 changed files with 34 additions and 0 deletions
+5
View File
@@ -315,6 +315,11 @@ impl<'m> FruitsPP<'m> {
}
}
#[inline]
pub async fn calculate_async(self) -> PpResult {
self.calculate()
}
#[inline]
fn combo_hits(&self) -> usize {
self.n_fruits.unwrap_or(0) + self.n_droplets.unwrap_or(0) + self.n_misses
+5
View File
@@ -136,6 +136,11 @@ impl<'m> ManiaPP<'m> {
}
}
#[inline]
pub async fn calculate_async(self) -> PpResult {
self.calculate()
}
fn compute_strain(&self, score: f32, stars: f32) -> f32 {
let mut strain_value = (5.0 * (stars / 0.2).max(1.0) - 4.0).powf(2.2) / 135.0;
+5
View File
@@ -261,6 +261,11 @@ impl<'m> OsuPP<'m> {
unreachable!()
}
#[inline]
pub async fn calculate_async(self) -> PpResult {
self.calculate()
}
/// Returns an object which contains the pp and [`DifficultyAttributes`](crate::osu::DifficultyAttributes)
/// containing stars and other attributes.
///
+14
View File
@@ -55,6 +55,20 @@ impl<'m> AnyPP<'m> {
}
}
#[inline]
pub async fn calculate_async(self) -> PpResult {
match self {
#[cfg(feature = "fruits")]
Self::Fruits(f) => f.calculate_async().await,
#[cfg(feature = "mania")]
Self::Mania(m) => m.calculate_async().await,
#[cfg(feature = "osu")]
Self::Osu(o) => o.calculate_async().await,
#[cfg(feature = "taiko")]
Self::Taiko(t) => t.calculate_async().await,
}
}
/// [`AttributeProvider`] is implemented by [`StarResult`](crate::StarResult)
/// and [`PpResult`](crate::PpResult) meaning you can give the result of a \
/// star calculation or the result of a pp calculation.
+5
View File
@@ -181,6 +181,11 @@ impl<'m> TaikoPP<'m> {
}
}
#[inline]
pub async fn calculate_async(self) -> PpResult {
self.calculate()
}
fn compute_strain_value(&self, stars: f32) -> f32 {
let exp_base = 5.0 * (stars / 0.0075).max(1.0) - 4.0;
let mut strain = exp_base * exp_base / 100_000.0;