From 395a72b7d45fc8d50be120cef62a277aff7efa13 Mon Sep 17 00:00:00 2001 From: Olly Rybak Date: Thu, 11 May 2023 21:10:40 +1000 Subject: [PATCH] Added comments / reformat --- Source/Engine/Input/Enums.h | 22 ++++++++++++++-------- Source/Engine/Input/Input.cpp | 10 ++++++++-- Source/Engine/Input/Input.h | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Source/Engine/Input/Enums.h b/Source/Engine/Input/Enums.h index 272231e41..4c96f715f 100644 --- a/Source/Engine/Input/Enums.h +++ b/Source/Engine/Input/Enums.h @@ -264,28 +264,34 @@ API_ENUM() enum class InputActionMode }; /// -/// The input action event trigger modes. +/// The input action event phases. /// API_ENUM() enum class InputActionPhase { + /// + /// The key/button is not assigned. + /// + None = 0, + + /// + /// The key/button is waiting for input. + /// + Waiting = 1, + /// /// User is pressing the key/button. /// - Pressing = 0, + Pressing = 2, /// /// User pressed the key/button (but wasn't pressing it in the previous frame). /// - Press = 1, + Press = 3, /// /// User released the key/button (was pressing it in the previous frame). /// - Release = 2, - - Waiting = 3, - - None = 4, + Release = 4, }; /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 32a672635..2f45a4a16 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -25,7 +25,7 @@ struct AxisEvaluation bool Used; }; -struct ActionData +struct ActionData { bool Active; uint64 FrameIndex; @@ -35,7 +35,7 @@ struct ActionData { Active = false; FrameIndex = 0; - Phase = InputActionPhase::None; + Phase = InputActionPhase::Waiting; } }; @@ -844,11 +844,17 @@ void InputService::Update() } if (Input::GetKeyDown(config.Key) || Input::GetMouseButtonDown(config.MouseButton) || Input::GetGamepadButtonDown(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Press; + } else if (Input::GetKey(config.Key) || Input::GetMouseButton(config.MouseButton) || Input::GetGamepadButton(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Pressing; + } else if (Input::GetKeyUp(config.Key) || Input::GetMouseButtonUp(config.MouseButton) || Input::GetGamepadButtonUp(config.Gamepad, config.GamepadButton)) + { data.Phase = InputActionPhase::Release; + } data.Active |= isActive; } diff --git a/Source/Engine/Input/Input.h b/Source/Engine/Input/Input.h index dd40c485a..35f3dac32 100644 --- a/Source/Engine/Input/Input.h +++ b/Source/Engine/Input/Input.h @@ -313,7 +313,7 @@ public: /// Gets the value of the virtual action identified by name. Use to get the current config. /// /// The action name. - /// True if action has been triggered in the current frame (e.g. button pressed), otherwise false. + /// A InputActionPhase determining the current phase of the Action (e.g If it was just pressed, is being held or just released). /// API_FUNCTION() static InputActionPhase GetActionPhase(const StringView& name);