1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-11 10:17:18 +08:00
osu-lazer/osu.Game/Rulesets/Difficulty/Utils/DifficultyCalculationUtils.cs
StanR f722f94f26
Simplify osu! high-bpm acute angle jumps bonus (#30902)
* Simplify osu! high-bpm acute angle jumps bonus

* Add aim wiggle bonus

* Add hitwindow-based aim velocity decrease

* Revert "Add hitwindow-based aim velocity decrease"

This reverts commit bcebe9662cfcb7a72805e48712525ef54ec9820e.

* Move wiggle multiplier to a const, slightly decrease acute bonus multiplier

* Make sure the previous object in the wiggle bonus is also part of the wiggle

* Scale the wiggle bonus multiplayer down

* Increase the acute angle jump bonus multiplier

* Make wiggle bonus only apply on >150 bpm streams, make repetitive angle penalty

* Reduce wiggle bonus multiplier to not break velocity>difficulty relation

* Adjust wiggle falloff function to fix stability issues

* Adjust wiggle consts

* Update tests
2024-12-20 23:32:51 +00:00

84 lines
4.0 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;
using System.Linq;
namespace osu.Game.Rulesets.Difficulty.Utils
{
public static class DifficultyCalculationUtils
{
/// <summary>
/// Converts BPM value into milliseconds
/// </summary>
/// <param name="bpm">Beats per minute</param>
/// <param name="delimiter">Which rhythm delimiter to use, default is 1/4</param>
/// <returns>BPM conveted to milliseconds</returns>
public static double BPMToMilliseconds(double bpm, int delimiter = 4)
{
return 60000.0 / delimiter / bpm;
}
/// <summary>
/// Converts milliseconds value into a BPM value
/// </summary>
/// <param name="ms">Milliseconds</param>
/// <param name="delimiter">Which rhythm delimiter to use, default is 1/4</param>
/// <returns>Milliseconds conveted to beats per minute</returns>
public static double MillisecondsToBPM(double ms, int delimiter = 4)
{
return 60000.0 / (ms * delimiter);
}
/// <summary>
/// Calculates a S-shaped logistic function (https://en.wikipedia.org/wiki/Logistic_function)
/// </summary>
/// <param name="x">Value to calculate the function for</param>
/// <param name="maxValue">Maximum value returnable by the function</param>
/// <param name="multiplier">Growth rate of the function</param>
/// <param name="midpointOffset">How much the function midpoint is offset from zero <paramref name="x"/></param>
/// <returns>The output of logistic function of <paramref name="x"/></returns>
public static double Logistic(double x, double midpointOffset, double multiplier, double maxValue = 1) => maxValue / (1 + Math.Exp(multiplier * (midpointOffset - x)));
/// <summary>
/// Calculates a S-shaped logistic function (https://en.wikipedia.org/wiki/Logistic_function)
/// </summary>
/// <param name="maxValue">Maximum value returnable by the function</param>
/// <param name="exponent">Exponent</param>
/// <returns>The output of logistic function</returns>
public static double Logistic(double exponent, double maxValue = 1) => maxValue / (1 + Math.Exp(exponent));
/// <summary>
/// Returns the <i>p</i>-norm of an <i>n</i>-dimensional vector (https://en.wikipedia.org/wiki/Norm_(mathematics))
/// </summary>
/// <param name="p">The value of <i>p</i> to calculate the norm for.</param>
/// <param name="values">The coefficients of the vector.</param>
/// <returns>The <i>p</i>-norm of the vector.</returns>
public static double Norm(double p, params double[] values) => Math.Pow(values.Sum(x => Math.Pow(x, p)), 1 / p);
/// <summary>
/// Smootherstep function (https://en.wikipedia.org/wiki/Smoothstep#Variations)
/// </summary>
/// <param name="x">Value to calculate the function for</param>
/// <param name="start">Value at which function returns 0</param>
/// <param name="end">Value at which function returns 1</param>
public static double Smootherstep(double x, double start, double end)
{
x = Math.Clamp((x - start) / (end - start), 0.0, 1.0);
return x * x * x * (x * (6.0 * x - 15.0) + 10.0);
}
/// <summary>
/// Reverse linear interpolation function (https://en.wikipedia.org/wiki/Linear_interpolation)
/// </summary>
/// <param name="x">Value to calculate the function for</param>
/// <param name="start">Value at which function returns 0</param>
/// <param name="end">Value at which function returns 1</param>
public static double ReverseLerp(double x, double start, double end)
{
return Math.Clamp((x - start) / (end - start), 0.0, 1.0);
}
}
}