From a1745e25a1de226901b1d307da270f8230cce8c0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 28 Aug 2024 16:48:52 +0200 Subject: [PATCH] Fix `Input::AxisValueChanged` event to properly handle value changes when using keyboard #2393 --- Source/Engine/Input/Input.cpp | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/Source/Engine/Input/Input.cpp b/Source/Engine/Input/Input.cpp index 7d267f21b..d1ccd367e 100644 --- a/Source/Engine/Input/Input.cpp +++ b/Source/Engine/Input/Input.cpp @@ -27,32 +27,18 @@ struct AxisEvaluation struct ActionData { - bool Active; - uint64 FrameIndex; - InputActionState State; - - ActionData() - { - Active = false; - FrameIndex = 0; - State = InputActionState::Waiting; - } + bool Active = false; + uint64 FrameIndex = 0; + InputActionState State = InputActionState::Waiting; }; struct AxisData { - float Value; - float ValueRaw; - float PrevKeyValue; - uint64 FrameIndex; - - AxisData() - { - Value = 0.0f; - ValueRaw = 0.0f; - PrevKeyValue = 0.0f; - FrameIndex = 0; - } + float Value = 0.0f; + float ValueRaw = 0.0f; + float PrevValue = 0.0f; + float PrevKeyValue = 0.0f; + uint64 FrameIndex = 0; }; namespace InputImpl @@ -990,6 +976,7 @@ void InputService::Update() // Setup axis data data.PrevKeyValue = e.PrevKeyValue; + data.PrevValue = data.Value; data.ValueRaw = e.RawValue; data.Value = e.Value; @@ -1025,7 +1012,7 @@ void InputService::Update() { for (auto i = Axes.Begin(); i.IsNotEnd(); ++i) { - if (Math::NotNearEqual(i->Value.Value, i->Value.PrevKeyValue)) + if (Math::NotNearEqual(i->Value.Value, i->Value.PrevValue)) { Input::AxisValueChanged(i->Key); }