From 0608bb14463111c1b0eb094aee39beb5412d391a Mon Sep 17 00:00:00 2001 From: OvertureGames Date: Wed, 9 Aug 2017 17:36:38 -0400 Subject: [PATCH] Added an array to InputDevice that keeps track of any button that received both a 'down' and 'up' message in the same update. This array then apply itself to InputDevice's previousState_ so these inputs can be detected. --- lib/include/gainput/GainputHelpers.h | 2 ++ lib/include/gainput/GainputInputDevice.h | 6 ++++++ lib/source/gainput/GainputInputDevice.cpp | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/include/gainput/GainputHelpers.h b/lib/include/gainput/GainputHelpers.h index ddfae41..38e32fb 100644 --- a/lib/include/gainput/GainputHelpers.h +++ b/lib/include/gainput/GainputHelpers.h @@ -25,6 +25,8 @@ namespace gainput } } + device.ApplyBufferedButton(buttonId, value); + state.Set(buttonId, value); } diff --git a/lib/include/gainput/GainputInputDevice.h b/lib/include/gainput/GainputInputDevice.h index d1c9716..d14821b 100644 --- a/lib/include/gainput/GainputInputDevice.h +++ b/lib/include/gainput/GainputInputDevice.h @@ -154,6 +154,9 @@ class GAINPUT_LIBEXPORT InputDevice void SetDebugRenderingEnabled(bool enabled); /// Returns true if debug rendering is enabled, false otherwise. bool IsDebugRenderingEnabled() const { return debugRenderingEnabled_; } + + /// Used internally to determine whether a button received both a "down" and "up" message in a single update + void ApplyBufferedButton(DeviceButtonId buttonId, bool pressed); #if defined(GAINPUT_DEV) || defined(GAINPUT_ENABLE_RECORDER) /// Returns true if this device is being controlled by a remote device @@ -180,6 +183,9 @@ class GAINPUT_LIBEXPORT InputDevice InputState* state_; /// The previous state of this device. InputState* previousState_; + + /// Stores any button that received both a "down" and "up" message before being handled by InputManager's Update() + Array bufferedButtonInputs_; float* deadZones_; diff --git a/lib/source/gainput/GainputInputDevice.cpp b/lib/source/gainput/GainputInputDevice.cpp index b7df8ce..6d3cef9 100644 --- a/lib/source/gainput/GainputInputDevice.cpp +++ b/lib/source/gainput/GainputInputDevice.cpp @@ -10,7 +10,8 @@ InputDevice::InputDevice(InputManager& manager, DeviceId device, unsigned index) deviceId_(device), index_(index), deadZones_(0), - debugRenderingEnabled_(false) + debugRenderingEnabled_(false), + bufferedButtonInputs_(manager.GetAllocator()) #if defined(GAINPUT_DEV) || defined(GAINPUT_ENABLE_RECORDER) , synced_(false) #endif @@ -26,6 +27,16 @@ void InputDevice::Update(InputDeltaState* delta) { *previousState_ = *state_; + + // Apply button downs to previousState_ if both "down" and "up" messages were handled before this update occured + for(size_t i = 0; + i < bufferedButtonInputs_.size(); + ++i) + { + previousState_->Set(bufferedButtonInputs_[i], true); + } + bufferedButtonInputs_.clear(); + #if defined(GAINPUT_DEV) if (synced_) { @@ -76,6 +87,13 @@ InputDevice::SetDebugRenderingEnabled(bool enabled) debugRenderingEnabled_ = enabled; } +void +InputDevice::ApplyBufferedButton(DeviceButtonId buttonId, bool pressed) +{ + if(pressed == false && previousState_->GetBool(buttonId) == false) + bufferedButtonInputs_.push_back(buttonId); +} + size_t InputDevice::CheckAllButtonsDown(DeviceButtonSpec* outButtons, size_t maxButtonCount, unsigned start, unsigned end) const {