From 8a91c24e3be941669ff22f62e26497a68e3077c8 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 14:32:29 +0300 Subject: [PATCH 1/8] Create `IInputBinding`. --- Modules/Orama.Input/IInputBinding.cs | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Modules/Orama.Input/IInputBinding.cs diff --git a/Modules/Orama.Input/IInputBinding.cs b/Modules/Orama.Input/IInputBinding.cs new file mode 100644 index 0000000..e1a22fd --- /dev/null +++ b/Modules/Orama.Input/IInputBinding.cs @@ -0,0 +1,9 @@ +// This file is part of the Orama Game Engine. +// Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) + +namespace Orama.Input; + +public interface IInputBinding +{ + public float Read(); +} From 5e33aa32ccb65c4456edbe9fdf71b2f75fb45e64 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 14:33:15 +0300 Subject: [PATCH 2/8] Create bindings for `GamepadButton`, `MouseButton` and `Key`. --- .../Bindings/GamepadButtonBinding.cs | 27 +++++++++++++++++++ Modules/Orama.Input/Bindings/KeyBinding.cs | 27 +++++++++++++++++++ .../Bindings/MouseButtonBinding.cs | 27 +++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 Modules/Orama.Input/Bindings/GamepadButtonBinding.cs create mode 100644 Modules/Orama.Input/Bindings/KeyBinding.cs create mode 100644 Modules/Orama.Input/Bindings/MouseButtonBinding.cs diff --git a/Modules/Orama.Input/Bindings/GamepadButtonBinding.cs b/Modules/Orama.Input/Bindings/GamepadButtonBinding.cs new file mode 100644 index 0000000..d17fb3b --- /dev/null +++ b/Modules/Orama.Input/Bindings/GamepadButtonBinding.cs @@ -0,0 +1,27 @@ +// This file is part of the Orama Game Engine. +// Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) + +using Orama.Common; +using Orama.Input.Devices; + +namespace Orama.Input.Bindings; + +public class GamepadButtonBinding : IInputBinding +{ + Gamepad.Button Button { get; set; } + + public GamepadButtonBinding(Gamepad.Button button) + { + Button = button; + } + + public float Read() + { + var input = ModuleManager.GetModule(); + + if (input == null || input.PrimaryGamepad == null) + return 0f; + + return input.PrimaryGamepad.IsButtonPressed(Button) ? 1f : 0f; + } +} diff --git a/Modules/Orama.Input/Bindings/KeyBinding.cs b/Modules/Orama.Input/Bindings/KeyBinding.cs new file mode 100644 index 0000000..da0860a --- /dev/null +++ b/Modules/Orama.Input/Bindings/KeyBinding.cs @@ -0,0 +1,27 @@ +// This file is part of the Orama Game Engine. +// Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) + +using Orama.Common; +using Orama.Input.Devices; + +namespace Orama.Input.Bindings; + +public class KeyBinding : IInputBinding +{ + Keyboard.Key Key { get; set; } + + public KeyBinding(Keyboard.Key key) + { + Key = key; + } + + public float Read() + { + var input = ModuleManager.GetModule(); + + if (input == null || input.PrimaryKeyboard == null) + return 0f; + + return input.PrimaryKeyboard.IsKeyDown(Key) ? 1f : 0f; + } +} diff --git a/Modules/Orama.Input/Bindings/MouseButtonBinding.cs b/Modules/Orama.Input/Bindings/MouseButtonBinding.cs new file mode 100644 index 0000000..096be18 --- /dev/null +++ b/Modules/Orama.Input/Bindings/MouseButtonBinding.cs @@ -0,0 +1,27 @@ +// This file is part of the Orama Game Engine. +// Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) + +using Orama.Common; +using Orama.Input.Devices; + +namespace Orama.Input.Bindings; + +public class MouseButtonBinding : IInputBinding +{ + Mouse.Button Button { get; set; } + + public MouseButtonBinding(Mouse.Button button) + { + Button = button; + } + + public float Read() + { + var input = ModuleManager.GetModule(); + + if (input == null || input.PrimaryMouse == null) + return 0f; + + return input.PrimaryMouse.IsButtonDown(Button) ? 1f : 0f; + } +} From e2a47fecb67cd167f1f49426b714f6a564654038 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 14:33:28 +0300 Subject: [PATCH 3/8] Create `InputAction`. --- Modules/Orama.Input/InputAction.cs | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Modules/Orama.Input/InputAction.cs diff --git a/Modules/Orama.Input/InputAction.cs b/Modules/Orama.Input/InputAction.cs new file mode 100644 index 0000000..08a542b --- /dev/null +++ b/Modules/Orama.Input/InputAction.cs @@ -0,0 +1,54 @@ +// This file is part of the Orama Game Engine. +// Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) + +namespace Orama.Input; + +public class InputAction +{ + public string Name { get; } + + public List Bindings { get; } = new(); + + public float Value { get; private set; } + + public float PreviousValue { get; private set; } + + public bool IsPressed => Value != 0f; + + public bool WasPressed => PreviousValue != 0f; + + public bool Triggered => IsPressed && !WasPressed; + + public bool Released => !IsPressed && WasPressed; + + public InputAction(string name) + { + Name = name; + } + + public InputAction(string name, params IInputBinding[] bindings) : this(name) + { + Bindings.AddRange(bindings); + } + + public InputAction AddBinding(IInputBinding binding) + { + Bindings.Add(binding); + return this; + } + + internal void Update() + { + PreviousValue = Value; + + float value = 0f; + foreach (var binding in Bindings) + { + float bindingValue = binding.Read(); + if (bindingValue != 0f) + value = bindingValue; + } + + Value = value; + } +} From 52cb60f1ecc2f6ce1f08fd6413076a75eddf9517 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 14:34:17 +0300 Subject: [PATCH 4/8] Implement `InputAction` methods in Input module. --- Modules/Orama.Input/InputModule.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Modules/Orama.Input/InputModule.cs b/Modules/Orama.Input/InputModule.cs index a254664..b493b5c 100644 --- a/Modules/Orama.Input/InputModule.cs +++ b/Modules/Orama.Input/InputModule.cs @@ -26,6 +26,7 @@ public class InputModule : BaseModule public Gamepad? PrimaryGamepad { get; private set; } private readonly List devices = new(); + private readonly Dictionary actions = new(); private IInputContext input = null!; @@ -52,6 +53,13 @@ public override void Initialize() PrimaryGamepad = devices.OfType().FirstOrDefault(); } + public InputAction RegisterAction(InputAction action) + { + actions[action.Name] = action; + return action; + } + public InputAction GetAction(string name) => actions[name]; + /// public override void Dispose() { @@ -66,5 +74,8 @@ public void Update() { foreach (var device in devices) device.Update(); + + foreach (var action in actions.Values) + action.Update(); } } From 29e16fa6a148626791039cee67e6bde95a4c6a66 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 15:51:12 +0300 Subject: [PATCH 5/8] Add XML comments to everything new. --- Modules/Orama.Input/IInputBinding.cs | 4 ++++ Modules/Orama.Input/InputAction.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Modules/Orama.Input/IInputBinding.cs b/Modules/Orama.Input/IInputBinding.cs index e1a22fd..f3c21b5 100644 --- a/Modules/Orama.Input/IInputBinding.cs +++ b/Modules/Orama.Input/IInputBinding.cs @@ -3,7 +3,11 @@ namespace Orama.Input; +/// +/// A single physical input source (a key, button, or axis) that can drive an . +/// public interface IInputBinding { + /// Reads the current value of this binding. public float Read(); } diff --git a/Modules/Orama.Input/InputAction.cs b/Modules/Orama.Input/InputAction.cs index 08a542b..5e1da74 100644 --- a/Modules/Orama.Input/InputAction.cs +++ b/Modules/Orama.Input/InputAction.cs @@ -3,22 +3,33 @@ namespace Orama.Input; +/// +/// A named input action resolved each frame from one or more s. +/// public class InputAction { + /// The unique name used to look this action up via . public string Name { get; } + /// All bindings that can drive this action's value. public List Bindings { get; } = new(); + /// The resolved value for this frame. public float Value { get; private set; } + /// The resolved value from the previous frame. public float PreviousValue { get; private set; } + /// True while this action's value is nonzero. public bool IsPressed => Value != 0f; + /// Same as , evaluated against last frame's value. public bool WasPressed => PreviousValue != 0f; + /// True only on the frame this action goes from released to pressed. public bool Triggered => IsPressed && !WasPressed; + /// True only on the frame this action goes from pressed to released. public bool Released => !IsPressed && WasPressed; public InputAction(string name) @@ -31,12 +42,14 @@ public InputAction(string name, params IInputBinding[] bindings) : this(name) Bindings.AddRange(bindings); } + /// Adds a binding to this action. public InputAction AddBinding(IInputBinding binding) { Bindings.Add(binding); return this; } + /// Re-reads all bindings and resolves this action's value for the current frame. internal void Update() { PreviousValue = Value; From d5e5b4f6239616093b38ce18262749cbd334bf59 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 15:51:33 +0300 Subject: [PATCH 6/8] Add test action in `Program.cs`. --- Players/Orama.Players.Desktop/Program.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Players/Orama.Players.Desktop/Program.cs b/Players/Orama.Players.Desktop/Program.cs index 683aae3..4c2ca69 100644 --- a/Players/Orama.Players.Desktop/Program.cs +++ b/Players/Orama.Players.Desktop/Program.cs @@ -7,6 +7,7 @@ using Orama.Common.Utility; using Orama.GUI; using Orama.Input; +using Orama.Input.Bindings; using Orama.Math; using Orama.Physics; using Orama.Rendering; @@ -55,6 +56,10 @@ static void Main(string[] args) for (int i = 0; i < 1000; i++) OramaConsole.Log($"Logging {i} times."); + var testAction = new InputAction("TestAction"); + testAction.AddBinding(new KeyBinding(Input.Devices.Keyboard.Key.Space)); + testAction.AddBinding(new GamepadButtonBinding(Input.Devices.Gamepad.Button.ActionDown)); + ModuleManager.GetModule()?.RegisterAction(testAction); ModuleManager.GetModule()?.CurrentScene.StartAll(); }; @@ -66,6 +71,10 @@ static void Main(string[] args) Application.OnUpdate += () => { + var input = ModuleManager.GetModule(); + if (input!.GetAction("TestAction").Triggered) + OramaConsole.Log("Test action triggered"); + }; From 2e8baf1d812bdc018712cc93024988d3155e9aca Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Sun, 19 Jul 2026 15:53:24 +0300 Subject: [PATCH 7/8] Add XML comments to new Input module additions and clean up `IInputBinding` comment. --- Modules/Orama.Input/IInputBinding.cs | 2 +- Modules/Orama.Input/InputModule.cs | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/Orama.Input/IInputBinding.cs b/Modules/Orama.Input/IInputBinding.cs index f3c21b5..3f147e6 100644 --- a/Modules/Orama.Input/IInputBinding.cs +++ b/Modules/Orama.Input/IInputBinding.cs @@ -4,7 +4,7 @@ namespace Orama.Input; /// -/// A single physical input source (a key, button, or axis) that can drive an . +/// A single physical input source that can drive an . /// public interface IInputBinding { diff --git a/Modules/Orama.Input/InputModule.cs b/Modules/Orama.Input/InputModule.cs index b493b5c..84e61bb 100644 --- a/Modules/Orama.Input/InputModule.cs +++ b/Modules/Orama.Input/InputModule.cs @@ -53,11 +53,14 @@ public override void Initialize() PrimaryGamepad = devices.OfType().FirstOrDefault(); } + /// Registers an so it's updated each frame and can be looked up by name. public InputAction RegisterAction(InputAction action) { actions[action.Name] = action; return action; } + + /// Gets a previously registered by name. public InputAction GetAction(string name) => actions[name]; /// From ae64a0507738b5941936ed080f7bcd647a0e8cd1 Mon Sep 17 00:00:00 2001 From: Pan <76873505+atskas@users.noreply.github.com> Date: Tue, 21 Jul 2026 20:50:18 +0300 Subject: [PATCH 8/8] Move `IInputBinding` to the Bindings folder in Orama.Input --- Modules/Orama.Input/{ => Bindings}/IInputBinding.cs | 2 +- Modules/Orama.Input/InputAction.cs | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) rename Modules/Orama.Input/{ => Bindings}/IInputBinding.cs (92%) diff --git a/Modules/Orama.Input/IInputBinding.cs b/Modules/Orama.Input/Bindings/IInputBinding.cs similarity index 92% rename from Modules/Orama.Input/IInputBinding.cs rename to Modules/Orama.Input/Bindings/IInputBinding.cs index 3f147e6..5a78447 100644 --- a/Modules/Orama.Input/IInputBinding.cs +++ b/Modules/Orama.Input/Bindings/IInputBinding.cs @@ -1,7 +1,7 @@ // This file is part of the Orama Game Engine. // Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) -namespace Orama.Input; +namespace Orama.Input.Bindings; /// /// A single physical input source that can drive an . diff --git a/Modules/Orama.Input/InputAction.cs b/Modules/Orama.Input/InputAction.cs index 5e1da74..f6dd5ee 100644 --- a/Modules/Orama.Input/InputAction.cs +++ b/Modules/Orama.Input/InputAction.cs @@ -1,6 +1,8 @@ // This file is part of the Orama Game Engine. // Licensed under the MIT license. (https://github.com/Orama-Engine/Orama/blob/main/LICENSE) +using Orama.Input.Bindings; + namespace Orama.Input; ///