mirror of
https://github.com/ppy/osu.git
synced 2026-05-15 22:23:43 +08:00
8b542e5442
This change pulls back a significant degree of overspecialisation and rigidity in the class structure of `HitWindows` to make subsequent changes to hit windows, whose purpose is to improve replay playback accuracy, possible to do cleanly. Notably: - `HitWindows` is full abstract now. In a few use cases, and as a reference for ruleset implementors, `DefaultHitWindows` is provided as a separate class instead. This fixes the weirdness wherein `HitWindows` always declared 6 fields for result types but some of them would never be set to a non-zero value or read. - `HitWindow.GetRanges()` is deleted because it is overspecialised and prevents being able to adjust hitwindows by ±0.5ms cleanly which will be required later. The fallout of this is that the assertion that used `GetRanges()` in the `HitWindows` ctor must use something else now, and the closest thing to it was `GetAllAvailableWindows()`, which didn't return the miss window - so I made it return the miss window and fixed the one consumer that didn't want it (bar hit error meter) to skip it. - Diff also contains some clean-up around `DifficultyRange` to unify handling of it.
133 lines
6.4 KiB
C#
133 lines
6.4 KiB
C#
// 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.
|
|
|
|
using System;
|
|
|
|
namespace osu.Game.Beatmaps
|
|
{
|
|
/// <summary>
|
|
/// A representation of all top-level difficulty settings for a beatmap.
|
|
/// </summary>
|
|
public interface IBeatmapDifficultyInfo
|
|
{
|
|
/// <summary>
|
|
/// The default value used for all difficulty settings except <see cref="SliderMultiplier"/> and <see cref="SliderTickRate"/>.
|
|
/// </summary>
|
|
const float DEFAULT_DIFFICULTY = 5;
|
|
|
|
/// <summary>
|
|
/// The drain rate of the associated beatmap.
|
|
/// </summary>
|
|
float DrainRate { get; }
|
|
|
|
/// <summary>
|
|
/// The circle size of the associated beatmap.
|
|
/// </summary>
|
|
float CircleSize { get; }
|
|
|
|
/// <summary>
|
|
/// The overall difficulty of the associated beatmap.
|
|
/// </summary>
|
|
float OverallDifficulty { get; }
|
|
|
|
/// <summary>
|
|
/// The approach rate of the associated beatmap.
|
|
/// </summary>
|
|
float ApproachRate { get; }
|
|
|
|
/// <summary>
|
|
/// The base slider velocity of the associated beatmap.
|
|
/// This was known as "SliderMultiplier" in the .osu format and stable editor.
|
|
/// </summary>
|
|
double SliderMultiplier { get; }
|
|
|
|
/// <summary>
|
|
/// The slider tick rate of the associated beatmap.
|
|
/// </summary>
|
|
double SliderTickRate { get; }
|
|
|
|
/// <summary>
|
|
/// Maps a difficulty value [0, 10] to a two-piece linear range of values.
|
|
/// </summary>
|
|
/// <param name="difficulty">The difficulty value to be mapped.</param>
|
|
/// <param name="min">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
|
|
/// <param name="mid">Midpoint of the resulting range which will be achieved by a difficulty value of 5.</param>
|
|
/// <param name="max">Maximum of the resulting range which will be achieved by a difficulty value of 10.</param>
|
|
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
|
|
static double DifficultyRange(double difficulty, double min, double mid, double max)
|
|
{
|
|
if (difficulty > 5)
|
|
return mid + (max - mid) * DifficultyRange(difficulty);
|
|
if (difficulty < 5)
|
|
return mid + (mid - min) * DifficultyRange(difficulty);
|
|
|
|
return mid;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Maps a difficulty value [0, 10] to a linear range of [-1, 1].
|
|
/// </summary>
|
|
/// <param name="difficulty">The difficulty value to be mapped.</param>
|
|
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
|
|
static double DifficultyRange(double difficulty) => (difficulty - 5) / 5;
|
|
|
|
/// <summary>
|
|
/// Maps a difficulty value [0, 10] to a two-piece linear range of values.
|
|
/// </summary>
|
|
/// <param name="difficulty">The difficulty value to be mapped.</param>
|
|
/// <param name="range">The values that define the two linear ranges.
|
|
/// <list type="table">
|
|
/// <item>
|
|
/// <term>od0</term>
|
|
/// <description>Minimum of the resulting range which will be achieved by a difficulty value of 0.</description>
|
|
/// </item>
|
|
/// <item>
|
|
/// <term>od5</term>
|
|
/// <description>Midpoint of the resulting range which will be achieved by a difficulty value of 5.</description>
|
|
/// </item>
|
|
/// <item>
|
|
/// <term>od10</term>
|
|
/// <description>Maximum of the resulting range which will be achieved by a difficulty value of 10.</description>
|
|
/// </item>
|
|
/// </list>
|
|
/// </param>
|
|
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
|
|
static double DifficultyRange(double difficulty, DifficultyRange range)
|
|
=> DifficultyRange(difficulty, range.Min, range.Mid, range.Max);
|
|
|
|
/// <summary>
|
|
/// Inverse function to <see cref="DifficultyRange(double,double,double,double)"/>.
|
|
/// Maps a value returned by the function above back to the difficulty that produced it.
|
|
/// </summary>
|
|
/// <param name="difficultyValue">The difficulty-dependent value to be unmapped.</param>
|
|
/// <param name="diff0">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
|
|
/// <param name="diff5">Midpoint of the resulting range which will be achieved by a difficulty value of 5.</param>
|
|
/// <param name="diff10">Maximum of the resulting range which will be achieved by a difficulty value of 10.</param>
|
|
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
|
|
static double InverseDifficultyRange(double difficultyValue, double diff0, double diff5, double diff10)
|
|
{
|
|
return Math.Sign(difficultyValue - diff5) == Math.Sign(diff10 - diff5)
|
|
? (difficultyValue - diff5) / (diff10 - diff5) * 5 + 5
|
|
: (difficultyValue - diff5) / (diff5 - diff0) * 5 + 5;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Inverse function to <see cref="DifficultyRange(double,osu.Game.Beatmaps.DifficultyRange)"/>.
|
|
/// Maps a value returned by the function above back to the difficulty that produced it.
|
|
/// </summary>
|
|
/// <param name="difficultyValue">The difficulty-dependent value to be unmapped.</param>
|
|
/// <param name="range">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
|
|
/// <returns>Value to which the difficulty value maps in the specified range.</returns>
|
|
static double InverseDifficultyRange(double difficultyValue, DifficultyRange range)
|
|
=> InverseDifficultyRange(difficultyValue, range.Min, range.Mid, range.Max);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Represents a piecewise-linear difficulty curve for a given gameplay quantity.
|
|
/// </summary>
|
|
/// <param name="Min">Minimum of the resulting range which will be achieved by a difficulty value of 0.</param>
|
|
/// <param name="Mid">Midpoint of the resulting range which will be achieved by a difficulty value of 5.</param>
|
|
/// <param name="Max">Maximum of the resulting range which will be achieved by a difficulty value of 10.</param>
|
|
public record struct DifficultyRange(double Min, double Mid, double Max);
|
|
}
|