Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

In response to issue #36 #38

Open
wants to merge 1 commit into
base: contrib
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/include/gainput/GainputHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace gainput
}
}

device.ApplyBufferedButton(buttonId, value);

state.Set(buttonId, value);
}

Expand Down
6 changes: 6 additions & 0 deletions lib/include/gainput/GainputInputDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<DeviceButtonId> bufferedButtonInputs_;

float* deadZones_;

Expand Down
20 changes: 19 additions & 1 deletion lib/source/gainput/GainputInputDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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_)
{
Expand Down Expand Up @@ -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
{
Expand Down