summaryrefslogtreecommitdiff
path: root/Source/Core/InputCommon/ControlReference
diff options
context:
space:
mode:
authorJMC47 <JMC4789@gmail.com>2019-03-13 19:00:24 -0400
committerGitHub <noreply@github.com>2019-03-13 19:00:24 -0400
commit011ecd92e8e2b0b78471cc7ad394b6ed1f7a451e (patch)
treeee12d70ff3889b093c2696715eace0952aee8ccb /Source/Core/InputCommon/ControlReference
parentbc9e9caf19749778d01b9721a1ff92acccf70fac (diff)
parentc389d68186ea7fa95d763d7bb55bc09e5a45c4cd (diff)
Merge pull request #7829 from jordan-woyak/detect-input-improve
ControllerInterface/DolphinQt: Improve input detection.
Diffstat (limited to 'Source/Core/InputCommon/ControlReference')
-rw-r--r--Source/Core/InputCommon/ControlReference/ControlReference.cpp90
-rw-r--r--Source/Core/InputCommon/ControlReference/ControlReference.h6
-rw-r--r--Source/Core/InputCommon/ControlReference/ExpressionParser.cpp14
3 files changed, 15 insertions, 95 deletions
diff --git a/Source/Core/InputCommon/ControlReference/ControlReference.cpp b/Source/Core/InputCommon/ControlReference/ControlReference.cpp
index b3355418e2..1f392c4e3a 100644
--- a/Source/Core/InputCommon/ControlReference/ControlReference.cpp
+++ b/Source/Core/InputCommon/ControlReference/ControlReference.cpp
@@ -2,19 +2,16 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
-#include "Common/Thread.h"
+#include "InputCommon/ControlReference/ControlReference.h"
+
// For InputGateOn()
// This is a bad layering violation, but it's the cleanest
// place I could find to put it.
#include "Core/ConfigManager.h"
#include "Core/Host.h"
-#include "InputCommon/ControlReference/ControlReference.h"
-
using namespace ciface::ExpressionParser;
-constexpr ControlState INPUT_DETECT_THRESHOLD = 0.55;
-
bool ControlReference::InputGateOn()
{
return SConfig::GetInstance().m_BackgroundInput || Host_RendererHasFocus() ||
@@ -109,86 +106,3 @@ ControlState OutputReference::State(const ControlState state)
m_parsed_expression->SetValue(state * range);
return 0.0;
}
-
-//
-// InputReference :: Detect
-//
-// Wait for input on all binded devices
-// supports not detecting inputs that were held down at the time of Detect start,
-// which is useful for those crazy flightsticks that have certain buttons that are always held down
-// or some crazy axes or something
-// upon input, return pointer to detected Control
-// else return nullptr
-//
-ciface::Core::Device::Control* InputReference::Detect(const unsigned int ms,
- ciface::Core::Device* const device)
-{
- unsigned int time = 0;
- std::vector<bool> states(device->Inputs().size());
-
- if (device->Inputs().empty())
- return nullptr;
-
- // get starting state of all inputs,
- // so we can ignore those that were activated at time of Detect start
- std::vector<ciface::Core::Device::Input*>::const_iterator i = device->Inputs().begin(),
- e = device->Inputs().end();
- for (std::vector<bool>::iterator state = states.begin(); i != e; ++i)
- *state++ = ((*i)->GetState() > (1 - INPUT_DETECT_THRESHOLD));
-
- while (time < ms)
- {
- device->UpdateInput();
- i = device->Inputs().begin();
- for (std::vector<bool>::iterator state = states.begin(); i != e; ++i, ++state)
- {
- // detected an input
- if ((*i)->IsDetectable() && (*i)->GetState() > INPUT_DETECT_THRESHOLD)
- {
- // input was released at some point during Detect call
- // return the detected input
- if (false == *state)
- return *i;
- }
- else if ((*i)->GetState() < (1 - INPUT_DETECT_THRESHOLD))
- {
- *state = false;
- }
- }
- Common::SleepCurrentThread(10);
- time += 10;
- }
-
- // no input was detected
- return nullptr;
-}
-
-//
-// OutputReference :: Detect
-//
-// Totally different from the inputReference detect / I have them combined so it was simpler to make
-// the GUI.
-// The GUI doesn't know the difference between an input and an output / it's odd but I was lazy and
-// it was easy
-//
-// set all binded outputs to <range> power for x milliseconds return false
-//
-ciface::Core::Device::Control* OutputReference::Detect(const unsigned int ms,
- ciface::Core::Device* const device)
-{
- // ignore device
-
- // don't hang if we don't even have any controls mapped
- if (BoundCount() > 0)
- {
- State(1);
- unsigned int slept = 0;
-
- // this loop is to make stuff like flashing keyboard LEDs work
- while (ms > (slept += 10))
- Common::SleepCurrentThread(10);
-
- State(0);
- }
- return nullptr;
-}
diff --git a/Source/Core/InputCommon/ControlReference/ControlReference.h b/Source/Core/InputCommon/ControlReference/ControlReference.h
index 6740ed8be0..83fa288676 100644
--- a/Source/Core/InputCommon/ControlReference/ControlReference.h
+++ b/Source/Core/InputCommon/ControlReference/ControlReference.h
@@ -26,8 +26,6 @@ public:
virtual ~ControlReference();
virtual ControlState State(const ControlState state = 0) = 0;
- virtual ciface::Core::Device::Control* Detect(const unsigned int ms,
- ciface::Core::Device* const device) = 0;
virtual bool IsInput() const = 0;
int BoundCount() const;
@@ -57,8 +55,6 @@ public:
InputReference();
bool IsInput() const override;
ControlState State(const ControlState state) override;
- ciface::Core::Device::Control* Detect(const unsigned int ms,
- ciface::Core::Device* const device) override;
};
//
@@ -72,6 +68,4 @@ public:
OutputReference();
bool IsInput() const override;
ControlState State(const ControlState state) override;
- ciface::Core::Device::Control* Detect(const unsigned int ms,
- ciface::Core::Device* const device) override;
};
diff --git a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
index ba3f78170d..a73b1c94cf 100644
--- a/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
+++ b/Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
@@ -217,7 +217,19 @@ public:
std::shared_ptr<Device> m_device;
explicit ControlExpression(ControlQualifier qualifier_) : qualifier(qualifier_) {}
- ControlState GetValue() const override { return control ? control->ToInput()->GetState() : 0.0; }
+ ControlState GetValue() const override
+ {
+ if (!control)
+ return 0.0;
+
+ // Note: Inputs may return negative values in situations where opposing directions are
+ // activated. We clamp off the negative values here.
+
+ // FYI: Clamping values greater than 1.0 is purposely not done to support unbounded values in
+ // the future. (e.g. raw accelerometer/gyro data)
+
+ return std::max(0.0, control->ToInput()->GetState());
+ }
void SetValue(ControlState value) override
{
if (control)