From 0da0d4f35e71bb37f3994b9adf0a106b7d321da1 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 24 Sep 2016 10:04:08 +0800 Subject: [PATCH] Avoid accessing container in each counter. --- osu.Game/Graphics/UserInterface/KeyCounter.cs | 4 ++-- .../UserInterface/KeyCounterCollection.cs | 20 +++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/KeyCounter.cs b/osu.Game/Graphics/UserInterface/KeyCounter.cs index ae7a1b5c3e..095ecc2394 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounter.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounter.cs @@ -17,7 +17,7 @@ namespace osu.Game.Graphics.UserInterface private SpriteText countSpriteText; public override string Name { get; } - public KeyCounterCollection ParentCounter { get; set; } + public bool IsCounting { get; set; } public int Count { get; private set; } private bool isLit; @@ -30,7 +30,7 @@ namespace osu.Game.Graphics.UserInterface { isLit = value; UpdateGlowSprite(); - if (value && ParentCounter.IsCounting) + if (value && IsCounting) IncreaseCount(); } } diff --git a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs index 7ee313423c..f9811a4b25 100644 --- a/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs +++ b/osu.Game/Graphics/UserInterface/KeyCounterCollection.cs @@ -1,6 +1,7 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System.Collections.Generic; using OpenTK; using osu.Framework.Graphics.Containers; @@ -13,14 +14,29 @@ namespace osu.Game.Graphics.UserInterface Direction = FlowDirection.HorizontalOnly; } + private List counters = new List(); + //default capacity is 4, and osu! uses 4 keys usually, so it won't trouble + public IReadOnlyList Counters => counters; + public void AddKey(KeyCounter key) { - key.ParentCounter = this; + counters.Add(key); + key.IsCounting = this.IsCounting; base.Add(key); } public override bool Contains(Vector2 screenSpacePos) => true; - public bool IsCounting { get; set; } + private bool isCounting; + public bool IsCounting + { + get { return isCounting; } + set + { + isCounting = value; + foreach (var child in counters) + child.IsCounting = value; + } + } } }