added distinct strains struct for each mode

This commit is contained in:
MaxOhn
2022-07-06 12:54:00 +02:00
parent af2530e836
commit 8ec61f96d0
7 changed files with 168 additions and 72 deletions
+2
View File
@@ -2,6 +2,8 @@
- __Fixes:__
- Slider velocity is now adjusted properly for taiko converts
- __Breaking changes:__
- Replaced the simple `Strains` struct with a new struct `{Mode}Strains` that contains more detail w.r.t. the mode.
# v0.6.0 (2022-07-05)
+23 -7
View File
@@ -16,9 +16,7 @@ use movement::Movement;
pub use pp::*;
use slider_state::SliderState;
use crate::{
catch::fruit_or_juice::FruitParams, curve::CurveBuffers, Beatmap, Mods, OsuStars, Strains,
};
use crate::{catch::fruit_or_juice::FruitParams, curve::CurveBuffers, Beatmap, Mods, OsuStars};
const SECTION_LENGTH: f64 = 750.0;
const STAR_SCALING_FACTOR: f64 = 0.153;
@@ -110,17 +108,35 @@ impl<'map> CatchStars<'map> {
///
/// Suitable to plot the difficulty of a map over time.
#[inline]
pub fn strains(self) -> Strains {
pub fn strains(self) -> CatchStrains {
let clock_rate = self.clock_rate.unwrap_or_else(|| self.mods.clock_rate());
let (movement, _) = calculate_movement(self);
Strains {
section_length: SECTION_LENGTH * clock_rate,
strains: movement.strain_peaks,
CatchStrains {
section_len: SECTION_LENGTH * clock_rate,
movement: movement.strain_peaks,
}
}
}
/// The result of calculating the strains on a osu!catch map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug)]
pub struct CatchStrains {
/// Time in ms inbetween two strains.
pub section_len: f64,
/// Strain peaks of the movement skill.
pub movement: Vec<f64>,
}
impl CatchStrains {
/// Returns the number of strain peaks per skill.
#[inline]
pub fn len(&self) -> usize {
self.movement.len()
}
}
fn calculate_movement(params: CatchStars<'_>) -> (Movement, CatchDifficultyAttributes) {
let CatchStars {
map,
+42 -13
View File
@@ -286,10 +286,10 @@ impl BeatmapExt for Beatmap {
#[inline]
fn strains(&self, mods: u32) -> Strains {
match self.mode {
GameMode::STD => OsuStars::new(self).mods(mods).strains(),
GameMode::MNA => ManiaStars::new(self).mods(mods).strains(),
GameMode::TKO => TaikoStars::new(self).mods(mods).strains(),
GameMode::CTB => CatchStars::new(self).mods(mods).strains(),
GameMode::STD => Strains::Osu(OsuStars::new(self).mods(mods).strains()),
GameMode::MNA => Strains::Mania(ManiaStars::new(self).mods(mods).strains()),
GameMode::TKO => Strains::Taiko(TaikoStars::new(self).mods(mods).strains()),
GameMode::CTB => Strains::Catch(CatchStars::new(self).mods(mods).strains()),
}
}
@@ -306,24 +306,52 @@ impl BeatmapExt for Beatmap {
/// The result of calculating the strains on a map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug, Default)]
pub struct Strains {
#[derive(Clone, Debug)]
pub enum Strains {
/// osu!catch strain values.
Catch(catch::CatchStrains),
/// osu!mania strain values.
Mania(mania::ManiaStrains),
/// osu!standard strain values.
Osu(osu::OsuStrains),
/// osu!taiko strain values.
Taiko(taiko::TaikoStrains),
}
impl Strains {
/// Time in ms inbetween two strains.
pub section_length: f64,
/// Summed strains for each skill of the map's mode.
pub strains: Vec<f64>,
#[inline]
pub fn section_len(&self) -> f64 {
match self {
Strains::Catch(strains) => strains.section_len,
Strains::Mania(strains) => strains.section_len,
Strains::Osu(strains) => strains.section_len,
Strains::Taiko(strains) => strains.section_len,
}
}
/// Returns the number of strain peaks per skill.
#[inline]
pub fn len(&self) -> usize {
match self {
Strains::Catch(strains) => strains.len(),
Strains::Mania(strains) => strains.len(),
Strains::Osu(strains) => strains.len(),
Strains::Taiko(strains) => strains.len(),
}
}
}
/// The result of a difficulty calculation based on the mode.
#[derive(Clone, Debug)]
pub enum DifficultyAttributes {
/// osu!catch difficulty calculation reseult.
/// osu!catch difficulty calculation result.
Catch(catch::CatchDifficultyAttributes),
/// osu!mania difficulty calculation reseult.
/// osu!mania difficulty calculation result.
Mania(mania::ManiaDifficultyAttributes),
/// osu!standard difficulty calculation reseult.
/// osu!standard difficulty calculation result.
Osu(osu::OsuDifficultyAttributes),
/// osu!taiko difficulty calculation reseult.
/// osu!taiko difficulty calculation result.
Taiko(taiko::TaikoDifficultyAttributes),
}
@@ -443,6 +471,7 @@ impl PerformanceAttributes {
}
impl From<PerformanceAttributes> for DifficultyAttributes {
#[inline]
fn from(attributes: PerformanceAttributes) -> Self {
match attributes {
PerformanceAttributes::Catch(attributes) => Self::Catch(attributes.difficulty),
+22 -4
View File
@@ -10,7 +10,7 @@ pub use gradual_performance::*;
pub use pp::*;
use strain::Strain;
use crate::{parse::HitObject, Beatmap, GameMode, Mods, OsuStars, Strains};
use crate::{parse::HitObject, Beatmap, GameMode, Mods, OsuStars};
const SECTION_LEN: f64 = 400.0;
const STAR_SCALING_FACTOR: f64 = 0.018;
@@ -99,17 +99,35 @@ impl<'map> ManiaStars<'map> {
///
/// Suitable to plot the difficulty of a map over time.
#[inline]
pub fn strains(self) -> Strains {
pub fn strains(self) -> ManiaStrains {
let clock_rate = self.clock_rate.unwrap_or_else(|| self.mods.clock_rate());
let strain = calculate_strain(self);
Strains {
section_length: SECTION_LEN * clock_rate,
ManiaStrains {
section_len: SECTION_LEN * clock_rate,
strains: strain.strain_peaks,
}
}
}
/// The result of calculating the strains on a osu!taiko map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug)]
pub struct ManiaStrains {
/// Time in ms inbetween two strains.
pub section_len: f64,
/// Strain peaks of the strain skill.
pub strains: Vec<f64>,
}
impl ManiaStrains {
/// Returns the number of strain peaks per skill.
#[inline]
pub fn len(&self) -> usize {
self.strains.len()
}
}
fn calculate_strain(params: ManiaStars<'_>) -> Strain {
let ManiaStars {
map,
+42 -27
View File
@@ -20,7 +20,7 @@ use skill::Skill;
use skill_kind::SkillKind;
use slider_state::SliderState;
use crate::{curve::CurveBuffers, AnyStars, Beatmap, GameMode, Mods, Strains};
use crate::{curve::CurveBuffers, AnyStars, Beatmap, GameMode, Mods};
use self::skill::Skills;
@@ -173,42 +173,57 @@ impl<'map> OsuStars<'map> {
///
/// Suitable to plot the difficulty of a map over time.
#[inline]
pub fn strains(self) -> Strains {
pub fn strains(self) -> OsuStrains {
let clock_rate = self.clock_rate.unwrap_or_else(|| self.mods.clock_rate());
let (mut skills, _) = calculate_skills(self);
let mut aim = mem::take(&mut skills.aim().strain_peaks);
let tuple = skills.speed_flashlight();
let len = skills.aim().strain_peaks.len();
let (speed, flashlight) = skills.speed_flashlight();
let strains = match tuple {
(Some(speed), Some(flashlight)) => {
for ((aim, speed), flashlight) in aim
.iter_mut()
.zip(&speed.strain_peaks)
.zip(&flashlight.strain_peaks)
{
*aim += speed + flashlight;
}
let speed = speed.map_or_else(
|| vec![0.0; len],
|skill| mem::take(&mut skill.strain_peaks),
);
aim
}
(Some(strains), None) | (None, Some(strains)) => {
for (aim, strain) in aim.iter_mut().zip(&strains.strain_peaks) {
*aim += strain;
}
let flashlight = flashlight.map_or_else(
|| vec![0.0; len],
|skill| mem::take(&mut skill.strain_peaks),
);
aim
}
(None, None) => aim,
};
Strains {
section_length: SECTION_LEN * clock_rate,
strains,
OsuStrains {
section_len: SECTION_LEN * clock_rate,
aim: mem::take(&mut skills.aim().strain_peaks),
aim_no_sliders: mem::take(&mut skills.aim_no_sliders().strain_peaks),
speed,
flashlight,
}
}
}
/// The result of calculating the strains on a osu!taiko map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug)]
pub struct OsuStrains {
/// Time in ms inbetween two strains.
pub section_len: f64,
/// Strain peaks of the aim skill.
pub aim: Vec<f64>,
/// Strain peaks of the aim skill without sliders.
pub aim_no_sliders: Vec<f64>,
/// Strain peaks of the speed skill.
pub speed: Vec<f64>,
/// Strain peaks of the flashlight skill.
pub flashlight: Vec<f64>,
}
impl OsuStrains {
/// Returns the number of strain peaks per skill.
#[inline]
pub fn len(&self) -> usize {
self.aim.len()
}
}
fn calculate_star_rating(aim_rating: f64, speed_rating: f64, flashlight_rating: f64) -> f64 {
let base_aim_performance = {
let base = 5.0 * (aim_rating / 0.0675).max(1.0) - 4.0;
+5 -4
View File
@@ -45,6 +45,7 @@ impl<'map> AnyStars<'map> {
}
/// If the map is an osu!standard map, convert it to another mode.
#[inline]
pub fn mode(self, mode: GameMode) -> Self {
match self {
AnyStars::Osu(o) => match mode {
@@ -117,10 +118,10 @@ impl<'map> AnyStars<'map> {
#[inline]
pub fn strains(self) -> Strains {
match self {
Self::Catch(f) => f.strains(),
Self::Mania(m) => m.strains(),
Self::Osu(o) => o.strains(),
Self::Taiko(t) => t.strains(),
Self::Catch(f) => Strains::Catch(f.strains()),
Self::Mania(m) => Strains::Mania(m.strains()),
Self::Osu(o) => Strains::Osu(o.strains()),
Self::Taiko(t) => Strains::Taiko(t.strains()),
}
}
}
+32 -17
View File
@@ -20,7 +20,7 @@ use stamina_cheese::StaminaCheeseDetector;
use taiko_object::IntoTaikoObjectIter;
use crate::taiko::skill::Skills;
use crate::{Beatmap, GameMode, Mods, OsuStars, Strains};
use crate::{Beatmap, GameMode, Mods, OsuStars};
use std::borrow::Cow;
use std::cmp::Ordering;
@@ -137,29 +137,44 @@ impl<'map> TaikoStars<'map> {
///
/// Suitable to plot the difficulty of a map over time.
#[inline]
pub fn strains(self) -> Strains {
pub fn strains(self) -> TaikoStrains {
let clock_rate = self.clock_rate.unwrap_or_else(|| self.mods.clock_rate());
let (skills, _) = calculate_skills(self);
let strains = skills
.color
.strain_peaks
.iter()
.zip(skills.rhythm.strain_peaks.iter())
.zip(skills.stamina_right.strain_peaks.iter())
.zip(skills.stamina_left.strain_peaks.iter())
.map(|(((color, rhythm), stamina_right), stamina_left)| {
color + rhythm + stamina_right + stamina_left
})
.collect();
Strains {
section_length: SECTION_LEN * clock_rate,
strains,
TaikoStrains {
section_len: SECTION_LEN * clock_rate,
color: skills.color.strain_peaks,
rhythm: skills.rhythm.strain_peaks,
stamina_right: skills.stamina_right.strain_peaks,
stamina_left: skills.stamina_left.strain_peaks,
}
}
}
/// The result of calculating the strains on a osu!taiko map.
/// Suitable to plot the difficulty of a map over time.
#[derive(Clone, Debug)]
pub struct TaikoStrains {
/// Time in ms inbetween two strains.
pub section_len: f64,
/// Strain peaks of the color skill.
pub color: Vec<f64>,
/// Strain peaks of the rhythm skill.
pub rhythm: Vec<f64>,
/// Strain peaks of the left-stamina skill.
pub stamina_right: Vec<f64>,
/// Strain peaks of the right-stamina skill.
pub stamina_left: Vec<f64>,
}
impl TaikoStrains {
/// Returns the number of strain peaks per skill.
#[inline]
pub fn len(&self) -> usize {
self.color.len()
}
}
fn calculate_skills(params: TaikoStars<'_>) -> (Skills, usize) {
let TaikoStars {
map,