From 6abd3bd031e722bcb1e8ab854b792fba785dd5a6 Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Thu, 15 Aug 2024 00:58:23 +1000 Subject: [PATCH] Update legacy input VIP --- Hypercube.Client/ClientConstants.cs | 1 + .../Graphics/Viewports/CameraManager.cs | 16 ++++++++-------- .../GLFW/GlfwWindowManager.Callbacks.cs | 4 ++-- Hypercube.Client/Input/Handler/IInputHandler.cs | 6 +++++- .../Controls/ControlsSystem.cs | 4 ++-- Hypercube.Input/KeyState.cs | 4 ++-- 6 files changed, 20 insertions(+), 15 deletions(-) diff --git a/Hypercube.Client/ClientConstants.cs b/Hypercube.Client/ClientConstants.cs index 5a4c8f6..21a936a 100644 --- a/Hypercube.Client/ClientConstants.cs +++ b/Hypercube.Client/ClientConstants.cs @@ -3,4 +3,5 @@ public static class ClientConstants { public static bool MultiThreadingWindow = false; + } \ No newline at end of file diff --git a/Hypercube.Client/Graphics/Viewports/CameraManager.cs b/Hypercube.Client/Graphics/Viewports/CameraManager.cs index 03e58d2..ac5c37f 100644 --- a/Hypercube.Client/Graphics/Viewports/CameraManager.cs +++ b/Hypercube.Client/Graphics/Viewports/CameraManager.cs @@ -28,28 +28,28 @@ public void UpdateInput(ICamera? camera, float delta) var speed = 60f; - if (_inputHandler.IsKeyDown(Key.W)) + if (_inputHandler.IsKeyHeld(Key.W)) position += Vector3.UnitY * speed * delta; - if (_inputHandler.IsKeyDown(Key.S)) + if (_inputHandler.IsKeyHeld(Key.S)) position -= Vector3.UnitY * speed * delta; - if (_inputHandler.IsKeyDown(Key.A)) + if (_inputHandler.IsKeyHeld(Key.A)) position -= Vector3.UnitX * speed * delta; - if (_inputHandler.IsKeyDown(Key.D)) + if (_inputHandler.IsKeyHeld(Key.D)) position += Vector3.UnitX * speed * delta; - if (_inputHandler.IsKeyDown(Key.Q)) + if (_inputHandler.IsKeyHeld(Key.Q)) rotation -= Vector3.UnitZ * delta; - if (_inputHandler.IsKeyDown(Key.E)) + if (_inputHandler.IsKeyHeld(Key.E)) rotation += Vector3.UnitZ * delta; - if (_inputHandler.IsKeyDown(Key.T)) + if (_inputHandler.IsKeyHeld(Key.T)) scale -= Vector3.One * delta; - if (_inputHandler.IsKeyDown(Key.Y)) + if (_inputHandler.IsKeyHeld(Key.Y)) scale += Vector3.One * delta; camera.SetPosition(position); diff --git a/Hypercube.Client/Graphics/Windows/Realisation/GLFW/GlfwWindowManager.Callbacks.cs b/Hypercube.Client/Graphics/Windows/Realisation/GLFW/GlfwWindowManager.Callbacks.cs index 5c72ff0..7236508 100644 --- a/Hypercube.Client/Graphics/Windows/Realisation/GLFW/GlfwWindowManager.Callbacks.cs +++ b/Hypercube.Client/Graphics/Windows/Realisation/GLFW/GlfwWindowManager.Callbacks.cs @@ -126,8 +126,8 @@ private static KeyState Convert(InputAction action) return action switch { InputAction.Release => KeyState.Release, - InputAction.Press => KeyState.Press, - InputAction.Repeat => KeyState.Repeat, + InputAction.Press => KeyState.Pressed, + InputAction.Repeat => KeyState.Held, _ => throw new ArgumentOutOfRangeException() }; } diff --git a/Hypercube.Client/Input/Handler/IInputHandler.cs b/Hypercube.Client/Input/Handler/IInputHandler.cs index ea6007f..fcb3442 100644 --- a/Hypercube.Client/Input/Handler/IInputHandler.cs +++ b/Hypercube.Client/Input/Handler/IInputHandler.cs @@ -10,5 +10,9 @@ namespace Hypercube.Client.Input.Handler; /// public interface IInputHandler : IEventSubscriber { - bool IsKeyDown(Key key); + bool IsKeyState(Key key, KeyState state); + bool IsKeyHeld(Key key); + bool IsKeyPressed(Key key); + bool IsKeyReleased(Key key); + void KeyClear(); } \ No newline at end of file diff --git a/Hypercube.Example.Client/Controls/ControlsSystem.cs b/Hypercube.Example.Client/Controls/ControlsSystem.cs index db7d64a..adab2e2 100644 --- a/Hypercube.Example.Client/Controls/ControlsSystem.cs +++ b/Hypercube.Example.Client/Controls/ControlsSystem.cs @@ -17,8 +17,8 @@ public override void FrameUpdate(UpdateFrameEvent args) { base.FrameUpdate(args); - var inputX = (_inputHandler.IsKeyDown(Key.D) ? 1 : 0) - (_inputHandler.IsKeyDown(Key.A) ? 1 : 0); - var inputY = (_inputHandler.IsKeyDown(Key.W) ? 1 : 0) - (_inputHandler.IsKeyDown(Key.S) ? 1 : 0); + var inputX = (_inputHandler.IsKeyHeld(Key.D) ? 1 : 0) - (_inputHandler.IsKeyHeld(Key.A) ? 1 : 0); + var inputY = (_inputHandler.IsKeyHeld(Key.W) ? 1 : 0) - (_inputHandler.IsKeyHeld(Key.S) ? 1 : 0); foreach (var entity in GetEntities()) { diff --git a/Hypercube.Input/KeyState.cs b/Hypercube.Input/KeyState.cs index e110596..11d2905 100644 --- a/Hypercube.Input/KeyState.cs +++ b/Hypercube.Input/KeyState.cs @@ -3,6 +3,6 @@ public enum KeyState { Release, - Press, - Repeat + Pressed, + Held } \ No newline at end of file