From 5afe57033ddc19da134009b4967409022b2f8dea Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 9 May 2023 19:30:54 +0900 Subject: [PATCH 01/66] Add parent hitobject to strong hits --- osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs | 7 ++++++- osu.Game.Rulesets.Taiko/Objects/DrumRollTick.cs | 6 +++++- osu.Game.Rulesets.Taiko/Objects/Hit.cs | 6 +++++- osu.Game.Rulesets.Taiko/Objects/StrongNestedHitObject.cs | 7 +++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs index b4a12fd314..80553a1033 100644 --- a/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs +++ b/osu.Game.Rulesets.Taiko/Objects/DrumRoll.cs @@ -109,12 +109,17 @@ namespace osu.Game.Rulesets.Taiko.Objects protected override HitWindows CreateHitWindows() => HitWindows.Empty; - protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit { StartTime = startTime }; + protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit(this) { StartTime = startTime }; public class StrongNestedHit : StrongNestedHitObject { // The strong hit of the drum roll doesn't actually provide any score. public override Judgement CreateJudgement() => new IgnoreJudgement(); + + public StrongNestedHit(TaikoHitObject parent) + : base(parent) + { + } } #region LegacyBeatmapEncoder diff --git a/osu.Game.Rulesets.Taiko/Objects/DrumRollTick.cs b/osu.Game.Rulesets.Taiko/Objects/DrumRollTick.cs index 6bcb8674e6..56dbe3ce38 100644 --- a/osu.Game.Rulesets.Taiko/Objects/DrumRollTick.cs +++ b/osu.Game.Rulesets.Taiko/Objects/DrumRollTick.cs @@ -33,10 +33,14 @@ namespace osu.Game.Rulesets.Taiko.Objects public override double MaximumJudgementOffset => HitWindow; - protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit { StartTime = startTime }; + protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit(this) { StartTime = startTime }; public class StrongNestedHit : StrongNestedHitObject { + public StrongNestedHit(TaikoHitObject parent) + : base(parent) + { + } } } } diff --git a/osu.Game.Rulesets.Taiko/Objects/Hit.cs b/osu.Game.Rulesets.Taiko/Objects/Hit.cs index 787079bfee..6a3c8467e9 100644 --- a/osu.Game.Rulesets.Taiko/Objects/Hit.cs +++ b/osu.Game.Rulesets.Taiko/Objects/Hit.cs @@ -72,10 +72,14 @@ namespace osu.Game.Rulesets.Taiko.Objects } } - protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit { StartTime = startTime }; + protected override StrongNestedHitObject CreateStrongNestedHit(double startTime) => new StrongNestedHit(this) { StartTime = startTime }; public class StrongNestedHit : StrongNestedHitObject { + public StrongNestedHit(TaikoHitObject parent) + : base(parent) + { + } } } } diff --git a/osu.Game.Rulesets.Taiko/Objects/StrongNestedHitObject.cs b/osu.Game.Rulesets.Taiko/Objects/StrongNestedHitObject.cs index 628c41d878..316115f44d 100644 --- a/osu.Game.Rulesets.Taiko/Objects/StrongNestedHitObject.cs +++ b/osu.Game.Rulesets.Taiko/Objects/StrongNestedHitObject.cs @@ -15,6 +15,13 @@ namespace osu.Game.Rulesets.Taiko.Objects /// public abstract class StrongNestedHitObject : TaikoHitObject { + public readonly TaikoHitObject Parent; + + protected StrongNestedHitObject(TaikoHitObject parent) + { + Parent = parent; + } + public override Judgement CreateJudgement() => new TaikoStrongJudgement(); protected override HitWindows CreateHitWindows() => HitWindows.Empty; From 3c3c812ed6dfca27d7ffa2db07703c93d57d52b9 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 9 May 2023 19:33:33 +0900 Subject: [PATCH 02/66] Initial implementation of ScoreV2 --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../Scoring/CatchScoreProcessor.cs | 78 +++- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- .../Scoring/ManiaScoreProcessor.cs | 49 ++- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- .../Scoring/OsuScoreProcessor.cs | 37 +- .../Scoring/TaikoScoreProcessor.cs | 58 ++- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 +- .../Spectator/SpectatorScoreProcessor.cs | 3 +- .../PerformanceBreakdownCalculator.cs | 4 +- .../Rulesets/Mods/ModAccuracyChallenge.cs | 4 +- osu.Game/Rulesets/Ruleset.cs | 21 +- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 392 ++++-------------- osu.Game/Scoring/ScoreManager.cs | 4 +- .../OnlinePlay/Playlists/PlaylistsPlayer.cs | 3 +- 15 files changed, 300 insertions(+), 361 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 8a0b8250d5..e2255fa6f7 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Catch { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableCatchRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); + public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(this); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new CatchBeatmapConverter(beatmap, this); diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index b6a42407da..bf5c3a91d6 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -1,17 +1,87 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; +using osu.Game.Rulesets.Catch.Objects; +using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Catch.Scoring { public partial class CatchScoreProcessor : ScoreProcessor { - public CatchScoreProcessor() - : base(new CatchRuleset()) + private const int combo_cap = 200; + private const double combo_base = 4; + + protected override double ClassicScoreMultiplier => 28; + + private double tinyDropletScale; + + private int maximumTinyDroplets; + private int hitTinyDroplets; + + public CatchScoreProcessor(Ruleset ruleset) + : base(ruleset) { } - protected override double ClassicScoreMultiplier => 28; + protected override double ComputeTotalScore() + { + double fruitHitsRatio = maximumTinyDroplets == 0 ? 0 : (double)hitTinyDroplets / maximumTinyDroplets; + + const int tiny_droplets_portion = 400000; + + return + (int)Math.Round + (( + ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * ComboPortion / MaxComboPortion + + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + + BonusPortion + ) * ScoreMultiplier); + } + + protected override void AddScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + ComboPortion += change.combo; + BonusPortion += change.bonus; + hitTinyDroplets += change.tinyDropletHits; + } + + protected override void RemoveScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + ComboPortion -= change.combo; + BonusPortion -= change.bonus; + hitTinyDroplets -= change.tinyDropletHits; + } + + private (double combo, double bonus, int tinyDropletHits) computeScoreChange(JudgementResult result) + { + if (result.HitObject is TinyDroplet) + return (0, 0, 1); + + if (result.Type.IsBonus()) + return (0, Judgement.ToNumericResult(result.Type), 0); + + return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(combo_cap, combo_base)), 0, 0); + } + + protected override void Reset(bool storeResults) + { + base.Reset(storeResults); + + if (storeResults) + { + maximumTinyDroplets = hitTinyDroplets; + + if (maximumTinyDroplets + MaxBasicJudgements == 0) + tinyDropletScale = 0; + else + tinyDropletScale = (double)maximumTinyDroplets / (maximumTinyDroplets + MaxBasicJudgements); + } + + hitTinyDroplets = 0; + } } } diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index d324682989..c6065c9b96 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Mania public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableManiaRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); + public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this); public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new ManiaHealthProcessor(drainStartTime); diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index f724972a29..7d188c6786 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -1,23 +1,54 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; +using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Mania.Scoring { - internal partial class ManiaScoreProcessor : ScoreProcessor + public partial class ManiaScoreProcessor : ScoreProcessor { - public ManiaScoreProcessor() - : base(new ManiaRuleset()) + private const double combo_base = 4; + + protected override double ClassicScoreMultiplier => 16; + + public ManiaScoreProcessor(Ruleset ruleset) + : base(ruleset) { } - protected override double DefaultAccuracyPortion => 0.99; + protected override double ComputeTotalScore() + { + return + (int)Math.Round + (( + 200000 * ComboPortion / MaxComboPortion + + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier); + } - protected override double DefaultComboPortion => 0.01; + protected override void AddScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + ComboPortion += change.combo; + BonusPortion += change.bonus; + } - protected override double ClassicScoreMultiplier => 16; + protected override void RemoveScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + ComboPortion -= change.combo; + BonusPortion -= change.bonus; + } + + private (double combo, double bonus) computeScoreChange(JudgementResult result) + { + if (result.Type.IsBonus()) + return (0, Judgement.ToNumericResult(result.Type)); + + return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(400, combo_base)), 0); + } } } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 922594a93a..497d405436 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Osu { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableOsuRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(); + public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new OsuBeatmapConverter(beatmap, this); diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index 50d4eb6258..5f5997b0c1 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -1,38 +1,29 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - -using osu.Game.Rulesets.Judgements; -using osu.Game.Rulesets.Objects; -using osu.Game.Rulesets.Osu.Judgements; -using osu.Game.Rulesets.Osu.Objects; +using System; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Osu.Scoring { public partial class OsuScoreProcessor : ScoreProcessor { - public OsuScoreProcessor() - : base(new OsuRuleset()) + protected override double ClassicScoreMultiplier => 36; + + public OsuScoreProcessor(Ruleset ruleset) + : base(ruleset) { } - protected override double ClassicScoreMultiplier => 36; - - protected override HitEvent CreateHitEvent(JudgementResult result) - => base.CreateHitEvent(result).With((result as OsuHitCircleJudgementResult)?.CursorPositionAtHit); - - protected override JudgementResult CreateResult(HitObject hitObject, Judgement judgement) + protected override double ComputeTotalScore() { - switch (hitObject) - { - case HitCircle: - return new OsuHitCircleJudgementResult(hitObject, judgement); - - default: - return new OsuJudgementResult(hitObject, judgement); - } + return + (int)Math.Round + (( + 700000 * ComboPortion / MaxComboPortion + + 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier); } } } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index 4b60ee3ccb..caf0a799a2 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -1,23 +1,63 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - +using System; +using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; +using osu.Game.Rulesets.Taiko.Objects; namespace osu.Game.Rulesets.Taiko.Scoring { - internal partial class TaikoScoreProcessor : ScoreProcessor + public partial class TaikoScoreProcessor : ScoreProcessor { - public TaikoScoreProcessor() - : base(new TaikoRuleset()) + private const double combo_base = 4; + + protected override double ClassicScoreMultiplier => 22; + + public TaikoScoreProcessor(Ruleset ruleset) + : base(ruleset) { } - protected override double DefaultAccuracyPortion => 0.75; + protected override double ComputeTotalScore() + { + return + (int)Math.Round + (( + 250000 * ComboPortion / MaxComboPortion + + 750000 * Math.Pow(Accuracy.Value, 3.6) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier); + } - protected override double DefaultComboPortion => 0.25; + protected override void AddScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + BonusPortion += change.bonus; + ComboPortion += change.combo; + } - protected override double ClassicScoreMultiplier => 22; + protected override void RemoveScoreChange(JudgementResult result) + { + var change = computeScoreChange(result); + BonusPortion -= change.bonus; + ComboPortion -= change.combo; + } + + private (double combo, double bonus) computeScoreChange(JudgementResult result) + { + double hitValue = Judgement.ToNumericResult(result.Type); + + if (result.HitObject is StrongNestedHitObject strong) + { + double strongBonus = strong.Parent is DrumRollTick ? 3 : 7; + hitValue *= strongBonus; + } + + if (result.Type.IsBonus()) + return (0, hitValue); + + return (hitValue * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(400, combo_base)), 0); + } } } diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index a35fdb890d..599d0dc33c 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Taiko { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableTaikoRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); + public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new TaikoHealthProcessor(); diff --git a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs index 1c505ea107..cb23164c00 100644 --- a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs +++ b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs @@ -157,7 +157,8 @@ namespace osu.Game.Online.Spectator Accuracy.Value = frame.Header.Accuracy; Combo.Value = frame.Header.Combo; - TotalScore.Value = scoreProcessor.ComputeScore(Mode.Value, scoreInfo); + // Todo: + // TotalScore.Value = scoreProcessor.ComputeScore(Mode.Value, scoreInfo); } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs index 4f802a22a1..03bd0f7509 100644 --- a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs @@ -66,7 +66,9 @@ namespace osu.Game.Rulesets.Difficulty // calculate total score ScoreProcessor scoreProcessor = ruleset.CreateScoreProcessor(); scoreProcessor.Mods.Value = perfectPlay.Mods; - perfectPlay.TotalScore = scoreProcessor.ComputeScore(ScoringMode.Standardised, perfectPlay); + + // Todo: + // perfectPlay.TotalScore = scoreProcessor.ComputeScore(ScoringMode.Standardised, perfectPlay); // compute rank achieved // default to SS, then adjust the rank with mods diff --git a/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs b/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs index d4223a80c2..13b8ad5d84 100644 --- a/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs +++ b/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs @@ -65,7 +65,9 @@ namespace osu.Game.Rulesets.Mods scoreProcessor.PopulateScore(score); score.Statistics[result.Type]++; - return scoreProcessor.ComputeAccuracy(score); + // Todo: + return 0; + // return scoreProcessor.ComputeAccuracy(score); } } } diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index a77068eb14..2e7a58b96c 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -232,7 +232,7 @@ namespace osu.Game.Rulesets /// Creates a for this . /// /// The score processor. - public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor(this); + public virtual ScoreProcessor CreateScoreProcessor() => new DefaultScoreProcessor(this); /// /// Creates a for this . @@ -381,4 +381,23 @@ namespace osu.Game.Rulesets /// public virtual RulesetSetupSection? CreateEditorSetupSection() => null; } + + public partial class DefaultScoreProcessor : ScoreProcessor + { + public DefaultScoreProcessor(Ruleset ruleset) + : base(ruleset) + { + } + + protected override double ComputeTotalScore() + { + return + (int)Math.Round + (( + 700000 * ComboPortion / MaxComboPortion + + 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier); + } + } } diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 96f6922224..8373ebd50c 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -4,11 +4,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Diagnostics.Contracts; using System.Linq; using osu.Framework.Bindables; using osu.Framework.Localisation; -using osu.Framework.Utils; using osu.Game.Beatmaps; using osu.Game.Extensions; using osu.Game.Localisation; @@ -20,8 +18,10 @@ using osu.Game.Scoring; namespace osu.Game.Rulesets.Scoring { - public partial class ScoreProcessor : JudgementProcessor + public abstract partial class ScoreProcessor : JudgementProcessor { + protected const double MAX_SCORE = 1000000; + private const double accuracy_cutoff_x = 1; private const double accuracy_cutoff_s = 0.95; private const double accuracy_cutoff_a = 0.9; @@ -29,8 +29,6 @@ namespace osu.Game.Rulesets.Scoring private const double accuracy_cutoff_c = 0.7; private const double accuracy_cutoff_d = 0; - private const double max_score = 1000000; - /// /// Invoked when this was reset from a replay frame. /// @@ -89,16 +87,6 @@ namespace osu.Game.Rulesets.Scoring /// public IReadOnlyList HitEvents => hitEvents; - /// - /// The default portion of awarded for hitting s accurately. Defaults to 30%. - /// - protected virtual double DefaultAccuracyPortion => 0.3; - - /// - /// The default portion of awarded for achieving a high combo. Default to 70%. - /// - protected virtual double DefaultComboPortion => 0.7; - /// /// An arbitrary multiplier to scale scores in the scoring mode. /// @@ -109,8 +97,45 @@ namespace osu.Game.Rulesets.Scoring /// public readonly Ruleset Ruleset; - private readonly double accuracyPortion; - private readonly double comboPortion; + /// + /// The sum of all basic judgements at the current time. + /// + private double currentBasicScore; + + /// + /// The maximum sum of basic judgements at the current time. + /// + private double currentMaxBasicScore; + + /// + /// The total count of basic judgements in the beatmap. + /// + protected int MaxBasicJudgements { get; private set; } + + /// + /// The current count of basic judgements by the player. + /// + protected int CurrentBasicJudgements { get; private set; } + + /// + /// The current combo score. + /// + protected double ComboPortion { get; set; } + + /// + /// The maximum achievable combo score. + /// + protected double MaxComboPortion { get; private set; } + + /// + /// The current bonus score. + /// + protected double BonusPortion { get; set; } + + /// + /// The total score multiplier. + /// + protected double ScoreMultiplier { get; private set; } = 1; public Dictionary MaximumStatistics { @@ -123,27 +148,6 @@ namespace osu.Game.Rulesets.Scoring } } - private ScoringValues maximumScoringValues; - - /// - /// Scoring values for the current play assuming all perfect hits. - /// - /// - /// This is only used to determine the accuracy with respect to the current point in time for an ongoing play session. - /// - private ScoringValues currentMaximumScoringValues; - - /// - /// Scoring values for the current play. - /// - private ScoringValues currentScoringValues; - - /// - /// The maximum of a basic (non-tick and non-bonus) hitobject. - /// Only populated via or . - /// - private HitResult? maxBasicResult; - private bool beatmapApplied; private readonly Dictionary scoreResultCounts = new Dictionary(); @@ -152,18 +156,10 @@ namespace osu.Game.Rulesets.Scoring private readonly List hitEvents = new List(); private HitObject? lastHitObject; - private double scoreMultiplier = 1; - - public ScoreProcessor(Ruleset ruleset) + protected ScoreProcessor(Ruleset ruleset) { Ruleset = ruleset; - accuracyPortion = DefaultAccuracyPortion; - comboPortion = DefaultComboPortion; - - if (!Precision.AlmostEquals(1.0, accuracyPortion + comboPortion)) - throw new InvalidOperationException($"{nameof(DefaultAccuracyPortion)} + {nameof(DefaultComboPortion)} must equal 1."); - Combo.ValueChanged += combo => HighestCombo.Value = Math.Max(HighestCombo.Value, combo.NewValue); Accuracy.ValueChanged += accuracy => { @@ -175,10 +171,10 @@ namespace osu.Game.Rulesets.Scoring Mode.ValueChanged += _ => updateScore(); Mods.ValueChanged += mods => { - scoreMultiplier = 1; + ScoreMultiplier = 1; foreach (var m in mods.NewValue) - scoreMultiplier *= m.ScoreMultiplier; + ScoreMultiplier *= m.ScoreMultiplier; updateScore(); }; @@ -200,10 +196,6 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) + 1; - // Always update the maximum scoring values. - applyResult(result.Judgement.MaxResult, ref currentMaximumScoringValues); - currentMaximumScoringValues.MaxCombo += result.Judgement.MaxResult.IncreasesCombo() ? 1 : 0; - if (!result.Type.IsScorable()) return; @@ -212,8 +204,13 @@ namespace osu.Game.Rulesets.Scoring else if (result.Type.BreaksCombo()) Combo.Value = 0; - applyResult(result.Type, ref currentScoringValues); - currentScoringValues.MaxCombo = HighestCombo.Value; + if (result.Type.IsBasic()) + CurrentBasicJudgements++; + + currentMaxBasicScore += Judgement.ToNumericResult(result.Judgement.MaxResult); + currentBasicScore += Judgement.ToNumericResult(result.Type); + + AddScoreChange(result); hitEvents.Add(CreateHitEvent(result)); lastHitObject = result.HitObject; @@ -221,20 +218,6 @@ namespace osu.Game.Rulesets.Scoring updateScore(); } - private static void applyResult(HitResult result, ref ScoringValues scoringValues) - { - if (!result.IsScorable()) - return; - - if (result.IsBonus()) - scoringValues.BonusScore += result.IsHit() ? Judgement.ToNumericResult(result) : 0; - else - scoringValues.BaseScore += result.IsHit() ? Judgement.ToNumericResult(result) : 0; - - if (result.IsBasic()) - scoringValues.CountBasicHitObjects++; - } - /// /// Creates the that describes a . /// @@ -253,15 +236,16 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts[result.Type] = scoreResultCounts.GetValueOrDefault(result.Type) - 1; - // Always update the maximum scoring values. - revertResult(result.Judgement.MaxResult, ref currentMaximumScoringValues); - currentMaximumScoringValues.MaxCombo -= result.Judgement.MaxResult.IncreasesCombo() ? 1 : 0; - if (!result.Type.IsScorable()) return; - revertResult(result.Type, ref currentScoringValues); - currentScoringValues.MaxCombo = HighestCombo.Value; + if (result.Type.IsBasic()) + CurrentBasicJudgements--; + + currentMaxBasicScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); + currentBasicScore -= Judgement.ToNumericResult(result.Type); + + RemoveScoreChange(result); Debug.Assert(hitEvents.Count > 0); lastHitObject = hitEvents[^1].LastHitObject; @@ -270,111 +254,31 @@ namespace osu.Game.Rulesets.Scoring updateScore(); } - private static void revertResult(HitResult result, ref ScoringValues scoringValues) + protected virtual void AddScoreChange(JudgementResult result) { - if (!result.IsScorable()) - return; - - if (result.IsBonus()) - scoringValues.BonusScore -= result.IsHit() ? Judgement.ToNumericResult(result) : 0; + if (result.Type.IsBonus()) + BonusPortion += Judgement.ToNumericResult(result.Type); else - scoringValues.BaseScore -= result.IsHit() ? Judgement.ToNumericResult(result) : 0; + ComboPortion += Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); + } - if (result.IsBasic()) - scoringValues.CountBasicHitObjects--; + protected virtual void RemoveScoreChange(JudgementResult result) + { + if (result.Type.IsBonus()) + BonusPortion -= Judgement.ToNumericResult(result.Type); + else + ComboPortion -= Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); } private void updateScore() { - Accuracy.Value = currentMaximumScoringValues.BaseScore > 0 ? (double)currentScoringValues.BaseScore / currentMaximumScoringValues.BaseScore : 1; - MinimumAccuracy.Value = maximumScoringValues.BaseScore > 0 ? (double)currentScoringValues.BaseScore / maximumScoringValues.BaseScore : 0; - MaximumAccuracy.Value = maximumScoringValues.BaseScore > 0 - ? (double)(currentScoringValues.BaseScore + (maximumScoringValues.BaseScore - currentMaximumScoringValues.BaseScore)) / maximumScoringValues.BaseScore - : 1; - TotalScore.Value = computeScore(Mode.Value, currentScoringValues, maximumScoringValues); + Accuracy.Value = currentMaxBasicScore > 0 ? currentBasicScore / currentMaxBasicScore : 1; + + // Todo: Classic/Standardised + TotalScore.Value = (long)Math.Round(ComputeTotalScore()); } - /// - /// Computes the accuracy of a given . - /// - /// The to compute the total score of. - /// The score's accuracy. - [Pure] - public double ComputeAccuracy(ScoreInfo scoreInfo) - { - if (!Ruleset.RulesetInfo.Equals(scoreInfo.Ruleset)) - throw new ArgumentException($"Unexpected score ruleset. Expected \"{Ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\"."); - - // We only extract scoring values from the score's statistics. This is because accuracy is always relative to the point of pass or fail rather than relative to the whole beatmap. - extractScoringValues(scoreInfo.Statistics, out var current, out var maximum); - - return maximum.BaseScore > 0 ? (double)current.BaseScore / maximum.BaseScore : 1; - } - - /// - /// Computes the total score of a given . - /// - /// - /// Does not require to have been called before use. - /// - /// The to represent the score as. - /// The to compute the total score of. - /// The total score in the given . - [Pure] - public long ComputeScore(ScoringMode mode, ScoreInfo scoreInfo) - { - if (!Ruleset.RulesetInfo.Equals(scoreInfo.Ruleset)) - throw new ArgumentException($"Unexpected score ruleset. Expected \"{Ruleset.RulesetInfo.ShortName}\" but was \"{scoreInfo.Ruleset.ShortName}\"."); - - extractScoringValues(scoreInfo, out var current, out var maximum); - - return computeScore(mode, current, maximum); - } - - /// - /// Computes the total score from scoring values. - /// - /// The to represent the score as. - /// The current scoring values. - /// The maximum scoring values. - /// The total score computed from the given scoring values. - [Pure] - private long computeScore(ScoringMode mode, ScoringValues current, ScoringValues maximum) - { - double accuracyRatio = maximum.BaseScore > 0 ? (double)current.BaseScore / maximum.BaseScore : 1; - double comboRatio = maximum.MaxCombo > 0 ? (double)current.MaxCombo / maximum.MaxCombo : 1; - return ComputeScore(mode, accuracyRatio, comboRatio, current.BonusScore, maximum.CountBasicHitObjects); - } - - /// - /// Computes the total score from individual scoring components. - /// - /// The to represent the score as. - /// The accuracy percentage achieved by the player. - /// The portion of the max combo achieved by the player. - /// The total bonus score. - /// The total number of basic (non-tick and non-bonus) hitobjects in the beatmap. - /// The total score computed from the given scoring component ratios. - [Pure] - public long ComputeScore(ScoringMode mode, double accuracyRatio, double comboRatio, long bonusScore, int totalBasicHitObjects) - { - double accuracyScore = accuracyPortion * accuracyRatio; - double comboScore = comboPortion * comboRatio; - double rawScore = (max_score * (accuracyScore + comboScore) + bonusScore) * scoreMultiplier; - - switch (mode) - { - default: - case ScoringMode.Standardised: - return (long)Math.Round(rawScore); - - case ScoringMode.Classic: - // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. - // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. - double scaledRawScore = rawScore / max_score; - return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, totalBasicHitObjects), 2) * ClassicScoreMultiplier); - } - } + protected abstract double ComputeTotalScore(); /// /// Resets this ScoreProcessor to a default state. @@ -389,7 +293,8 @@ namespace osu.Game.Rulesets.Scoring if (storeResults) { - maximumScoringValues = currentScoringValues; + MaxComboPortion = ComboPortion; + MaxBasicJudgements = CurrentBasicJudgements; maximumResultCounts.Clear(); maximumResultCounts.AddRange(scoreResultCounts); @@ -397,8 +302,11 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts.Clear(); - currentScoringValues = default; - currentMaximumScoringValues = default; + currentBasicScore = 0; + currentMaxBasicScore = 0; + CurrentBasicJudgements = 0; + ComboPortion = 0; + BonusPortion = 0; TotalScore.Value = 0; Accuracy.Value = 1; @@ -406,6 +314,9 @@ namespace osu.Game.Rulesets.Scoring Rank.Disabled = false; Rank.Value = ScoreRank.X; HighestCombo.Value = 0; + + currentBasicScore = 0; + currentMaxBasicScore = 0; } /// @@ -428,7 +339,7 @@ namespace osu.Game.Rulesets.Scoring score.MaximumStatistics[result] = maximumResultCounts.GetValueOrDefault(result); // Populate total score after everything else. - score.TotalScore = ComputeScore(ScoringMode.Standardised, score); + score.TotalScore = TotalScore.Value; } /// @@ -452,12 +363,6 @@ namespace osu.Game.Rulesets.Scoring if (frame.Header == null) return; - extractScoringValues(frame.Header.Statistics, out var current, out var maximum); - currentScoringValues.BaseScore = current.BaseScore; - currentScoringValues.MaxCombo = frame.Header.MaxCombo; - currentMaximumScoringValues.BaseScore = maximum.BaseScore; - currentMaximumScoringValues.MaxCombo = maximum.MaxCombo; - Combo.Value = frame.Header.Combo; HighestCombo.Value = frame.Header.MaxCombo; @@ -469,105 +374,6 @@ namespace osu.Game.Rulesets.Scoring OnResetFromReplayFrame?.Invoke(); } - #region ScoringValue extraction - - /// - /// Applies a best-effort extraction of hit statistics into . - /// - /// - /// This method is useful in a variety of situations, with a few drawbacks that need to be considered: - /// - /// The maximum will always be 0. - /// The current and maximum will always be the same value. - /// - /// Consumers are expected to more accurately fill in the above values through external means. - /// - /// Ensure to fill in the maximum for use in - /// . - /// - /// - /// The score to extract scoring values from. - /// The "current" scoring values, representing the hit statistics as they appear. - /// The "maximum" scoring values, representing the hit statistics as if the maximum hit result was attained each time. - [Pure] - private void extractScoringValues(ScoreInfo scoreInfo, out ScoringValues current, out ScoringValues maximum) - { - extractScoringValues(scoreInfo.Statistics, out current, out maximum); - current.MaxCombo = scoreInfo.MaxCombo; - - if (scoreInfo.MaximumStatistics.Count > 0) - extractScoringValues(scoreInfo.MaximumStatistics, out _, out maximum); - } - - /// - /// Applies a best-effort extraction of hit statistics into . - /// - /// - /// This method is useful in a variety of situations, with a few drawbacks that need to be considered: - /// - /// The current will always be 0. - /// The maximum will always be 0. - /// The current and maximum will always be the same value. - /// - /// Consumers are expected to more accurately fill in the above values (especially the current ) via external means (e.g. ). - /// - /// The hit statistics to extract scoring values from. - /// The "current" scoring values, representing the hit statistics as they appear. - /// The "maximum" scoring values, representing the hit statistics as if the maximum hit result was attained each time. - [Pure] - private void extractScoringValues(IReadOnlyDictionary statistics, out ScoringValues current, out ScoringValues maximum) - { - current = default; - maximum = default; - - foreach ((HitResult result, int count) in statistics) - { - if (!result.IsScorable()) - continue; - - if (result.IsBonus()) - current.BonusScore += count * Judgement.ToNumericResult(result); - - if (result.AffectsAccuracy()) - { - // The maximum result of this judgement if it wasn't a miss. - // E.g. For a GOOD judgement, the max result is either GREAT/PERFECT depending on which one the ruleset uses (osu!: GREAT, osu!mania: PERFECT). - HitResult maxResult; - - switch (result) - { - case HitResult.LargeTickHit: - case HitResult.LargeTickMiss: - maxResult = HitResult.LargeTickHit; - break; - - case HitResult.SmallTickHit: - case HitResult.SmallTickMiss: - maxResult = HitResult.SmallTickHit; - break; - - default: - maxResult = maxBasicResult ??= Ruleset.GetHitResults().MaxBy(kvp => Judgement.ToNumericResult(kvp.result)).result; - break; - } - - current.BaseScore += count * Judgement.ToNumericResult(result); - maximum.BaseScore += count * Judgement.ToNumericResult(maxResult); - } - - if (result.AffectsCombo()) - maximum.MaxCombo += count; - - if (result.IsBasic()) - { - current.CountBasicHitObjects += count; - maximum.CountBasicHitObjects += count; - } - } - } - - #endregion - protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); @@ -629,32 +435,6 @@ namespace osu.Game.Rulesets.Scoring } #endregion - - /// - /// Stores the required scoring data that fulfils the minimum requirements for a to calculate score. - /// - private struct ScoringValues - { - /// - /// The sum of all "basic" scoring values. See: and . - /// - public long BaseScore; - - /// - /// The sum of all "bonus" scoring values. See: and . - /// - public long BonusScore; - - /// - /// The highest achieved combo. - /// - public int MaxCombo; - - /// - /// The count of "basic" s. See: . - /// - public int CountBasicHitObjects; - } } public enum ScoringMode diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 3e6d09b74a..3779156fda 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -115,7 +115,9 @@ namespace osu.Game.Scoring var scoreProcessor = ruleset.CreateScoreProcessor(); scoreProcessor.Mods.Value = score.Mods; - return scoreProcessor.ComputeScore(mode, score); + // Todo: + return 0; + // return scoreProcessor.ComputeScore(mode, score); } /// diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs index 0c25a32259..7b77785c7a 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs @@ -67,7 +67,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists { await base.PrepareScoreForResultsAsync(score).ConfigureAwait(false); - Score.ScoreInfo.TotalScore = ScoreProcessor.ComputeScore(ScoringMode.Standardised, Score.ScoreInfo); + // Todo: + // Score.ScoreInfo.TotalScore = ScoreProcessor.ComputeScore(ScoringMode.Standardised, Score.ScoreInfo); } protected override void Dispose(bool isDisposing) From a7b623f52af08fd05d89366f169fe75031fa14c3 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 9 May 2023 20:00:14 +0900 Subject: [PATCH 03/66] Reimplement classic scoring mode --- .../Scoring/CatchScoreProcessor.cs | 12 +++++------- .../Scoring/ManiaScoreProcessor.cs | 12 +++++------- .../Scoring/OsuScoreProcessor.cs | 12 +++++------- .../Scoring/TaikoScoreProcessor.cs | 12 +++++------- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 16 ++++++++++++++-- osu.Game/Scoring/ScoreManager.cs | 8 +++----- 6 files changed, 37 insertions(+), 35 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index bf5c3a91d6..9c5359ebeb 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -31,13 +31,11 @@ namespace osu.Game.Rulesets.Catch.Scoring const int tiny_droplets_portion = 400000; - return - (int)Math.Round - (( - ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * ComboPortion / MaxComboPortion + - tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + - BonusPortion - ) * ScoreMultiplier); + return ( + ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * ComboPortion / MaxComboPortion + + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + + BonusPortion + ) * ScoreMultiplier; } protected override void AddScoreChange(JudgementResult result) diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 7d188c6786..19f8a4a639 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -20,13 +20,11 @@ namespace osu.Game.Rulesets.Mania.Scoring protected override double ComputeTotalScore() { - return - (int)Math.Round - (( - 200000 * ComboPortion / MaxComboPortion + - 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + - BonusPortion - ) * ScoreMultiplier); + return ( + 200000 * ComboPortion / MaxComboPortion + + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier; } protected override void AddScoreChange(JudgementResult result) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index 5f5997b0c1..f8cbf1a641 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -17,13 +17,11 @@ namespace osu.Game.Rulesets.Osu.Scoring protected override double ComputeTotalScore() { - return - (int)Math.Round - (( - 700000 * ComboPortion / MaxComboPortion + - 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + - BonusPortion - ) * ScoreMultiplier); + return ( + 700000 * ComboPortion / MaxComboPortion + + 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier; } } } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index caf0a799a2..71eb0b1602 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -21,13 +21,11 @@ namespace osu.Game.Rulesets.Taiko.Scoring protected override double ComputeTotalScore() { - return - (int)Math.Round - (( - 250000 * ComboPortion / MaxComboPortion + - 750000 * Math.Pow(Accuracy.Value, 3.6) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + - BonusPortion - ) * ScoreMultiplier); + return ( + 250000 * ComboPortion / MaxComboPortion + + 750000 * Math.Pow(Accuracy.Value, 3.6) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier; } protected override void AddScoreChange(JudgementResult result) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 8373ebd50c..9172034ff6 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -274,8 +274,20 @@ namespace osu.Game.Rulesets.Scoring { Accuracy.Value = currentMaxBasicScore > 0 ? currentBasicScore / currentMaxBasicScore : 1; - // Todo: Classic/Standardised - TotalScore.Value = (long)Math.Round(ComputeTotalScore()); + double standardisedScore = ComputeTotalScore(); + + if (Mode.Value == ScoringMode.Standardised) + TotalScore.Value = (long)Math.Round(standardisedScore); + else + TotalScore.Value = ConvertToClassic(standardisedScore); + } + + public long ConvertToClassic(double standardised) + { + // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. + // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. + double scaledRawScore = standardised / MAX_SCORE; + return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, MaxBasicJudgements), 2) * ClassicScoreMultiplier); } protected abstract double ComputeTotalScore(); diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 3779156fda..0674947f30 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -107,17 +107,15 @@ namespace osu.Game.Scoring /// The total score. public long GetTotalScore([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised) { - // TODO: This is required for playlist aggregate scores. They should likely not be getting here in the first place. - if (string.IsNullOrEmpty(score.BeatmapInfo.MD5Hash)) + if (mode == ScoringMode.Standardised) return score.TotalScore; var ruleset = score.Ruleset.CreateInstance(); var scoreProcessor = ruleset.CreateScoreProcessor(); scoreProcessor.Mods.Value = score.Mods; - // Todo: - return 0; - // return scoreProcessor.ComputeScore(mode, score); + // Todo: This loses precision because we're dealing with pre-rounded total scores. + return scoreProcessor.ConvertToClassic(score.TotalScore); } /// From f2483a1cf8c4f91fd8c9374b803e2bd553fe68f4 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 17:27:47 +0900 Subject: [PATCH 04/66] Add some helper methods, fix precision differences Introduces some error at all times, but if we're to store scores everywhere as `long`, then the same precision should be applied to the "during gameplay" path as well. --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 40 ++++++++++++++++----- osu.Game/Scoring/IScoreInfo.cs | 3 ++ osu.Game/Scoring/ScoreManager.cs | 10 +++--- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 9172034ff6..cbcf0dceaf 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -274,20 +274,44 @@ namespace osu.Game.Rulesets.Scoring { Accuracy.Value = currentMaxBasicScore > 0 ? currentBasicScore / currentMaxBasicScore : 1; - double standardisedScore = ComputeTotalScore(); + long standardisedScore = (long)Math.Round(ComputeTotalScore()); - if (Mode.Value == ScoringMode.Standardised) - TotalScore.Value = (long)Math.Round(standardisedScore); - else - TotalScore.Value = ConvertToClassic(standardisedScore); + TotalScore.Value = Mode.Value == ScoringMode.Standardised + ? standardisedScore + : convertToClassic(standardisedScore, MaxBasicJudgements, ClassicScoreMultiplier); } - public long ConvertToClassic(double standardised) + /// + /// Retrieves the total score from a in the given scoring mode. + /// + /// The mode to return the total score in. + /// The score to get the total score of. + /// The total score. + public long ComputeScore(ScoringMode mode, ScoreInfo scoreInfo) + { + int maxBasicJudgements = scoreInfo.MaximumStatistics.Where(k => k.Key.IsBasic()) + .Select(k => k.Value) + .DefaultIfEmpty(0) + .Sum(); + + return mode == ScoringMode.Standardised + ? scoreInfo.TotalScore + : convertToClassic(scoreInfo.TotalScore, maxBasicJudgements, ClassicScoreMultiplier); + } + + /// + /// Converts a standardised total score to the classic score. + /// + /// The standardised score. + /// The maximum possible number of basic judgements. + /// The classic multiplier. + /// The classic score. + private static long convertToClassic(long score, int maxBasicJudgements, double classicMultiplier) { // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. - double scaledRawScore = standardised / MAX_SCORE; - return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, MaxBasicJudgements), 2) * ClassicScoreMultiplier); + double scaledRawScore = score / MAX_SCORE; + return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, maxBasicJudgements), 2) * classicMultiplier); } protected abstract double ComputeTotalScore(); diff --git a/osu.Game/Scoring/IScoreInfo.cs b/osu.Game/Scoring/IScoreInfo.cs index 289679a724..ffc30384d2 100644 --- a/osu.Game/Scoring/IScoreInfo.cs +++ b/osu.Game/Scoring/IScoreInfo.cs @@ -15,6 +15,9 @@ namespace osu.Game.Scoring { IUser User { get; } + /// + /// The standardised total score. + /// long TotalScore { get; } int MaxCombo { get; } diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 0674947f30..f616c6db6d 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -107,15 +107,13 @@ namespace osu.Game.Scoring /// The total score. public long GetTotalScore([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised) { + // Shortcut to avoid potentially creating many ruleset objects in the default scoring mode. if (mode == ScoringMode.Standardised) return score.TotalScore; - var ruleset = score.Ruleset.CreateInstance(); - var scoreProcessor = ruleset.CreateScoreProcessor(); - scoreProcessor.Mods.Value = score.Mods; - - // Todo: This loses precision because we're dealing with pre-rounded total scores. - return scoreProcessor.ConvertToClassic(score.TotalScore); + return score.Ruleset.CreateInstance() + .CreateScoreProcessor() + .ComputeScore(mode, score); } /// From 829e47d30b279ca949b9b2f02d57724a9048e27e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 17:47:25 +0900 Subject: [PATCH 05/66] Add MaxTotalScore for performance breakdown calculator --- .../Rulesets/Difficulty/PerformanceBreakdownCalculator.cs | 6 +++--- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs index 03bd0f7509..3dd7f934a8 100644 --- a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs @@ -62,13 +62,13 @@ namespace osu.Game.Rulesets.Difficulty .GroupBy(hr => hr, (hr, list) => (hitResult: hr, count: list.Count())) .ToDictionary(pair => pair.hitResult, pair => pair.count); perfectPlay.Statistics = statistics; + perfectPlay.MaximumStatistics = statistics; // calculate total score ScoreProcessor scoreProcessor = ruleset.CreateScoreProcessor(); scoreProcessor.Mods.Value = perfectPlay.Mods; - - // Todo: - // perfectPlay.TotalScore = scoreProcessor.ComputeScore(ScoringMode.Standardised, perfectPlay); + scoreProcessor.ApplyBeatmap(playableBeatmap); + perfectPlay.TotalScore = scoreProcessor.MaxTotalScore; // compute rank achieved // default to SS, then adjust the rank with mods diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index cbcf0dceaf..ebecc39aa7 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -97,6 +97,11 @@ namespace osu.Game.Rulesets.Scoring /// public readonly Ruleset Ruleset; + /// + /// The maximum achievable total score. + /// + public long MaxTotalScore { get; private set; } + /// /// The sum of all basic judgements at the current time. /// @@ -334,6 +339,8 @@ namespace osu.Game.Rulesets.Scoring maximumResultCounts.Clear(); maximumResultCounts.AddRange(scoreResultCounts); + + MaxTotalScore = TotalScore.Value; } scoreResultCounts.Clear(); From 510b8e4c7887df92574ec0963154082a9ebb8347 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 18:53:43 +0900 Subject: [PATCH 06/66] Remove ScoreManager.Mode, handle per-use --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 48 +------------------ .../Scoring/Legacy/ScoreInfoExtensions.cs | 45 +++++++++++++++++ osu.Game/Scoring/ScoreManager.cs | 12 +---- .../Play/HUD/GameplayLeaderboardScore.cs | 18 ++++++- .../Screens/Play/HUD/GameplayScoreCounter.cs | 5 +- .../Screens/Play/HUD/ILeaderboardScore.cs | 4 ++ .../Play/HUD/SoloGameplayLeaderboard.cs | 18 ++----- osu.Game/Screens/Play/Player.cs | 3 -- 8 files changed, 77 insertions(+), 76 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index ebecc39aa7..bda2d7140d 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Scoring { public abstract partial class ScoreProcessor : JudgementProcessor { - protected const double MAX_SCORE = 1000000; + public const double MAX_SCORE = 1000000; private const double accuracy_cutoff_x = 1; private const double accuracy_cutoff_s = 0.95; @@ -76,11 +76,6 @@ namespace osu.Game.Rulesets.Scoring /// public readonly BindableInt HighestCombo = new BindableInt(); - /// - /// The used to calculate scores. - /// - public readonly Bindable Mode = new Bindable(); - /// /// The s collected during gameplay thus far. /// Intended for use with various statistics displays. @@ -173,7 +168,6 @@ namespace osu.Game.Rulesets.Scoring Rank.Value = mod.AdjustRank(Rank.Value, accuracy.NewValue); }; - Mode.ValueChanged += _ => updateScore(); Mods.ValueChanged += mods => { ScoreMultiplier = 1; @@ -278,45 +272,7 @@ namespace osu.Game.Rulesets.Scoring private void updateScore() { Accuracy.Value = currentMaxBasicScore > 0 ? currentBasicScore / currentMaxBasicScore : 1; - - long standardisedScore = (long)Math.Round(ComputeTotalScore()); - - TotalScore.Value = Mode.Value == ScoringMode.Standardised - ? standardisedScore - : convertToClassic(standardisedScore, MaxBasicJudgements, ClassicScoreMultiplier); - } - - /// - /// Retrieves the total score from a in the given scoring mode. - /// - /// The mode to return the total score in. - /// The score to get the total score of. - /// The total score. - public long ComputeScore(ScoringMode mode, ScoreInfo scoreInfo) - { - int maxBasicJudgements = scoreInfo.MaximumStatistics.Where(k => k.Key.IsBasic()) - .Select(k => k.Value) - .DefaultIfEmpty(0) - .Sum(); - - return mode == ScoringMode.Standardised - ? scoreInfo.TotalScore - : convertToClassic(scoreInfo.TotalScore, maxBasicJudgements, ClassicScoreMultiplier); - } - - /// - /// Converts a standardised total score to the classic score. - /// - /// The standardised score. - /// The maximum possible number of basic judgements. - /// The classic multiplier. - /// The classic score. - private static long convertToClassic(long score, int maxBasicJudgements, double classicMultiplier) - { - // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. - // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. - double scaledRawScore = score / MAX_SCORE; - return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, maxBasicJudgements), 2) * classicMultiplier); + TotalScore.Value = (long)Math.Round(ComputeTotalScore()); } protected abstract double ComputeTotalScore(); diff --git a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs index e42f6caf26..af991c7ea3 100644 --- a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs +++ b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs @@ -3,13 +3,58 @@ #nullable disable +using System; using System.Collections.Generic; +using System.Linq; using osu.Game.Rulesets.Scoring; namespace osu.Game.Scoring.Legacy { public static class ScoreInfoExtensions { + public static long GetDisplayScore(this ScoreProcessor scoreProcessor, ScoringMode mode) + => getDisplayScore(scoreProcessor.Ruleset.RulesetInfo.OnlineID, scoreProcessor.TotalScore.Value, mode, scoreProcessor.MaximumStatistics); + + public static long GetDisplayScore(this ScoreInfo scoreInfo, ScoringMode mode) + => getDisplayScore(scoreInfo.Ruleset.OnlineID, scoreInfo.TotalScore, mode, scoreInfo.MaximumStatistics); + + private static long getDisplayScore(int rulesetId, long score, ScoringMode mode, IReadOnlyDictionary maximumStatistics) + { + if (mode == ScoringMode.Standardised) + return score; + + double multiplier; + + switch (rulesetId) + { + case 0: + multiplier = 36; + break; + + case 1: + multiplier = 22; + break; + + case 2: + multiplier = 28; + break; + + case 3: + multiplier = 16; + break; + + default: + return score; + } + + int maxBasicJudgements = maximumStatistics.Where(k => k.Key.IsBasic()).Select(k => k.Value).DefaultIfEmpty(0).Sum(); + + // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. + // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. + double scaledRawScore = score / ScoreProcessor.MAX_SCORE; + return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, maxBasicJudgements), 2) * multiplier); + } + public static int? GetCountGeki(this ScoreInfo scoreInfo) { switch (scoreInfo.Ruleset.OnlineID) diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index f616c6db6d..fa5a9fc7c1 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -20,6 +20,7 @@ using osu.Game.Overlays.Notifications; using osu.Game.Rulesets; using osu.Game.Rulesets.Scoring; using osu.Game.Online.API; +using osu.Game.Scoring.Legacy; namespace osu.Game.Scoring { @@ -105,16 +106,7 @@ namespace osu.Game.Scoring /// The to calculate the total score of. /// The to return the total score as. /// The total score. - public long GetTotalScore([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised) - { - // Shortcut to avoid potentially creating many ruleset objects in the default scoring mode. - if (mode == ScoringMode.Standardised) - return score.TotalScore; - - return score.Ruleset.CreateInstance() - .CreateScoreProcessor() - .ComputeScore(mode, score); - } + public long GetTotalScore([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised) => score.GetDisplayScore(mode); /// /// Retrieves the maximum achievable combo for the provided score. diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 07b80feb3e..74a3925435 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -11,8 +11,10 @@ using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using osu.Game.Rulesets.Scoring; using osu.Game.Users; using osu.Game.Users.Drawables; using osu.Game.Utils; @@ -55,6 +57,7 @@ namespace osu.Game.Screens.Play.HUD public BindableInt Combo { get; } = new BindableInt(); public BindableBool HasQuit { get; } = new BindableBool(); public Bindable DisplayOrder { get; } = new Bindable(); + public Func GetDisplayScore { get; set; } public Color4? BackgroundColour { get; set; } @@ -100,6 +103,8 @@ namespace osu.Game.Screens.Play.HUD private Container scoreComponents; + private IBindable scoreDisplayMode; + /// /// Creates a new . /// @@ -112,10 +117,12 @@ namespace osu.Game.Screens.Play.HUD AutoSizeAxes = Axes.X; Height = PANEL_HEIGHT; + + GetDisplayScore = _ => TotalScore.Value; } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OsuColour colours, OsuConfigManager osuConfigManager) { Container avatarContainer; @@ -286,7 +293,9 @@ namespace osu.Game.Screens.Play.HUD LoadComponentAsync(new DrawableAvatar(User), avatarContainer.Add); - TotalScore.BindValueChanged(v => scoreText.Text = v.NewValue.ToString("N0"), true); + scoreDisplayMode = osuConfigManager.GetBindable(OsuSetting.ScoreDisplayMode); + scoreDisplayMode.BindValueChanged(_ => updateScore()); + TotalScore.BindValueChanged(_ => updateScore(), true); Accuracy.BindValueChanged(v => { @@ -303,6 +312,11 @@ namespace osu.Game.Screens.Play.HUD HasQuit.BindValueChanged(_ => updateState()); } + private void updateScore() + { + scoreText.Text = GetDisplayScore(scoreDisplayMode.Value).ToString("N0"); + } + protected override void LoadComplete() { base.LoadComplete(); diff --git a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs index a11cccd97c..a696d2cad7 100644 --- a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs +++ b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs @@ -9,12 +9,14 @@ using osu.Framework.Bindables; using osu.Game.Configuration; using osu.Game.Graphics.UserInterface; using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring.Legacy; namespace osu.Game.Screens.Play.HUD { public abstract partial class GameplayScoreCounter : ScoreCounter { private Bindable scoreDisplayMode; + private Bindable totalScoreBindable; protected GameplayScoreCounter() : base(6) @@ -42,7 +44,8 @@ namespace osu.Game.Screens.Play.HUD } }, true); - Current.BindTo(scoreProcessor.TotalScore); + totalScoreBindable = scoreProcessor.TotalScore.GetBoundCopy(); + totalScoreBindable.BindValueChanged(_ => Current.Value = scoreProcessor.GetDisplayScore(scoreDisplayMode.Value), true); } } } diff --git a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs index 428390f90c..cc1d83e0c7 100644 --- a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs @@ -3,7 +3,9 @@ #nullable disable +using System; using osu.Framework.Bindables; +using osu.Game.Rulesets.Scoring; namespace osu.Game.Screens.Play.HUD { @@ -20,5 +22,7 @@ namespace osu.Game.Screens.Play.HUD /// Lower numbers will appear higher in cases of ties. /// Bindable DisplayOrder { get; } + + Func GetDisplayScore { get; set; } } } diff --git a/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs index 9f92880919..e9bb1d2101 100644 --- a/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs +++ b/osu.Game/Screens/Play/HUD/SoloGameplayLeaderboard.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -10,6 +9,7 @@ using osu.Game.Configuration; using osu.Game.Online.API.Requests; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; using osu.Game.Screens.Select; using osu.Game.Users; @@ -27,15 +27,9 @@ namespace osu.Game.Screens.Play.HUD public readonly IBindableList Scores = new BindableList(); - // hold references to ensure bindables are updated. - private readonly List> scoreBindables = new List>(); - [Resolved] private ScoreProcessor scoreProcessor { get; set; } = null!; - [Resolved] - private ScoreManager scoreManager { get; set; } = null!; - /// /// Whether the leaderboard should be visible regardless of the configuration value. /// This is true by default, but can be changed. @@ -70,7 +64,6 @@ namespace osu.Game.Screens.Play.HUD private void showScores() { Clear(); - scoreBindables.Clear(); if (!Scores.Any()) return; @@ -79,12 +72,8 @@ namespace osu.Game.Screens.Play.HUD { var score = Add(s.User, false); - var bindableTotal = scoreManager.GetBindableTotalScore(s); - - // Direct binding not possible due to differing types (see https://github.com/ppy/osu/issues/20298). - bindableTotal.BindValueChanged(total => score.TotalScore.Value = total.NewValue, true); - scoreBindables.Add(bindableTotal); - + score.GetDisplayScore = s.GetDisplayScore; + score.TotalScore.Value = s.TotalScore; score.Accuracy.Value = s.Accuracy; score.Combo.Value = s.MaxCombo; score.DisplayOrder.Value = s.OnlineID > 0 ? s.OnlineID : s.Date.ToUnixTimeSeconds(); @@ -92,6 +81,7 @@ namespace osu.Game.Screens.Play.HUD ILeaderboardScore local = Add(trackingUser, true); + local.GetDisplayScore = scoreProcessor.GetDisplayScore; local.TotalScore.BindTarget = scoreProcessor.TotalScore; local.Accuracy.BindTarget = scoreProcessor.Accuracy; local.Combo.BindTarget = scoreProcessor.HighestCombo; diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 5174adfc06..18ea9d0acb 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -237,9 +237,6 @@ namespace osu.Game.Screens.Play dependencies.CacheAs(HealthProcessor); - if (!ScoreProcessor.Mode.Disabled) - config.BindWith(OsuSetting.ScoreDisplayMode, ScoreProcessor.Mode); - InternalChild = GameplayClockContainer = CreateGameplayClockContainer(Beatmap.Value, DrawableRuleset.GameplayStartTime); AddInternal(screenSuspension = new ScreenSuspensionHandler(GameplayClockContainer)); From f3591f83a2d831a737f094afed372c365c3a40a5 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 18:55:10 +0900 Subject: [PATCH 07/66] Remove ScoreManager.GetTotalScore() --- osu.Game/Scoring/ScoreManager.cs | 17 ++++------------- osu.Game/Screens/Ranking/ScorePanelList.cs | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index fa5a9fc7c1..d5509538fd 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -75,7 +75,7 @@ namespace osu.Game.Scoring /// The array of s to reorder. /// The given ordered by decreasing total score. public IEnumerable OrderByTotalScore(IEnumerable scores) - => scores.OrderByDescending(s => GetTotalScore(s)) + => scores.OrderByDescending(s => s.TotalScore) .ThenBy(s => s.OnlineID) // Local scores may not have an online ID. Fall back to date in these cases. .ThenBy(s => s.Date); @@ -88,7 +88,7 @@ namespace osu.Game.Scoring /// /// The to retrieve the bindable for. /// The bindable containing the total score. - public Bindable GetBindableTotalScore([NotNull] ScoreInfo score) => new TotalScoreBindable(score, this, configManager); + public Bindable GetBindableTotalScore([NotNull] ScoreInfo score) => new TotalScoreBindable(score, configManager); /// /// Retrieves a bindable that represents the formatted total score string of a . @@ -100,14 +100,6 @@ namespace osu.Game.Scoring /// The bindable containing the formatted total score string. public Bindable GetBindableTotalScoreString([NotNull] ScoreInfo score) => new TotalScoreStringBindable(GetBindableTotalScore(score)); - /// - /// Retrieves the total score of a in the given . - /// - /// The to calculate the total score of. - /// The to return the total score as. - /// The total score. - public long GetTotalScore([NotNull] ScoreInfo score, ScoringMode mode = ScoringMode.Standardised) => score.GetDisplayScore(mode); - /// /// Retrieves the maximum achievable combo for the provided score. /// @@ -126,12 +118,11 @@ namespace osu.Game.Scoring /// Creates a new . /// /// The to provide the total score of. - /// The . /// The config. - public TotalScoreBindable(ScoreInfo score, ScoreManager scoreManager, OsuConfigManager configManager) + public TotalScoreBindable(ScoreInfo score, OsuConfigManager configManager) { configManager?.BindWith(OsuSetting.ScoreDisplayMode, scoringMode); - scoringMode.BindValueChanged(mode => Value = scoreManager.GetTotalScore(score, mode.NewValue), true); + scoringMode.BindValueChanged(mode => Value = score.GetDisplayScore(mode.NewValue), true); } } diff --git a/osu.Game/Screens/Ranking/ScorePanelList.cs b/osu.Game/Screens/Ranking/ScorePanelList.cs index 29dec42083..1f93389e94 100644 --- a/osu.Game/Screens/Ranking/ScorePanelList.cs +++ b/osu.Game/Screens/Ranking/ScorePanelList.cs @@ -149,7 +149,7 @@ namespace osu.Game.Screens.Ranking var score = trackingContainer.Panel.Score; - flow.SetLayoutPosition(trackingContainer, scoreManager.GetTotalScore(score)); + flow.SetLayoutPosition(trackingContainer, score.TotalScore); trackingContainer.Show(); From 808818768bf46710191b7071f67f512078cddd2e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 19:02:49 +0900 Subject: [PATCH 08/66] Add TotalScore to replay frame headers --- osu.Game/Online/Spectator/FrameHeader.cs | 10 +++++++++- osu.Game/Online/Spectator/SpectatorScoreProcessor.cs | 4 +--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Spectator/FrameHeader.cs b/osu.Game/Online/Spectator/FrameHeader.cs index b6dcd8aaa5..4d1ff23530 100644 --- a/osu.Game/Online/Spectator/FrameHeader.cs +++ b/osu.Game/Online/Spectator/FrameHeader.cs @@ -44,6 +44,12 @@ namespace osu.Game.Online.Spectator [Key(4)] public DateTimeOffset ReceivedTime { get; set; } + /// + /// The total score. + /// + [Key(5)] + public long TotalScore { get; set; } + /// /// Construct header summary information from a point-in-time reference to a score which is actively being played. /// @@ -53,6 +59,7 @@ namespace osu.Game.Online.Spectator Combo = score.Combo; MaxCombo = score.MaxCombo; Accuracy = score.Accuracy; + TotalScore = score.TotalScore; // copy for safety Statistics = new Dictionary(score.Statistics); @@ -60,13 +67,14 @@ namespace osu.Game.Online.Spectator [JsonConstructor] [SerializationConstructor] - public FrameHeader(double accuracy, int combo, int maxCombo, Dictionary statistics, DateTimeOffset receivedTime) + public FrameHeader(double accuracy, int combo, int maxCombo, Dictionary statistics, DateTimeOffset receivedTime, long totalScore) { Combo = combo; MaxCombo = maxCombo; Accuracy = accuracy; Statistics = statistics; ReceivedTime = receivedTime; + TotalScore = totalScore; } } } diff --git a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs index cb23164c00..90b584a89f 100644 --- a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs +++ b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs @@ -153,12 +153,10 @@ namespace osu.Game.Online.Spectator scoreInfo.MaxCombo = frame.Header.MaxCombo; scoreInfo.Statistics = frame.Header.Statistics; scoreInfo.MaximumStatistics = spectatorState.MaximumStatistics; + scoreInfo.TotalScore = frame.Header.TotalScore; Accuracy.Value = frame.Header.Accuracy; Combo.Value = frame.Header.Combo; - - // Todo: - // TotalScore.Value = scoreProcessor.ComputeScore(Mode.Value, scoreInfo); } protected override void Dispose(bool isDisposing) From c33e4fe75ea22c129bfbae9a5df268d8036a1ddb Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 20:10:28 +0900 Subject: [PATCH 09/66] Remove unnecessary override --- .../Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs index 7b77785c7a..b0e4585986 100644 --- a/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs +++ b/osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs @@ -6,14 +6,12 @@ using System; using System.Diagnostics; using System.Linq; -using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Screens; using osu.Game.Extensions; using osu.Game.Online.Rooms; using osu.Game.Rulesets; -using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Play; using osu.Game.Screens.Ranking; @@ -63,14 +61,6 @@ namespace osu.Game.Screens.OnlinePlay.Playlists return new PlaylistsResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, true); } - protected override async Task PrepareScoreForResultsAsync(Score score) - { - await base.PrepareScoreForResultsAsync(score).ConfigureAwait(false); - - // Todo: - // Score.ScoreInfo.TotalScore = ScoreProcessor.ComputeScore(ScoringMode.Standardised, Score.ScoreInfo); - } - protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); From ef86be6d21c56a3350bc0969705a91074d7b112d Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 20:29:26 +0900 Subject: [PATCH 10/66] Fix base score added for non-accuracy-affecting objects --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 44 ++++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index bda2d7140d..1162b6ac04 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -98,14 +98,20 @@ namespace osu.Game.Rulesets.Scoring public long MaxTotalScore { get; private set; } /// - /// The sum of all basic judgements at the current time. + /// The sum of all accuracy-affecting judgements at the current time. /// - private double currentBasicScore; + /// + /// Used to compute accuracy. + /// + private double currentBaseScore; /// - /// The maximum sum of basic judgements at the current time. + /// The maximum sum of accuracy-affecting judgements at the current time. /// - private double currentMaxBasicScore; + /// + /// Used to compute accuracy. + /// + private double currentMaxBaseScore; /// /// The total count of basic judgements in the beatmap. @@ -206,8 +212,11 @@ namespace osu.Game.Rulesets.Scoring if (result.Type.IsBasic()) CurrentBasicJudgements++; - currentMaxBasicScore += Judgement.ToNumericResult(result.Judgement.MaxResult); - currentBasicScore += Judgement.ToNumericResult(result.Type); + if (result.Type.AffectsAccuracy()) + { + currentMaxBaseScore += Judgement.ToNumericResult(result.Judgement.MaxResult); + currentBaseScore += Judgement.ToNumericResult(result.Type); + } AddScoreChange(result); @@ -241,8 +250,11 @@ namespace osu.Game.Rulesets.Scoring if (result.Type.IsBasic()) CurrentBasicJudgements--; - currentMaxBasicScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); - currentBasicScore -= Judgement.ToNumericResult(result.Type); + if (result.Type.AffectsAccuracy()) + { + currentMaxBaseScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); + currentBaseScore -= Judgement.ToNumericResult(result.Type); + } RemoveScoreChange(result); @@ -257,7 +269,8 @@ namespace osu.Game.Rulesets.Scoring { if (result.Type.IsBonus()) BonusPortion += Judgement.ToNumericResult(result.Type); - else + + if (result.Type.AffectsCombo()) ComboPortion += Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); } @@ -265,13 +278,14 @@ namespace osu.Game.Rulesets.Scoring { if (result.Type.IsBonus()) BonusPortion -= Judgement.ToNumericResult(result.Type); - else + + if (result.Type.AffectsCombo()) ComboPortion -= Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); } private void updateScore() { - Accuracy.Value = currentMaxBasicScore > 0 ? currentBasicScore / currentMaxBasicScore : 1; + Accuracy.Value = currentMaxBaseScore > 0 ? currentBaseScore / currentMaxBaseScore : 1; TotalScore.Value = (long)Math.Round(ComputeTotalScore()); } @@ -301,8 +315,8 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts.Clear(); - currentBasicScore = 0; - currentMaxBasicScore = 0; + currentBaseScore = 0; + currentMaxBaseScore = 0; CurrentBasicJudgements = 0; ComboPortion = 0; BonusPortion = 0; @@ -314,8 +328,8 @@ namespace osu.Game.Rulesets.Scoring Rank.Value = ScoreRank.X; HighestCombo.Value = 0; - currentBasicScore = 0; - currentMaxBasicScore = 0; + currentBaseScore = 0; + currentMaxBaseScore = 0; } /// From 00e0411369a14e724705fcc35f2088832aa91bcb Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 20:37:13 +0900 Subject: [PATCH 11/66] Fix/rework ModAccuracyChallenge calculation --- .../Rulesets/Mods/ModAccuracyChallenge.cs | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs b/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs index 13b8ad5d84..57284b7eaa 100644 --- a/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs +++ b/osu.Game/Rulesets/Mods/ModAccuracyChallenge.cs @@ -42,9 +42,29 @@ namespace osu.Game.Rulesets.Mods Value = 0.9, }; - private ScoreProcessor scoreProcessor = null!; + private int baseScore; + private int maxBaseScore; - public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) => this.scoreProcessor = scoreProcessor; + public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor) + { + scoreProcessor.NewJudgement += j => + { + if (!j.Type.AffectsAccuracy()) + return; + + baseScore += Judgement.ToNumericResult(j.Type); + maxBaseScore += Judgement.ToNumericResult(j.Judgement.MaxResult); + }; + + scoreProcessor.JudgementReverted += j => + { + if (!j.Type.AffectsAccuracy()) + return; + + baseScore -= Judgement.ToNumericResult(j.Type); + maxBaseScore -= Judgement.ToNumericResult(j.Judgement.MaxResult); + }; + } public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank; @@ -58,16 +78,11 @@ namespace osu.Game.Rulesets.Mods private double getAccuracyWithImminentResultAdded(JudgementResult result) { - var score = new ScoreInfo { Ruleset = scoreProcessor.Ruleset.RulesetInfo }; + // baseScore and maxBaseScore are always exactly one judgement behind because the health processor is processed first (see: Player). + int imminentBaseScore = baseScore + Judgement.ToNumericResult(result.Type); + int imminentMaxBaseScore = maxBaseScore + Judgement.ToNumericResult(result.Judgement.MaxResult); - // This is super ugly, but if we don't do it this way we will not have the most recent result added to the accuracy value. - // Hopefully we can improve this in the future. - scoreProcessor.PopulateScore(score); - score.Statistics[result.Type]++; - - // Todo: - return 0; - // return scoreProcessor.ComputeAccuracy(score); + return imminentMaxBaseScore > 0 ? imminentBaseScore / (double)imminentMaxBaseScore : 1; } } } From 8b56a3f87d568dfd2c9fdf63b8bd534181b18d2f Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 18 May 2023 20:52:40 +0900 Subject: [PATCH 12/66] Remove ClassicScoreMultiplier and DefaultScoreProcessor --- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../Scoring/CatchScoreProcessor.cs | 8 +++---- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- .../Scoring/ManiaScoreProcessor.cs | 8 +++---- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- .../Scoring/OsuScoreProcessor.cs | 8 +++---- .../Scoring/TaikoScoreProcessor.cs | 8 +++---- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 21 +------------------ osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 20 +++++++++++------- 10 files changed, 29 insertions(+), 52 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index e2255fa6f7..8a0b8250d5 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Catch { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableCatchRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(this); + public override ScoreProcessor CreateScoreProcessor() => new CatchScoreProcessor(); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new CatchBeatmapConverter(beatmap, this); diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 9c5359ebeb..435b39150b 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -13,15 +13,13 @@ namespace osu.Game.Rulesets.Catch.Scoring private const int combo_cap = 200; private const double combo_base = 4; - protected override double ClassicScoreMultiplier => 28; - private double tinyDropletScale; private int maximumTinyDroplets; private int hitTinyDroplets; - public CatchScoreProcessor(Ruleset ruleset) - : base(ruleset) + public CatchScoreProcessor() + : base(new CatchRuleset()) { } diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index c6065c9b96..d324682989 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Mania public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableManiaRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this); + public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(); public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new ManiaHealthProcessor(drainStartTime); diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 19f8a4a639..1c55f9ffce 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -11,10 +11,8 @@ namespace osu.Game.Rulesets.Mania.Scoring { private const double combo_base = 4; - protected override double ClassicScoreMultiplier => 16; - - public ManiaScoreProcessor(Ruleset ruleset) - : base(ruleset) + public ManiaScoreProcessor() + : base(new ManiaRuleset()) { } diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 497d405436..922594a93a 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -45,7 +45,7 @@ namespace osu.Game.Rulesets.Osu { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableOsuRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(this); + public override ScoreProcessor CreateScoreProcessor() => new OsuScoreProcessor(); public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => new OsuBeatmapConverter(beatmap, this); diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index f8cbf1a641..d4677d92c1 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -8,10 +8,8 @@ namespace osu.Game.Rulesets.Osu.Scoring { public partial class OsuScoreProcessor : ScoreProcessor { - protected override double ClassicScoreMultiplier => 36; - - public OsuScoreProcessor(Ruleset ruleset) - : base(ruleset) + public OsuScoreProcessor() + : base(new OsuRuleset()) { } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index 71eb0b1602..e2b442739b 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -1,4 +1,4 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System; @@ -12,10 +12,8 @@ namespace osu.Game.Rulesets.Taiko.Scoring { private const double combo_base = 4; - protected override double ClassicScoreMultiplier => 22; - - public TaikoScoreProcessor(Ruleset ruleset) - : base(ruleset) + public TaikoScoreProcessor() + : base(new TaikoRuleset()) { } diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index 599d0dc33c..a35fdb890d 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Taiko { public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList? mods = null) => new DrawableTaikoRuleset(this, beatmap, mods); - public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(this); + public override ScoreProcessor CreateScoreProcessor() => new TaikoScoreProcessor(); public override HealthProcessor CreateHealthProcessor(double drainStartTime) => new TaikoHealthProcessor(); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 2e7a58b96c..a77068eb14 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -232,7 +232,7 @@ namespace osu.Game.Rulesets /// Creates a for this . /// /// The score processor. - public virtual ScoreProcessor CreateScoreProcessor() => new DefaultScoreProcessor(this); + public virtual ScoreProcessor CreateScoreProcessor() => new ScoreProcessor(this); /// /// Creates a for this . @@ -381,23 +381,4 @@ namespace osu.Game.Rulesets /// public virtual RulesetSetupSection? CreateEditorSetupSection() => null; } - - public partial class DefaultScoreProcessor : ScoreProcessor - { - public DefaultScoreProcessor(Ruleset ruleset) - : base(ruleset) - { - } - - protected override double ComputeTotalScore() - { - return - (int)Math.Round - (( - 700000 * ComboPortion / MaxComboPortion + - 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + - BonusPortion - ) * ScoreMultiplier); - } - } } diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 1162b6ac04..4ded3d5d91 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -18,7 +18,7 @@ using osu.Game.Scoring; namespace osu.Game.Rulesets.Scoring { - public abstract partial class ScoreProcessor : JudgementProcessor + public partial class ScoreProcessor : JudgementProcessor { public const double MAX_SCORE = 1000000; @@ -82,11 +82,6 @@ namespace osu.Game.Rulesets.Scoring /// public IReadOnlyList HitEvents => hitEvents; - /// - /// An arbitrary multiplier to scale scores in the scoring mode. - /// - protected virtual double ClassicScoreMultiplier => 36; - /// /// The ruleset this score processor is valid for. /// @@ -162,7 +157,7 @@ namespace osu.Game.Rulesets.Scoring private readonly List hitEvents = new List(); private HitObject? lastHitObject; - protected ScoreProcessor(Ruleset ruleset) + public ScoreProcessor(Ruleset ruleset) { Ruleset = ruleset; @@ -289,7 +284,16 @@ namespace osu.Game.Rulesets.Scoring TotalScore.Value = (long)Math.Round(ComputeTotalScore()); } - protected abstract double ComputeTotalScore(); + protected virtual double ComputeTotalScore() + { + return + (int)Math.Round + (( + 700000 * ComboPortion / MaxComboPortion + + 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + BonusPortion + ) * ScoreMultiplier); + } /// /// Resets this ScoreProcessor to a default state. From 035d0d5c9ce27d79d84ffee0b24b89064699b538 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 13:16:57 +0900 Subject: [PATCH 13/66] Fix multiplayer leaderboard not working --- .../Spectator/SpectatorScoreProcessor.cs | 25 ++++++++++--------- .../HUD/MultiplayerGameplayLeaderboard.cs | 1 + 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs index 90b584a89f..3242e21994 100644 --- a/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs +++ b/osu.Game/Online/Spectator/SpectatorScoreProcessor.cs @@ -14,6 +14,7 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; namespace osu.Game.Online.Spectator { @@ -46,7 +47,9 @@ namespace osu.Game.Online.Spectator /// /// The applied s. /// - public IReadOnlyList Mods => scoreProcessor?.Mods.Value ?? Array.Empty(); + public IReadOnlyList Mods => scoreInfo?.Mods ?? Array.Empty(); + + public Func GetDisplayScore => mode => scoreInfo?.GetDisplayScore(mode) ?? 0; private IClock? referenceClock; @@ -70,7 +73,6 @@ namespace osu.Game.Online.Spectator private readonly int userId; private SpectatorState? spectatorState; - private ScoreProcessor? scoreProcessor; private ScoreInfo? scoreInfo; public SpectatorScoreProcessor(int userId) @@ -94,19 +96,15 @@ namespace osu.Game.Online.Spectator { if (!spectatorStates.TryGetValue(userId, out var userState) || userState.BeatmapID == null || userState.RulesetID == null) { - scoreProcessor?.RemoveAndDisposeImmediately(); - scoreProcessor = null; scoreInfo = null; spectatorState = null; replayFrames.Clear(); return; } - if (scoreProcessor != null) + if (scoreInfo != null) return; - Debug.Assert(scoreInfo == null); - RulesetInfo? rulesetInfo = rulesetStore.GetRuleset(userState.RulesetID.Value); if (rulesetInfo == null) return; @@ -114,9 +112,11 @@ namespace osu.Game.Online.Spectator Ruleset ruleset = rulesetInfo.CreateInstance(); spectatorState = userState; - scoreInfo = new ScoreInfo { Ruleset = rulesetInfo }; - scoreProcessor = ruleset.CreateScoreProcessor(); - scoreProcessor.Mods.Value = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray(); + scoreInfo = new ScoreInfo + { + Ruleset = rulesetInfo, + Mods = userState.Mods.Select(m => m.ToMod(ruleset)).ToArray() + }; } private void onNewFrames(int incomingUserId, FrameDataBundle bundle) @@ -126,7 +126,7 @@ namespace osu.Game.Online.Spectator Schedule(() => { - if (scoreProcessor == null) + if (scoreInfo == null) return; replayFrames.Add(new TimedFrame(bundle.Frames.First().Time, bundle.Header)); @@ -140,7 +140,6 @@ namespace osu.Game.Online.Spectator return; Debug.Assert(spectatorState != null); - Debug.Assert(scoreProcessor != null); int frameIndex = replayFrames.BinarySearch(new TimedFrame(ReferenceClock.CurrentTime)); if (frameIndex < 0) @@ -150,6 +149,7 @@ namespace osu.Game.Online.Spectator TimedFrame frame = replayFrames[frameIndex]; Debug.Assert(frame.Header != null); + scoreInfo.Accuracy = frame.Header.Accuracy; scoreInfo.MaxCombo = frame.Header.MaxCombo; scoreInfo.Statistics = frame.Header.Statistics; scoreInfo.MaximumStatistics = spectatorState.MaximumStatistics; @@ -157,6 +157,7 @@ namespace osu.Game.Online.Spectator Accuracy.Value = frame.Header.Accuracy; Combo.Value = frame.Header.Combo; + TotalScore.Value = frame.Header.TotalScore; } protected override void Dispose(bool isDisposing) diff --git a/osu.Game/Screens/Play/HUD/MultiplayerGameplayLeaderboard.cs b/osu.Game/Screens/Play/HUD/MultiplayerGameplayLeaderboard.cs index 620f3718c2..922def6174 100644 --- a/osu.Game/Screens/Play/HUD/MultiplayerGameplayLeaderboard.cs +++ b/osu.Game/Screens/Play/HUD/MultiplayerGameplayLeaderboard.cs @@ -98,6 +98,7 @@ namespace osu.Game.Screens.Play.HUD var trackedUser = UserScores[user.Id]; var leaderboardScore = Add(user, user.Id == api.LocalUser.Value.Id); + leaderboardScore.GetDisplayScore = trackedUser.ScoreProcessor.GetDisplayScore; leaderboardScore.Accuracy.BindTo(trackedUser.ScoreProcessor.Accuracy); leaderboardScore.TotalScore.BindTo(trackedUser.ScoreProcessor.TotalScore); leaderboardScore.Combo.BindTo(trackedUser.ScoreProcessor.Combo); From 4d14467d95cf3b0a1cab08b70a5408d587f056f7 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 13:23:04 +0900 Subject: [PATCH 14/66] Invert order of operations --- osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index e2b442739b..f86a6669ca 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -29,15 +29,15 @@ namespace osu.Game.Rulesets.Taiko.Scoring protected override void AddScoreChange(JudgementResult result) { var change = computeScoreChange(result); - BonusPortion += change.bonus; ComboPortion += change.combo; + BonusPortion += change.bonus; } protected override void RemoveScoreChange(JudgementResult result) { var change = computeScoreChange(result); - BonusPortion -= change.bonus; ComboPortion -= change.combo; + BonusPortion -= change.bonus; } private (double combo, double bonus) computeScoreChange(JudgementResult result) From 73544231de1c75263e0dc116890b5119350abc7a Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 14:06:46 +0900 Subject: [PATCH 15/66] Fix TestSceneTopLocalRank --- osu.Game.Tests/Resources/TestResources.cs | 2 +- .../Visual/SongSelect/TestSceneTopLocalRank.cs | 11 ++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tests/Resources/TestResources.cs b/osu.Game.Tests/Resources/TestResources.cs index a2d81c0a75..a77dc8d49b 100644 --- a/osu.Game.Tests/Resources/TestResources.cs +++ b/osu.Game.Tests/Resources/TestResources.cs @@ -179,7 +179,7 @@ namespace osu.Game.Tests.Resources BeatmapHash = beatmap.Hash, Ruleset = beatmap.Ruleset, Mods = new Mod[] { new TestModHardRock(), new TestModDoubleTime() }, - TotalScore = 2845370, + TotalScore = 284537, Accuracy = 0.95, MaxCombo = 999, Position = 1, diff --git a/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs b/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs index cf0de14541..79baae53e8 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestSceneTopLocalRank.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System.Diagnostics; using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; @@ -12,7 +11,6 @@ using osu.Framework.Platform; using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Rulesets; -using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Select.Carousel; using osu.Game.Tests.Resources; @@ -143,25 +141,20 @@ namespace osu.Game.Tests.Visual.SongSelect testScoreInfo.User = API.LocalUser.Value; testScoreInfo.Rank = ScoreRank.B; - testScoreInfo.TotalScore = scoreManager.GetTotalScore(testScoreInfo, ScoringMode.Classic); scoreManager.Import(testScoreInfo); }); AddUntilStep("B rank displayed", () => topLocalRank.DisplayedRank == ScoreRank.B); - AddStep("Add higher score for current user", () => + AddStep("Add higher-graded score for current user", () => { var testScoreInfo2 = TestResources.CreateTestScoreInfo(importedBeatmap); testScoreInfo2.User = API.LocalUser.Value; testScoreInfo2.Rank = ScoreRank.X; testScoreInfo2.Statistics = testScoreInfo2.MaximumStatistics; - testScoreInfo2.TotalScore = scoreManager.GetTotalScore(testScoreInfo2); - - // ensure second score has a total score (standardised) less than first one (classic) - // despite having better statistics, otherwise this test is pointless. - Debug.Assert(testScoreInfo2.TotalScore < testScoreInfo.TotalScore); + testScoreInfo2.TotalScore = testScoreInfo.TotalScore + 1; scoreManager.Import(testScoreInfo2); }); From 9a1d749020e365fe0519e5ca06a6b551370c4aa6 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 14:06:53 +0900 Subject: [PATCH 16/66] Fix TestSceneDrawableTaikoMascot --- .../Skinning/TestSceneDrawableTaikoMascot.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs b/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs index e4e68c7207..dd8748f6e3 100644 --- a/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs +++ b/osu.Game.Rulesets.Taiko.Tests/Skinning/TestSceneDrawableTaikoMascot.cs @@ -91,8 +91,9 @@ namespace osu.Game.Rulesets.Taiko.Tests.Skinning { prepareDrawableRulesetAndBeatmap(false); - assertStateAfterResult(new JudgementResult(new Hit(), new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle); - assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle); + var hit = new Hit(); + assertStateAfterResult(new JudgementResult(hit, new TaikoJudgement()) { Type = HitResult.Great }, TaikoMascotAnimationState.Idle); + assertStateAfterResult(new JudgementResult(new Hit.StrongNestedHit(hit), new TaikoStrongJudgement()) { Type = HitResult.IgnoreMiss }, TaikoMascotAnimationState.Idle); } [Test] From 7cbf48ffcff775dcfa77a5787fa72d0f89df7d8e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 14:09:19 +0900 Subject: [PATCH 17/66] Fix TestSceneScoring and incorrect combo calculations --- .../Scoring/CatchScoreProcessor.cs | 2 +- .../Scoring/ManiaScoreProcessor.cs | 2 +- .../Scoring/TaikoScoreProcessor.cs | 2 +- osu.Game.Tests/Visual/Gameplay/TestSceneScoring.cs | 11 ++++++----- osu.Game/Rulesets/Judgements/JudgementResult.cs | 5 +++++ osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 6 ++++-- 6 files changed, 18 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 435b39150b..ae3966ccc5 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -60,7 +60,7 @@ namespace osu.Game.Rulesets.Catch.Scoring if (result.Type.IsBonus()) return (0, Judgement.ToNumericResult(result.Type), 0); - return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(combo_cap, combo_base)), 0, 0); + return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(combo_cap, combo_base)), 0, 0); } protected override void Reset(bool storeResults) diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 1c55f9ffce..4c8f8ef65e 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Mania.Scoring if (result.Type.IsBonus()) return (0, Judgement.ToNumericResult(result.Type)); - return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(400, combo_base)), 0); + return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)), 0); } } } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index f86a6669ca..2ecd962d72 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -53,7 +53,7 @@ namespace osu.Game.Rulesets.Taiko.Scoring if (result.Type.IsBonus()) return (0, hitValue); - return (hitValue * Math.Min(Math.Max(0.5, Math.Log(result.ComboAtJudgement, combo_base)), Math.Log(400, combo_base)), 0); + return (hitValue * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)), 0); } } } diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneScoring.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneScoring.cs index 8fff07e6d8..2b378c8013 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneScoring.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneScoring.cs @@ -22,6 +22,7 @@ using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Scoring; +using osu.Game.Scoring.Legacy; using osuTK; using osuTK.Graphics; using osuTK.Input; @@ -124,8 +125,8 @@ namespace osu.Game.Tests.Visual.Gameplay graphs.Clear(); legend.Clear(); - runForProcessor("lazer-standardised", Color4.YellowGreen, new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Standardised } }); - runForProcessor("lazer-classic", Color4.MediumPurple, new ScoreProcessor(new OsuRuleset()) { Mode = { Value = ScoringMode.Classic } }); + runForProcessor("lazer-standardised", Color4.YellowGreen, new ScoreProcessor(new OsuRuleset()), ScoringMode.Standardised); + runForProcessor("lazer-classic", Color4.MediumPurple, new ScoreProcessor(new OsuRuleset()), ScoringMode.Classic); runScoreV1(); runScoreV2(); @@ -218,7 +219,7 @@ namespace osu.Game.Tests.Visual.Gameplay }); } - private void runForProcessor(string name, Color4 colour, ScoreProcessor processor) + private void runForProcessor(string name, Color4 colour, ScoreProcessor processor, ScoringMode mode) { int maxCombo = sliderMaxCombo.Current.Value; @@ -232,10 +233,10 @@ namespace osu.Game.Tests.Visual.Gameplay () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Great }), () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Ok }), () => processor.ApplyResult(new OsuJudgementResult(new HitCircle(), new OsuJudgement()) { Type = HitResult.Miss }), - () => (int)processor.TotalScore.Value); + () => processor.GetDisplayScore(mode)); } - private void runForAlgorithm(string name, Color4 colour, Action applyHit, Action applyNonPerfect, Action applyMiss, Func getTotalScore) + private void runForAlgorithm(string name, Color4 colour, Action applyHit, Action applyNonPerfect, Action applyMiss, Func getTotalScore) { int maxCombo = sliderMaxCombo.Current.Value; diff --git a/osu.Game/Rulesets/Judgements/JudgementResult.cs b/osu.Game/Rulesets/Judgements/JudgementResult.cs index bf29919e34..34d1f1f6e9 100644 --- a/osu.Game/Rulesets/Judgements/JudgementResult.cs +++ b/osu.Game/Rulesets/Judgements/JudgementResult.cs @@ -64,6 +64,11 @@ namespace osu.Game.Rulesets.Judgements /// public int ComboAtJudgement { get; internal set; } + /// + /// The combo after this occurred. + /// + public int ComboAfterJudgement { get; internal set; } + /// /// The highest combo achieved prior to this occurring. /// diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 4ded3d5d91..b014b12297 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -204,6 +204,8 @@ namespace osu.Game.Rulesets.Scoring else if (result.Type.BreaksCombo()) Combo.Value = 0; + result.ComboAfterJudgement = Combo.Value; + if (result.Type.IsBasic()) CurrentBasicJudgements++; @@ -266,7 +268,7 @@ namespace osu.Game.Rulesets.Scoring BonusPortion += Judgement.ToNumericResult(result.Type); if (result.Type.AffectsCombo()) - ComboPortion += Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); + ComboPortion += Judgement.ToNumericResult(result.Type) * (1 + result.ComboAfterJudgement / 10d); } protected virtual void RemoveScoreChange(JudgementResult result) @@ -275,7 +277,7 @@ namespace osu.Game.Rulesets.Scoring BonusPortion -= Judgement.ToNumericResult(result.Type); if (result.Type.AffectsCombo()) - ComboPortion -= Judgement.ToNumericResult(result.Type) * (1 + result.ComboAtJudgement / 10d); + ComboPortion -= Judgement.ToNumericResult(result.Type) * (1 + result.ComboAfterJudgement / 10d); } private void updateScore() From 2ae34530f787e9420bdaefda85583bc165984075 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 14:14:34 +0900 Subject: [PATCH 18/66] Avoid NaN values during ApplyBeatmap processing() --- osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs | 3 ++- osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs | 7 +++++-- osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs | 7 +++++-- osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs | 7 +++++-- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 7 +++++-- 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index ae3966ccc5..dc6d5b28ee 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -25,12 +25,13 @@ namespace osu.Game.Rulesets.Catch.Scoring protected override double ComputeTotalScore() { + double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; double fruitHitsRatio = maximumTinyDroplets == 0 ? 0 : (double)hitTinyDroplets / maximumTinyDroplets; const int tiny_droplets_portion = 400000; return ( - ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * ComboPortion / MaxComboPortion + + ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboRatio + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + BonusPortion ) * ScoreMultiplier; diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 4c8f8ef65e..544b9add32 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -18,9 +18,12 @@ namespace osu.Game.Rulesets.Mania.Scoring protected override double ComputeTotalScore() { + double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; + double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; + return ( - 200000 * ComboPortion / MaxComboPortion + - 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + 200000 * comboRatio + + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * accuracyRatio + BonusPortion ) * ScoreMultiplier; } diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index d4677d92c1..edd0880271 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -15,9 +15,12 @@ namespace osu.Game.Rulesets.Osu.Scoring protected override double ComputeTotalScore() { + double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; + double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; + return ( - 700000 * ComboPortion / MaxComboPortion + - 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + 700000 * comboRatio + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + BonusPortion ) * ScoreMultiplier; } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index 2ecd962d72..32f4421ed2 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -19,9 +19,12 @@ namespace osu.Game.Rulesets.Taiko.Scoring protected override double ComputeTotalScore() { + double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; + double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; + return ( - 250000 * ComboPortion / MaxComboPortion + - 750000 * Math.Pow(Accuracy.Value, 3.6) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + 250000 * comboRatio + + 750000 * Math.Pow(Accuracy.Value, 3.6) * accuracyRatio + BonusPortion ) * ScoreMultiplier; } diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index b014b12297..0ec9c884c3 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -288,11 +288,14 @@ namespace osu.Game.Rulesets.Scoring protected virtual double ComputeTotalScore() { + double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; + double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; + return (int)Math.Round (( - 700000 * ComboPortion / MaxComboPortion + - 300000 * Math.Pow(Accuracy.Value, 10) * ((double)CurrentBasicJudgements / MaxBasicJudgements) + + 700000 * comboRatio + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + BonusPortion ) * ScoreMultiplier); } From d74bf2a096575a0f55f74f417724ad4d3593f8cf Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 14:37:26 +0900 Subject: [PATCH 19/66] Refactor for safety --- .../Scoring/CatchScoreProcessor.cs | 51 ++++---- .../Scoring/ManiaScoreProcessor.cs | 36 +----- .../Scoring/OsuScoreProcessor.cs | 13 +- .../Scoring/TaikoScoreProcessor.cs | 44 ++----- .../PerformanceBreakdownCalculator.cs | 2 +- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 117 ++++++++++-------- 6 files changed, 111 insertions(+), 152 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index dc6d5b28ee..c74d4b84e4 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -17,51 +17,48 @@ namespace osu.Game.Rulesets.Catch.Scoring private int maximumTinyDroplets; private int hitTinyDroplets; + private int maximumBasicJudgements; + private int currentBasicJudgements; public CatchScoreProcessor() : base(new CatchRuleset()) { } - protected override double ComputeTotalScore() + protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) { - double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; double fruitHitsRatio = maximumTinyDroplets == 0 ? 0 : (double)hitTinyDroplets / maximumTinyDroplets; const int tiny_droplets_portion = 400000; - return ( - ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboRatio + - tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + - BonusPortion - ) * ScoreMultiplier; + return ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboRatio + + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + + bonusPortion; } - protected override void AddScoreChange(JudgementResult result) + protected override double GetComboScoreChange(JudgementResult result) + => Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(combo_cap, combo_base)); + + protected override void ApplyScoreChange(JudgementResult result) { - var change = computeScoreChange(result); - ComboPortion += change.combo; - BonusPortion += change.bonus; - hitTinyDroplets += change.tinyDropletHits; + base.ApplyScoreChange(result); + + if (result.HitObject is TinyDroplet) + hitTinyDroplets++; + + if (result.Type.IsBasic()) + currentBasicJudgements++; } protected override void RemoveScoreChange(JudgementResult result) { - var change = computeScoreChange(result); - ComboPortion -= change.combo; - BonusPortion -= change.bonus; - hitTinyDroplets -= change.tinyDropletHits; - } + base.RemoveScoreChange(result); - private (double combo, double bonus, int tinyDropletHits) computeScoreChange(JudgementResult result) - { if (result.HitObject is TinyDroplet) - return (0, 0, 1); + hitTinyDroplets--; - if (result.Type.IsBonus()) - return (0, Judgement.ToNumericResult(result.Type), 0); - - return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(combo_cap, combo_base)), 0, 0); + if (result.Type.IsBasic()) + currentBasicJudgements--; } protected override void Reset(bool storeResults) @@ -71,14 +68,16 @@ namespace osu.Game.Rulesets.Catch.Scoring if (storeResults) { maximumTinyDroplets = hitTinyDroplets; + maximumBasicJudgements = currentBasicJudgements; - if (maximumTinyDroplets + MaxBasicJudgements == 0) + if (maximumTinyDroplets + maximumBasicJudgements == 0) tinyDropletScale = 0; else - tinyDropletScale = (double)maximumTinyDroplets / (maximumTinyDroplets + MaxBasicJudgements); + tinyDropletScale = (double)maximumTinyDroplets / (maximumTinyDroplets + maximumBasicJudgements); } hitTinyDroplets = 0; + currentBasicJudgements = 0; } } } diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 544b9add32..214aded2d7 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -16,38 +16,14 @@ namespace osu.Game.Rulesets.Mania.Scoring { } - protected override double ComputeTotalScore() + protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) { - double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; - double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; - - return ( - 200000 * comboRatio + - 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * accuracyRatio + - BonusPortion - ) * ScoreMultiplier; + return 200000 * comboRatio + + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * accuracyRatio + + bonusPortion; } - protected override void AddScoreChange(JudgementResult result) - { - var change = computeScoreChange(result); - ComboPortion += change.combo; - BonusPortion += change.bonus; - } - - protected override void RemoveScoreChange(JudgementResult result) - { - var change = computeScoreChange(result); - ComboPortion -= change.combo; - BonusPortion -= change.bonus; - } - - private (double combo, double bonus) computeScoreChange(JudgementResult result) - { - if (result.Type.IsBonus()) - return (0, Judgement.ToNumericResult(result.Type)); - - return (Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)), 0); - } + protected override double GetComboScoreChange(JudgementResult result) + => Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)); } } diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index edd0880271..5028d5b8d6 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -13,16 +13,11 @@ namespace osu.Game.Rulesets.Osu.Scoring { } - protected override double ComputeTotalScore() + protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) { - double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; - double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; - - return ( - 700000 * comboRatio + - 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + - BonusPortion - ) * ScoreMultiplier; + return 700000 * comboRatio + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + + bonusPortion; } } } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index 32f4421ed2..e0f83505cf 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -17,46 +17,28 @@ namespace osu.Game.Rulesets.Taiko.Scoring { } - protected override double ComputeTotalScore() + protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) { - double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; - double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; - - return ( - 250000 * comboRatio + - 750000 * Math.Pow(Accuracy.Value, 3.6) * accuracyRatio + - BonusPortion - ) * ScoreMultiplier; + return 250000 * comboRatio + + 750000 * Math.Pow(Accuracy.Value, 3.6) * accuracyRatio + + bonusPortion; } - protected override void AddScoreChange(JudgementResult result) + protected override double GetBonusScoreChange(JudgementResult result) => base.GetBonusScoreChange(result) * strongScaleValue(result); + + protected override double GetComboScoreChange(JudgementResult result) { - var change = computeScoreChange(result); - ComboPortion += change.combo; - BonusPortion += change.bonus; + return Judgement.ToNumericResult(result.Type) + * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)) + * strongScaleValue(result); } - protected override void RemoveScoreChange(JudgementResult result) + private double strongScaleValue(JudgementResult result) { - var change = computeScoreChange(result); - ComboPortion -= change.combo; - BonusPortion -= change.bonus; - } - - private (double combo, double bonus) computeScoreChange(JudgementResult result) - { - double hitValue = Judgement.ToNumericResult(result.Type); - if (result.HitObject is StrongNestedHitObject strong) - { - double strongBonus = strong.Parent is DrumRollTick ? 3 : 7; - hitValue *= strongBonus; - } + return strong.Parent is DrumRollTick ? 3 : 7; - if (result.Type.IsBonus()) - return (0, hitValue); - - return (hitValue * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(400, combo_base)), 0); + return 1; } } } diff --git a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs index 3dd7f934a8..64a04f896f 100644 --- a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs @@ -68,7 +68,7 @@ namespace osu.Game.Rulesets.Difficulty ScoreProcessor scoreProcessor = ruleset.CreateScoreProcessor(); scoreProcessor.Mods.Value = perfectPlay.Mods; scoreProcessor.ApplyBeatmap(playableBeatmap); - perfectPlay.TotalScore = scoreProcessor.MaxTotalScore; + perfectPlay.TotalScore = scoreProcessor.MaximumTotalScore; // compute rank achieved // default to SS, then adjust the rank with mods diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 0ec9c884c3..a94ee9c181 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -90,10 +90,18 @@ namespace osu.Game.Rulesets.Scoring /// /// The maximum achievable total score. /// - public long MaxTotalScore { get; private set; } + public long MaximumTotalScore { get; private set; } /// - /// The sum of all accuracy-affecting judgements at the current time. + /// The maximum sum of accuracy-affecting judgements at the current point in time. + /// + /// + /// Used to compute accuracy. + /// + private double currentMaximumBaseScore; + + /// + /// The sum of all accuracy-affecting judgements at the current point in time. /// /// /// Used to compute accuracy. @@ -101,42 +109,34 @@ namespace osu.Game.Rulesets.Scoring private double currentBaseScore; /// - /// The maximum sum of accuracy-affecting judgements at the current time. + /// The count of all basic judgements in the beatmap. /// - /// - /// Used to compute accuracy. - /// - private double currentMaxBaseScore; + private int maximumCountBasicJudgements; /// - /// The total count of basic judgements in the beatmap. + /// The count of basic judgements at the current point in time. /// - protected int MaxBasicJudgements { get; private set; } + private int currentCountBasicJudgements; /// - /// The current count of basic judgements by the player. + /// The maximum combo score in the beatmap. /// - protected int CurrentBasicJudgements { get; private set; } + private double maximumComboPortion; /// - /// The current combo score. + /// The combo score at the current point in time. /// - protected double ComboPortion { get; set; } + private double currentComboPortion; /// - /// The maximum achievable combo score. + /// The bonus score at the current point in time. /// - protected double MaxComboPortion { get; private set; } - - /// - /// The current bonus score. - /// - protected double BonusPortion { get; set; } + private double currentBonusPortion; /// /// The total score multiplier. /// - protected double ScoreMultiplier { get; private set; } = 1; + private double scoreMultiplier = 1; public Dictionary MaximumStatistics { @@ -171,10 +171,10 @@ namespace osu.Game.Rulesets.Scoring Mods.ValueChanged += mods => { - ScoreMultiplier = 1; + scoreMultiplier = 1; foreach (var m in mods.NewValue) - ScoreMultiplier *= m.ScoreMultiplier; + scoreMultiplier *= m.ScoreMultiplier; updateScore(); }; @@ -207,15 +207,21 @@ namespace osu.Game.Rulesets.Scoring result.ComboAfterJudgement = Combo.Value; if (result.Type.IsBasic()) - CurrentBasicJudgements++; + currentCountBasicJudgements++; if (result.Type.AffectsAccuracy()) { - currentMaxBaseScore += Judgement.ToNumericResult(result.Judgement.MaxResult); + currentMaximumBaseScore += Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore += Judgement.ToNumericResult(result.Type); } - AddScoreChange(result); + if (result.Type.IsBonus()) + currentBonusPortion += GetBonusScoreChange(result); + + if (result.Type.AffectsCombo()) + currentComboPortion += GetComboScoreChange(result); + + ApplyScoreChange(result); hitEvents.Add(CreateHitEvent(result)); lastHitObject = result.HitObject; @@ -245,14 +251,20 @@ namespace osu.Game.Rulesets.Scoring return; if (result.Type.IsBasic()) - CurrentBasicJudgements--; + currentCountBasicJudgements--; if (result.Type.AffectsAccuracy()) { - currentMaxBaseScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); + currentMaximumBaseScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore -= Judgement.ToNumericResult(result.Type); } + if (result.Type.IsBonus()) + currentBonusPortion -= GetBonusScoreChange(result); + + if (result.Type.AffectsCombo()) + currentComboPortion -= GetComboScoreChange(result); + RemoveScoreChange(result); Debug.Assert(hitEvents.Count > 0); @@ -262,42 +274,37 @@ namespace osu.Game.Rulesets.Scoring updateScore(); } - protected virtual void AddScoreChange(JudgementResult result) - { - if (result.Type.IsBonus()) - BonusPortion += Judgement.ToNumericResult(result.Type); + protected virtual double GetBonusScoreChange(JudgementResult result) => Judgement.ToNumericResult(result.Type); - if (result.Type.AffectsCombo()) - ComboPortion += Judgement.ToNumericResult(result.Type) * (1 + result.ComboAfterJudgement / 10d); + protected virtual double GetComboScoreChange(JudgementResult result) => Judgement.ToNumericResult(result.Type) * (1 + result.ComboAfterJudgement / 10d); + + protected virtual void ApplyScoreChange(JudgementResult result) + { } protected virtual void RemoveScoreChange(JudgementResult result) { - if (result.Type.IsBonus()) - BonusPortion -= Judgement.ToNumericResult(result.Type); - - if (result.Type.AffectsCombo()) - ComboPortion -= Judgement.ToNumericResult(result.Type) * (1 + result.ComboAfterJudgement / 10d); } private void updateScore() { - Accuracy.Value = currentMaxBaseScore > 0 ? currentBaseScore / currentMaxBaseScore : 1; - TotalScore.Value = (long)Math.Round(ComputeTotalScore()); + Accuracy.Value = currentMaximumBaseScore > 0 ? currentBaseScore / currentMaximumBaseScore : 1; + + double comboRatio = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; + double accuracyRatio = maximumCountBasicJudgements > 0 ? (double)currentCountBasicJudgements / maximumCountBasicJudgements : 1; + + TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboRatio, accuracyRatio, currentBonusPortion) * scoreMultiplier); } - protected virtual double ComputeTotalScore() + protected virtual double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) { - double comboRatio = MaxComboPortion > 0 ? ComboPortion / MaxComboPortion : 1; - double accuracyRatio = MaxBasicJudgements > 0 ? (double)CurrentBasicJudgements / MaxBasicJudgements : 1; - return (int)Math.Round (( 700000 * comboRatio + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + - BonusPortion - ) * ScoreMultiplier); + bonusPortion + ) * scoreMultiplier); } /// @@ -313,22 +320,22 @@ namespace osu.Game.Rulesets.Scoring if (storeResults) { - MaxComboPortion = ComboPortion; - MaxBasicJudgements = CurrentBasicJudgements; + maximumComboPortion = currentComboPortion; + maximumCountBasicJudgements = currentCountBasicJudgements; maximumResultCounts.Clear(); maximumResultCounts.AddRange(scoreResultCounts); - MaxTotalScore = TotalScore.Value; + MaximumTotalScore = TotalScore.Value; } scoreResultCounts.Clear(); currentBaseScore = 0; - currentMaxBaseScore = 0; - CurrentBasicJudgements = 0; - ComboPortion = 0; - BonusPortion = 0; + currentMaximumBaseScore = 0; + currentCountBasicJudgements = 0; + currentComboPortion = 0; + currentBonusPortion = 0; TotalScore.Value = 0; Accuracy.Value = 1; @@ -338,7 +345,7 @@ namespace osu.Game.Rulesets.Scoring HighestCombo.Value = 0; currentBaseScore = 0; - currentMaxBaseScore = 0; + currentMaximumBaseScore = 0; } /// From 6c6f8621c1ae5b7ea26116b3883c9ae9683b8bde Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 16:25:52 +0900 Subject: [PATCH 20/66] Add score processor statistics to replay header --- .../Scoring/CatchScoreProcessor.cs | 17 +++++++ osu.Game/Online/Spectator/FrameDataBundle.cs | 5 ++- osu.Game/Online/Spectator/FrameHeader.cs | 45 ++++++++++++------- osu.Game/Online/Spectator/SpectatorClient.cs | 6 ++- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 27 +++++++++-- .../Visual/Spectator/TestSpectatorClient.cs | 7 ++- 6 files changed, 83 insertions(+), 24 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index c74d4b84e4..63937600bb 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -2,6 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System; +using System.Collections.Generic; using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; @@ -79,5 +80,21 @@ namespace osu.Game.Rulesets.Catch.Scoring hitTinyDroplets = 0; currentBasicJudgements = 0; } + + public override void WriteScoreProcessorStatistics(IDictionary statistics) + { + base.WriteScoreProcessorStatistics(statistics); + + statistics.Add(nameof(hitTinyDroplets), hitTinyDroplets); + statistics.Add(nameof(currentBasicJudgements), currentBasicJudgements); + } + + public override void ReadScoreProcessorStatistics(IReadOnlyDictionary statistics) + { + base.ReadScoreProcessorStatistics(statistics); + + hitTinyDroplets = (int)statistics.GetValueOrDefault(nameof(hitTinyDroplets), 0); + currentBasicJudgements = (int)statistics.GetValueOrDefault(nameof(currentBasicJudgements), 0); + } } } diff --git a/osu.Game/Online/Spectator/FrameDataBundle.cs b/osu.Game/Online/Spectator/FrameDataBundle.cs index 97ae468875..b936847434 100644 --- a/osu.Game/Online/Spectator/FrameDataBundle.cs +++ b/osu.Game/Online/Spectator/FrameDataBundle.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using MessagePack; using Newtonsoft.Json; using osu.Game.Replays.Legacy; +using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; namespace osu.Game.Online.Spectator @@ -20,10 +21,10 @@ namespace osu.Game.Online.Spectator [Key(1)] public IList Frames { get; set; } - public FrameDataBundle(ScoreInfo score, IList frames) + public FrameDataBundle(ScoreInfo score, ScoreProcessor scoreProcessor, IList frames) { Frames = frames; - Header = new FrameHeader(score); + Header = new FrameHeader(score, scoreProcessor); } [JsonConstructor] diff --git a/osu.Game/Online/Spectator/FrameHeader.cs b/osu.Game/Online/Spectator/FrameHeader.cs index 4d1ff23530..baebb28e4f 100644 --- a/osu.Game/Online/Spectator/FrameHeader.cs +++ b/osu.Game/Online/Spectator/FrameHeader.cs @@ -15,66 +15,77 @@ namespace osu.Game.Online.Spectator public class FrameHeader { /// - /// The current accuracy of the score. + /// The total score. /// [Key(0)] + public long TotalScore { get; set; } + + /// + /// The current accuracy of the score. + /// + [Key(1)] public double Accuracy { get; set; } /// /// The current combo of the score. /// - [Key(1)] + [Key(2)] public int Combo { get; set; } /// /// The maximum combo achieved up to the current point in time. /// - [Key(2)] + [Key(3)] public int MaxCombo { get; set; } /// /// Cumulative hit statistics. /// - [Key(3)] + [Key(4)] public Dictionary Statistics { get; set; } + /// + /// Additional statistics that guides the score processor to calculate the correct score for this frame. + /// + [Key(5)] + public Dictionary ScoreProcessorStatistics { get; set; } + /// /// The time at which this frame was received by the server. /// - [Key(4)] + [Key(6)] public DateTimeOffset ReceivedTime { get; set; } - /// - /// The total score. - /// - [Key(5)] - public long TotalScore { get; set; } - /// /// Construct header summary information from a point-in-time reference to a score which is actively being played. /// /// The score for reference. - public FrameHeader(ScoreInfo score) + /// The score processor for reference. + public FrameHeader(ScoreInfo score, ScoreProcessor scoreProcessor) { + TotalScore = score.TotalScore; + Accuracy = score.Accuracy; Combo = score.Combo; MaxCombo = score.MaxCombo; - Accuracy = score.Accuracy; - TotalScore = score.TotalScore; // copy for safety Statistics = new Dictionary(score.Statistics); + + ScoreProcessorStatistics = new Dictionary(); + scoreProcessor.WriteScoreProcessorStatistics(ScoreProcessorStatistics); } [JsonConstructor] [SerializationConstructor] - public FrameHeader(double accuracy, int combo, int maxCombo, Dictionary statistics, DateTimeOffset receivedTime, long totalScore) + public FrameHeader(long totalScore, double accuracy, int combo, int maxCombo, Dictionary statistics, Dictionary scoreProcessorStatistics, DateTimeOffset receivedTime) { + TotalScore = totalScore; + Accuracy = accuracy; Combo = combo; MaxCombo = maxCombo; - Accuracy = accuracy; Statistics = statistics; + ScoreProcessorStatistics = scoreProcessorStatistics; ReceivedTime = receivedTime; - TotalScore = totalScore; } } } diff --git a/osu.Game/Online/Spectator/SpectatorClient.cs b/osu.Game/Online/Spectator/SpectatorClient.cs index 55ec75f4ce..89da8b9d32 100644 --- a/osu.Game/Online/Spectator/SpectatorClient.cs +++ b/osu.Game/Online/Spectator/SpectatorClient.cs @@ -16,6 +16,7 @@ using osu.Game.Online.API; using osu.Game.Replays.Legacy; using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays.Types; +using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Play; @@ -82,6 +83,7 @@ namespace osu.Game.Online.Spectator private IBeatmap? currentBeatmap; private Score? currentScore; private long? currentScoreToken; + private ScoreProcessor? currentScoreProcessor; private readonly Queue pendingFrameBundles = new Queue(); @@ -192,6 +194,7 @@ namespace osu.Game.Online.Spectator currentBeatmap = state.Beatmap; currentScore = score; currentScoreToken = scoreToken; + currentScoreProcessor = state.ScoreProcessor; BeginPlayingInternal(currentScoreToken, currentState); }); @@ -302,9 +305,10 @@ namespace osu.Game.Online.Spectator return; Debug.Assert(currentScore != null); + Debug.Assert(currentScoreProcessor != null); var frames = pendingFrames.ToArray(); - var bundle = new FrameDataBundle(currentScore.ScoreInfo, frames); + var bundle = new FrameDataBundle(currentScore.ScoreInfo, currentScoreProcessor, frames); pendingFrames.Clear(); lastPurgeTime = Time.Current; diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index a94ee9c181..0244e7f5e3 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -394,19 +394,34 @@ namespace osu.Game.Rulesets.Scoring Combo.Value = frame.Header.Combo; HighestCombo.Value = frame.Header.MaxCombo; + TotalScore.Value = frame.Header.TotalScore; scoreResultCounts.Clear(); scoreResultCounts.AddRange(frame.Header.Statistics); + ReadScoreProcessorStatistics(frame.Header.ScoreProcessorStatistics); + updateScore(); OnResetFromReplayFrame?.Invoke(); } - protected override void Dispose(bool isDisposing) + public virtual void WriteScoreProcessorStatistics(IDictionary statistics) { - base.Dispose(isDisposing); - hitEvents.Clear(); + statistics.Add(nameof(currentMaximumBaseScore), currentMaximumBaseScore); + statistics.Add(nameof(currentBaseScore), currentBaseScore); + statistics.Add(nameof(currentCountBasicJudgements), currentCountBasicJudgements); + statistics.Add(nameof(currentComboPortion), currentComboPortion); + statistics.Add(nameof(currentBonusPortion), currentBonusPortion); + } + + public virtual void ReadScoreProcessorStatistics(IReadOnlyDictionary statistics) + { + currentMaximumBaseScore = (double)statistics.GetValueOrDefault(nameof(currentMaximumBaseScore), 0); + currentBaseScore = (double)statistics.GetValueOrDefault(nameof(currentBaseScore), 0); + currentCountBasicJudgements = (int)statistics.GetValueOrDefault(nameof(currentCountBasicJudgements), 0); + currentComboPortion = (double)statistics.GetValueOrDefault(nameof(currentComboPortion), 0); + currentBonusPortion = (double)statistics.GetValueOrDefault(nameof(currentBonusPortion), 0); } #region Static helper methods @@ -464,6 +479,12 @@ namespace osu.Game.Rulesets.Scoring } #endregion + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + hitEvents.Clear(); + } } public enum ScoringMode diff --git a/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs b/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs index 1db35b3aaa..305a615102 100644 --- a/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs +++ b/osu.Game/Tests/Visual/Spectator/TestSpectatorClient.cs @@ -12,7 +12,9 @@ using osu.Framework.Utils; using osu.Game.Online.API; using osu.Game.Online.Spectator; using osu.Game.Replays.Legacy; +using osu.Game.Rulesets; using osu.Game.Rulesets.Replays; +using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; namespace osu.Game.Tests.Visual.Spectator @@ -44,6 +46,9 @@ namespace osu.Game.Tests.Visual.Spectator [Resolved] private IAPIProvider api { get; set; } = null!; + [Resolved] + private RulesetStore rulesetStore { get; set; } = null!; + public TestSpectatorClient() { OnNewFrames += (i, bundle) => lastReceivedUserFrames[i] = bundle.Frames[^1]; @@ -119,7 +124,7 @@ namespace osu.Game.Tests.Visual.Spectator if (frames.Count == 0) return; - var bundle = new FrameDataBundle(new ScoreInfo { Combo = currentFrameIndex }, frames.ToArray()); + var bundle = new FrameDataBundle(new ScoreInfo { Combo = currentFrameIndex }, new ScoreProcessor(rulesetStore.GetRuleset(0)!.CreateInstance()), frames.ToArray()); ((ISpectatorClient)this).UserSentFrames(userId, bundle); frames.Clear(); From 30a296bd094604d5f2c7a2c3ddc1e9d03c60fa80 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Fri, 19 May 2023 17:27:02 +0900 Subject: [PATCH 21/66] Rename parameters --- osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs | 4 ++-- osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs | 6 +++--- osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs | 6 +++--- osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs | 6 +++--- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 63937600bb..9d5fc553de 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -26,13 +26,13 @@ namespace osu.Game.Rulesets.Catch.Scoring { } - protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { double fruitHitsRatio = maximumTinyDroplets == 0 ? 0 : (double)hitTinyDroplets / maximumTinyDroplets; const int tiny_droplets_portion = 400000; - return ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboRatio + return ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboProgress + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + bonusPortion; } diff --git a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs index 214aded2d7..3341f834dd 100644 --- a/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Rulesets.Mania/Scoring/ManiaScoreProcessor.cs @@ -16,10 +16,10 @@ namespace osu.Game.Rulesets.Mania.Scoring { } - protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { - return 200000 * comboRatio - + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * accuracyRatio + return 200000 * comboProgress + + 800000 * Math.Pow(Accuracy.Value, 2 + 2 * Accuracy.Value) * accuracyProgress + bonusPortion; } diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index 5028d5b8d6..ab07ac3e9d 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -13,10 +13,10 @@ namespace osu.Game.Rulesets.Osu.Scoring { } - protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { - return 700000 * comboRatio - + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + return 700000 * comboProgress + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyProgress + bonusPortion; } } diff --git a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs index e0f83505cf..a77e6db6f3 100644 --- a/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Rulesets.Taiko/Scoring/TaikoScoreProcessor.cs @@ -17,10 +17,10 @@ namespace osu.Game.Rulesets.Taiko.Scoring { } - protected override double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { - return 250000 * comboRatio - + 750000 * Math.Pow(Accuracy.Value, 3.6) * accuracyRatio + return 250000 * comboProgress + + 750000 * Math.Pow(Accuracy.Value, 3.6) * accuracyProgress + bonusPortion; } diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 0244e7f5e3..d0bbe863fb 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -296,13 +296,13 @@ namespace osu.Game.Rulesets.Scoring TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboRatio, accuracyRatio, currentBonusPortion) * scoreMultiplier); } - protected virtual double ComputeTotalScore(double comboRatio, double accuracyRatio, double bonusPortion) + protected virtual double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { return (int)Math.Round (( - 700000 * comboRatio + - 300000 * Math.Pow(Accuracy.Value, 10) * accuracyRatio + + 700000 * comboProgress + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyProgress + bonusPortion ) * scoreMultiplier); } From 25d72d370e95c8e0722bbccb96b0cc01a78e61f9 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Sat, 20 May 2023 00:24:43 +0900 Subject: [PATCH 22/66] Always add non-bonus change to combo portion --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index d0bbe863fb..f2b1607f5e 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -217,8 +217,7 @@ namespace osu.Game.Rulesets.Scoring if (result.Type.IsBonus()) currentBonusPortion += GetBonusScoreChange(result); - - if (result.Type.AffectsCombo()) + else currentComboPortion += GetComboScoreChange(result); ApplyScoreChange(result); @@ -261,8 +260,7 @@ namespace osu.Game.Rulesets.Scoring if (result.Type.IsBonus()) currentBonusPortion -= GetBonusScoreChange(result); - - if (result.Type.AffectsCombo()) + else currentComboPortion -= GetComboScoreChange(result); RemoveScoreChange(result); From c291d6fc829d02103230f4cb0881fe2bdeca1985 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 22 May 2023 12:02:44 +0900 Subject: [PATCH 23/66] Remove catch tiny droplet portion --- .../Scoring/CatchScoreProcessor.cs | 74 +------------------ 1 file changed, 2 insertions(+), 72 deletions(-) diff --git a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs index 9d5fc553de..9323296b7f 100644 --- a/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Rulesets.Catch/Scoring/CatchScoreProcessor.cs @@ -2,8 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; -using osu.Game.Rulesets.Catch.Objects; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Scoring; @@ -14,13 +12,6 @@ namespace osu.Game.Rulesets.Catch.Scoring private const int combo_cap = 200; private const double combo_base = 4; - private double tinyDropletScale; - - private int maximumTinyDroplets; - private int hitTinyDroplets; - private int maximumBasicJudgements; - private int currentBasicJudgements; - public CatchScoreProcessor() : base(new CatchRuleset()) { @@ -28,73 +19,12 @@ namespace osu.Game.Rulesets.Catch.Scoring protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { - double fruitHitsRatio = maximumTinyDroplets == 0 ? 0 : (double)hitTinyDroplets / maximumTinyDroplets; - - const int tiny_droplets_portion = 400000; - - return ((1000000 - tiny_droplets_portion) + tiny_droplets_portion * (1 - tinyDropletScale)) * comboProgress - + tiny_droplets_portion * tinyDropletScale * fruitHitsRatio + return 600000 * comboProgress + + 400000 * Accuracy.Value * accuracyProgress + bonusPortion; } protected override double GetComboScoreChange(JudgementResult result) => Judgement.ToNumericResult(result.Type) * Math.Min(Math.Max(0.5, Math.Log(result.ComboAfterJudgement, combo_base)), Math.Log(combo_cap, combo_base)); - - protected override void ApplyScoreChange(JudgementResult result) - { - base.ApplyScoreChange(result); - - if (result.HitObject is TinyDroplet) - hitTinyDroplets++; - - if (result.Type.IsBasic()) - currentBasicJudgements++; - } - - protected override void RemoveScoreChange(JudgementResult result) - { - base.RemoveScoreChange(result); - - if (result.HitObject is TinyDroplet) - hitTinyDroplets--; - - if (result.Type.IsBasic()) - currentBasicJudgements--; - } - - protected override void Reset(bool storeResults) - { - base.Reset(storeResults); - - if (storeResults) - { - maximumTinyDroplets = hitTinyDroplets; - maximumBasicJudgements = currentBasicJudgements; - - if (maximumTinyDroplets + maximumBasicJudgements == 0) - tinyDropletScale = 0; - else - tinyDropletScale = (double)maximumTinyDroplets / (maximumTinyDroplets + maximumBasicJudgements); - } - - hitTinyDroplets = 0; - currentBasicJudgements = 0; - } - - public override void WriteScoreProcessorStatistics(IDictionary statistics) - { - base.WriteScoreProcessorStatistics(statistics); - - statistics.Add(nameof(hitTinyDroplets), hitTinyDroplets); - statistics.Add(nameof(currentBasicJudgements), currentBasicJudgements); - } - - public override void ReadScoreProcessorStatistics(IReadOnlyDictionary statistics) - { - base.ReadScoreProcessorStatistics(statistics); - - hitTinyDroplets = (int)statistics.GetValueOrDefault(nameof(hitTinyDroplets), 0); - currentBasicJudgements = (int)statistics.GetValueOrDefault(nameof(currentBasicJudgements), 0); - } } } From e1feeded127aeb95b6a5f34c95c93ee0cd484b78 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 22 May 2023 12:49:41 +0900 Subject: [PATCH 24/66] Change statistics type, remove overridability --- osu.Game/Online/Spectator/FrameHeader.cs | 7 ++- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 49 +++++++++++++++------ 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/osu.Game/Online/Spectator/FrameHeader.cs b/osu.Game/Online/Spectator/FrameHeader.cs index baebb28e4f..4d1c2c2cff 100644 --- a/osu.Game/Online/Spectator/FrameHeader.cs +++ b/osu.Game/Online/Spectator/FrameHeader.cs @@ -48,7 +48,7 @@ namespace osu.Game.Online.Spectator /// Additional statistics that guides the score processor to calculate the correct score for this frame. /// [Key(5)] - public Dictionary ScoreProcessorStatistics { get; set; } + public ScoreProcessorStatistics ScoreProcessorStatistics { get; set; } /// /// The time at which this frame was received by the server. @@ -71,13 +71,12 @@ namespace osu.Game.Online.Spectator // copy for safety Statistics = new Dictionary(score.Statistics); - ScoreProcessorStatistics = new Dictionary(); - scoreProcessor.WriteScoreProcessorStatistics(ScoreProcessorStatistics); + ScoreProcessorStatistics = scoreProcessor.GetScoreProcessorStatistics(); } [JsonConstructor] [SerializationConstructor] - public FrameHeader(long totalScore, double accuracy, int combo, int maxCombo, Dictionary statistics, Dictionary scoreProcessorStatistics, DateTimeOffset receivedTime) + public FrameHeader(long totalScore, double accuracy, int combo, int maxCombo, Dictionary statistics, ScoreProcessorStatistics scoreProcessorStatistics, DateTimeOffset receivedTime) { TotalScore = totalScore; Accuracy = accuracy; diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index f2b1607f5e..013dd4b8e7 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using MessagePack; using osu.Framework.Bindables; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -397,29 +398,29 @@ namespace osu.Game.Rulesets.Scoring scoreResultCounts.Clear(); scoreResultCounts.AddRange(frame.Header.Statistics); - ReadScoreProcessorStatistics(frame.Header.ScoreProcessorStatistics); + SetScoreProcessorStatistics(frame.Header.ScoreProcessorStatistics); updateScore(); OnResetFromReplayFrame?.Invoke(); } - public virtual void WriteScoreProcessorStatistics(IDictionary statistics) + public ScoreProcessorStatistics GetScoreProcessorStatistics() => new ScoreProcessorStatistics { - statistics.Add(nameof(currentMaximumBaseScore), currentMaximumBaseScore); - statistics.Add(nameof(currentBaseScore), currentBaseScore); - statistics.Add(nameof(currentCountBasicJudgements), currentCountBasicJudgements); - statistics.Add(nameof(currentComboPortion), currentComboPortion); - statistics.Add(nameof(currentBonusPortion), currentBonusPortion); - } + MaximumBaseScore = currentMaximumBaseScore, + BaseScore = currentBaseScore, + CountBasicJudgements = currentCountBasicJudgements, + ComboPortion = currentComboPortion, + BonusPortion = currentBonusPortion + }; - public virtual void ReadScoreProcessorStatistics(IReadOnlyDictionary statistics) + public void SetScoreProcessorStatistics(ScoreProcessorStatistics statistics) { - currentMaximumBaseScore = (double)statistics.GetValueOrDefault(nameof(currentMaximumBaseScore), 0); - currentBaseScore = (double)statistics.GetValueOrDefault(nameof(currentBaseScore), 0); - currentCountBasicJudgements = (int)statistics.GetValueOrDefault(nameof(currentCountBasicJudgements), 0); - currentComboPortion = (double)statistics.GetValueOrDefault(nameof(currentComboPortion), 0); - currentBonusPortion = (double)statistics.GetValueOrDefault(nameof(currentBonusPortion), 0); + currentMaximumBaseScore = statistics.MaximumBaseScore; + currentBaseScore = statistics.BaseScore; + currentCountBasicJudgements = statistics.CountBasicJudgements; + currentComboPortion = statistics.ComboPortion; + currentBonusPortion = statistics.BonusPortion; } #region Static helper methods @@ -493,4 +494,24 @@ namespace osu.Game.Rulesets.Scoring [LocalisableDescription(typeof(GameplaySettingsStrings), nameof(GameplaySettingsStrings.ClassicScoreDisplay))] Classic } + + [Serializable] + [MessagePackObject] + public class ScoreProcessorStatistics + { + [Key(0)] + public double MaximumBaseScore { get; set; } + + [Key(1)] + public double BaseScore { get; set; } + + [Key(2)] + public int CountBasicJudgements { get; set; } + + [Key(3)] + public double ComboPortion { get; set; } + + [Key(4)] + public double BonusPortion { get; set; } + } } From 62d504af921f7de8ac6c7933425aec975f6c3206 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 15:59:24 +0900 Subject: [PATCH 25/66] Fix base implementation of ComputeTotalScore --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 013dd4b8e7..2108e99def 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -297,13 +297,9 @@ namespace osu.Game.Rulesets.Scoring protected virtual double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { - return - (int)Math.Round - (( - 700000 * comboProgress + - 300000 * Math.Pow(Accuracy.Value, 10) * accuracyProgress + - bonusPortion - ) * scoreMultiplier); + return 700000 * comboProgress + + 300000 * Math.Pow(Accuracy.Value, 10) * accuracyProgress + + bonusPortion; } /// From f8101fbbc7b3606d6e8510846eb186f221bef85e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 17:44:17 +0900 Subject: [PATCH 26/66] Rename variables --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 2108e99def..c539820f13 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -289,10 +289,10 @@ namespace osu.Game.Rulesets.Scoring { Accuracy.Value = currentMaximumBaseScore > 0 ? currentBaseScore / currentMaximumBaseScore : 1; - double comboRatio = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; - double accuracyRatio = maximumCountBasicJudgements > 0 ? (double)currentCountBasicJudgements / maximumCountBasicJudgements : 1; + double comboProgress = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; + double accuracyProcess = maximumCountBasicJudgements > 0 ? (double)currentCountBasicJudgements / maximumCountBasicJudgements : 1; - TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboRatio, accuracyRatio, currentBonusPortion) * scoreMultiplier); + TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboProgress, accuracyProcess, currentBonusPortion) * scoreMultiplier); } protected virtual double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) From 8570f825ed20a32733f104a2778df0685d92261e Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 17:47:35 +0900 Subject: [PATCH 27/66] Consider all accuracy judgements in accuracy progress --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 28 +++++++++------------ 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index c539820f13..8c3cd27012 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -110,14 +110,14 @@ namespace osu.Game.Rulesets.Scoring private double currentBaseScore; /// - /// The count of all basic judgements in the beatmap. + /// The count of all accuracy-affecting judgements in the beatmap. /// - private int maximumCountBasicJudgements; + private int maximumCountAccuracyJudgements; /// - /// The count of basic judgements at the current point in time. + /// The count of accuracy-affecting judgements at the current point in time. /// - private int currentCountBasicJudgements; + private int currentCountAccuracyJudgements; /// /// The maximum combo score in the beatmap. @@ -207,13 +207,11 @@ namespace osu.Game.Rulesets.Scoring result.ComboAfterJudgement = Combo.Value; - if (result.Type.IsBasic()) - currentCountBasicJudgements++; - if (result.Type.AffectsAccuracy()) { currentMaximumBaseScore += Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore += Judgement.ToNumericResult(result.Type); + currentCountAccuracyJudgements++; } if (result.Type.IsBonus()) @@ -250,13 +248,11 @@ namespace osu.Game.Rulesets.Scoring if (!result.Type.IsScorable()) return; - if (result.Type.IsBasic()) - currentCountBasicJudgements--; - if (result.Type.AffectsAccuracy()) { currentMaximumBaseScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore -= Judgement.ToNumericResult(result.Type); + currentCountAccuracyJudgements--; } if (result.Type.IsBonus()) @@ -290,7 +286,7 @@ namespace osu.Game.Rulesets.Scoring Accuracy.Value = currentMaximumBaseScore > 0 ? currentBaseScore / currentMaximumBaseScore : 1; double comboProgress = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; - double accuracyProcess = maximumCountBasicJudgements > 0 ? (double)currentCountBasicJudgements / maximumCountBasicJudgements : 1; + double accuracyProcess = maximumCountAccuracyJudgements > 0 ? (double)currentCountAccuracyJudgements / maximumCountAccuracyJudgements : 1; TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboProgress, accuracyProcess, currentBonusPortion) * scoreMultiplier); } @@ -316,7 +312,7 @@ namespace osu.Game.Rulesets.Scoring if (storeResults) { maximumComboPortion = currentComboPortion; - maximumCountBasicJudgements = currentCountBasicJudgements; + maximumCountAccuracyJudgements = currentCountAccuracyJudgements; maximumResultCounts.Clear(); maximumResultCounts.AddRange(scoreResultCounts); @@ -328,7 +324,7 @@ namespace osu.Game.Rulesets.Scoring currentBaseScore = 0; currentMaximumBaseScore = 0; - currentCountBasicJudgements = 0; + currentCountAccuracyJudgements = 0; currentComboPortion = 0; currentBonusPortion = 0; @@ -405,7 +401,7 @@ namespace osu.Game.Rulesets.Scoring { MaximumBaseScore = currentMaximumBaseScore, BaseScore = currentBaseScore, - CountBasicJudgements = currentCountBasicJudgements, + CountAccuracyJudgements = currentCountAccuracyJudgements, ComboPortion = currentComboPortion, BonusPortion = currentBonusPortion }; @@ -414,7 +410,7 @@ namespace osu.Game.Rulesets.Scoring { currentMaximumBaseScore = statistics.MaximumBaseScore; currentBaseScore = statistics.BaseScore; - currentCountBasicJudgements = statistics.CountBasicJudgements; + currentCountAccuracyJudgements = statistics.CountAccuracyJudgements; currentComboPortion = statistics.ComboPortion; currentBonusPortion = statistics.BonusPortion; } @@ -502,7 +498,7 @@ namespace osu.Game.Rulesets.Scoring public double BaseScore { get; set; } [Key(2)] - public int CountBasicJudgements { get; set; } + public int CountAccuracyJudgements { get; set; } [Key(3)] public double ComboPortion { get; set; } From 3598ca91251ed4991d716c32878d751e8de13e60 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 18:05:10 +0900 Subject: [PATCH 28/66] Adjust xmldoc --- osu.Game/Rulesets/Scoring/HitResult.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Scoring/HitResult.cs b/osu.Game/Rulesets/Scoring/HitResult.cs index 83ed98768c..0013a9f20d 100644 --- a/osu.Game/Rulesets/Scoring/HitResult.cs +++ b/osu.Game/Rulesets/Scoring/HitResult.cs @@ -150,7 +150,7 @@ namespace osu.Game.Rulesets.Scoring => AffectsCombo(result) && !IsHit(result); /// - /// Whether a increases/breaks the combo, and affects the combo portion of the score. + /// Whether a increases or breaks the combo. /// public static bool AffectsCombo(this HitResult result) { From d45b54399b376289531a37f5635f03dfa64cc8c2 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 18:15:32 +0900 Subject: [PATCH 29/66] Add back minimum/maximum accuracy --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index 8c3cd27012..b470c09859 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -109,6 +109,11 @@ namespace osu.Game.Rulesets.Scoring /// private double currentBaseScore; + /// + /// The maximum sum of all accuracy-affecting judgements in the beatmap. + /// + private double maximumBaseScore; + /// /// The count of all accuracy-affecting judgements in the beatmap. /// @@ -284,6 +289,8 @@ namespace osu.Game.Rulesets.Scoring private void updateScore() { Accuracy.Value = currentMaximumBaseScore > 0 ? currentBaseScore / currentMaximumBaseScore : 1; + MinimumAccuracy.Value = maximumBaseScore > 0 ? currentBaseScore / maximumBaseScore : 0; + MaximumAccuracy.Value = maximumBaseScore > 0 ? (currentBaseScore + (maximumBaseScore - currentMaximumBaseScore)) / maximumBaseScore : 1; double comboProgress = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; double accuracyProcess = maximumCountAccuracyJudgements > 0 ? (double)currentCountAccuracyJudgements / maximumCountAccuracyJudgements : 1; @@ -311,6 +318,8 @@ namespace osu.Game.Rulesets.Scoring if (storeResults) { + maximumBaseScore = currentBaseScore; + maximumComboPortion = currentComboPortion; maximumCountAccuracyJudgements = currentCountAccuracyJudgements; @@ -334,9 +343,6 @@ namespace osu.Game.Rulesets.Scoring Rank.Disabled = false; Rank.Value = ScoreRank.X; HighestCombo.Value = 0; - - currentBaseScore = 0; - currentMaximumBaseScore = 0; } /// From 844c023fb71fc6b87386650e820c621b6ca5b2bd Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 18:18:27 +0900 Subject: [PATCH 30/66] Fix tests --- .../Gameplay/TestSceneScoreProcessor.cs | 20 +- .../Rulesets/Scoring/ScoreProcessorTest.cs | 189 +++++------------- ...MultiplayerGameplayLeaderboardTestScene.cs | 14 +- 3 files changed, 75 insertions(+), 148 deletions(-) diff --git a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs index 90c7688443..fbe4dba8ed 100644 --- a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs +++ b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs @@ -76,22 +76,38 @@ namespace osu.Game.Tests.Gameplay // Reset with a miss instead. scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame { - Header = new FrameHeader(0, 0, 0, new Dictionary { { HitResult.Miss, 1 } }, DateTimeOffset.Now) + Header = new FrameHeader(0, 0, 0, 0, new Dictionary { { HitResult.Miss, 1 } }, new ScoreProcessorStatistics + { + MaximumBaseScore = 300, + BaseScore = 0, + CountAccuracyJudgements = 1, + ComboPortion = 0, + BonusPortion = 0 + }, DateTimeOffset.Now) }); Assert.That(scoreProcessor.TotalScore.Value, Is.Zero); Assert.That(scoreProcessor.JudgedHits, Is.EqualTo(1)); Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(0)); + Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(0)); // Reset with no judged hit. scoreProcessor.ResetFromReplayFrame(new OsuReplayFrame { - Header = new FrameHeader(0, 0, 0, new Dictionary(), DateTimeOffset.Now) + Header = new FrameHeader(0, 0, 0, 0, new Dictionary(), new ScoreProcessorStatistics + { + MaximumBaseScore = 0, + BaseScore = 0, + CountAccuracyJudgements = 0, + ComboPortion = 0, + BonusPortion = 0 + }, DateTimeOffset.Now) }); Assert.That(scoreProcessor.TotalScore.Value, Is.Zero); Assert.That(scoreProcessor.JudgedHits, Is.Zero); Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(0)); + Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(1)); } [Test] diff --git a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs index 826c610f56..f51a4ad52b 100644 --- a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs +++ b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs @@ -14,11 +14,12 @@ using osu.Game.Rulesets.Difficulty; using osu.Game.Rulesets.Judgements; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; -using osu.Game.Scoring; +using osu.Game.Scoring.Legacy; using osu.Game.Tests.Beatmaps; namespace osu.Game.Tests.Rulesets.Scoring @@ -31,7 +32,7 @@ namespace osu.Game.Tests.Rulesets.Scoring [SetUp] public void SetUp() { - scoreProcessor = new ScoreProcessor(new TestRuleset()); + scoreProcessor = new ScoreProcessor(new OsuRuleset()); beatmap = new TestBeatmap(new RulesetInfo()) { HitObjects = new List @@ -41,15 +42,14 @@ namespace osu.Game.Tests.Rulesets.Scoring }; } - [TestCase(ScoringMode.Standardised, HitResult.Meh, 750_000)] - [TestCase(ScoringMode.Standardised, HitResult.Ok, 800_000)] + [TestCase(ScoringMode.Standardised, HitResult.Meh, 116_667)] + [TestCase(ScoringMode.Standardised, HitResult.Ok, 233_338)] [TestCase(ScoringMode.Standardised, HitResult.Great, 1_000_000)] - [TestCase(ScoringMode.Classic, HitResult.Meh, 20)] - [TestCase(ScoringMode.Classic, HitResult.Ok, 23)] + [TestCase(ScoringMode.Classic, HitResult.Meh, 0)] + [TestCase(ScoringMode.Classic, HitResult.Ok, 2)] [TestCase(ScoringMode.Classic, HitResult.Great, 36)] public void TestSingleOsuHit(ScoringMode scoringMode, HitResult hitResult, int expectedScore) { - scoreProcessor.Mode.Value = scoringMode; scoreProcessor.ApplyBeatmap(beatmap); var judgementResult = new JudgementResult(beatmap.HitObjects.Single(), new OsuJudgement()) @@ -58,7 +58,7 @@ namespace osu.Game.Tests.Rulesets.Scoring }; scoreProcessor.ApplyResult(judgementResult); - Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(expectedScore).Within(0.5d)); + Assert.That(scoreProcessor.GetDisplayScore(scoringMode), Is.EqualTo(expectedScore).Within(0.5d)); } /// @@ -70,39 +70,29 @@ namespace osu.Game.Tests.Rulesets.Scoring /// Expected score after all objects have been judged, rounded to the nearest integer. /// /// This test intentionally misses the 3rd hitobject to achieve lower than 75% accuracy and 50% max combo. - /// - /// For standardised scoring, is calculated using the following formula: - /// 1_000_000 * (((3 * ) / (4 * )) * 30% + (bestCombo / maxCombo) * 70%) - /// - /// - /// For classic scoring, is calculated using the following formula: - /// / * 936 - /// where 936 is simplified from: - /// 75% * 4 * 300 * (1 + 1/25) - /// /// - [TestCase(ScoringMode.Standardised, HitResult.Miss, HitResult.Great, 0)] // (3 * 0) / (4 * 300) * 300_000 + (0 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.Meh, HitResult.Great, 387_500)] // (3 * 50) / (4 * 300) * 300_000 + (2 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.Ok, HitResult.Great, 425_000)] // (3 * 100) / (4 * 300) * 300_000 + (2 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.Good, HitResult.Perfect, 492_857)] // (3 * 200) / (4 * 350) * 300_000 + (2 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.Great, HitResult.Great, 575_000)] // (3 * 300) / (4 * 300) * 300_000 + (2 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.Perfect, HitResult.Perfect, 575_000)] // (3 * 350) / (4 * 350) * 300_000 + (2 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.SmallTickMiss, HitResult.SmallTickHit, 700_000)] // (3 * 0) / (4 * 10) * 300_000 + 700_000 (max combo 0) - [TestCase(ScoringMode.Standardised, HitResult.SmallTickHit, HitResult.SmallTickHit, 925_000)] // (3 * 10) / (4 * 10) * 300_000 + 700_000 (max combo 0) - [TestCase(ScoringMode.Standardised, HitResult.LargeTickMiss, HitResult.LargeTickHit, 0)] // (3 * 0) / (4 * 30) * 300_000 + (0 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.LargeTickHit, HitResult.LargeTickHit, 575_000)] // (3 * 30) / (4 * 30) * 300_000 + (0 / 4) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.SmallBonus, HitResult.SmallBonus, 1_000_030)] // 1 * 300_000 + 700_000 (max combo 0) + 3 * 10 (bonus points) - [TestCase(ScoringMode.Standardised, HitResult.LargeBonus, HitResult.LargeBonus, 1_000_150)] // 1 * 300_000 + 700_000 (max combo 0) + 3 * 50 (bonus points) + [TestCase(ScoringMode.Standardised, HitResult.Miss, HitResult.Great, 0)] + [TestCase(ScoringMode.Standardised, HitResult.Meh, HitResult.Great, 79_333)] + [TestCase(ScoringMode.Standardised, HitResult.Ok, HitResult.Great, 158_667)] + [TestCase(ScoringMode.Standardised, HitResult.Good, HitResult.Perfect, 302_402)] + [TestCase(ScoringMode.Standardised, HitResult.Great, HitResult.Great, 492_894)] + [TestCase(ScoringMode.Standardised, HitResult.Perfect, HitResult.Perfect, 492_894)] + [TestCase(ScoringMode.Standardised, HitResult.SmallTickMiss, HitResult.SmallTickHit, 0)] + [TestCase(ScoringMode.Standardised, HitResult.SmallTickHit, HitResult.SmallTickHit, 541_894)] + [TestCase(ScoringMode.Standardised, HitResult.LargeTickMiss, HitResult.LargeTickHit, 0)] + [TestCase(ScoringMode.Standardised, HitResult.LargeTickHit, HitResult.LargeTickHit, 492_894)] + [TestCase(ScoringMode.Standardised, HitResult.SmallBonus, HitResult.SmallBonus, 1_000_030)] + [TestCase(ScoringMode.Standardised, HitResult.LargeBonus, HitResult.LargeBonus, 1_000_150)] [TestCase(ScoringMode.Classic, HitResult.Miss, HitResult.Great, 0)] - [TestCase(ScoringMode.Classic, HitResult.Meh, HitResult.Great, 86)] - [TestCase(ScoringMode.Classic, HitResult.Ok, HitResult.Great, 104)] - [TestCase(ScoringMode.Classic, HitResult.Good, HitResult.Perfect, 140)] - [TestCase(ScoringMode.Classic, HitResult.Great, HitResult.Great, 190)] - [TestCase(ScoringMode.Classic, HitResult.Perfect, HitResult.Perfect, 190)] - [TestCase(ScoringMode.Classic, HitResult.SmallTickMiss, HitResult.SmallTickHit, 18)] - [TestCase(ScoringMode.Classic, HitResult.SmallTickHit, HitResult.SmallTickHit, 31)] + [TestCase(ScoringMode.Classic, HitResult.Meh, HitResult.Great, 4)] + [TestCase(ScoringMode.Classic, HitResult.Ok, HitResult.Great, 15)] + [TestCase(ScoringMode.Classic, HitResult.Good, HitResult.Perfect, 53)] + [TestCase(ScoringMode.Classic, HitResult.Great, HitResult.Great, 140)] + [TestCase(ScoringMode.Classic, HitResult.Perfect, HitResult.Perfect, 140)] + [TestCase(ScoringMode.Classic, HitResult.SmallTickMiss, HitResult.SmallTickHit, 0)] + [TestCase(ScoringMode.Classic, HitResult.SmallTickHit, HitResult.SmallTickHit, 11)] [TestCase(ScoringMode.Classic, HitResult.LargeTickMiss, HitResult.LargeTickHit, 0)] - [TestCase(ScoringMode.Classic, HitResult.LargeTickHit, HitResult.LargeTickHit, 12)] + [TestCase(ScoringMode.Classic, HitResult.LargeTickHit, HitResult.LargeTickHit, 9)] [TestCase(ScoringMode.Classic, HitResult.SmallBonus, HitResult.SmallBonus, 36)] [TestCase(ScoringMode.Classic, HitResult.LargeBonus, HitResult.LargeBonus, 36)] public void TestFourVariousResultsOneMiss(ScoringMode scoringMode, HitResult hitResult, HitResult maxResult, int expectedScore) @@ -113,59 +103,18 @@ namespace osu.Game.Tests.Rulesets.Scoring { HitObjects = new List(Enumerable.Repeat(new TestHitObject(maxResult), 4)) }; - scoreProcessor.Mode.Value = scoringMode; scoreProcessor.ApplyBeatmap(fourObjectBeatmap); for (int i = 0; i < 4; i++) { - var judgementResult = new JudgementResult(fourObjectBeatmap.HitObjects[i], new Judgement()) + var judgementResult = new JudgementResult(fourObjectBeatmap.HitObjects[i], new TestJudgement(maxResult)) { Type = i == 2 ? minResult : hitResult }; scoreProcessor.ApplyResult(judgementResult); } - Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(expectedScore).Within(0.5d)); - } - - /// - /// This test uses a beatmap with four small ticks and one object with the of . - /// Its goal is to ensure that with the of , - /// small ticks contribute to the accuracy portion, but not the combo portion. - /// In contrast, does not have separate combo and accuracy portion (they are multiplied by each other). - /// - [TestCase(ScoringMode.Standardised, HitResult.SmallTickHit, 978_571)] // (3 * 10 + 100) / (4 * 10 + 100) * 300_000 + (1 / 1) * 700_000 - [TestCase(ScoringMode.Standardised, HitResult.SmallTickMiss, 914_286)] // (3 * 0 + 100) / (4 * 10 + 100) * 300_000 + (1 / 1) * 700_000 - [TestCase(ScoringMode.Classic, HitResult.SmallTickHit, 34)] - [TestCase(ScoringMode.Classic, HitResult.SmallTickMiss, 30)] - public void TestSmallTicksAccuracy(ScoringMode scoringMode, HitResult hitResult, int expectedScore) - { - IEnumerable hitObjects = Enumerable - .Repeat(new TestHitObject(HitResult.SmallTickHit), 4) - .Append(new TestHitObject(HitResult.Ok)); - IBeatmap fiveObjectBeatmap = new TestBeatmap(new RulesetInfo()) - { - HitObjects = hitObjects.ToList() - }; - scoreProcessor.Mode.Value = scoringMode; - scoreProcessor.ApplyBeatmap(fiveObjectBeatmap); - - for (int i = 0; i < 4; i++) - { - var judgementResult = new JudgementResult(fiveObjectBeatmap.HitObjects[i], new Judgement()) - { - Type = i == 2 ? HitResult.SmallTickMiss : hitResult - }; - scoreProcessor.ApplyResult(judgementResult); - } - - var lastJudgementResult = new JudgementResult(fiveObjectBeatmap.HitObjects.Last(), new Judgement()) - { - Type = HitResult.Ok - }; - scoreProcessor.ApplyResult(lastJudgementResult); - - Assert.That(scoreProcessor.TotalScore.Value, Is.EqualTo(expectedScore).Within(0.5d)); + Assert.That(scoreProcessor.GetDisplayScore(scoringMode), Is.EqualTo(expectedScore).Within(0.5d)); } [Test] @@ -173,10 +122,9 @@ namespace osu.Game.Tests.Rulesets.Scoring [Values(ScoringMode.Standardised, ScoringMode.Classic)] ScoringMode scoringMode) { - scoreProcessor.Mode.Value = scoringMode; scoreProcessor.ApplyBeatmap(new TestBeatmap(new RulesetInfo())); - Assert.That(scoreProcessor.TotalScore.Value, Is.Zero); + Assert.That(scoreProcessor.GetDisplayScore(scoringMode), Is.Zero); } [TestCase(HitResult.IgnoreHit, HitResult.IgnoreMiss)] @@ -294,28 +242,6 @@ namespace osu.Game.Tests.Rulesets.Scoring Assert.AreEqual(expectedReturnValue, hitResult.IsScorable()); } - [TestCase(HitResult.Perfect, 1_000_000)] - [TestCase(HitResult.SmallTickHit, 1_000_000)] - [TestCase(HitResult.LargeTickHit, 1_000_000)] - [TestCase(HitResult.SmallBonus, 1_000_000 + Judgement.SMALL_BONUS_SCORE)] - [TestCase(HitResult.LargeBonus, 1_000_000 + Judgement.LARGE_BONUS_SCORE)] - public void TestGetScoreWithExternalStatistics(HitResult result, int expectedScore) - { - var statistic = new Dictionary { { result, 1 } }; - - scoreProcessor.ApplyBeatmap(new Beatmap - { - HitObjects = { new TestHitObject(result) } - }); - - Assert.That(scoreProcessor.ComputeScore(ScoringMode.Standardised, new ScoreInfo - { - Ruleset = new TestRuleset().RulesetInfo, - MaxCombo = result.AffectsCombo() ? 1 : 0, - Statistics = statistic - }), Is.EqualTo(expectedScore).Within(0.5d)); - } - #pragma warning disable CS0618 [Test] public void TestLegacyComboIncrease() @@ -330,29 +256,6 @@ namespace osu.Game.Tests.Rulesets.Scoring Assert.That(HitResult.LegacyComboIncrease.IsHit(), Is.True); Assert.That(HitResult.LegacyComboIncrease.IsScorable(), Is.True); Assert.That(HitResultExtensions.ALL_TYPES, Does.Not.Contain(HitResult.LegacyComboIncrease)); - - // Cannot be used to apply results. - Assert.Throws(() => scoreProcessor.ApplyBeatmap(new Beatmap - { - HitObjects = { new TestHitObject(HitResult.LegacyComboIncrease) } - })); - - ScoreInfo testScore = new ScoreInfo - { - MaxCombo = 1, - Statistics = new Dictionary - { - { HitResult.Great, 1 } - }, - MaximumStatistics = new Dictionary - { - { HitResult.Great, 1 }, - { HitResult.LegacyComboIncrease, 1 } - } - }; - - double totalScore = new TestScoreProcessor().ComputeScore(ScoringMode.Standardised, testScore); - Assert.That(totalScore, Is.EqualTo(750_000)); // 500K from accuracy (100%), and 250K from combo (50%). } #pragma warning restore CS0618 @@ -362,16 +265,24 @@ namespace osu.Game.Tests.Rulesets.Scoring const int count_judgements = 1000; const int count_misses = 1; - double actual = new TestScoreProcessor().ComputeAccuracy(new ScoreInfo + beatmap = new TestBeatmap(new RulesetInfo()) { - Statistics = new Dictionary + HitObjects = new List(Enumerable.Repeat(new TestHitObject(HitResult.Great), count_judgements)) + }; + + scoreProcessor = new TestScoreProcessor(); + scoreProcessor.ApplyBeatmap(beatmap); + + for (int i = 0; i < beatmap.HitObjects.Count; i++) + { + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], new TestJudgement(HitResult.Great)) { - { HitResult.Great, count_judgements - count_misses }, - { HitResult.Miss, count_misses } - } - }); + Type = i == 0 ? HitResult.Miss : HitResult.Great + }); + } const double expected = (count_judgements - count_misses) / (double)count_judgements; + double actual = scoreProcessor.Accuracy.Value; Assert.That(actual, Is.Not.EqualTo(0.0)); Assert.That(actual, Is.Not.EqualTo(1.0)); @@ -419,14 +330,18 @@ namespace osu.Game.Tests.Rulesets.Scoring private partial class TestScoreProcessor : ScoreProcessor { - protected override double DefaultAccuracyPortion => 0.5; - protected override double DefaultComboPortion => 0.5; - public TestScoreProcessor() : base(new TestRuleset()) { } + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) + { + return 500000 * comboProgress + + 500000 * Accuracy.Value * accuracyProgress + + bonusPortion; + } + // ReSharper disable once MemberHidesStaticFromOuterClass private class TestRuleset : Ruleset { diff --git a/osu.Game.Tests/Visual/Multiplayer/MultiplayerGameplayLeaderboardTestScene.cs b/osu.Game.Tests/Visual/Multiplayer/MultiplayerGameplayLeaderboardTestScene.cs index 649c662e41..906eea9553 100644 --- a/osu.Game.Tests/Visual/Multiplayer/MultiplayerGameplayLeaderboardTestScene.cs +++ b/osu.Game.Tests/Visual/Multiplayer/MultiplayerGameplayLeaderboardTestScene.cs @@ -21,7 +21,6 @@ using osu.Game.Online.Multiplayer; using osu.Game.Online.Spectator; using osu.Game.Replays.Legacy; using osu.Game.Rulesets.Scoring; -using osu.Game.Scoring; using osu.Game.Screens.Play.HUD; namespace osu.Game.Tests.Visual.Multiplayer @@ -188,15 +187,12 @@ namespace osu.Game.Tests.Visual.Multiplayer if (!lastHeaders.TryGetValue(userId, out var header)) { - lastHeaders[userId] = header = new FrameHeader(new ScoreInfo + lastHeaders[userId] = header = new FrameHeader(0, 0, 0, 0, new Dictionary { - Statistics = new Dictionary - { - [HitResult.Miss] = 0, - [HitResult.Meh] = 0, - [HitResult.Great] = 0 - } - }); + [HitResult.Miss] = 0, + [HitResult.Meh] = 0, + [HitResult.Great] = 0 + }, new ScoreProcessorStatistics(), DateTimeOffset.Now); } switch (RNG.Next(0, 3)) From 7658536b5afcd3b499aa0b5b5bc70ba5b22b88ec Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 23 May 2023 19:32:19 +0900 Subject: [PATCH 31/66] Fix CI issues --- .../Rulesets/Scoring/ScoreProcessorTest.cs | 14 -------------- osu.Game/Screens/Ranking/ScorePanelList.cs | 4 ---- 2 files changed, 18 deletions(-) diff --git a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs index f51a4ad52b..e5e96d2033 100644 --- a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs +++ b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs @@ -289,20 +289,6 @@ namespace osu.Game.Tests.Rulesets.Scoring Assert.That(actual, Is.EqualTo(expected).Within(Precision.FLOAT_EPSILON)); } - private class TestRuleset : Ruleset - { - public override IEnumerable GetModsFor(ModType type) => throw new NotImplementedException(); - - public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList mods = null) => throw new NotImplementedException(); - - public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap) => throw new NotImplementedException(); - - public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap) => throw new NotImplementedException(); - - public override string Description => string.Empty; - public override string ShortName => string.Empty; - } - private class TestJudgement : Judgement { public override HitResult MaxResult { get; } diff --git a/osu.Game/Screens/Ranking/ScorePanelList.cs b/osu.Game/Screens/Ranking/ScorePanelList.cs index 1f93389e94..b75f3d86ff 100644 --- a/osu.Game/Screens/Ranking/ScorePanelList.cs +++ b/osu.Game/Screens/Ranking/ScorePanelList.cs @@ -9,7 +9,6 @@ using System.Diagnostics; using System.Linq; using System.Threading; using JetBrains.Annotations; -using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -67,9 +66,6 @@ namespace osu.Game.Screens.Ranking public readonly Bindable SelectedScore = new Bindable(); - [Resolved] - private ScoreManager scoreManager { get; set; } - private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource(); private readonly Flow flow; private readonly Scroll scroll; From 6d9ba9248dd2dd01a75c988fceabc44fd716f2ad Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Thu, 25 May 2023 16:38:22 +0900 Subject: [PATCH 32/66] Massage tests a bit more --- osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs | 4 ++-- .../Visual/Gameplay/TestSceneSkinEditorMultipleSkins.cs | 4 ++-- .../Visual/Gameplay/TestSceneSkinnableHUDOverlay.cs | 4 ++-- .../Visual/Gameplay/TestSceneSkinnableScoreCounter.cs | 5 +++-- .../Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs | 5 +++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs index ae46dda750..f97019e466 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneHUDOverlay.cs @@ -31,8 +31,8 @@ namespace osu.Game.Tests.Visual.Gameplay private HUDOverlay hudOverlay = null!; - [Cached] - private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset()); + [Cached(typeof(ScoreProcessor))] + private ScoreProcessor scoreProcessor => gameplayState.ScoreProcessor; [Cached(typeof(HealthProcessor))] private HealthProcessor healthProcessor = new DrainingHealthProcessor(0); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditorMultipleSkins.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditorMultipleSkins.cs index 93fec60de4..4ae115a68d 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditorMultipleSkins.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinEditorMultipleSkins.cs @@ -22,8 +22,8 @@ namespace osu.Game.Tests.Visual.Gameplay { public partial class TestSceneSkinEditorMultipleSkins : SkinnableTestScene { - [Cached] - private readonly ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset()); + [Cached(typeof(ScoreProcessor))] + private ScoreProcessor scoreProcessor => gameplayState.ScoreProcessor; [Cached(typeof(HealthProcessor))] private HealthProcessor healthProcessor = new DrainingHealthProcessor(0); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableHUDOverlay.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableHUDOverlay.cs index 0439656aae..89432940ba 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableHUDOverlay.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableHUDOverlay.cs @@ -28,8 +28,8 @@ namespace osu.Game.Tests.Visual.Gameplay { private HUDOverlay hudOverlay; - [Cached] - private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset()); + [Cached(typeof(ScoreProcessor))] + private ScoreProcessor scoreProcessor => gameplayState.ScoreProcessor; [Cached(typeof(HealthProcessor))] private HealthProcessor healthProcessor = new DrainingHealthProcessor(0); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableScoreCounter.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableScoreCounter.cs index c95e8ee5b2..2cb3303dd6 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableScoreCounter.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSkinnableScoreCounter.cs @@ -10,13 +10,14 @@ using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Play.HUD; using osu.Game.Skinning; +using osu.Game.Tests.Gameplay; namespace osu.Game.Tests.Visual.Gameplay { public partial class TestSceneSkinnableScoreCounter : SkinnableHUDComponentTestScene { - [Cached] - private ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset()); + [Cached(typeof(ScoreProcessor))] + private ScoreProcessor scoreProcessor = TestGameplayState.Create(new OsuRuleset()).ScoreProcessor; protected override Drawable CreateDefaultImplementation() => new DefaultScoreCounter(); protected override Drawable CreateLegacyImplementation() => new LegacyScoreCounter(); diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs index 8ae6a2a5fc..dbd14db818 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneSoloGameplayLeaderboard.cs @@ -16,13 +16,14 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Scoring; using osu.Game.Screens.Play.HUD; using osu.Game.Screens.Select; +using osu.Game.Tests.Gameplay; namespace osu.Game.Tests.Visual.Gameplay { public partial class TestSceneSoloGameplayLeaderboard : OsuTestScene { - [Cached] - private readonly ScoreProcessor scoreProcessor = new ScoreProcessor(new OsuRuleset()); + [Cached(typeof(ScoreProcessor))] + private readonly ScoreProcessor scoreProcessor = TestGameplayState.Create(new OsuRuleset()).ScoreProcessor; private readonly BindableList scores = new BindableList(); From 57c63dbb290a32faa39e9a68af10dc032bfeeb23 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 May 2023 19:24:15 +0900 Subject: [PATCH 33/66] Add xmldoc for `GetDisplayScore` --- osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 74a3925435..b7247ed8cc 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -57,6 +57,10 @@ namespace osu.Game.Screens.Play.HUD public BindableInt Combo { get; } = new BindableInt(); public BindableBool HasQuit { get; } = new BindableBool(); public Bindable DisplayOrder { get; } = new Bindable(); + + /// + /// A function providing a display score. If a custom function is not provided, this defaults to using . + /// public Func GetDisplayScore { get; set; } public Color4? BackgroundColour { get; set; } From b3c2d120bf8e8d6e60e6a618f1df976d82b6d406 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 May 2023 20:39:11 +0900 Subject: [PATCH 34/66] Fix `OnResume` / `OnSuspending` potentially getting called before `OnEntering` on a sub screen --- osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs index 3d80248306..cfaae56d0f 100644 --- a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs +++ b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs @@ -132,7 +132,9 @@ namespace osu.Game.Screens.OnlinePlay this.ScaleTo(1, 250, Easing.OutSine); Debug.Assert(screenStack.CurrentScreen != null); - screenStack.CurrentScreen.OnResuming(e); + + if (screenStack.CurrentScreen.IsCurrentScreen()) + screenStack.CurrentScreen.OnResuming(e); base.OnResuming(e); } @@ -143,7 +145,9 @@ namespace osu.Game.Screens.OnlinePlay this.FadeOut(250); Debug.Assert(screenStack.CurrentScreen != null); - screenStack.CurrentScreen.OnSuspending(e); + + if (screenStack.CurrentScreen.IsCurrentScreen()) + screenStack.CurrentScreen.OnSuspending(e); } public override bool OnExiting(ScreenExitEvent e) From a789d1e49c85687e120e42f83a7dbc4a6980c0eb Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 18:38:16 +0900 Subject: [PATCH 35/66] Add xmldoc and change naming around `ScoreProcessorStatistics` a bit --- .../Gameplay/TestSceneScoreProcessor.cs | 4 +-- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs index fbe4dba8ed..a261185473 100644 --- a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs +++ b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs @@ -80,7 +80,7 @@ namespace osu.Game.Tests.Gameplay { MaximumBaseScore = 300, BaseScore = 0, - CountAccuracyJudgements = 1, + AccuracyJudgementCount = 1, ComboPortion = 0, BonusPortion = 0 }, DateTimeOffset.Now) @@ -98,7 +98,7 @@ namespace osu.Game.Tests.Gameplay { MaximumBaseScore = 0, BaseScore = 0, - CountAccuracyJudgements = 0, + AccuracyJudgementCount = 0, ComboPortion = 0, BonusPortion = 0 }, DateTimeOffset.Now) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index b470c09859..a0d8187642 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -407,7 +407,7 @@ namespace osu.Game.Rulesets.Scoring { MaximumBaseScore = currentMaximumBaseScore, BaseScore = currentBaseScore, - CountAccuracyJudgements = currentCountAccuracyJudgements, + AccuracyJudgementCount = currentCountAccuracyJudgements, ComboPortion = currentComboPortion, BonusPortion = currentBonusPortion }; @@ -416,7 +416,7 @@ namespace osu.Game.Rulesets.Scoring { currentMaximumBaseScore = statistics.MaximumBaseScore; currentBaseScore = statistics.BaseScore; - currentCountAccuracyJudgements = statistics.CountAccuracyJudgements; + currentCountAccuracyJudgements = statistics.AccuracyJudgementCount; currentComboPortion = statistics.ComboPortion; currentBonusPortion = statistics.BonusPortion; } @@ -497,18 +497,40 @@ namespace osu.Game.Rulesets.Scoring [MessagePackObject] public class ScoreProcessorStatistics { + /// + /// The sum of all accuracy-affecting judgements at the current point in time. + /// + /// + /// Used to compute accuracy. + /// See: and . + /// [Key(0)] - public double MaximumBaseScore { get; set; } - - [Key(1)] public double BaseScore { get; set; } - [Key(2)] - public int CountAccuracyJudgements { get; set; } + /// + /// The maximum sum of accuracy-affecting judgements at the current point in time. + /// + /// + /// Used to compute accuracy. + /// + [Key(1)] + public double MaximumBaseScore { get; set; } + /// + /// The count of accuracy-affecting judgements at the current point in time. + /// + [Key(2)] + public int AccuracyJudgementCount { get; set; } + + /// + /// The combo score at the current point in time. + /// [Key(3)] public double ComboPortion { get; set; } + /// + /// The bonus score at the current point in time. + /// [Key(4)] public double BonusPortion { get; set; } } From 22be045de3bd788529e1dd52eabf41597350abd3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 18:48:17 +0900 Subject: [PATCH 36/66] Apply NRT to `GameplayScoreCounter` --- osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs index a696d2cad7..bc953e05d2 100644 --- a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs +++ b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -15,8 +13,9 @@ namespace osu.Game.Screens.Play.HUD { public abstract partial class GameplayScoreCounter : ScoreCounter { - private Bindable scoreDisplayMode; - private Bindable totalScoreBindable; + private Bindable scoreDisplayMode = null!; + + private Bindable totalScoreBindable = null!; protected GameplayScoreCounter() : base(6) From 9a886125ad973f7af619c7f284e340e26855ec79 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 19:00:01 +0900 Subject: [PATCH 37/66] Ensure `GameplayScoreCounter`'s display score is updated on `ScoringMode` change This isn't strictly required, but only because of a kind of hacky behaviour where `HUDOverlay` will recreate all components on a scoring mode change currently (see https://github.com/ppy/osu/blob/8f6df5ea0f7f721c630fc8cad93bb3eef869d1d9/osu.Game/Screens/Play/HUDOverlay.cs#L410-L418). Best we do this just in case that happens to go away in the future. --- osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs index bc953e05d2..a086aa6d72 100644 --- a/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs +++ b/osu.Game/Screens/Play/HUD/GameplayScoreCounter.cs @@ -25,6 +25,9 @@ namespace osu.Game.Screens.Play.HUD [BackgroundDependencyLoader] private void load(OsuConfigManager config, ScoreProcessor scoreProcessor) { + totalScoreBindable = scoreProcessor.TotalScore.GetBoundCopy(); + totalScoreBindable.BindValueChanged(_ => updateDisplayScore()); + scoreDisplayMode = config.GetBindable(OsuSetting.ScoreDisplayMode); scoreDisplayMode.BindValueChanged(scoreMode => { @@ -41,10 +44,11 @@ namespace osu.Game.Screens.Play.HUD default: throw new ArgumentOutOfRangeException(nameof(scoreMode)); } + + updateDisplayScore(); }, true); - totalScoreBindable = scoreProcessor.TotalScore.GetBoundCopy(); - totalScoreBindable.BindValueChanged(_ => Current.Value = scoreProcessor.GetDisplayScore(scoreDisplayMode.Value), true); + void updateDisplayScore() => Current.Value = scoreProcessor.GetDisplayScore(scoreDisplayMode.Value); } } } From fcd7a1d51a915d289e14a69d6b29a8294f59bfb1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 19:41:53 +0900 Subject: [PATCH 38/66] Move `GetDisplayScore` xmldoc to interface and remove getter --- osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs | 3 --- osu.Game/Screens/Play/HUD/ILeaderboardScore.cs | 5 ++++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index b7247ed8cc..496fc82019 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -58,9 +58,6 @@ namespace osu.Game.Screens.Play.HUD public BindableBool HasQuit { get; } = new BindableBool(); public Bindable DisplayOrder { get; } = new Bindable(); - /// - /// A function providing a display score. If a custom function is not provided, this defaults to using . - /// public Func GetDisplayScore { get; set; } public Color4? BackgroundColour { get; set; } diff --git a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs index cc1d83e0c7..5de38396fb 100644 --- a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs @@ -23,6 +23,9 @@ namespace osu.Game.Screens.Play.HUD /// Bindable DisplayOrder { get; } - Func GetDisplayScore { get; set; } + /// + /// A function providing a display score. If a custom function is not provided, this defaults to using . + /// + Func GetDisplayScore { set; } } } From 1a6d9e9ff0dded325167a333eed03f1e8e85f928 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 19:46:50 +0900 Subject: [PATCH 39/66] Apply NRT to `GameplayLeaderboardScore` and change `GetDisplayedScore` handling I don't feel too confident with the default scoring function being assigned in the constructor to a publicly settable delegate. This just feels a bit more elegant, and handles the (likely-never-used) case where we need to restore the default function. An alternative would be to provide the function as a `ctor` argument, but I believe that wasn't done here to allow using the `ILeaderboardScore` interface. --- .../Play/HUD/GameplayLeaderboardScore.cs | 38 +++++++++---------- .../Screens/Play/HUD/ILeaderboardScore.cs | 6 +-- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs index 496fc82019..4ac2f1afda 100644 --- a/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/GameplayLeaderboardScore.cs @@ -1,10 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; @@ -50,7 +47,7 @@ namespace osu.Game.Screens.Play.HUD public Bindable Expanded = new Bindable(); - private OsuSpriteText positionText, scoreText, accuracyText, comboText, usernameText; + private OsuSpriteText positionText = null!, scoreText = null!, accuracyText = null!, comboText = null!, usernameText = null!; public BindableLong TotalScore { get; } = new BindableLong(); public BindableDouble Accuracy { get; } = new BindableDouble(1); @@ -58,7 +55,12 @@ namespace osu.Game.Screens.Play.HUD public BindableBool HasQuit { get; } = new BindableBool(); public Bindable DisplayOrder { get; } = new Bindable(); - public Func GetDisplayScore { get; set; } + private Func? getDisplayScoreFunction; + + public Func GetDisplayScore + { + set => getDisplayScoreFunction = value; + } public Color4? BackgroundColour { get; set; } @@ -86,32 +88,31 @@ namespace osu.Game.Screens.Play.HUD } } - [CanBeNull] - public IUser User { get; } + public IUser? User { get; } /// /// Whether this score is the local user or a replay player (and should be focused / always visible). /// public readonly bool Tracked; - private Container mainFillContainer; + private Container mainFillContainer = null!; - private Box centralFill; + private Box centralFill = null!; - private Container backgroundPaddingAdjustContainer; + private Container backgroundPaddingAdjustContainer = null!; - private GridContainer gridContainer; + private GridContainer gridContainer = null!; - private Container scoreComponents; + private Container scoreComponents = null!; - private IBindable scoreDisplayMode; + private IBindable scoreDisplayMode = null!; /// /// Creates a new . /// /// The score's player. /// Whether the player is the local user or a replay player. - public GameplayLeaderboardScore([CanBeNull] IUser user, bool tracked) + public GameplayLeaderboardScore(IUser? user, bool tracked) { User = user; Tracked = tracked; @@ -242,7 +243,7 @@ namespace osu.Game.Screens.Play.HUD Origin = Anchor.CentreLeft, Colour = Color4.White, Font = OsuFont.Torus.With(size: 14, weight: FontWeight.SemiBold), - Text = User?.Username, + Text = User?.Username ?? string.Empty, Truncate = true, Shadow = false, } @@ -313,11 +314,6 @@ namespace osu.Game.Screens.Play.HUD HasQuit.BindValueChanged(_ => updateState()); } - private void updateScore() - { - scoreText.Text = GetDisplayScore(scoreDisplayMode.Value).ToString("N0"); - } - protected override void LoadComplete() { base.LoadComplete(); @@ -328,6 +324,8 @@ namespace osu.Game.Screens.Play.HUD FinishTransforms(true); } + private void updateScore() => scoreText.Text = (getDisplayScoreFunction?.Invoke(scoreDisplayMode.Value) ?? TotalScore.Value).ToString("N0"); + private void changeExpandedState(ValueChangedEvent expanded) { if (expanded.NewValue) diff --git a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs index 5de38396fb..1a5d7fd9a8 100644 --- a/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs +++ b/osu.Game/Screens/Play/HUD/ILeaderboardScore.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable disable - using System; using osu.Framework.Bindables; using osu.Game.Rulesets.Scoring; @@ -24,8 +22,10 @@ namespace osu.Game.Screens.Play.HUD Bindable DisplayOrder { get; } /// - /// A function providing a display score. If a custom function is not provided, this defaults to using . + /// A custom function which handles converting a score to a display score using a provide . /// + /// + /// If no function is provided, will be used verbatim. Func GetDisplayScore { set; } } } From df662afbd56a9f2e7042eb4f1900ac6a1647c5f4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 20:00:42 +0900 Subject: [PATCH 40/66] Pass `ScoreProcessorStatistics` to `FrameHeader`, rather than the full processor --- osu.Game/Online/Spectator/FrameDataBundle.cs | 2 +- osu.Game/Online/Spectator/FrameHeader.cs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Online/Spectator/FrameDataBundle.cs b/osu.Game/Online/Spectator/FrameDataBundle.cs index b936847434..d58ddd5310 100644 --- a/osu.Game/Online/Spectator/FrameDataBundle.cs +++ b/osu.Game/Online/Spectator/FrameDataBundle.cs @@ -24,7 +24,7 @@ namespace osu.Game.Online.Spectator public FrameDataBundle(ScoreInfo score, ScoreProcessor scoreProcessor, IList frames) { Frames = frames; - Header = new FrameHeader(score, scoreProcessor); + Header = new FrameHeader(score, scoreProcessor.GetScoreProcessorStatistics()); } [JsonConstructor] diff --git a/osu.Game/Online/Spectator/FrameHeader.cs b/osu.Game/Online/Spectator/FrameHeader.cs index 4d1c2c2cff..45f920e65b 100644 --- a/osu.Game/Online/Spectator/FrameHeader.cs +++ b/osu.Game/Online/Spectator/FrameHeader.cs @@ -60,18 +60,17 @@ namespace osu.Game.Online.Spectator /// Construct header summary information from a point-in-time reference to a score which is actively being played. /// /// The score for reference. - /// The score processor for reference. - public FrameHeader(ScoreInfo score, ScoreProcessor scoreProcessor) + /// The score processor statistics for the current point in time. + public FrameHeader(ScoreInfo score, ScoreProcessorStatistics statistics) { TotalScore = score.TotalScore; Accuracy = score.Accuracy; Combo = score.Combo; MaxCombo = score.MaxCombo; - // copy for safety Statistics = new Dictionary(score.Statistics); - ScoreProcessorStatistics = scoreProcessor.GetScoreProcessorStatistics(); + ScoreProcessorStatistics = statistics; } [JsonConstructor] From b3ca409339fd15fa7f06608b584f614847d58885 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 29 May 2023 20:08:22 +0900 Subject: [PATCH 41/66] Rename a few remaining `CountAccuracyJudgement` variable --- osu.Game/Rulesets/Scoring/ScoreProcessor.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs index a0d8187642..ac17de32d8 100644 --- a/osu.Game/Rulesets/Scoring/ScoreProcessor.cs +++ b/osu.Game/Rulesets/Scoring/ScoreProcessor.cs @@ -117,12 +117,12 @@ namespace osu.Game.Rulesets.Scoring /// /// The count of all accuracy-affecting judgements in the beatmap. /// - private int maximumCountAccuracyJudgements; + private int maximumAccuracyJudgementCount; /// /// The count of accuracy-affecting judgements at the current point in time. /// - private int currentCountAccuracyJudgements; + private int currentAccuracyJudgementCount; /// /// The maximum combo score in the beatmap. @@ -216,7 +216,7 @@ namespace osu.Game.Rulesets.Scoring { currentMaximumBaseScore += Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore += Judgement.ToNumericResult(result.Type); - currentCountAccuracyJudgements++; + currentAccuracyJudgementCount++; } if (result.Type.IsBonus()) @@ -257,7 +257,7 @@ namespace osu.Game.Rulesets.Scoring { currentMaximumBaseScore -= Judgement.ToNumericResult(result.Judgement.MaxResult); currentBaseScore -= Judgement.ToNumericResult(result.Type); - currentCountAccuracyJudgements--; + currentAccuracyJudgementCount--; } if (result.Type.IsBonus()) @@ -293,7 +293,7 @@ namespace osu.Game.Rulesets.Scoring MaximumAccuracy.Value = maximumBaseScore > 0 ? (currentBaseScore + (maximumBaseScore - currentMaximumBaseScore)) / maximumBaseScore : 1; double comboProgress = maximumComboPortion > 0 ? currentComboPortion / maximumComboPortion : 1; - double accuracyProcess = maximumCountAccuracyJudgements > 0 ? (double)currentCountAccuracyJudgements / maximumCountAccuracyJudgements : 1; + double accuracyProcess = maximumAccuracyJudgementCount > 0 ? (double)currentAccuracyJudgementCount / maximumAccuracyJudgementCount : 1; TotalScore.Value = (long)Math.Round(ComputeTotalScore(comboProgress, accuracyProcess, currentBonusPortion) * scoreMultiplier); } @@ -321,7 +321,7 @@ namespace osu.Game.Rulesets.Scoring maximumBaseScore = currentBaseScore; maximumComboPortion = currentComboPortion; - maximumCountAccuracyJudgements = currentCountAccuracyJudgements; + maximumAccuracyJudgementCount = currentAccuracyJudgementCount; maximumResultCounts.Clear(); maximumResultCounts.AddRange(scoreResultCounts); @@ -333,7 +333,7 @@ namespace osu.Game.Rulesets.Scoring currentBaseScore = 0; currentMaximumBaseScore = 0; - currentCountAccuracyJudgements = 0; + currentAccuracyJudgementCount = 0; currentComboPortion = 0; currentBonusPortion = 0; @@ -407,7 +407,7 @@ namespace osu.Game.Rulesets.Scoring { MaximumBaseScore = currentMaximumBaseScore, BaseScore = currentBaseScore, - AccuracyJudgementCount = currentCountAccuracyJudgements, + AccuracyJudgementCount = currentAccuracyJudgementCount, ComboPortion = currentComboPortion, BonusPortion = currentBonusPortion }; @@ -416,7 +416,7 @@ namespace osu.Game.Rulesets.Scoring { currentMaximumBaseScore = statistics.MaximumBaseScore; currentBaseScore = statistics.BaseScore; - currentCountAccuracyJudgements = statistics.AccuracyJudgementCount; + currentAccuracyJudgementCount = statistics.AccuracyJudgementCount; currentComboPortion = statistics.ComboPortion; currentBonusPortion = statistics.BonusPortion; } From 1c199b83e3453678888cfbe03b73cb123e43cfdb Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Mon, 29 May 2023 21:14:03 +0900 Subject: [PATCH 42/66] Replace mania scroll "time" with scroll "speed" --- .../ManiaRulesetConfigManager.cs | 29 +++++++++++--- .../ManiaSettingsSubsection.cs | 9 ++--- .../UI/DrawableManiaRuleset.cs | 38 ++++++++++--------- .../Localisation/RulesetSettingsStrings.cs | 2 +- 4 files changed, 49 insertions(+), 29 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs index 99a80ef28d..5ba5125c2d 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs @@ -15,24 +15,41 @@ namespace osu.Game.Rulesets.Mania.Configuration public ManiaRulesetConfigManager(SettingsStore? settings, RulesetInfo ruleset, int? variant = null) : base(settings, ruleset, variant) { + migrate(); } protected override void InitialiseDefaults() { base.InitialiseDefaults(); - SetDefault(ManiaRulesetSetting.ScrollTime, 1500.0, DrawableManiaRuleset.MIN_TIME_RANGE, DrawableManiaRuleset.MAX_TIME_RANGE, 5); +#pragma warning disable CS0618 + // Although obsolete, this is still required to populate the bindable from the database in case migration is required. + SetDefault(ManiaRulesetSetting.ScrollTime, null); +#pragma warning restore CS0618 + + SetDefault(ManiaRulesetSetting.ScrollSpeed, 8, 1, 40); SetDefault(ManiaRulesetSetting.ScrollDirection, ManiaScrollingDirection.Down); SetDefault(ManiaRulesetSetting.TimingBasedNoteColouring, false); } +#pragma warning disable CS0618 + private void migrate() + { + if (Get(ManiaRulesetSetting.ScrollTime) is double scrollTime) + { + SetValue(ManiaRulesetSetting.ScrollSpeed, (int)Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / scrollTime)); + SetValue(ManiaRulesetSetting.ScrollTime, null); + } + } +#pragma warning restore CS0618 + public override TrackedSettings CreateTrackedSettings() => new TrackedSettings { - new TrackedSetting(ManiaRulesetSetting.ScrollTime, - scrollTime => new SettingDescription( - rawValue: scrollTime, + new TrackedSetting(ManiaRulesetSetting.ScrollSpeed, + speed => new SettingDescription( + rawValue: speed, name: RulesetSettingsStrings.ScrollSpeed, - value: RulesetSettingsStrings.ScrollSpeedTooltip(scrollTime, (int)Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / scrollTime)) + value: RulesetSettingsStrings.ScrollSpeedTooltip(DrawableManiaRuleset.ComputeScrollTime(speed), speed) ) ) }; @@ -40,7 +57,9 @@ namespace osu.Game.Rulesets.Mania.Configuration public enum ManiaRulesetSetting { + [Obsolete("Use ScrollSpeed instead.")] // Can be removed 2023-11-30 ScrollTime, + ScrollSpeed, ScrollDirection, TimingBasedNoteColouring } diff --git a/osu.Game.Rulesets.Mania/ManiaSettingsSubsection.cs b/osu.Game.Rulesets.Mania/ManiaSettingsSubsection.cs index fc0b4a9ed9..a5434a36ab 100644 --- a/osu.Game.Rulesets.Mania/ManiaSettingsSubsection.cs +++ b/osu.Game.Rulesets.Mania/ManiaSettingsSubsection.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Localisation; @@ -34,10 +33,10 @@ namespace osu.Game.Rulesets.Mania LabelText = RulesetSettingsStrings.ScrollingDirection, Current = config.GetBindable(ManiaRulesetSetting.ScrollDirection) }, - new SettingsSlider + new SettingsSlider { LabelText = RulesetSettingsStrings.ScrollSpeed, - Current = config.GetBindable(ManiaRulesetSetting.ScrollTime), + Current = config.GetBindable(ManiaRulesetSetting.ScrollSpeed), KeyboardStep = 5 }, new SettingsCheckbox @@ -48,9 +47,9 @@ namespace osu.Game.Rulesets.Mania }; } - private partial class ManiaScrollSlider : RoundedSliderBar + private partial class ManiaScrollSlider : RoundedSliderBar { - public override LocalisableString TooltipText => RulesetSettingsStrings.ScrollSpeedTooltip(Current.Value, (int)Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / Current.Value)); + public override LocalisableString TooltipText => RulesetSettingsStrings.ScrollSpeedTooltip(DrawableManiaRuleset.ComputeScrollTime(Current.Value), Current.Value); } } } diff --git a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs index af8758fb5e..2d373c0471 100644 --- a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs @@ -33,12 +33,12 @@ namespace osu.Game.Rulesets.Mania.UI public partial class DrawableManiaRuleset : DrawableScrollingRuleset { /// - /// The minimum time range. This occurs at a of 40. + /// The minimum time range. This occurs at a of 40. /// public const double MIN_TIME_RANGE = 290; /// - /// The maximum time range. This occurs at a of 1. + /// The maximum time range. This occurs with a of 1. /// public const double MAX_TIME_RANGE = 11485; @@ -69,7 +69,8 @@ namespace osu.Game.Rulesets.Mania.UI protected override ScrollVisualisationMethod VisualisationMethod => scrollMethod; private readonly Bindable configDirection = new Bindable(); - private readonly BindableDouble configTimeRange = new BindableDouble(); + private readonly BindableInt configScrollSpeed = new BindableInt(); + private double smoothTimeRange; // Stores the current speed adjustment active in gameplay. private readonly Track speedAdjustmentTrack = new TrackVirtual(0); @@ -78,6 +79,9 @@ namespace osu.Game.Rulesets.Mania.UI : base(ruleset, beatmap, mods) { BarLines = new BarLineGenerator(Beatmap).BarLines; + + TimeRange.MinValue = 1; + TimeRange.MaxValue = MAX_TIME_RANGE; } [BackgroundDependencyLoader] @@ -104,30 +108,28 @@ namespace osu.Game.Rulesets.Mania.UI Config.BindWith(ManiaRulesetSetting.ScrollDirection, configDirection); configDirection.BindValueChanged(direction => Direction.Value = (ScrollingDirection)direction.NewValue, true); - Config.BindWith(ManiaRulesetSetting.ScrollTime, configTimeRange); - TimeRange.MinValue = configTimeRange.MinValue; - TimeRange.MaxValue = configTimeRange.MaxValue; + Config.BindWith(ManiaRulesetSetting.ScrollSpeed, configScrollSpeed); + configScrollSpeed.BindValueChanged(speed => this.TransformTo(nameof(smoothTimeRange), ComputeScrollTime(speed.NewValue), 200, Easing.OutQuint)); + + TimeRange.Value = smoothTimeRange = ComputeScrollTime(configScrollSpeed.Value); } - protected override void AdjustScrollSpeed(int amount) - { - this.TransformTo(nameof(relativeTimeRange), relativeTimeRange + amount, 200, Easing.OutQuint); - } - - private double relativeTimeRange - { - get => MAX_TIME_RANGE / configTimeRange.Value; - set => configTimeRange.Value = MAX_TIME_RANGE / value; - } + protected override void AdjustScrollSpeed(int amount) => configScrollSpeed.Value += amount; protected override void Update() { base.Update(); - updateTimeRange(); } - private void updateTimeRange() => TimeRange.Value = configTimeRange.Value * speedAdjustmentTrack.AggregateTempo.Value * speedAdjustmentTrack.AggregateFrequency.Value; + private void updateTimeRange() => TimeRange.Value = smoothTimeRange * speedAdjustmentTrack.AggregateTempo.Value * speedAdjustmentTrack.AggregateFrequency.Value; + + /// + /// Computes a scroll time (in milliseconds) from a scroll speed in the range of 1-40. + /// + /// The scroll speed. + /// The scroll time. + public static double ComputeScrollTime(int scrollSpeed) => MAX_TIME_RANGE / scrollSpeed; public override PlayfieldAdjustmentContainer CreatePlayfieldAdjustmentContainer() => new ManiaPlayfieldAdjustmentContainer(); diff --git a/osu.Game/Localisation/RulesetSettingsStrings.cs b/osu.Game/Localisation/RulesetSettingsStrings.cs index 52e6a5eaac..91bbece004 100644 --- a/osu.Game/Localisation/RulesetSettingsStrings.cs +++ b/osu.Game/Localisation/RulesetSettingsStrings.cs @@ -82,7 +82,7 @@ namespace osu.Game.Localisation /// /// "{0}ms (speed {1})" /// - public static LocalisableString ScrollSpeedTooltip(double arg0, int arg1) => new TranslatableString(getKey(@"ruleset"), @"{0}ms (speed {1})", arg0, arg1); + public static LocalisableString ScrollSpeedTooltip(double scrollTime, int scrollSpeed) => new TranslatableString(getKey(@"ruleset"), @"{0:0}ms (speed {1})", scrollTime, scrollSpeed); private static string getKey(string key) => $@"{prefix}:{key}"; } From 79694897bef29810846bc156455880b19658723f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 12:58:22 +0900 Subject: [PATCH 43/66] Ensure a potential exception from `cleanupPendingDeletions` doesn't mark realm corrupt The whole restructure here is to move the nested call out of the `try-catch`. I noticed this while looking at a corrupt database issue a user reported (https://github.com/ppy/osu/discussions/23694). It's not the first time we've seen a corrupt database error where the "corrupt" version works just fine on a second attempt. Maybe this isn't the issue and it's just a transitive file access violation but it definitely feels like this should be fixed regardless. --- osu.Game/Database/RealmAccess.cs | 79 +++++++++++++++++--------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 831e328439..55b5e0114d 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -179,43 +179,9 @@ namespace osu.Game.Database applyFilenameSchemaSuffix(ref Filename); #endif - string newerVersionFilename = $"{Filename.Replace(realm_extension, string.Empty)}_newer_version{realm_extension}"; - - // Attempt to recover a newer database version if available. - if (storage.Exists(newerVersionFilename)) - { - Logger.Log(@"A newer realm database has been found, attempting recovery...", LoggingTarget.Database); - attemptRecoverFromFile(newerVersionFilename); - } - - try - { + using (var realm = prepareFirstRealmAccess()) // This method triggers the first `getRealmInstance` call, which will implicitly run realm migrations and bring the schema up-to-date. - cleanupPendingDeletions(); - } - catch (Exception e) - { - // See https://github.com/realm/realm-core/blob/master/src%2Frealm%2Fobject-store%2Fobject_store.cpp#L1016-L1022 - // This is the best way we can detect a schema version downgrade. - if (e.Message.StartsWith(@"Provided schema version", StringComparison.Ordinal)) - { - Logger.Error(e, "Your local database is too new to work with this version of osu!. Please close osu! and install the latest release to recover your data."); - - // If a newer version database already exists, don't backup again. We can presume that the first backup is the one we care about. - if (!storage.Exists(newerVersionFilename)) - createBackup(newerVersionFilename); - - storage.Delete(Filename); - } - else - { - Logger.Error(e, "Realm startup failed with unrecoverable error; starting with a fresh database. A backup of your database has been made."); - createBackup($"{Filename.Replace(realm_extension, string.Empty)}_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_corrupt{realm_extension}"); - storage.Delete(Filename); - } - - cleanupPendingDeletions(); - } + cleanupPendingDeletions(realm); } /// @@ -312,9 +278,46 @@ namespace osu.Game.Database Logger.Log(@"Recovery complete!", LoggingTarget.Database); } - private void cleanupPendingDeletions() + private Realm prepareFirstRealmAccess() + { + string newerVersionFilename = $"{Filename.Replace(realm_extension, string.Empty)}_newer_version{realm_extension}"; + + // Attempt to recover a newer database version if available. + if (storage.Exists(newerVersionFilename)) + { + Logger.Log(@"A newer realm database has been found, attempting recovery...", LoggingTarget.Database); + attemptRecoverFromFile(newerVersionFilename); + } + + try + { + return getRealmInstance(); + } + catch (Exception e) + { + // See https://github.com/realm/realm-core/blob/master/src%2Frealm%2Fobject-store%2Fobject_store.cpp#L1016-L1022 + // This is the best way we can detect a schema version downgrade. + if (e.Message.StartsWith(@"Provided schema version", StringComparison.Ordinal)) + { + Logger.Error(e, "Your local database is too new to work with this version of osu!. Please close osu! and install the latest release to recover your data."); + + // If a newer version database already exists, don't backup again. We can presume that the first backup is the one we care about. + if (!storage.Exists(newerVersionFilename)) + createBackup(newerVersionFilename); + } + else + { + Logger.Error(e, "Realm startup failed with unrecoverable error; starting with a fresh database. A backup of your database has been made."); + createBackup($"{Filename.Replace(realm_extension, string.Empty)}_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_corrupt{realm_extension}"); + } + + storage.Delete(Filename); + return getRealmInstance(); + } + } + + private void cleanupPendingDeletions(Realm realm) { - using (var realm = getRealmInstance()) using (var transaction = realm.BeginWrite()) { var pendingDeleteScores = realm.All().Where(s => s.DeletePending); From a0be52626639b8cbe2e6db7280fc3c106bdb9cd6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 13:04:32 +0900 Subject: [PATCH 44/66] Adjust realm backup procedure to hard fail if running out of attempts Previously, if the backup procedure failed, startup would continue and the user's realm database may be deleted. I think in such a fail case I'd rather the game didn't startup so the user gets in touch (or reads the log files themselves) rather than potentially losing data. --- osu.Game/Database/RealmAccess.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 55b5e0114d..2e66ad8b02 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -912,7 +912,7 @@ namespace osu.Game.Database int attempts = 10; - while (attempts-- > 0) + while (true) { try { @@ -930,6 +930,9 @@ namespace osu.Game.Database } catch (IOException) { + if (attempts-- <= 0) + throw; + // file may be locked during use. Thread.Sleep(500); } From 4e0f40bee5f31dc15b6165d2d65ef7a283048ffc Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 14:20:26 +0900 Subject: [PATCH 45/66] Split out multiplier retrieval into a function and use a default multiplier for all rulesets --- .../Scoring/Legacy/ScoreInfoExtensions.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs index af991c7ea3..84bf6d15f6 100644 --- a/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs +++ b/osu.Game/Scoring/Legacy/ScoreInfoExtensions.cs @@ -23,10 +23,32 @@ namespace osu.Game.Scoring.Legacy if (mode == ScoringMode.Standardised) return score; + int maxBasicJudgements = maximumStatistics + .Where(k => k.Key.IsBasic()) + .Select(k => k.Value) + .DefaultIfEmpty(0) + .Sum(); + + // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. + // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. + double scaledRawScore = score / ScoreProcessor.MAX_SCORE; + + return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, maxBasicJudgements), 2) * getStandardisedToClassicMultiplier(rulesetId)); + } + + /// + /// Returns a ballpark multiplier which gives a similar "feel" for how large scores should get when displayed in "classic" mode. + /// This is different per ruleset to match the different algorithms used in the scoring implementation. + /// + private static double getStandardisedToClassicMultiplier(int rulesetId) + { double multiplier; switch (rulesetId) { + // For non-legacy rulesets, just go with the same as the osu! ruleset. + // This is arbitrary, but at least allows the setting to do something to the score. + default: case 0: multiplier = 36; break; @@ -42,17 +64,9 @@ namespace osu.Game.Scoring.Legacy case 3: multiplier = 16; break; - - default: - return score; } - int maxBasicJudgements = maximumStatistics.Where(k => k.Key.IsBasic()).Select(k => k.Value).DefaultIfEmpty(0).Sum(); - - // This gives a similar feeling to osu!stable scoring (ScoreV1) while keeping classic scoring as only a constant multiple of standardised scoring. - // The invariant is important to ensure that scores don't get re-ordered on leaderboards between the two scoring modes. - double scaledRawScore = score / ScoreProcessor.MAX_SCORE; - return (long)Math.Round(Math.Pow(scaledRawScore * Math.Max(1, maxBasicJudgements), 2) * multiplier); + return multiplier; } public static int? GetCountGeki(this ScoreInfo scoreInfo) From 3e94d4bb5ad417c2df44cff2a9818ce0b0ebdf8f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 15:18:22 +0900 Subject: [PATCH 46/66] Fix cursor ripples appearing in a weird place when "autopilot" mod is enabled --- osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs index 4782a0e49c..3841c9c716 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModAutopilot.cs @@ -24,7 +24,17 @@ namespace osu.Game.Rulesets.Osu.Mods public override ModType Type => ModType.Automation; public override LocalisableString Description => @"Automatic cursor movement - just follow the rhythm."; public override double ScoreMultiplier => 0.1; - public override Type[] IncompatibleMods => new[] { typeof(OsuModSpunOut), typeof(ModRelax), typeof(ModFailCondition), typeof(ModNoFail), typeof(ModAutoplay), typeof(OsuModMagnetised), typeof(OsuModRepel) }; + + public override Type[] IncompatibleMods => new[] + { + typeof(OsuModSpunOut), + typeof(ModRelax), + typeof(ModFailCondition), + typeof(ModNoFail), + typeof(ModAutoplay), + typeof(OsuModMagnetised), + typeof(OsuModRepel) + }; public bool PerformFail() => false; @@ -34,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Mods private List replayFrames = null!; - private int currentFrame; + private int currentFrame = -1; public void Update(Playfield playfield) { @@ -43,8 +53,9 @@ namespace osu.Game.Rulesets.Osu.Mods double time = playfield.Clock.CurrentTime; // Very naive implementation of autopilot based on proximity to replay frames. + // Special case for the first frame is required to ensure the mouse is in a sane position until the actual time of the first frame is hit. // TODO: this needs to be based on user interactions to better match stable (pausing until judgement is registered). - if (Math.Abs(replayFrames[currentFrame + 1].Time - time) <= Math.Abs(replayFrames[currentFrame].Time - time)) + if (currentFrame < 0 || Math.Abs(replayFrames[currentFrame + 1].Time - time) <= Math.Abs(replayFrames[currentFrame].Time - time)) { currentFrame++; new MousePositionAbsoluteInput { Position = playfield.ToScreenSpace(replayFrames[currentFrame].Position) }.Apply(inputManager.CurrentState, inputManager); From 1bde35c61b30a1bda2e5f468b40fdbc9a441e917 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 15:24:06 +0900 Subject: [PATCH 47/66] Remove link to very dated blog post --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index eb2fe6d0eb..91f1746183 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ We are accepting bug reports (please report with as much detail as possible and - Detailed release changelogs are available on the [official osu! site](https://osu.ppy.sh/home/changelog/lazer). - You can learn more about our approach to [project management](https://github.com/ppy/osu/wiki/Project-management). -- Read peppy's [blog post](https://blog.ppy.sh/a-definitive-lazer-faq/) exploring where the project is currently and the roadmap going forward. ## Running osu! From 654940afb0256cff12aef9f90737b25b135a1fed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 15:28:41 +0900 Subject: [PATCH 48/66] Update various text --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 91f1746183..d4b401e528 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ The future of [osu!](https://osu.ppy.sh) and the beginning of an open era! Curre ## Status -This project is under heavy development, but is in a stable state. Users are encouraged to try it out and keep it installed alongside the stable *osu!* client. It will continue to evolve to the point of eventually replacing the existing stable client as an update. +This project is under constant development, but we aim to keep things in a stable state. Users are encouraged to try it out and keep it installed alongside the stable *osu!* client. It will continue to evolve to the point of eventually replacing the existing stable client as an update. -**IMPORTANT:** Gameplay mechanics (and other features which you may have come to know and love) are in a constant state of flux. Game balance and final quality-of-life passes come at the end of development, preceded by experimentation and changes which may potentially **reduce playability or usability**. This is done in order to allow us to move forward as developers and designers more efficiently. If this offends you, please consider sticking to the stable releases of osu! (found on the website). We are not yet open to heated discussion over game mechanics and will not be using github as a forum for such discussions just yet. +**IMPORTANT:** Gameplay mechanics (and other features which you may have come to know and love) are in a constant state of flux. Game balance and final quality-of-life passes come at the end of development, preceded by experimentation and changes which may potentially **reduce playability or usability**. This is done in order to allow us to move forward as developers and designers more efficiently. If this offends you, please consider sticking to a [stable release](https://osu.ppy.sh/home/download) of osu!. We are not yet open to heated discussion over game mechanics and will not be using github as a forum for such discussions just yet. We are accepting bug reports (please report with as much detail as possible and follow the existing issue templates). Feature requests are also welcome, but understand that our focus is on completing the game to feature parity before adding new features. A few resources are available as starting points to getting involved and understanding the project: @@ -27,9 +27,9 @@ We are accepting bug reports (please report with as much detail as possible and ## Running osu! -If you are looking to install or test osu! without setting up a development environment, you can consume our [binary releases](https://github.com/ppy/osu/releases). Handy links below will download the latest version for your operating system of choice: +If you are looking to install or test osu! without setting up a development environment, you can consume our [releases](https://github.com/ppy/osu/releases). You can also generally download a version for your current device from the [osu! site](https://osu.ppy.sh/home/download). Failing that, you may use the links below to download the latest version for your operating system of choice: -**Latest build:** +**Latest release:** | [Windows 8.1+ (x64)](https://github.com/ppy/osu/releases/latest/download/install.exe) | macOS 10.15+ ([Intel](https://github.com/ppy/osu/releases/latest/download/osu.app.Intel.zip), [Apple Silicon](https://github.com/ppy/osu/releases/latest/download/osu.app.Apple.Silicon.zip)) | [Linux (x64)](https://github.com/ppy/osu/releases/latest/download/osu.AppImage) | [iOS 13.4+](https://osu.ppy.sh/home/testflight) | [Android 5+](https://github.com/ppy/osu/releases/latest/download/sh.ppy.osulazer.apk) | | ------------- | ------------- | ------------- | ------------- | ------------- | From 4d2c3f17e828ab991344c866d897051d65184f6a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 15:30:29 +0900 Subject: [PATCH 49/66] Remove outdated prerequisites --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d4b401e528..e4b8e1fc97 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,8 @@ You can see some examples of custom rulesets by visiting the [custom ruleset dir Please make sure you have the following prerequisites: - A desktop platform with the [.NET 6.0 SDK](https://dotnet.microsoft.com/download) installed. -- When developing with mobile, [Xamarin](https://docs.microsoft.com/en-us/xamarin/) is required, which is shipped together with Visual Studio or [Visual Studio for Mac](https://visualstudio.microsoft.com/vs/mac/). -- When working with the codebase, we recommend using an IDE with intelligent code completion and syntax highlighting, such as the latest version of [Visual Studio](https://visualstudio.microsoft.com/vs/), [JetBrains Rider](https://www.jetbrains.com/rider/) or [Visual Studio Code](https://code.visualstudio.com/). -- When running on Linux, please have a system-wide FFmpeg installation available to support video decoding. + +When working with the codebase, we recommend using an IDE with intelligent code completion and syntax highlighting, such as the latest version of [Visual Studio](https://visualstudio.microsoft.com/vs/), [JetBrains Rider](https://www.jetbrains.com/rider/) or [Visual Studio Code](https://code.visualstudio.com/). ### Downloading the source code From 9d844f2381ba0b81c7312f9e2779ed131176d39b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 15:37:12 +0900 Subject: [PATCH 50/66] Update documentation for local framework / resources --- README.md | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index e4b8e1fc97..cf7ce35791 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,29 @@ _Due to a historical feature gap between .NET Core and Xamarin, running `dotnet` ### Testing with resource/framework modifications -Sometimes it may be necessary to cross-test changes in [osu-resources](https://github.com/ppy/osu-resources) or [osu-framework](https://github.com/ppy/osu-framework). This can be achieved by running some commands as documented on the [osu-resources](https://github.com/ppy/osu-resources/wiki/Testing-local-resources-checkout-with-other-projects) and [osu-framework](https://github.com/ppy/osu-framework/wiki/Testing-local-framework-checkout-with-other-projects) wiki pages. +Sometimes it may be necessary to cross-test changes in [osu-resources](https://github.com/ppy/osu-resources) or [osu-framework](https://github.com/ppy/osu-framework). This can be quickly achieved using included commands: + +Windows: + +```ps +UseLocalFramework.ps1 +UseLocalResources.ps1 +``` + +macOS / Linux: + +```ps +UseLocalFramework.sh +UseLocalResources.sh +``` + +Note that these commands assume you have the relevant project(s) checked out in adjacent directories: + +``` +|- osu // this repository +|- osu-framework +|- osu-resources +``` ### Code analysis From b456c36f6453309ad902c8a488696dd6798ed86f Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Tue, 30 May 2023 17:27:48 +0900 Subject: [PATCH 51/66] Migrate in InitialiseDefaults() --- .../Configuration/ManiaRulesetConfigManager.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs index 5ba5125c2d..b2155968ea 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaRulesetConfigManager.cs @@ -15,33 +15,27 @@ namespace osu.Game.Rulesets.Mania.Configuration public ManiaRulesetConfigManager(SettingsStore? settings, RulesetInfo ruleset, int? variant = null) : base(settings, ruleset, variant) { - migrate(); } protected override void InitialiseDefaults() { base.InitialiseDefaults(); -#pragma warning disable CS0618 - // Although obsolete, this is still required to populate the bindable from the database in case migration is required. - SetDefault(ManiaRulesetSetting.ScrollTime, null); -#pragma warning restore CS0618 - SetDefault(ManiaRulesetSetting.ScrollSpeed, 8, 1, 40); SetDefault(ManiaRulesetSetting.ScrollDirection, ManiaScrollingDirection.Down); SetDefault(ManiaRulesetSetting.TimingBasedNoteColouring, false); - } #pragma warning disable CS0618 - private void migrate() - { + // Although obsolete, this is still required to populate the bindable from the database in case migration is required. + SetDefault(ManiaRulesetSetting.ScrollTime, null); + if (Get(ManiaRulesetSetting.ScrollTime) is double scrollTime) { SetValue(ManiaRulesetSetting.ScrollSpeed, (int)Math.Round(DrawableManiaRuleset.MAX_TIME_RANGE / scrollTime)); SetValue(ManiaRulesetSetting.ScrollTime, null); } - } #pragma warning restore CS0618 + } public override TrackedSettings CreateTrackedSettings() => new TrackedSettings { From 741ee84ed6f14bc8b4e0bf7f073698d4319399c6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 30 May 2023 18:38:28 +0900 Subject: [PATCH 52/66] Add comment and use full conditional similar to extension method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Bartłomiej Dach --- osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs index cfaae56d0f..50d1d1addd 100644 --- a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs +++ b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs @@ -133,7 +133,10 @@ namespace osu.Game.Screens.OnlinePlay Debug.Assert(screenStack.CurrentScreen != null); - if (screenStack.CurrentScreen.IsCurrentScreen()) + // if a subscreen was pushed to the nested stack while this screen was not present, this path will proxy `OnResuming()` + // to the subscreen before `OnEntering()` can even be called for the subscreen, breaking ordering expectations. + // to work around this, do not proxy resume to screens that haven't loaded yet. + if ((screenStack.CurrentScreen as Drawable)?.IsLoaded == true) screenStack.CurrentScreen.OnResuming(e); base.OnResuming(e); From d119447a10a1ac0312a6aa9691348cbabed8c6ba Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 30 May 2023 16:41:42 +0300 Subject: [PATCH 53/66] Fix editor timeline hitobjects popping in --- .../Compose/Components/Timeline/TimelineHitObjectBlueprint.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index ea063e9216..900f0ff4a2 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -244,6 +244,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public override Vector2 ScreenSpaceSelectionPoint => ScreenSpaceDrawQuad.TopLeft; + protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false; + private partial class Tick : Circle { public Tick() From 62d177440730e507ff3b080dd8c1c1eca66ea6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 30 May 2023 21:54:56 +0200 Subject: [PATCH 54/66] Apply same comment & reworded condition to suspend too --- osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs index 50d1d1addd..37b50b4863 100644 --- a/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs +++ b/osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs @@ -133,7 +133,7 @@ namespace osu.Game.Screens.OnlinePlay Debug.Assert(screenStack.CurrentScreen != null); - // if a subscreen was pushed to the nested stack while this screen was not present, this path will proxy `OnResuming()` + // if a subscreen was pushed to the nested stack while the stack was not present, this path will proxy `OnResuming()` // to the subscreen before `OnEntering()` can even be called for the subscreen, breaking ordering expectations. // to work around this, do not proxy resume to screens that haven't loaded yet. if ((screenStack.CurrentScreen as Drawable)?.IsLoaded == true) @@ -149,7 +149,10 @@ namespace osu.Game.Screens.OnlinePlay Debug.Assert(screenStack.CurrentScreen != null); - if (screenStack.CurrentScreen.IsCurrentScreen()) + // if a subscreen was pushed to the nested stack while the stack was not present, this path will proxy `OnSuspending()` + // to the subscreen before `OnEntering()` can even be called for the subscreen, breaking ordering expectations. + // to work around this, do not proxy suspend to screens that haven't loaded yet. + if ((screenStack.CurrentScreen as Drawable)?.IsLoaded == true) screenStack.CurrentScreen.OnSuspending(e); } From 2e81cae201e77229445b97923aaa62be739ac47a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Tue, 30 May 2023 23:17:07 +0200 Subject: [PATCH 55/66] Move comment to more correct place --- osu.Game/Database/RealmAccess.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 2e66ad8b02..1aef8f1c67 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -179,8 +179,8 @@ namespace osu.Game.Database applyFilenameSchemaSuffix(ref Filename); #endif + // `prepareFirstRealmAccess()` triggers the first `getRealmInstance` call, which will implicitly run realm migrations and bring the schema up-to-date. using (var realm = prepareFirstRealmAccess()) - // This method triggers the first `getRealmInstance` call, which will implicitly run realm migrations and bring the schema up-to-date. cleanupPendingDeletions(realm); } From 18eb15bfa5af004fc2e35f2ec6c017b0cf4a44f4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 31 May 2023 19:39:43 +0900 Subject: [PATCH 56/66] Gracefully handle failures in cleaning up pending file deletions --- osu.Game/Database/RealmAccess.cs | 71 ++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/osu.Game/Database/RealmAccess.cs b/osu.Game/Database/RealmAccess.cs index 1aef8f1c67..94108531e8 100644 --- a/osu.Game/Database/RealmAccess.cs +++ b/osu.Game/Database/RealmAccess.cs @@ -318,46 +318,53 @@ namespace osu.Game.Database private void cleanupPendingDeletions(Realm realm) { - using (var transaction = realm.BeginWrite()) + try { - var pendingDeleteScores = realm.All().Where(s => s.DeletePending); - - foreach (var score in pendingDeleteScores) - realm.Remove(score); - - var pendingDeleteSets = realm.All().Where(s => s.DeletePending); - - foreach (var beatmapSet in pendingDeleteSets) + using (var transaction = realm.BeginWrite()) { - foreach (var beatmap in beatmapSet.Beatmaps) - { - // Cascade delete related scores, else they will have a null beatmap against the model's spec. - foreach (var score in beatmap.Scores) - realm.Remove(score); + var pendingDeleteScores = realm.All().Where(s => s.DeletePending); - realm.Remove(beatmap.Metadata); - realm.Remove(beatmap); + foreach (var score in pendingDeleteScores) + realm.Remove(score); + + var pendingDeleteSets = realm.All().Where(s => s.DeletePending); + + foreach (var beatmapSet in pendingDeleteSets) + { + foreach (var beatmap in beatmapSet.Beatmaps) + { + // Cascade delete related scores, else they will have a null beatmap against the model's spec. + foreach (var score in beatmap.Scores) + realm.Remove(score); + + realm.Remove(beatmap.Metadata); + realm.Remove(beatmap); + } + + realm.Remove(beatmapSet); } - realm.Remove(beatmapSet); + var pendingDeleteSkins = realm.All().Where(s => s.DeletePending); + + foreach (var s in pendingDeleteSkins) + realm.Remove(s); + + var pendingDeletePresets = realm.All().Where(s => s.DeletePending); + + foreach (var s in pendingDeletePresets) + realm.Remove(s); + + transaction.Commit(); } - var pendingDeleteSkins = realm.All().Where(s => s.DeletePending); - - foreach (var s in pendingDeleteSkins) - realm.Remove(s); - - var pendingDeletePresets = realm.All().Where(s => s.DeletePending); - - foreach (var s in pendingDeletePresets) - realm.Remove(s); - - transaction.Commit(); + // clean up files after dropping any pending deletions. + // in the future we may want to only do this when the game is idle, rather than on every startup. + new RealmFileStore(this, storage).Cleanup(); + } + catch (Exception e) + { + Logger.Error(e, "Failed to clean up unused files. This is not critical but please report if it happens regularly."); } - - // clean up files after dropping any pending deletions. - // in the future we may want to only do this when the game is idle, rather than on every startup. - new RealmFileStore(this, storage).Cleanup(); } /// From 20439e80f6658937a940b3d603582212acb605c2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 31 May 2023 23:24:15 +0900 Subject: [PATCH 57/66] Adjust background colour used in `LabelledDrawable`s to allow visibility of sliders --- osu.Game/Graphics/UserInterfaceV2/LabelledDrawable.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/UserInterfaceV2/LabelledDrawable.cs b/osu.Game/Graphics/UserInterfaceV2/LabelledDrawable.cs index 9b7087ce6d..16bad5785f 100644 --- a/osu.Game/Graphics/UserInterfaceV2/LabelledDrawable.cs +++ b/osu.Game/Graphics/UserInterfaceV2/LabelledDrawable.cs @@ -152,7 +152,7 @@ namespace osu.Game.Graphics.UserInterfaceV2 [BackgroundDependencyLoader(true)] private void load(OverlayColourProvider? colourProvider, OsuColour osuColour) { - background.Colour = colourProvider?.Background5 ?? Color4Extensions.FromHex(@"1c2125"); + background.Colour = colourProvider?.Background4 ?? Color4Extensions.FromHex(@"1c2125"); descriptionText.Colour = osuColour.Yellow; } From 7bc3b2072caed1124ddc3b722957a08e0084fd44 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 00:44:13 +0900 Subject: [PATCH 58/66] Update framework --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 6aebae665d..c88bea8265 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -11,7 +11,7 @@ manifestmerger.jar - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 0fd2b0c2c5..8a941ca6c1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -36,7 +36,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/osu.iOS.props b/osu.iOS.props index e4a169f8e5..1dcece7741 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -16,6 +16,6 @@ iossimulator-x64 - + From 310c54fe28ed32af6ac804c084c5c1de18d38651 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 13:26:46 +0900 Subject: [PATCH 59/66] Add test coverage ensuring positional data is present in hit events --- .../Mods/TestSceneOsuModAutoplay.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs index 8fdab9f1f9..616a9c362d 100644 --- a/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs +++ b/osu.Game.Rulesets.Osu.Tests/Mods/TestSceneOsuModAutoplay.cs @@ -17,6 +17,18 @@ namespace osu.Game.Rulesets.Osu.Tests.Mods { public partial class TestSceneOsuModAutoplay : OsuModTestScene { + [Test] + public void TestCursorPositionStoredToJudgement() + { + CreateModTest(new ModTestData + { + Autoplay = true, + PassCondition = () => + Player.ScoreProcessor.JudgedHits >= 1 + && Player.ScoreProcessor.HitEvents.Any(e => e.Position != null) + }); + } + [Test] public void TestSpmUnaffectedByRateAdjust() => runSpmTest(new OsuModDaycore From e830b96e6182308093e0ab61afcb6f3bf01db9cd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 13:09:47 +0900 Subject: [PATCH 60/66] Add back required override to make `AccuracyHeatmap` work --- osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs index ab07ac3e9d..f97be0d7ff 100644 --- a/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Rulesets.Osu/Scoring/OsuScoreProcessor.cs @@ -2,6 +2,8 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Osu.Judgements; using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Osu.Scoring @@ -13,6 +15,9 @@ namespace osu.Game.Rulesets.Osu.Scoring { } + protected override HitEvent CreateHitEvent(JudgementResult result) + => base.CreateHitEvent(result).With((result as OsuHitCircleJudgementResult)?.CursorPositionAtHit); + protected override double ComputeTotalScore(double comboProgress, double accuracyProgress, double bonusPortion) { return 700000 * comboProgress From 0a7d5a51d419055990d9da48345de1284408639f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 15:50:10 +0900 Subject: [PATCH 61/66] Fix mouse cursor potentially disappearing for good if screenshot capture fails --- osu.Game/Graphics/ScreenshotManager.cs | 115 +++++++++++++------------ 1 file changed, 60 insertions(+), 55 deletions(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index d799e82bc9..dd90cbc074 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -86,70 +86,75 @@ namespace osu.Game.Graphics { Interlocked.Increment(ref screenShotTasks); - if (!captureMenuCursor.Value) + try { - cursorVisibility.Value = false; - - // We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value - const int frames_to_wait = 3; - - int framesWaited = 0; - - using (var framesWaitedEvent = new ManualResetEventSlim(false)) + if (!captureMenuCursor.Value) { - ScheduledDelegate waitDelegate = host.DrawThread.Scheduler.AddDelayed(() => + cursorVisibility.Value = false; + + // We need to wait for at most 3 draw nodes to be drawn, following which we can be assured at least one DrawNode has been generated/drawn with the set value + const int frames_to_wait = 3; + + int framesWaited = 0; + + using (var framesWaitedEvent = new ManualResetEventSlim(false)) { - if (framesWaited++ >= frames_to_wait) - // ReSharper disable once AccessToDisposedClosure - framesWaitedEvent.Set(); - }, 10, true); + ScheduledDelegate waitDelegate = host.DrawThread.Scheduler.AddDelayed(() => + { + if (framesWaited++ >= frames_to_wait) + // ReSharper disable once AccessToDisposedClosure + framesWaitedEvent.Set(); + }, 10, true); - if (!framesWaitedEvent.Wait(1000)) - throw new TimeoutException("Screenshot data did not arrive in a timely fashion"); + if (!framesWaitedEvent.Wait(1000)) + throw new TimeoutException("Screenshot data did not arrive in a timely fashion"); - waitDelegate.Cancel(); + waitDelegate.Cancel(); + } + } + + using (var image = await host.TakeScreenshotAsync().ConfigureAwait(false)) + { + host.GetClipboard()?.SetImage(image); + + (string filename, var stream) = getWritableStream(); + + if (filename == null) return; + + using (stream) + { + switch (screenshotFormat.Value) + { + case ScreenshotFormat.Png: + await image.SaveAsPngAsync(stream).ConfigureAwait(false); + break; + + case ScreenshotFormat.Jpg: + const int jpeg_quality = 92; + + await image.SaveAsJpegAsync(stream, new JpegEncoder { Quality = jpeg_quality }).ConfigureAwait(false); + break; + + default: + throw new InvalidOperationException($"Unknown enum member {nameof(ScreenshotFormat)} {screenshotFormat.Value}."); + } + } + + notificationOverlay.Post(new SimpleNotification + { + Text = $"Screenshot {filename} saved!", + Activated = () => + { + storage.PresentFileExternally(filename); + return true; + } + }); } } - - using (var image = await host.TakeScreenshotAsync().ConfigureAwait(false)) + finally { - if (Interlocked.Decrement(ref screenShotTasks) == 0 && cursorVisibility.Value == false) + if (Interlocked.Decrement(ref screenShotTasks) == 0) cursorVisibility.Value = true; - - host.GetClipboard()?.SetImage(image); - - (string filename, var stream) = getWritableStream(); - - if (filename == null) return; - - using (stream) - { - switch (screenshotFormat.Value) - { - case ScreenshotFormat.Png: - await image.SaveAsPngAsync(stream).ConfigureAwait(false); - break; - - case ScreenshotFormat.Jpg: - const int jpeg_quality = 92; - - await image.SaveAsJpegAsync(stream, new JpegEncoder { Quality = jpeg_quality }).ConfigureAwait(false); - break; - - default: - throw new InvalidOperationException($"Unknown enum member {nameof(ScreenshotFormat)} {screenshotFormat.Value}."); - } - } - - notificationOverlay.Post(new SimpleNotification - { - Text = $"Screenshot {filename} saved!", - Activated = () => - { - storage.PresentFileExternally(filename); - return true; - } - }); } }); From 289f0e9862d690cf40e7fcd081cd962a1791fb39 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 15:50:37 +0900 Subject: [PATCH 62/66] Use `FireAndForget` to avoid unobserved exception --- osu.Game/Graphics/ScreenshotManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Graphics/ScreenshotManager.cs b/osu.Game/Graphics/ScreenshotManager.cs index dd90cbc074..82f89d6889 100644 --- a/osu.Game/Graphics/ScreenshotManager.cs +++ b/osu.Game/Graphics/ScreenshotManager.cs @@ -19,6 +19,7 @@ using osu.Framework.Platform; using osu.Framework.Threading; using osu.Game.Configuration; using osu.Game.Input.Bindings; +using osu.Game.Online.Multiplayer; using osu.Game.Overlays; using osu.Game.Overlays.Notifications; using SixLabors.ImageSharp; @@ -69,7 +70,7 @@ namespace osu.Game.Graphics { case GlobalAction.TakeScreenshot: shutter.Play(); - TakeScreenshotAsync(); + TakeScreenshotAsync().FireAndForget(); return true; } From 98f35f74811329500e558943464d003b3543f276 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 1 Jun 2023 16:06:34 +0900 Subject: [PATCH 63/66] Fix osu!mania hold notes snapping to judgement area too early on early hits Closes https://github.com/ppy/osu/issues/23515. --- .../Objects/Drawables/DrawableHoldNote.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs index ce34addeff..3f91328128 100644 --- a/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs +++ b/osu.Game.Rulesets.Mania/Objects/Drawables/DrawableHoldNote.cs @@ -245,7 +245,10 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables // As the note is being held, adjust the size of the sizing container. This has two effects: // 1. The contained masking container will mask the body and ticks. // 2. The head note will move along with the new "head position" in the container. - if (Head.IsHit && releaseTime == null && DrawHeight > 0) + // + // As per stable, this should not apply for early hits, waiting until the object starts to touch the + // judgement area first. + if (Head.IsHit && releaseTime == null && DrawHeight > 0 && Time.Current >= HitObject.StartTime) { // How far past the hit target this hold note is. float yOffset = Direction.Value == ScrollingDirection.Up ? -Y : Y; From 949fe327402bb9418b2875aba0a0e7658f931b91 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Wed, 31 May 2023 01:23:42 +0300 Subject: [PATCH 64/66] Use combined area of children as a mask instead --- .../Timeline/TimelineHitObjectBlueprint.cs | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 900f0ff4a2..31cf6ad766 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -50,6 +50,8 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Container colouredComponents; private readonly OsuSpriteText comboIndexText; + private readonly SamplePointPiece samplePointPiece; + private readonly DifficultyPointPiece difficultyPointPiece = null!; [Resolved] private ISkinSource skin { get; set; } = null!; @@ -101,7 +103,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline }, } }, - new SamplePointPiece(Item) + samplePointPiece = new SamplePointPiece(Item) { Anchor = Anchor.BottomLeft, Origin = Anchor.TopCentre @@ -118,7 +120,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline if (item is IHasSliderVelocity) { - AddInternal(new DifficultyPointPiece(Item) + AddInternal(difficultyPointPiece = new DifficultyPointPiece(Item) { Anchor = Anchor.TopLeft, Origin = Anchor.BottomCentre @@ -244,7 +246,23 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline public override Vector2 ScreenSpaceSelectionPoint => ScreenSpaceDrawQuad.TopLeft; - protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false; + protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) + { + // Since children are exceeding the component size, we need to use a custom quad to compute whether it should be masked away. + + // When component isn't masked away there's no need to apply custom logic. + if (!base.ComputeIsMaskedAway(maskingBounds)) + return false; + + // If component is considered masked away we'll use children to create an extended quad. + var rect = RectangleF.Union(ScreenSpaceDrawQuad.AABBFloat, circle.ScreenSpaceDrawQuad.AABBFloat); + rect = RectangleF.Union(rect, samplePointPiece.ScreenSpaceDrawQuad.AABBFloat); + + if (difficultyPointPiece != null) + rect = RectangleF.Union(rect, difficultyPointPiece.ScreenSpaceDrawQuad.AABBFloat); + + return !Precision.AlmostIntersects(maskingBounds, rect); + } private partial class Tick : Circle { From 03eb7c78300cd689d504dd8874b700a67dec1fa3 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Thu, 1 Jun 2023 21:21:01 +0300 Subject: [PATCH 65/66] Fix nullability --- .../Compose/Components/Timeline/TimelineHitObjectBlueprint.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 31cf6ad766..638e2d43c8 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -51,7 +51,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline private readonly Container colouredComponents; private readonly OsuSpriteText comboIndexText; private readonly SamplePointPiece samplePointPiece; - private readonly DifficultyPointPiece difficultyPointPiece = null!; + private readonly DifficultyPointPiece? difficultyPointPiece; [Resolved] private ISkinSource skin { get; set; } = null!; From c2d89a32a985515edb376b9abd3d23555dda5445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Thu, 1 Jun 2023 21:18:00 +0200 Subject: [PATCH 66/66] Adjust inline comment --- .../Components/Timeline/TimelineHitObjectBlueprint.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs index 638e2d43c8..55f122669d 100644 --- a/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs +++ b/osu.Game/Screens/Edit/Compose/Components/Timeline/TimelineHitObjectBlueprint.cs @@ -250,11 +250,12 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline { // Since children are exceeding the component size, we need to use a custom quad to compute whether it should be masked away. - // When component isn't masked away there's no need to apply custom logic. + // If the component isn't considered masked away by itself, there's no need to apply custom logic. if (!base.ComputeIsMaskedAway(maskingBounds)) return false; - // If component is considered masked away we'll use children to create an extended quad. + // If the component is considered masked away, we'll use children to create an extended quad that encapsulates all parts of this blueprint + // to ensure it doesn't pop in and out of existence abruptly when scrolling the timeline. var rect = RectangleF.Union(ScreenSpaceDrawQuad.AABBFloat, circle.ScreenSpaceDrawQuad.AABBFloat); rect = RectangleF.Union(rect, samplePointPiece.ScreenSpaceDrawQuad.AABBFloat);