mirror of
https://github.com/ppy/osu.git
synced 2026-05-27 20:48:44 +08:00
1d3e682c5e
- Part of https://github.com/ppy/osu/issues/37818 - Continued from https://github.com/ppy/osu/pull/37355#issuecomment-4449248107 ## Overview This PR introduces an alternative API, `ScoreMultiplierCalculator`, to be used going forward for calculating mod multipliers. The reason for introducing this new API is that it has been requested that: - For any two given mods, it should be possible to have the combined mod multipliers of them in combination be *different* than the product of the individual mods' multipliers in isolation, i.e. $mult( \\{ A, B \\} ) \neq mult( \\{ A \\} ) \cdot mult( \\{ B \\} )$. - For an individual mod, it should be possible to have the mod multipliers depend on a quantity that is *not* the presence of another mod or the direct value of a setting on the mod. This capability is being demonstrated in this PR via the `osu.Game.Tests.Rulesets.Scoring.ScoreMultiplierCalculatorTest` test fixture. ## Parity with `Mod.ScoreMultiplier` This PR contains a `ScoreMultiplierCalculator` implementation for each of the built-in four rulesets. The abstract `osu.Game.Tests.Rulesets.RulesetScoreMultiplierTest` and its four derived ruleset-specific test fixtures were written to ensure that the new implementations do not diverge from the current state of affairs. `Mod.ScoreMultiplier` is not removed in this diff to keep size low. It will be removed as a follow-up. ## Performance This PR contains a benchmark comparing the current implementation via `Mod.ScoreMultiplier` and the new `ScoreMultiplierCalculator` API. Results below. <details> | Method | Times | Mods | Mean | Error | StdDev | Gen0 | Allocated | |---------------------- |------ |--------------------- |--------------:|------------:|------------:|--------:|----------:| | ViaModScoreMultiplier | 1 | mods (...)tings [27] | 121.171 ns | 1.5284 ns | 1.4297 ns | 0.0782 | 656 B | | ViaCalculator | 1 | mods (...)tings [27] | 248.509 ns | 1.9313 ns | 1.6127 ns | 0.1364 | 1144 B | | ViaModScoreMultiplier | 1 | multiple mods | 128.357 ns | 0.4282 ns | 0.4006 ns | 0.0782 | 656 B | | ViaCalculator | 1 | multiple mods | 252.953 ns | 1.2860 ns | 1.2029 ns | 0.1364 | 1144 B | | ViaModScoreMultiplier | 1 | no mods | 3.007 ns | 0.0345 ns | 0.0288 ns | - | - | | ViaCalculator | 1 | no mods | 14.802 ns | 0.0616 ns | 0.0576 ns | 0.0134 | 112 B | | ViaModScoreMultiplier | 1 | single mod | 40.271 ns | 0.1238 ns | 0.1098 ns | 0.0258 | 216 B | | ViaCalculator | 1 | single mod | 113.033 ns | 0.3140 ns | 0.2937 ns | 0.0842 | 704 B | | ViaModScoreMultiplier | 1 | single mod 2 | 3.653 ns | 0.0384 ns | 0.0359 ns | 0.0038 | 32 B | | ViaCalculator | 1 | single mod 2 | 78.172 ns | 0.0680 ns | 0.0603 ns | 0.0621 | 520 B | | ViaModScoreMultiplier | 10 | mods (...)tings [27] | 1,169.609 ns | 4.3058 ns | 4.0276 ns | 0.7839 | 6560 B | | ViaCalculator | 10 | mods (...)tings [27] | 2,575.264 ns | 21.2705 ns | 19.8964 ns | 1.3657 | 11440 B | | ViaModScoreMultiplier | 10 | multiple mods | 1,171.775 ns | 6.2332 ns | 5.2050 ns | 0.7839 | 6560 B | | ViaCalculator | 10 | multiple mods | 2,579.593 ns | 22.1010 ns | 20.6733 ns | 1.3657 | 11440 B | | ViaModScoreMultiplier | 10 | no mods | 35.943 ns | 0.1665 ns | 0.1476 ns | - | - | | ViaCalculator | 10 | no mods | 154.980 ns | 0.2381 ns | 0.1988 ns | 0.1338 | 1120 B | | ViaModScoreMultiplier | 10 | single mod | 404.185 ns | 1.3190 ns | 1.2338 ns | 0.2580 | 2160 B | | ViaCalculator | 10 | single mod | 1,167.279 ns | 6.1641 ns | 5.7659 ns | 0.8411 | 7040 B | | ViaModScoreMultiplier | 10 | single mod 2 | 42.128 ns | 0.2878 ns | 0.2692 ns | 0.0382 | 320 B | | ViaCalculator | 10 | single mod 2 | 775.435 ns | 2.3318 ns | 2.1811 ns | 0.6208 | 5200 B | | ViaModScoreMultiplier | 100 | mods (...)tings [27] | 11,623.346 ns | 51.7174 ns | 43.1863 ns | 7.8430 | 65600 B | | ViaCalculator | 100 | mods (...)tings [27] | 25,252.987 ns | 44.4352 ns | 39.3906 ns | 13.6719 | 114400 B | | ViaModScoreMultiplier | 100 | multiple mods | 11,928.536 ns | 35.2079 ns | 32.9334 ns | 7.8430 | 65600 B | | ViaCalculator | 100 | multiple mods | 25,399.378 ns | 152.4597 ns | 127.3108 ns | 13.6719 | 114400 B | | ViaModScoreMultiplier | 100 | no mods | 328.158 ns | 0.5827 ns | 0.5165 ns | - | - | | ViaCalculator | 100 | no mods | 1,517.485 ns | 10.2304 ns | 9.5695 ns | 1.3390 | 11200 B | | ViaModScoreMultiplier | 100 | single mod | 3,986.251 ns | 24.2523 ns | 21.4991 ns | 2.5787 | 21600 B | | ViaCalculator | 100 | single mod | 11,479.514 ns | 23.3738 ns | 20.7203 ns | 8.4076 | 70400 B | | ViaModScoreMultiplier | 100 | single mod 2 | 385.679 ns | 3.5190 ns | 3.2917 ns | 0.3824 | 3200 B | | ViaCalculator | 100 | single mod 2 | 7,658.646 ns | 21.8274 ns | 19.3494 ns | 6.2103 | 52000 B | </details> While the calculator is obviously slower, in my view it is not egregiously so. The main overheads both time- and memory-wise are collection allocations for the dictionary and the set which I consider to be directly caused by the requested additional complexity and as such I don't really consider them eliminable. I have tried and applied some micro-optimisations (e2469ce338,cb33abec17), albeit with negligible effect. I have also tried to key the mods by `Acronym` instead of by `Type` and the difference was basically nil. <details> <summary>patch for keying by acronym</summary> ```diff diff --git a/osu.Game/Rulesets/Scoring/ScoreMultiplierCalculator.cs b/osu.Game/Rulesets/Scoring/ScoreMultiplierCalculator.cs index 772f9d178b..7f5907cbda 100644 --- a/osu.Game/Rulesets/Scoring/ScoreMultiplierCalculator.cs +++ b/osu.Game/Rulesets/Scoring/ScoreMultiplierCalculator.cs @@ -13,26 +13,26 @@ namespace osu.Game.Rulesets.Scoring /// </summary> public class ScoreMultiplierCalculator { - private static readonly List<(Type[] mods, Func<Mod[], double> multiplier)> combination_multipliers = []; - private static readonly Dictionary<Type, Func<Mod, ScoreMultiplierCalculator, double>> single_multipliers_with_context = []; - private static readonly Dictionary<Type, Func<Mod, double>> single_multipliers = []; + private static readonly List<(string[] modAcronyms, Func<Mod[], double> multiplier)> combination_multipliers = []; + private static readonly Dictionary<string, Func<Mod, ScoreMultiplierCalculator, double>> single_multipliers_with_context = []; + private static readonly Dictionary<string, Func<Mod, double>> single_multipliers = []; /// <summary> /// Defines a flat, setting-independent score multiplier for the given <typeparamref name="TMod"/>. /// </summary> public static void Single<TMod>(double hasMultiplier) - where TMod : Mod + where TMod : Mod, new() { - single_multipliers[typeof(TMod)] = _ => hasMultiplier; + single_multipliers[new TMod().Acronym] = _ => hasMultiplier; } /// <summary> /// Defines a setting-dependent score multiplier for the given <typeparamref name="TMod"/>. /// </summary> public static void Single<TMod>(Func<TMod, double> hasMultiplier) - where TMod : Mod + where TMod : Mod, new() { - single_multipliers[typeof(TMod)] = mod => hasMultiplier.Invoke((TMod)mod); + single_multipliers[new TMod().Acronym] = mod => hasMultiplier.Invoke((TMod)mod); } /// <summary> @@ -40,20 +40,20 @@ public static void Single<TMod>(Func<TMod, double> hasMultiplier) /// The multiplier calculation is given additional context to calculate the multiplier via the <typeparamref name="TContext"/> type instance. /// </summary> public static void Single<TMod, TContext>(Func<TMod, TContext, double> hasMultiplier) - where TMod : Mod + where TMod : Mod, new() where TContext : ScoreMultiplierCalculator { - single_multipliers_with_context[typeof(TMod)] = (mod, context) => hasMultiplier.Invoke((TMod)mod, (TContext)context); + single_multipliers_with_context[new TMod().Acronym] = (mod, context) => hasMultiplier.Invoke((TMod)mod, (TContext)context); } /// <summary> /// Defines a score multiplier specific to when both <typeparamref name="T1"/> and <typeparamref name="T2"/> mods are present. /// </summary> public static void Combination<T1, T2>(Func<T1, T2, double> hasMultiplier) - where T1 : Mod - where T2 : Mod + where T1 : Mod, new() + where T2 : Mod, new() { - combination_multipliers.Add(([typeof(T1), typeof(T2)], mods => hasMultiplier((T1)mods[0], (T2)mods[1]))); + combination_multipliers.Add(([new T1().Acronym, new T2().Acronym], mods => hasMultiplier((T1)mods[0], (T2)mods[1]))); } /// <summary> @@ -61,7 +61,7 @@ public static void Combination<T1, T2>(Func<T1, T2, double> hasMultiplier) /// </summary> public double CalculateFor(IEnumerable<Mod> mods) { - var allModsByType = mods.ToDictionary(m => m.GetType()); + var allModsByType = mods.ToDictionary(m => m.Acronym); if (allModsByType.Count == 0) return 1; @@ -83,7 +83,7 @@ public double CalculateFor(IEnumerable<Mod> mods) } } - foreach (var modType in remainingModTypes) + foreach (string modType in remainingModTypes) { if (single_multipliers.TryGetValue(modType, out var multiplier)) result *= multiplier(allModsByType[modType]); ``` </details> One particular parallel thread that may warrant follow-up is that `Mod.UsesDefaultConfiguration` is disproportionately expensive due to calling into regexes via Humanizer internals. <img width="1517" height="517" alt="Screenshot_2026-05-19_at_10 58 30" src="https://github.com/user-attachments/assets/68309a8c-74e7-4f96-8ef9-62868eeca337" />
482 lines
22 KiB
C#
482 lines
22 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.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using osu.Framework.Extensions;
|
|
using osu.Framework.Extensions.EnumExtensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Sprites;
|
|
using osu.Framework.Input.Bindings;
|
|
using osu.Framework.IO.Stores;
|
|
using osu.Framework.Localisation;
|
|
using osu.Framework.Utils;
|
|
using osu.Game.Beatmaps;
|
|
using osu.Game.Beatmaps.Legacy;
|
|
using osu.Game.Configuration;
|
|
using osu.Game.Extensions;
|
|
using osu.Game.Localisation;
|
|
using osu.Game.Overlays.Settings;
|
|
using osu.Game.Rulesets.Configuration;
|
|
using osu.Game.Rulesets.Difficulty;
|
|
using osu.Game.Rulesets.Edit;
|
|
using osu.Game.Rulesets.Filter;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Rulesets.Replays.Types;
|
|
using osu.Game.Rulesets.Scoring;
|
|
using osu.Game.Rulesets.UI;
|
|
using osu.Game.Scoring;
|
|
using osu.Game.Screens.Edit.Setup;
|
|
using osu.Game.Screens.Ranking.Statistics;
|
|
using osu.Game.Skinning;
|
|
using osu.Game.Users;
|
|
using osuTK;
|
|
|
|
namespace osu.Game.Rulesets
|
|
{
|
|
public abstract class Ruleset
|
|
{
|
|
public RulesetInfo RulesetInfo { get; }
|
|
|
|
private static readonly ConcurrentDictionary<string, IMod[]> mod_reference_cache = new ConcurrentDictionary<string, IMod[]>();
|
|
|
|
/// <summary>
|
|
/// Version history:
|
|
/// 2022.205.0 FramedReplayInputHandler.CollectPendingInputs renamed to FramedReplayHandler.CollectReplayInputs.
|
|
/// 2022.822.0 All strings return values have been converted to LocalisableString to allow for localisation support.
|
|
/// </summary>
|
|
public const string CURRENT_RULESET_API_VERSION = "2022.822.0";
|
|
|
|
/// <summary>
|
|
/// Define the ruleset API version supported by this ruleset.
|
|
/// Ruleset implementations should be updated to support the latest version to ensure they can still be loaded.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Generally, all ruleset implementations should point this directly to <see cref="CURRENT_RULESET_API_VERSION"/>.
|
|
/// This will ensure that each time you compile a new release, it will pull in the most recent version.
|
|
/// See https://github.com/ppy/osu/wiki/Breaking-Changes for full details on required ongoing changes.
|
|
/// </remarks>
|
|
public virtual string RulesetAPIVersionSupported => string.Empty;
|
|
|
|
/// <summary>
|
|
/// A queryable source containing all available mods.
|
|
/// Call <see cref="IMod.CreateInstance"/> for consumption purposes.
|
|
/// </summary>
|
|
public IEnumerable<IMod> AllMods
|
|
{
|
|
get
|
|
{
|
|
// Is the case for many test usages.
|
|
if (string.IsNullOrEmpty(ShortName))
|
|
return CreateAllMods();
|
|
|
|
if (!mod_reference_cache.TryGetValue(ShortName, out var mods))
|
|
mod_reference_cache[ShortName] = mods = CreateAllMods().Cast<IMod>().ToArray();
|
|
|
|
return mods;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns fresh instances of all mods.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// This comes with considerable allocation overhead. If only accessing for reference purposes (ie. not changing bindables / settings)
|
|
/// use <see cref="AllMods"/> instead.
|
|
/// </remarks>
|
|
public IEnumerable<Mod> CreateAllMods() => Enum.GetValues<ModType>()
|
|
// Confine all mods of each mod type into a single IEnumerable<Mod>
|
|
.SelectMany(GetModsFor)
|
|
// Filter out all null mods
|
|
// This is to handle old rulesets which were doing mods bad. Can be removed at some point we are sure nulls will not appear here.
|
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
|
|
.Where(mod => mod != null)
|
|
// Resolve MultiMods as their .Mods property
|
|
.SelectMany(mod => (mod as MultiMod)?.Mods ?? new[] { mod });
|
|
|
|
/// <summary>
|
|
/// Returns a fresh instance of the mod matching the specified acronym.
|
|
/// </summary>
|
|
/// <param name="acronym">The acronym to query for .</param>
|
|
public Mod? CreateModFromAcronym(string acronym)
|
|
{
|
|
return AllMods.FirstOrDefault(m => string.Equals(m.Acronym, acronym, StringComparison.OrdinalIgnoreCase))?.CreateInstance();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a fresh instance of the mod matching the specified type.
|
|
/// </summary>
|
|
public T? CreateMod<T>()
|
|
where T : Mod
|
|
{
|
|
return AllMods.FirstOrDefault(m => m is T)?.CreateInstance() as T;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates an enumerable with mods that are supported by the ruleset for the supplied <paramref name="type"/>.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// If there are no applicable mods from the given <paramref name="type"/> in this ruleset,
|
|
/// then the proper behaviour is to return an empty enumerable.
|
|
/// <see langword="null"/> mods should not be present in the returned enumerable.
|
|
/// </remarks>
|
|
public abstract IEnumerable<Mod> GetModsFor(ModType type);
|
|
|
|
/// <summary>
|
|
/// Converts mods from legacy enum values. Do not override if you're not a legacy ruleset.
|
|
/// </summary>
|
|
/// <param name="mods">The legacy enum which will be converted.</param>
|
|
/// <returns>An enumerable of constructed <see cref="Mod"/>s.</returns>
|
|
public virtual IEnumerable<Mod> ConvertFromLegacyMods(LegacyMods mods) => Array.Empty<Mod>();
|
|
|
|
/// <summary>
|
|
/// Converts mods to legacy enum values. Do not override if you're not a legacy ruleset.
|
|
/// </summary>
|
|
/// <param name="mods">The mods which will be converted.</param>
|
|
/// <returns>A single bitwise enumerable value representing (to the best of our ability) the mods.</returns>
|
|
public virtual LegacyMods ConvertToLegacyMods(Mod[] mods)
|
|
{
|
|
var value = LegacyMods.None;
|
|
|
|
foreach (var mod in mods)
|
|
{
|
|
switch (mod)
|
|
{
|
|
case ModNoFail:
|
|
value |= LegacyMods.NoFail;
|
|
break;
|
|
|
|
case ModEasy:
|
|
value |= LegacyMods.Easy;
|
|
break;
|
|
|
|
case ModHidden:
|
|
value |= LegacyMods.Hidden;
|
|
break;
|
|
|
|
case ModHardRock:
|
|
value |= LegacyMods.HardRock;
|
|
break;
|
|
|
|
case ModPerfect:
|
|
value |= LegacyMods.Perfect | LegacyMods.SuddenDeath;
|
|
break;
|
|
|
|
case ModSuddenDeath:
|
|
value |= LegacyMods.SuddenDeath;
|
|
break;
|
|
|
|
case ModNightcore:
|
|
value |= LegacyMods.Nightcore | LegacyMods.DoubleTime;
|
|
break;
|
|
|
|
case ModDoubleTime:
|
|
value |= LegacyMods.DoubleTime;
|
|
break;
|
|
|
|
case ModRelax:
|
|
value |= LegacyMods.Relax;
|
|
break;
|
|
|
|
case ModHalfTime:
|
|
value |= LegacyMods.HalfTime;
|
|
break;
|
|
|
|
case ModFlashlight:
|
|
value |= LegacyMods.Flashlight;
|
|
break;
|
|
|
|
case ModCinema:
|
|
value |= LegacyMods.Cinema | LegacyMods.Autoplay;
|
|
break;
|
|
|
|
case ModAutoplay:
|
|
value |= LegacyMods.Autoplay;
|
|
break;
|
|
|
|
case ModScoreV2:
|
|
value |= LegacyMods.ScoreV2;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
public ModAutoplay? GetAutoplayMod() => CreateMod<ModAutoplay>();
|
|
|
|
public ModTouchDevice? GetTouchDeviceMod() => CreateMod<ModTouchDevice>();
|
|
|
|
/// <summary>
|
|
/// Creates a <see cref="ScoreMultiplierCalculator"/> relevant to this ruleset.
|
|
/// </summary>
|
|
public virtual ScoreMultiplierCalculator CreateScoreMultiplierCalculator() => new ScoreMultiplierCalculator();
|
|
|
|
/// <summary>
|
|
/// Create a transformer which adds lookups specific to a ruleset to skin sources.
|
|
/// </summary>
|
|
/// <param name="skin">The source skin.</param>
|
|
/// <param name="beatmap">The current beatmap.</param>
|
|
/// <returns>A skin with a transformer applied, or null if no transformation is provided by this ruleset.</returns>
|
|
public virtual ISkin? CreateSkinTransformer(ISkin skin, IBeatmap beatmap) => null;
|
|
|
|
protected Ruleset()
|
|
{
|
|
RulesetInfo = new RulesetInfo
|
|
{
|
|
Name = Description,
|
|
ShortName = ShortName,
|
|
OnlineID = (this as ILegacyRuleset)?.LegacyID ?? -1,
|
|
InstantiationInfo = GetType().GetInvariantInstantiationInfo(),
|
|
Available = true,
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Attempt to create a hit renderer for a beatmap
|
|
/// </summary>
|
|
/// <param name="beatmap">The beatmap to create the hit renderer for.</param>
|
|
/// <param name="mods">The <see cref="Mod"/>s to apply.</param>
|
|
/// <exception cref="BeatmapInvalidForRulesetException">Unable to successfully load the beatmap to be usable with this ruleset.</exception>
|
|
public abstract DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod>? mods = null);
|
|
|
|
/// <summary>
|
|
/// Creates a <see cref="ScoreProcessor"/> for this <see cref="Ruleset"/>.
|
|
/// </summary>
|
|
/// <returns>The score processor.</returns>
|
|
public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor(this);
|
|
|
|
/// <summary>
|
|
/// Creates a <see cref="HealthProcessor"/> for this <see cref="Ruleset"/>.
|
|
/// </summary>
|
|
/// <returns>The health processor.</returns>
|
|
public virtual HealthProcessor CreateHealthProcessor(double drainStartTime) => new DrainingHealthProcessor(drainStartTime);
|
|
|
|
/// <summary>
|
|
/// Creates a <see cref="IBeatmapConverter"/> to convert a <see cref="IBeatmap"/> to one that is applicable for this <see cref="Ruleset"/>.
|
|
/// </summary>
|
|
/// <param name="beatmap">The <see cref="IBeatmap"/> to be converted.</param>
|
|
/// <returns>The <see cref="IBeatmapConverter"/>.</returns>
|
|
public abstract IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap);
|
|
|
|
/// <summary>
|
|
/// Optionally creates a <see cref="IBeatmapProcessor"/> to alter a <see cref="IBeatmap"/> after it has been converted.
|
|
/// </summary>
|
|
/// <param name="beatmap">The <see cref="IBeatmap"/> to be processed.</param>
|
|
/// <returns>The <see cref="IBeatmapProcessor"/>.</returns>
|
|
public virtual IBeatmapProcessor? CreateBeatmapProcessor(IBeatmap beatmap) => null;
|
|
|
|
public abstract DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap);
|
|
|
|
/// <summary>
|
|
/// Optionally creates a <see cref="PerformanceCalculator"/> to generate performance data from the provided score.
|
|
/// </summary>
|
|
/// <returns>A performance calculator instance for the provided score.</returns>
|
|
public virtual PerformanceCalculator? CreatePerformanceCalculator() => null;
|
|
|
|
public virtual HitObjectComposer? CreateHitObjectComposer() => null;
|
|
|
|
public virtual IBeatmapVerifier? CreateBeatmapVerifier() => null;
|
|
|
|
public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.Solid.QuestionCircle };
|
|
|
|
public virtual IResourceStore<byte[]> CreateResourceStore() => new NamespacedResourceStore<byte[]>(new DllResourceStore(GetType().Assembly), @"Resources");
|
|
|
|
public abstract string Description { get; }
|
|
|
|
public virtual RulesetSettingsSubsection? CreateSettings() => null;
|
|
|
|
/// <summary>
|
|
/// Creates the <see cref="IRulesetConfigManager"/> for this <see cref="Ruleset"/>.
|
|
/// </summary>
|
|
/// <param name="settings">The <see cref="SettingsStore"/> to store the settings.</param>
|
|
public virtual IRulesetConfigManager? CreateConfig(SettingsStore? settings) => null;
|
|
|
|
/// <summary>
|
|
/// A unique short name to reference this ruleset in online requests.
|
|
/// </summary>
|
|
public abstract string ShortName { get; }
|
|
|
|
/// <summary>
|
|
/// The playing verb to be shown in the <see cref="UserActivity.InGame"/> activities.
|
|
/// </summary>
|
|
public virtual string PlayingVerb => "Playing";
|
|
|
|
/// <summary>
|
|
/// A list of available variant ids.
|
|
/// </summary>
|
|
public virtual IEnumerable<int> AvailableVariants => new[] { 0 };
|
|
|
|
/// <summary>
|
|
/// Get a list of default keys for the specified variant.
|
|
/// </summary>
|
|
/// <param name="variant">A variant.</param>
|
|
/// <returns>A list of valid <see cref="KeyBinding"/>s.</returns>
|
|
public virtual IEnumerable<KeyBinding> GetDefaultKeyBindings(int variant = 0) => Array.Empty<KeyBinding>();
|
|
|
|
/// <summary>
|
|
/// Text that describes what variants in a ruleset are.
|
|
/// Override this to provide better copy than the generic "Variant" text which may not tell users much.
|
|
/// </summary>
|
|
public virtual LocalisableString VariantDescription => "Variant";
|
|
|
|
/// <summary>
|
|
/// Gets the name for a key binding variant. This is used for display in the settings overlay.
|
|
/// </summary>
|
|
/// <param name="variant">The variant.</param>
|
|
/// <returns>A descriptive name of the variant.</returns>
|
|
public virtual LocalisableString GetVariantName(int variant) => string.Empty;
|
|
|
|
/// <summary>
|
|
/// Returns the ID of the variant that is applicable for the given <paramref name="beatmapInfo"/>, given the current active <paramref name="mods"/>.
|
|
/// </summary>
|
|
public virtual int GetVariantForBeatmap(IBeatmapInfo beatmapInfo, IReadOnlyList<Mod>? mods = null) => 0;
|
|
|
|
/// <summary>
|
|
/// For rulesets which support legacy (osu-stable) replay conversion, this method will create an empty replay frame
|
|
/// for conversion use.
|
|
/// </summary>
|
|
/// <returns>An empty frame for the current ruleset, or null if unsupported.</returns>
|
|
public virtual IConvertibleReplayFrame? CreateConvertibleReplayFrame() => null;
|
|
|
|
/// <summary>
|
|
/// Creates the statistics for a <see cref="ScoreInfo"/> to be displayed in the results screen.
|
|
/// </summary>
|
|
/// <param name="score">The <see cref="ScoreInfo"/> to create the statistics for. The score is guaranteed to have <see cref="ScoreInfo.HitEvents"/> populated.</param>
|
|
/// <param name="playableBeatmap">The <see cref="IBeatmap"/>, converted for this <see cref="Ruleset"/> with all relevant <see cref="Mod"/>s applied.</param>
|
|
/// <returns>The <see cref="StatisticItem"/>s to display.</returns>
|
|
public virtual StatisticItem[] CreateStatisticsForScore(ScoreInfo score, IBeatmap playableBeatmap) => Array.Empty<StatisticItem>();
|
|
|
|
/// <summary>
|
|
/// Get all <see cref="HitResult"/>s for this ruleset which are important enough to displayed to the end user.
|
|
/// Used for results display purposes, where it can't be determined if zero-count means the user has not achieved any or the type is not used by this ruleset.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// <see cref="HitResult.Miss"/> is implicitly included. Special types like <see cref="HitResult.IgnoreHit"/> are not returned by this method.
|
|
/// Values are returned as ordered by <see cref="OrderAttribute"/>.
|
|
/// </remarks>
|
|
/// <returns>
|
|
/// All relevant <see cref="HitResult"/>s along with a display-friendly name.
|
|
/// </returns>
|
|
public IEnumerable<(HitResult result, LocalisableString displayName)> GetHitResultsForDisplay()
|
|
{
|
|
var validResults = GetValidHitResults();
|
|
|
|
// enumerate over ordered list to guarantee return order is stable.
|
|
foreach (var result in EnumExtensions.GetValuesInOrder<HitResult>())
|
|
{
|
|
switch (result)
|
|
{
|
|
// hard blocked types, should never be displayed even if the ruleset tells us to.
|
|
case HitResult.None:
|
|
case HitResult.IgnoreHit:
|
|
case HitResult.IgnoreMiss:
|
|
case HitResult.ComboBreak:
|
|
// display is handled as a completion count with corresponding "hit" type.
|
|
case HitResult.LargeTickMiss:
|
|
case HitResult.SmallTickMiss:
|
|
continue;
|
|
}
|
|
|
|
if (result == HitResult.Miss || validResults.Contains(result))
|
|
yield return (result, GetDisplayNameForHitResult(result));
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all valid <see cref="HitResult"/>s for this ruleset.
|
|
/// Used for strict validation purposes. The ruleset should return ALL applicable <see cref="HitResult"/> types here
|
|
/// (except <see cref="HitResult.None"/> and obsolete types).
|
|
/// </summary>
|
|
public virtual IEnumerable<HitResult> GetValidHitResults() => EnumExtensions.GetValuesInOrder<HitResult>();
|
|
|
|
/// <summary>
|
|
/// Get a display friendly name for the specified result type.
|
|
/// </summary>
|
|
/// <param name="result">The result type to get the name for.</param>
|
|
/// <returns>The display name.</returns>
|
|
public virtual LocalisableString GetDisplayNameForHitResult(HitResult result) => result.GetLocalisableDescription();
|
|
|
|
/// <summary>
|
|
/// Applies changes to difficulty attributes for presenting to a user a rough estimate of how mods affect difficulty.
|
|
/// Importantly, this should NOT BE USED FOR ANY CALCULATIONS.
|
|
///
|
|
/// It is also not always correct, and arguably is never correct depending on your frame of mind.
|
|
/// </summary>
|
|
/// <param name="beatmapInfo">The <see cref="IBeatmapInfo"/> for which to display the adjusted difficulty.</param>
|
|
/// <param name="mods">The active mods.</param>
|
|
/// <returns>The adjusted difficulty attributes.</returns>
|
|
public virtual BeatmapDifficulty GetAdjustedDisplayDifficulty(IBeatmapInfo beatmapInfo, IReadOnlyCollection<Mod> mods)
|
|
{
|
|
BeatmapDifficulty adjustedDifficulty = new BeatmapDifficulty(beatmapInfo.Difficulty);
|
|
|
|
foreach (var mod in mods.OfType<IApplicableToDifficulty>())
|
|
mod.ApplyToDifficulty(adjustedDifficulty);
|
|
|
|
return adjustedDifficulty;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns a list of <see cref="RulesetBeatmapAttribute"/>s to be displayed wherever it is wanted to display a given beatmap's difficulty information.
|
|
/// The returned data includes both material changes to difficulty from <see cref="IApplicableToDifficulty"/> mods,
|
|
/// as well as "effective" adjustments coming from <see cref="GetAdjustedDisplayDifficulty"/>.
|
|
/// </summary>
|
|
public virtual IEnumerable<RulesetBeatmapAttribute> GetBeatmapAttributesForDisplay(IBeatmapInfo beatmapInfo, IReadOnlyCollection<Mod> mods)
|
|
{
|
|
var originalDifficulty = beatmapInfo.Difficulty;
|
|
var adjustedDifficulty = GetAdjustedDisplayDifficulty(beatmapInfo, mods);
|
|
|
|
yield return new RulesetBeatmapAttribute(SongSelectStrings.CircleSize, @"CS", originalDifficulty.CircleSize, adjustedDifficulty.CircleSize, 10);
|
|
yield return new RulesetBeatmapAttribute(SongSelectStrings.ApproachRate, @"AR", originalDifficulty.ApproachRate, adjustedDifficulty.ApproachRate, 10);
|
|
yield return new RulesetBeatmapAttribute(SongSelectStrings.Accuracy, @"OD", originalDifficulty.OverallDifficulty, adjustedDifficulty.OverallDifficulty, 10);
|
|
yield return new RulesetBeatmapAttribute(SongSelectStrings.HPDrain, @"HP", originalDifficulty.DrainRate, adjustedDifficulty.DrainRate, 10);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Overload of <see cref="GetAdjustedDisplayDifficulty"/> for display on Ranked Cards
|
|
/// </summary>
|
|
public virtual IEnumerable<RulesetBeatmapAttribute> GetBeatmapAttributesForRankedPlayCard(IBeatmapInfo beatmapInfo, IReadOnlyCollection<Mod> mods) =>
|
|
GetBeatmapAttributesForDisplay(beatmapInfo, mods);
|
|
|
|
/// <summary>
|
|
/// Creates ruleset-specific beatmap filter criteria to be used on the song select screen.
|
|
/// </summary>
|
|
public virtual IRulesetFilterCriteria? CreateRulesetFilterCriteria() => null;
|
|
|
|
/// <summary>
|
|
/// Can be overridden to add ruleset-specific sections to the editor beatmap setup screen.
|
|
/// </summary>
|
|
public virtual IEnumerable<Drawable> CreateEditorSetupSections() =>
|
|
[
|
|
new MetadataSection(),
|
|
new DifficultySection(),
|
|
new FillFlowContainer
|
|
{
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FillDirection.Vertical,
|
|
Spacing = new Vector2(25),
|
|
Children = new Drawable[]
|
|
{
|
|
new ResourcesSection
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
},
|
|
new ColoursSection
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
}
|
|
}
|
|
},
|
|
new DesignSection(),
|
|
];
|
|
|
|
/// <summary>
|
|
/// Can be overridden to avoid showing scroll speed changes in the editor.
|
|
/// </summary>
|
|
public virtual bool EditorShowScrollSpeed => true;
|
|
}
|
|
}
|