Get key binding container once instead of getting on every touch

This commit is contained in:
pikokr 2021-12-27 21:20:52 +09:00
parent 327822de5b
commit 58994b790c
3 changed files with 12 additions and 15 deletions

View File

@ -13,6 +13,11 @@ public ManiaInputManager(RulesetInfo ruleset, int variant)
: base(ruleset, variant, SimultaneousBindingMode.Unique)
{
}
public RulesetKeyBindingContainer GetKeyBindingContainer()
{
return (RulesetKeyBindingContainer)KeyBindingContainer;
}
}
public enum ManiaAction

View File

@ -136,31 +136,22 @@ public void OnReleased(KeyBindingReleaseEvent<ManiaAction> e)
{
}
// https://github.com/ppy/osu-framework/blob/49c954321c3686628b2c223670363438f88a0341/osu.Framework/Graphics/Drawable.cs#L1513-L1524
private T findClosestParent<T>() 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 keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer();
}
return default;
}
private ManiaInputManager.RulesetKeyBindingContainer keyBindingManager => findClosestParent<ManiaInputManager.RulesetKeyBindingContainer>();
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)

View File

@ -50,6 +50,7 @@ public abstract class DrawableRuleset<TObject> : DrawableRuleset, IProvideCursor
/// <summary>
/// The key conversion input manager for this DrawableRuleset.
/// </summary>
[Cached]
public PassThroughInputManager KeyBindingInputManager;
public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0;