diff --git a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs index f60ae29f77..b03fa00f76 100644 --- a/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs +++ b/osu.Game.Rulesets.Catch.Tests/TestSceneCatcher.cs @@ -293,7 +293,7 @@ namespace osu.Game.Rulesets.Catch.Tests private JudgementResult createResult(CatchHitObject hitObject) { - return new CatchJudgementResult(hitObject, hitObject.CreateJudgement()) + return new CatchJudgementResult(hitObject, hitObject.Judgement) { Type = catcher.CanCatch(hitObject) ? HitResult.Great : HitResult.Miss }; diff --git a/osu.Game.Rulesets.Osu.Tests/TestSceneSpinnerRotation.cs b/osu.Game.Rulesets.Osu.Tests/TestSceneSpinnerRotation.cs index 6706d20080..8d81fe3017 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestSceneSpinnerRotation.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestSceneSpinnerRotation.cs @@ -134,7 +134,7 @@ namespace osu.Game.Rulesets.Osu.Tests // multipled by 2 to nullify the score multiplier. (autoplay mod selected) long totalScore = scoreProcessor.TotalScore.Value * 2; - return totalScore == (int)(drawableSpinner.Result.TotalRotation / 360) * scoreProcessor.GetBaseScoreForResult(new SpinnerTick().CreateJudgement().MaxResult); + return totalScore == (int)(drawableSpinner.Result.TotalRotation / 360) * scoreProcessor.GetBaseScoreForResult(new SpinnerTick().Judgement.MaxResult); }); addSeekStep(0); diff --git a/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs b/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs index f4a1e888c9..b28e870481 100644 --- a/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs +++ b/osu.Game.Rulesets.Taiko.Tests/TaikoHealthProcessorTest.cs @@ -126,11 +126,11 @@ namespace osu.Game.Rulesets.Taiko.Tests foreach (var nested in beatmap.HitObjects[0].NestedHitObjects) { - var nestedJudgement = nested.CreateJudgement(); + var nestedJudgement = nested.Judgement; healthProcessor.ApplyResult(new JudgementResult(nested, nestedJudgement) { Type = nestedJudgement.MaxResult }); } - var judgement = beatmap.HitObjects[0].CreateJudgement(); + var judgement = beatmap.HitObjects[0].Judgement; healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], judgement) { Type = judgement.MaxResult }); Assert.Multiple(() => @@ -159,11 +159,11 @@ namespace osu.Game.Rulesets.Taiko.Tests foreach (var nested in beatmap.HitObjects[0].NestedHitObjects) { - var nestedJudgement = nested.CreateJudgement(); + var nestedJudgement = nested.Judgement; healthProcessor.ApplyResult(new JudgementResult(nested, nestedJudgement) { Type = nestedJudgement.MaxResult }); } - var judgement = beatmap.HitObjects[0].CreateJudgement(); + var judgement = beatmap.HitObjects[0].Judgement; healthProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], judgement) { Type = judgement.MaxResult }); Assert.Multiple(() => diff --git a/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs b/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs index 73177e36e1..22643feebb 100644 --- a/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs +++ b/osu.Game.Tests/Gameplay/TestSceneDrawableHitObject.cs @@ -175,7 +175,7 @@ namespace osu.Game.Tests.Gameplay var hitObject = new HitObject { StartTime = Time.Current }; lifetimeEntry = new HitObjectLifetimeEntry(hitObject) { - Result = new JudgementResult(hitObject, hitObject.CreateJudgement()) + Result = new JudgementResult(hitObject, hitObject.Judgement) { Type = HitResult.Great } diff --git a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs index 1a644ad600..8ec18377f4 100644 --- a/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs +++ b/osu.Game.Tests/Gameplay/TestSceneScoreProcessor.cs @@ -129,10 +129,10 @@ namespace osu.Game.Tests.Gameplay var scoreProcessor = new ScoreProcessor(new OsuRuleset()); scoreProcessor.ApplyBeatmap(beatmap); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].CreateJudgement()) { Type = HitResult.Ok }); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].CreateJudgement()) { Type = HitResult.LargeTickHit }); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], beatmap.HitObjects[2].CreateJudgement()) { Type = HitResult.SmallTickMiss }); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], beatmap.HitObjects[3].CreateJudgement()) { Type = HitResult.SmallBonus }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].Judgement) { Type = HitResult.Ok }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].Judgement) { Type = HitResult.LargeTickHit }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[2], beatmap.HitObjects[2].Judgement) { Type = HitResult.SmallTickMiss }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[3], beatmap.HitObjects[3].Judgement) { Type = HitResult.SmallBonus }); var score = new ScoreInfo { Ruleset = new OsuRuleset().RulesetInfo }; scoreProcessor.FailScore(score); @@ -169,8 +169,8 @@ namespace osu.Game.Tests.Gameplay Assert.That(scoreProcessor.MinimumAccuracy.Value, Is.EqualTo(0)); Assert.That(scoreProcessor.MaximumAccuracy.Value, Is.EqualTo(1)); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].CreateJudgement()) { Type = HitResult.Ok }); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].CreateJudgement()) { Type = HitResult.Great }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].Judgement) { Type = HitResult.Ok }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].Judgement) { Type = HitResult.Great }); Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo((double)(100 + 300) / (2 * 300)).Within(Precision.DOUBLE_EPSILON)); Assert.That(scoreProcessor.MinimumAccuracy.Value, Is.EqualTo((double)(100 + 300) / (4 * 300)).Within(Precision.DOUBLE_EPSILON)); diff --git a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs index a3f91fffba..1647fbee42 100644 --- a/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs +++ b/osu.Game.Tests/Rulesets/Scoring/ScoreProcessorTest.cs @@ -112,7 +112,7 @@ namespace osu.Game.Tests.Rulesets.Scoring for (int i = 0; i < 4; i++) { - var judgementResult = new JudgementResult(fourObjectBeatmap.HitObjects[i], fourObjectBeatmap.HitObjects[i].CreateJudgement()) + var judgementResult = new JudgementResult(fourObjectBeatmap.HitObjects[i], fourObjectBeatmap.HitObjects[i].Judgement) { Type = i == 2 ? minResult : hitResult }; @@ -141,7 +141,7 @@ namespace osu.Game.Tests.Rulesets.Scoring for (int i = 0; i < object_count; ++i) { - var judgementResult = new JudgementResult(largeBeatmap.HitObjects[i], largeBeatmap.HitObjects[i].CreateJudgement()) + var judgementResult = new JudgementResult(largeBeatmap.HitObjects[i], largeBeatmap.HitObjects[i].Judgement) { Type = HitResult.Great }; @@ -325,11 +325,11 @@ namespace osu.Game.Tests.Rulesets.Scoring scoreProcessor = new TestScoreProcessor(); scoreProcessor.ApplyBeatmap(beatmap); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].CreateJudgement()) { Type = HitResult.Great }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[0], beatmap.HitObjects[0].Judgement) { Type = HitResult.Great }); Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(1)); Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(1)); - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].CreateJudgement()) { Type = HitResult.ComboBreak }); + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[1], beatmap.HitObjects[1].Judgement) { Type = HitResult.ComboBreak }); Assert.That(scoreProcessor.Combo.Value, Is.EqualTo(0)); Assert.That(scoreProcessor.Accuracy.Value, Is.EqualTo(1)); } @@ -350,7 +350,7 @@ namespace osu.Game.Tests.Rulesets.Scoring for (int i = 0; i < beatmap.HitObjects.Count; i++) { - scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], beatmap.HitObjects[i].CreateJudgement()) + scoreProcessor.ApplyResult(new JudgementResult(beatmap.HitObjects[i], beatmap.HitObjects[i].Judgement) { Type = i == 0 ? HitResult.Miss : HitResult.Great }); @@ -441,10 +441,7 @@ namespace osu.Game.Tests.Rulesets.Scoring private readonly HitResult maxResult; private readonly HitResult? minResult; - public override Judgement CreateJudgement() - { - return new TestJudgement(maxResult, minResult); - } + public override Judgement CreateJudgement() => new TestJudgement(maxResult, minResult); public TestHitObject(HitResult maxResult, HitResult? minResult = null) { diff --git a/osu.Game/Beatmaps/IBeatmap.cs b/osu.Game/Beatmaps/IBeatmap.cs index d97eb00d7e..b5bb6ccafc 100644 --- a/osu.Game/Beatmaps/IBeatmap.cs +++ b/osu.Game/Beatmaps/IBeatmap.cs @@ -94,7 +94,7 @@ namespace osu.Game.Beatmaps static void addCombo(HitObject hitObject, ref int combo) { - if (hitObject.CreateJudgement().MaxResult.AffectsCombo()) + if (hitObject.Judgement.MaxResult.AffectsCombo()) combo++; foreach (var nested in hitObject.NestedHitObjects) diff --git a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs index 4563c264f7..946d83b14b 100644 --- a/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs +++ b/osu.Game/Rulesets/Difficulty/PerformanceBreakdownCalculator.cs @@ -113,9 +113,9 @@ namespace osu.Game.Rulesets.Difficulty private IEnumerable getPerfectHitResults(HitObject hitObject) { foreach (HitObject nested in hitObject.NestedHitObjects) - yield return nested.CreateJudgement().MaxResult; + yield return nested.Judgement.MaxResult; - yield return hitObject.CreateJudgement().MaxResult; + yield return hitObject.Judgement.MaxResult; } } } diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index c9192ae3eb..16bd4b565c 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -770,7 +770,7 @@ namespace osu.Game.Rulesets.Objects.Drawables private void ensureEntryHasResult() { Debug.Assert(Entry != null); - Entry.Result ??= CreateResult(HitObject.CreateJudgement()) + Entry.Result ??= CreateResult(HitObject.Judgement) ?? throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}."); } diff --git a/osu.Game/Rulesets/Objects/HitObject.cs b/osu.Game/Rulesets/Objects/HitObject.cs index ef8bd08bf4..04bdc35941 100644 --- a/osu.Game/Rulesets/Objects/HitObject.cs +++ b/osu.Game/Rulesets/Objects/HitObject.cs @@ -163,8 +163,19 @@ namespace osu.Game.Rulesets.Objects protected void AddNested(HitObject hitObject) => nestedHitObjects.Add(hitObject); /// - /// Creates the that represents the scoring information for this . + /// The that represents the scoring information for this . /// + [JsonIgnore] + public Judgement Judgement => judgement ??= CreateJudgement(); + + private Judgement judgement; + + /// + /// Should be overridden to create a that represents the scoring information for this . + /// + /// + /// For read access, use to avoid unnecessary allocations. + /// [NotNull] public virtual Judgement CreateJudgement() => new Judgement(); diff --git a/osu.Game/Rulesets/Scoring/JudgementProcessor.cs b/osu.Game/Rulesets/Scoring/JudgementProcessor.cs index e9f3bcb949..0e90330651 100644 --- a/osu.Game/Rulesets/Scoring/JudgementProcessor.cs +++ b/osu.Game/Rulesets/Scoring/JudgementProcessor.cs @@ -149,7 +149,7 @@ namespace osu.Game.Rulesets.Scoring foreach (var obj in EnumerateHitObjects(beatmap)) { - var judgement = obj.CreateJudgement(); + var judgement = obj.Judgement; var result = CreateResult(obj, judgement); if (result == null) diff --git a/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs b/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs index ce2f7d5624..2bc3ea80ec 100644 --- a/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs +++ b/osu.Game/Rulesets/Scoring/LegacyDrainingHealthProcessor.cs @@ -141,7 +141,7 @@ namespace osu.Game.Rulesets.Scoring void increaseHp(HitObject hitObject) { - double amount = GetHealthIncreaseFor(hitObject, hitObject.CreateJudgement().MaxResult); + double amount = GetHealthIncreaseFor(hitObject, hitObject.Judgement.MaxResult); currentHpUncapped += amount; currentHp = Math.Max(0, Math.Min(1, currentHp + amount)); }