diff --git a/Source/Engine/Input/Gamepad.cpp b/Source/Engine/Input/Gamepad.cpp index 7835e7724..b7133dfbe 100644 --- a/Source/Engine/Input/Gamepad.cpp +++ b/Source/Engine/Input/Gamepad.cpp @@ -31,6 +31,15 @@ void Gamepad::ResetState() _mappedPrevState.Clear(); } +bool Gamepad::IsAnyKeyDown() const +{ + // TODO: optimize with SIMD + bool result = false; + for (auto e : _state.Buttons) + result |= e; + return result; +} + bool Gamepad::Update(EventQueue& queue) { // Copy state diff --git a/Source/Engine/Input/Gamepad.h b/Source/Engine/Input/Gamepad.h index 63decde7c..1fa0f20b8 100644 --- a/Source/Engine/Input/Gamepad.h +++ b/Source/Engine/Input/Gamepad.h @@ -164,6 +164,11 @@ public: return _mappedState.Buttons[static_cast(button)] && !_mappedPrevState.Buttons[static_cast(button)]; } + /// + /// Checks if any gamepad button is currently pressed. + /// + API_PROPERTY() bool IsAnyKeyDown() const; + /// /// Gets the gamepad button up state (true if was released during the current frame). /// diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index b7c202512..2fc75a15e 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -17,6 +17,8 @@ #include "Engine/Profiler/ProfilerCPU.h" #include "Engine/Serialization/JsonTools.h" +#include "Engine/Debug/DebugLog.h" + struct AxisEvaluation { float RawValue; @@ -183,6 +185,15 @@ void Mouse::OnMouseDown(const Float2& position, const MouseButton button, Window e.MouseData.Position = position; } +bool Mouse::IsAnyKeyDown() const +{ + // TODO: optimize with SIMD + bool result = false; + for (auto e : Mouse::_state.MouseButtons) + result |= e; + return result; +} + void Mouse::OnMouseUp(const Float2& position, const MouseButton button, Window* target) { Event& e = _queue.AddOne(); diff --git a/Source/Engine/Input/Mouse.h b/Source/Engine/Input/Mouse.h index ebf25ebb1..e137948bb 100644 --- a/Source/Engine/Input/Mouse.h +++ b/Source/Engine/Input/Mouse.h @@ -64,6 +64,11 @@ public: return _state.MousePosition; } + /// + /// Checks if any mouse key is currently pressed. + /// + API_PROPERTY() bool IsAnyKeyDown() const; + /// /// Gets the delta position of the mouse in the screen-space coordinates. ///