From 6445bea864d2bd3fdd3e0f9fc21186a65569857e Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 14:43:57 +0900 Subject: [PATCH 1/3] Make Playfield.HitObjects internal to playfields. Because not all playfields will be using this. --- osu.Game/Rulesets/UI/HitRenderer.cs | 11 ++++++++--- osu.Game/Rulesets/UI/Playfield.cs | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 8ee67df95a..4ca77f71df 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -187,17 +187,19 @@ namespace osu.Game.Rulesets.UI public sealed override bool ProvidingUserCursor => !HasReplayLoaded && Playfield.ProvidingUserCursor; - protected override Container Content => content; - protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result != HitResult.None); + public override IEnumerable Objects => Beatmap.HitObjects; + + protected override bool AllObjectsJudged => drawableObjects.All(h => h.Judgement.Result != HitResult.None); /// /// The playfield. /// protected Playfield Playfield; + protected override Container Content => content; private readonly Container content; - public override IEnumerable Objects => Beatmap.HitObjects; + private List> drawableObjects; protected HitRenderer(WorkingBeatmap beatmap) : base(beatmap) @@ -224,6 +226,8 @@ namespace osu.Game.Rulesets.UI private void loadObjects() { + drawableObjects = new List>(Beatmap.HitObjects.Count); + foreach (TObject h in Beatmap.HitObjects) { var drawableObject = GetVisualRepresentation(h); @@ -233,6 +237,7 @@ namespace osu.Game.Rulesets.UI drawableObject.OnJudgement += onJudgement; + drawableObjects.Add(drawableObject); Playfield.Add(drawableObject); } diff --git a/osu.Game/Rulesets/UI/Playfield.cs b/osu.Game/Rulesets/UI/Playfield.cs index 0586c0385a..612569a9ae 100644 --- a/osu.Game/Rulesets/UI/Playfield.cs +++ b/osu.Game/Rulesets/UI/Playfield.cs @@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.UI /// /// The HitObjects contained in this Playfield. /// - public HitObjectContainer> HitObjects; + protected HitObjectContainer> HitObjects; internal Container ScaledContent; From 2d2d1bedddf1664ef5037de502cc9b7885462b89 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 14:48:08 +0900 Subject: [PATCH 2/3] More concrete method to determine if all hit objects have been judged. Covers the case where nested hit objects are involved. --- .../Objects/Drawables/DrawableHitObject.cs | 14 ++++++++++++-- osu.Game/Rulesets/UI/HitRenderer.cs | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs index a300eeab31..45ef2553b5 100644 --- a/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Rulesets/Objects/Drawables/DrawableHitObject.cs @@ -12,6 +12,7 @@ using Container = osu.Framework.Graphics.Containers.Container; using osu.Game.Rulesets.Objects.Types; using OpenTK.Graphics; using osu.Game.Audio; +using System.Linq; namespace osu.Game.Rulesets.Objects.Drawables { @@ -24,6 +25,11 @@ namespace osu.Game.Rulesets.Objects.Drawables public TJudgement Judgement; + /// + /// Whether this hit object has been judged. + /// + public virtual bool Judged => (Judgement?.Result ?? HitResult.None) != HitResult.None; + protected abstract TJudgement CreateJudgement(); protected abstract void UpdateState(ArmedState state); @@ -86,6 +92,11 @@ namespace osu.Game.Rulesets.Objects.Drawables /// public Color4 AccentColour { get; protected set; } + /// + /// Whether this hit object and all of its nested hit objects have been judged. + /// + public sealed override bool Judged => base.Judged && (NestedHitObjects?.All(h => h.Judged) ?? true); + protected DrawableHitObject(TObject hitObject) { HitObject = hitObject; @@ -97,7 +108,7 @@ namespace osu.Game.Rulesets.Objects.Drawables /// Whether a hit was processed. protected bool UpdateJudgement(bool userTriggered) { - IPartialJudgement partial = Judgement as IPartialJudgement; + var partial = Judgement as IPartialJudgement; // Never re-process non-partial hits if (Judgement.Result != HitResult.None && partial == null) @@ -169,7 +180,6 @@ namespace osu.Game.Rulesets.Objects.Drawables } private List> nestedHitObjects; - protected IEnumerable> NestedHitObjects => nestedHitObjects; protected void AddNested(DrawableHitObject h) diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 4ca77f71df..559014ce95 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -189,7 +189,7 @@ namespace osu.Game.Rulesets.UI public override IEnumerable Objects => Beatmap.HitObjects; - protected override bool AllObjectsJudged => drawableObjects.All(h => h.Judgement.Result != HitResult.None); + protected override bool AllObjectsJudged => drawableObjects.All(h => h.Judged); /// /// The playfield. From a762f820c68d900df075e3a571b3e25878c9e286 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 14:50:18 +0900 Subject: [PATCH 3/3] Fix possible nullrefs. --- osu.Game/Rulesets/UI/HitRenderer.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/UI/HitRenderer.cs b/osu.Game/Rulesets/UI/HitRenderer.cs index 559014ce95..3ec5c353a0 100644 --- a/osu.Game/Rulesets/UI/HitRenderer.cs +++ b/osu.Game/Rulesets/UI/HitRenderer.cs @@ -199,7 +199,7 @@ namespace osu.Game.Rulesets.UI protected override Container Content => content; private readonly Container content; - private List> drawableObjects; + private readonly List> drawableObjects = new List>(); protected HitRenderer(WorkingBeatmap beatmap) : base(beatmap) @@ -226,7 +226,7 @@ namespace osu.Game.Rulesets.UI private void loadObjects() { - drawableObjects = new List>(Beatmap.HitObjects.Count); + drawableObjects.Capacity = Beatmap.HitObjects.Count; foreach (TObject h in Beatmap.HitObjects) {