1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 14:12:56 +08:00

Refactor and Cleanup of Stamina.cs

This commit is contained in:
Jay L 2022-05-15 22:09:54 +10:00
parent f15738fded
commit d174099016

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills; using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -10,30 +9,29 @@ using osu.Game.Rulesets.Taiko.Objects;
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{ {
class SingleKeyStamina /// <summary>
/// Stamina of a single key, calculated based on repetition speed.
/// </summary>
public class SingleKeyStamina
{ {
private double previousHitTime = -1; private double previousHitTime = -1;
private double strainValueOf(DifficultyHitObject current) /// <summary>
/// Similar to <see cref="StrainDecaySkill.StrainValueOf(DifficultyHitObject)"/>
/// </summary>
public double StrainValueOf(DifficultyHitObject current)
{ {
if (previousHitTime == -1) if (previousHitTime == -1)
{ {
previousHitTime = current.StartTime; previousHitTime = current.StartTime;
return 0; return 0;
} }
else
{
double objectStrain = 0.5; double objectStrain = 0.5;
objectStrain += speedBonus(current.StartTime - previousHitTime); objectStrain += speedBonus(current.StartTime - previousHitTime);
previousHitTime = current.StartTime; previousHitTime = current.StartTime;
return objectStrain; return objectStrain;
} }
}
public double StrainValueAt(DifficultyHitObject current)
{
return strainValueOf(current);
}
/// <summary> /// <summary>
/// Applies a speed bonus dependent on the time since the last hit performed using this key. /// Applies a speed bonus dependent on the time since the last hit performed using this key.
@ -41,7 +39,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
/// <param name="notePairDuration">The duration between the current and previous note hit using the same key.</param> /// <param name="notePairDuration">The duration between the current and previous note hit using the same key.</param>
private double speedBonus(double notePairDuration) private double speedBonus(double notePairDuration)
{ {
return 175 / Math.Pow(notePairDuration + 100, 1); return 175 / (notePairDuration + 100);
} }
} }
@ -56,7 +54,10 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
protected override double SkillMultiplier => 1; protected override double SkillMultiplier => 1;
protected override double StrainDecayBase => 0.4; protected override double StrainDecayBase => 0.4;
private SingleKeyStamina[] keyStamina = new SingleKeyStamina[4] /// <summary>
/// Stamina of each individual keys, calculated based on repetition speed.
/// </summary>
private readonly SingleKeyStamina[] keyStamina =
{ {
new SingleKeyStamina(), new SingleKeyStamina(),
new SingleKeyStamina(), new SingleKeyStamina(),
@ -64,7 +65,14 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
new SingleKeyStamina() new SingleKeyStamina()
}; };
/// <summary>
/// Current index to <see cref="keyStamina" /> for a don hit.
/// </summary>
private int donIndex = 1; private int donIndex = 1;
/// <summary>
/// Current index to <see cref="keyStamina" /> for a kat hit.
/// </summary>
private int katIndex = 3; private int katIndex = 3;
/// <summary> /// <summary>
@ -76,24 +84,22 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{ {
} }
/// <summary>
/// Get the next <see cref="SingleKeyStamina"/> to use for the given <see cref="TaikoDifficultyHitObject"/>.
/// </summary>
/// <param name="current">The current <see cref="TaikoDifficultyHitObject"/>.</param>
private SingleKeyStamina getNextSingleKeyStamina(TaikoDifficultyHitObject current) private SingleKeyStamina getNextSingleKeyStamina(TaikoDifficultyHitObject current)
{ {
// Alternate key for the same color.
if (current.HitType == HitType.Centre) if (current.HitType == HitType.Centre)
{ {
donIndex = donIndex == 0 ? 1 : 0; donIndex = donIndex == 0 ? 1 : 0;
return keyStamina[donIndex]; return keyStamina[donIndex];
} }
else
{
katIndex = katIndex == 2 ? 3 : 2; katIndex = katIndex == 2 ? 3 : 2;
return keyStamina[katIndex]; return keyStamina[katIndex];
} }
}
private double sigmoid(double val, double center, double width)
{
return Math.Tanh(Math.E * -(val - center) / width);
}
protected override double StrainValueOf(DifficultyHitObject current) protected override double StrainValueOf(DifficultyHitObject current)
{ {
@ -103,9 +109,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
} }
TaikoDifficultyHitObject hitObject = (TaikoDifficultyHitObject)current; TaikoDifficultyHitObject hitObject = (TaikoDifficultyHitObject)current;
double objectStrain = getNextSingleKeyStamina(hitObject).StrainValueAt(hitObject); return getNextSingleKeyStamina(hitObject).StrainValueOf(hitObject);
return objectStrain;
} }
} }
} }