From e45b26c742048cfe825005832e936d7115afa96c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 2 Feb 2018 19:35:44 +0900 Subject: [PATCH] Cleanup/minify HitWindows --- osu.Game/Beatmaps/BeatmapDifficulty.cs | 12 ++ osu.Game/Rulesets/Objects/HitWindows.cs | 168 +++++++----------------- 2 files changed, 57 insertions(+), 123 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapDifficulty.cs b/osu.Game/Beatmaps/BeatmapDifficulty.cs index 5be786a8e2..570faaea0a 100644 --- a/osu.Game/Beatmaps/BeatmapDifficulty.cs +++ b/osu.Game/Beatmaps/BeatmapDifficulty.cs @@ -40,5 +40,17 @@ namespace osu.Game.Beatmaps return mid - (mid - min) * (5 - difficulty) / 5; return mid; } + + /// + /// Maps a difficulty value [0, 10] to a two-piece linear range of values. + /// + /// The difficulty value to be mapped. + /// The values that define the two linear ranges. + /// Minimum of the resulting range which will be achieved by a difficulty value of 0. + /// Midpoint of the resulting range which will be achieved by a difficulty value of 5. + /// Maximum of the resulting range which will be achieved by a difficulty value of 10. + /// Value to which the difficulty value maps in the specified range. + public static double DifficultyRange(double difficulty, (double min, double mid, double max) range) + => DifficultyRange(difficulty, range.min, range.mid, range.max); } } diff --git a/osu.Game/Rulesets/Objects/HitWindows.cs b/osu.Game/Rulesets/Objects/HitWindows.cs index a7ffd5eb72..8fa6bb5e8b 100644 --- a/osu.Game/Rulesets/Objects/HitWindows.cs +++ b/osu.Game/Rulesets/Objects/HitWindows.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using osu.Game.Beatmaps; using osu.Game.Rulesets.Scoring; @@ -9,124 +10,45 @@ namespace osu.Game.Rulesets.Objects { public class HitWindows { - #region Constants - - /// - /// PERFECT hit window at OD = 10. - /// - private const double perfect_min = 27.8; - /// - /// PERFECT hit window at OD = 5. - /// - private const double perfect_mid = 38.8; - /// - /// PERFECT hit window at OD = 0. - /// - private const double perfect_max = 44.8; - - /// - /// GREAT hit window at OD = 10. - /// - private const double great_min = 68; - /// - /// GREAT hit window at OD = 5. - /// - private const double great_mid = 98; - /// - /// GREAT hit window at OD = 0. - /// - private const double great_max = 128; - - /// - /// GOOD hit window at OD = 10. - /// - private const double good_min = 134; - /// - /// GOOD hit window at OD = 5. - /// - private const double good_mid = 164; - /// - /// GOOD hit window at OD = 0. - /// - private const double good_max = 194; - - /// - /// OK hit window at OD = 10. - /// - private const double ok_min = 194; - /// - /// OK hit window at OD = 5. - /// - private const double ok_mid = 224; - /// - /// OK hit window at OD = 0. - /// - private const double ok_max = 254; - - /// - /// MEH hit window at OD = 10. - /// - private const double meh_min = 242; - /// - /// MEH hit window at OD = 5. - /// - private const double meh_mid = 272; - /// - /// MEH hit window at OD = 0. - /// - private const double meh_max = 302; - - /// - /// MISS hit window at OD = 10. - /// - private const double miss_min = 316; - /// - /// MISS hit window at OD = 5. - /// - private const double miss_mid = 346; - /// - /// MISS hit window at OD = 0. - /// - private const double miss_max = 376; - - #endregion - - /// - /// Hit window for a PERFECT hit. - /// - public double Perfect = perfect_mid; - - /// - /// Hit window for a GREAT hit. - /// - public double Great = great_mid; - - /// - /// Hit window for a GOOD hit. - /// - public double Good = good_mid; - - /// - /// Hit window for an OK hit. - /// - public double Ok = ok_mid; - - /// - /// Hit window for a MEH hit. - /// - public double Meh = meh_mid; - - /// - /// Hit window for a MISS hit. - /// - public double Miss = miss_mid; - - /// - /// Constructs default hit windows. - /// - public HitWindows() + private static readonly IReadOnlyDictionary base_ranges = new Dictionary { - } + { HitResult.Perfect, (44.8, 38.8, 27.8) }, + { HitResult.Great, (128, 98, 68 ) }, + { HitResult.Good, (194, 164, 134) }, + { HitResult.Ok, (254, 224, 194) }, + { HitResult.Meh, (382, 272, 242) }, + { HitResult.Miss, (376, 346, 316) }, + }; + + /// + /// Hit window for a hit. + /// + public double Perfect; + + /// + /// Hit window for a hit. + /// + public double Great; + + /// + /// Hit window for a hit. + /// + public double Good; + + /// + /// Hit window for an hit. + /// + public double Ok; + + /// + /// Hit window for a hit. + /// + public double Meh; + + /// + /// Hit window for a hit. + /// + public double Miss; /// /// Constructs hit windows by fitting a parameter to a 2-part piecewise linear function for each hit window. @@ -134,12 +56,12 @@ namespace osu.Game.Rulesets.Objects /// The parameter. public HitWindows(double difficulty) { - Perfect = BeatmapDifficulty.DifficultyRange(difficulty, perfect_max, perfect_mid, perfect_min); - Great = BeatmapDifficulty.DifficultyRange(difficulty, great_max, great_mid, great_min); - Good = BeatmapDifficulty.DifficultyRange(difficulty, good_max, good_mid, good_min); - Ok = BeatmapDifficulty.DifficultyRange(difficulty, ok_max, ok_mid, ok_min); - Meh = BeatmapDifficulty.DifficultyRange(difficulty, meh_max, meh_mid, meh_min); - Miss = BeatmapDifficulty.DifficultyRange(difficulty, miss_max, miss_mid, miss_min); + Perfect = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Perfect]); + Great = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Great]); + Good = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Good]); + Ok = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Ok]); + Meh = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Meh]); + Miss = BeatmapDifficulty.DifficultyRange(difficulty, base_ranges[HitResult.Miss]); } ///