mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-04-26 22:38:34 +00:00
InputCommon: Extract ControlReference from ControllerInterface
Better separation of concerns. Relegates `ControllerInterface` to enumerating input controls, and the new `ControlReference` deals with combining inputs and configuration expression parsing.
This commit is contained in:
parent
f621a6af43
commit
a509f56116
15 changed files with 274 additions and 282 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <mutex>
|
||||
|
||||
#include "Common/Thread.h"
|
||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||
|
||||
#ifdef CIFACE_USE_XINPUT
|
||||
|
@ -33,13 +32,6 @@
|
|||
#include "InputCommon/ControllerInterface/Pipes/Pipes.h"
|
||||
#endif
|
||||
|
||||
using namespace ciface::ExpressionParser;
|
||||
|
||||
namespace
|
||||
{
|
||||
const ControlState INPUT_DETECT_THRESHOLD = 0.55;
|
||||
}
|
||||
|
||||
ControllerInterface g_controller_interface;
|
||||
|
||||
//
|
||||
|
@ -236,133 +228,3 @@ void ControllerInterface::InvokeHotplugCallbacks() const
|
|||
for (const auto& callback : m_hotplug_callbacks)
|
||||
callback();
|
||||
}
|
||||
|
||||
//
|
||||
// InputReference :: State
|
||||
//
|
||||
// Gets the state of an input reference
|
||||
// override function for ControlReference::State ...
|
||||
//
|
||||
ControlState ControllerInterface::InputReference::State(const ControlState ignore)
|
||||
{
|
||||
if (parsed_expression)
|
||||
return parsed_expression->GetValue() * range;
|
||||
else
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//
|
||||
// OutputReference :: State
|
||||
//
|
||||
// Set the state of all binded outputs
|
||||
// overrides ControlReference::State .. combined them so I could make the GUI simple / inputs ==
|
||||
// same as outputs one list
|
||||
// I was lazy and it works so watever
|
||||
//
|
||||
ControlState ControllerInterface::OutputReference::State(const ControlState state)
|
||||
{
|
||||
if (parsed_expression)
|
||||
parsed_expression->SetValue(state);
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
//
|
||||
// UpdateReference
|
||||
//
|
||||
// Updates a controlreference's binded devices/controls
|
||||
// need to call this to re-parse a control reference's expression after changing it
|
||||
//
|
||||
void ControllerInterface::UpdateReference(ControllerInterface::ControlReference* ref,
|
||||
const ciface::Core::DeviceQualifier& default_device) const
|
||||
{
|
||||
delete ref->parsed_expression;
|
||||
ref->parsed_expression = nullptr;
|
||||
|
||||
ControlFinder finder(*this, default_device, ref->is_input);
|
||||
ref->parse_error = ParseExpression(ref->expression, finder, &ref->parsed_expression);
|
||||
}
|
||||
|
||||
//
|
||||
// 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*
|
||||
ControllerInterface::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().size() == 0)
|
||||
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*
|
||||
ControllerInterface::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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue