From 58994b790c8e8a3c85fa5d82edc2835b648b8843 Mon Sep 17 00:00:00 2001 From: pikokr Date: Mon, 27 Dec 2021 21:20:52 +0900 Subject: [PATCH] Get key binding container once instead of getting on every touch --- osu.Game.Rulesets.Mania/ManiaInputManager.cs | 5 +++++ osu.Game.Rulesets.Mania/UI/Column.cs | 21 ++++++-------------- osu.Game/Rulesets/UI/DrawableRuleset.cs | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaInputManager.cs b/osu.Game.Rulesets.Mania/ManiaInputManager.cs index 186fc4b15d..bf94735077 100644 --- a/osu.Game.Rulesets.Mania/ManiaInputManager.cs +++ b/osu.Game.Rulesets.Mania/ManiaInputManager.cs @@ -13,6 +13,11 @@ namespace osu.Game.Rulesets.Mania : base(ruleset, variant, SimultaneousBindingMode.Unique) { } + + public RulesetKeyBindingContainer GetKeyBindingContainer() + { + return (RulesetKeyBindingContainer)KeyBindingContainer; + } } public enum ManiaAction diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index df39b5397b..6be36619c7 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -136,31 +136,22 @@ namespace osu.Game.Rulesets.Mania.UI { } - // https://github.com/ppy/osu-framework/blob/49c954321c3686628b2c223670363438f88a0341/osu.Framework/Graphics/Drawable.cs#L1513-L1524 - private T findClosestParent() where T : class, IDrawable + private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + + private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingManager() { - Drawable cursor = this; - - while ((cursor = cursor.Parent) != null) - { - if (cursor is T match) - return match; - } - - return default; + return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); } - private ManiaInputManager.RulesetKeyBindingContainer keyBindingManager => findClosestParent(); - protected override bool OnTouchDown(TouchDownEvent e) { - keyBindingManager.TriggerPressed(Action.Value); + getKeyBindingManager().TriggerPressed(Action.Value); return base.OnTouchDown(e); } protected override void OnTouchUp(TouchUpEvent e) { - keyBindingManager.TriggerReleased(Action.Value); + getKeyBindingManager().TriggerReleased(Action.Value); } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) diff --git a/osu.Game/Rulesets/UI/DrawableRuleset.cs b/osu.Game/Rulesets/UI/DrawableRuleset.cs index 29559f5036..30012784a3 100644 --- a/osu.Game/Rulesets/UI/DrawableRuleset.cs +++ b/osu.Game/Rulesets/UI/DrawableRuleset.cs @@ -50,6 +50,7 @@ namespace osu.Game.Rulesets.UI /// /// The key conversion input manager for this DrawableRuleset. /// + [Cached] public PassThroughInputManager KeyBindingInputManager; public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0;