Add methods IsAnyKeyDown on Mouse/Gamepad class

This commit is contained in:
Ruan Lucas
2023-01-19 15:21:50 -04:00
parent 1e98fe2920
commit 8669a291fb
4 changed files with 30 additions and 0 deletions

View File

@@ -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

View File

@@ -164,6 +164,11 @@ public:
return _mappedState.Buttons[static_cast<int32>(button)] && !_mappedPrevState.Buttons[static_cast<int32>(button)];
}
/// <summary>
/// Checks if any gamepad button is currently pressed.
/// </summary>
API_PROPERTY() bool IsAnyKeyDown() const;
/// <summary>
/// Gets the gamepad button up state (true if was released during the current frame).
/// </summary>

View File

@@ -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();

View File

@@ -64,6 +64,11 @@ public:
return _state.MousePosition;
}
/// <summary>
/// Checks if any mouse key is currently pressed.
/// </summary>
API_PROPERTY() bool IsAnyKeyDown() const;
/// <summary>
/// Gets the delta position of the mouse in the screen-space coordinates.
/// </summary>