Development Merge 2025.10.18 #4
@@ -10,11 +10,11 @@ namespace Engine.Integration.MonoGame;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
					public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    public Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments> OnAnyButtonPressed { get; } = new();
 | 
					    public IButtonInputs<Keys>.InputEvent OnAnyButtonPressed { get; } = new();
 | 
				
			||||||
    public Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments> OnAnyButtonReleased { get; } = new();
 | 
					    public IButtonInputs<Keys>.InputEvent OnAnyButtonReleased { get; } = new();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private readonly Dictionary<Keys, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>> OnPressed = new(256);
 | 
					    private readonly Dictionary<Keys, IButtonInputs<Keys>.InputEvent> OnPressed = new(256);
 | 
				
			||||||
    private readonly Dictionary<Keys, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>> OnReleased = new(256);
 | 
					    private readonly Dictionary<Keys, IButtonInputs<Keys>.InputEvent> OnReleased = new(256);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private int cachePressedCurrentlyCount = 0;
 | 
					    private int cachePressedCurrentlyCount = 0;
 | 
				
			||||||
    private readonly Keys[] cachePressedCurrently = new Keys[256];
 | 
					    private readonly Keys[] cachePressedCurrently = new Keys[256];
 | 
				
			||||||
@@ -22,9 +22,9 @@ public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			|||||||
    private int cachePressedPreviouslyCount = 0;
 | 
					    private int cachePressedPreviouslyCount = 0;
 | 
				
			||||||
    private readonly Keys[] cachePressedPreviously = new Keys[256];
 | 
					    private readonly Keys[] cachePressedPreviously = new Keys[256];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void RegisterOnPress(Keys key, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>.EventHandler callback)
 | 
					    public void RegisterOnPress(Keys key, IButtonInputs<Keys>.InputEvent.EventHandler callback)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!OnPressed.TryGetValue(key, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? delegateCallback))
 | 
					        if (!OnPressed.TryGetValue(key, out IButtonInputs<Keys>.InputEvent? delegateCallback))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            delegateCallback = new();
 | 
					            delegateCallback = new();
 | 
				
			||||||
            OnPressed.Add(key, delegateCallback);
 | 
					            OnPressed.Add(key, delegateCallback);
 | 
				
			||||||
@@ -33,15 +33,15 @@ public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			|||||||
        delegateCallback.AddListener(callback);
 | 
					        delegateCallback.AddListener(callback);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void UnregisterOnPress(Keys key, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>.EventHandler callback)
 | 
					    public void UnregisterOnPress(Keys key, IButtonInputs<Keys>.InputEvent.EventHandler callback)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (OnPressed.TryGetValue(key, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? delegateCallback))
 | 
					        if (OnPressed.TryGetValue(key, out IButtonInputs<Keys>.InputEvent? delegateCallback))
 | 
				
			||||||
            delegateCallback.RemoveListener(callback);
 | 
					            delegateCallback.RemoveListener(callback);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void RegisterOnRelease(Keys key, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>.EventHandler callback)
 | 
					    public void RegisterOnRelease(Keys key, IButtonInputs<Keys>.InputEvent.EventHandler callback)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!OnReleased.TryGetValue(key, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? delegateCallback))
 | 
					        if (!OnReleased.TryGetValue(key, out IButtonInputs<Keys>.InputEvent? delegateCallback))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            delegateCallback = new();
 | 
					            delegateCallback = new();
 | 
				
			||||||
            OnReleased.Add(key, delegateCallback);
 | 
					            OnReleased.Add(key, delegateCallback);
 | 
				
			||||||
@@ -50,9 +50,9 @@ public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			|||||||
        delegateCallback.AddListener(callback);
 | 
					        delegateCallback.AddListener(callback);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void UnregisterOnRelease(Keys key, Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>.EventHandler callback)
 | 
					    public void UnregisterOnRelease(Keys key, IButtonInputs<Keys>.InputEvent.EventHandler callback)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (OnReleased.TryGetValue(key, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? delegateCallback))
 | 
					        if (OnReleased.TryGetValue(key, out IButtonInputs<Keys>.InputEvent? delegateCallback))
 | 
				
			||||||
            delegateCallback.RemoveListener(callback);
 | 
					            delegateCallback.RemoveListener(callback);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -69,7 +69,7 @@ public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			|||||||
            if (WasPressed(currentlyPressedKey))
 | 
					            if (WasPressed(currentlyPressedKey))
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (OnPressed.TryGetValue(currentlyPressedKey, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? callback))
 | 
					            if (OnPressed.TryGetValue(currentlyPressedKey, out IButtonInputs<Keys>.InputEvent? callback))
 | 
				
			||||||
                callback?.Invoke(this, new(currentlyPressedKey));
 | 
					                callback?.Invoke(this, new(currentlyPressedKey));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            OnAnyButtonPressed?.Invoke(this, new(currentlyPressedKey));
 | 
					            OnAnyButtonPressed?.Invoke(this, new(currentlyPressedKey));
 | 
				
			||||||
@@ -82,7 +82,7 @@ public class KeyboardInputs : Behaviour, IButtonInputs<Keys>, IUpdate
 | 
				
			|||||||
            if (IsPressed(previouslyPressedKey))
 | 
					            if (IsPressed(previouslyPressedKey))
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (OnReleased.TryGetValue(previouslyPressedKey, out Event<IButtonInputs<Keys>, IButtonInputs<Keys>.ButtonCallbackArguments>? callback))
 | 
					            if (OnReleased.TryGetValue(previouslyPressedKey, out IButtonInputs<Keys>.InputEvent? callback))
 | 
				
			||||||
                callback?.Invoke(this, new(previouslyPressedKey));
 | 
					                callback?.Invoke(this, new(previouslyPressedKey));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            OnAnyButtonReleased?.Invoke(this, new(previouslyPressedKey));
 | 
					            OnAnyButtonReleased?.Invoke(this, new(previouslyPressedKey));
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,15 +4,17 @@ namespace Engine.Systems.Input;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public interface IButtonInputs<T> : IHasStateEnable
 | 
					public interface IButtonInputs<T> : IHasStateEnable
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    Event<IButtonInputs<T>, ButtonCallbackArguments> OnAnyButtonPressed { get; }
 | 
					    InputEvent OnAnyButtonPressed { get; }
 | 
				
			||||||
    Event<IButtonInputs<T>, ButtonCallbackArguments> OnAnyButtonReleased { get; }
 | 
					    InputEvent OnAnyButtonReleased { get; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void RegisterOnPress(T button, Event<IButtonInputs<T>, ButtonCallbackArguments>.EventHandler callback);
 | 
					    void RegisterOnPress(T button, InputEvent.EventHandler callback);
 | 
				
			||||||
    void UnregisterOnPress(T button, Event<IButtonInputs<T>, ButtonCallbackArguments>.EventHandler callback);
 | 
					    void UnregisterOnPress(T button, InputEvent.EventHandler callback);
 | 
				
			||||||
    void RegisterOnRelease(T button, Event<IButtonInputs<T>, ButtonCallbackArguments>.EventHandler callback);
 | 
					    void RegisterOnRelease(T button, InputEvent.EventHandler callback);
 | 
				
			||||||
    void UnregisterOnRelease(T button, Event<IButtonInputs<T>, ButtonCallbackArguments>.EventHandler callback);
 | 
					    void UnregisterOnRelease(T button, InputEvent.EventHandler callback);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bool IsPressed(T button);
 | 
					    bool IsPressed(T button);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    readonly record struct ButtonCallbackArguments(T Button);
 | 
					    readonly record struct ButtonCallbackArguments(T Button);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    class InputEvent : Event<IButtonInputs<T>, ButtonCallbackArguments>;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user