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
|
@ -52,10 +52,10 @@
|
||||||
#include "DolphinWX/Input/NunchukInputConfigDiag.h"
|
#include "DolphinWX/Input/NunchukInputConfigDiag.h"
|
||||||
#include "DolphinWX/Input/TurntableInputConfigDiag.h"
|
#include "DolphinWX/Input/TurntableInputConfigDiag.h"
|
||||||
#include "DolphinWX/WxUtils.h"
|
#include "DolphinWX/WxUtils.h"
|
||||||
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
#include "InputCommon/ControllerInterface/Device.h"
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
|
||||||
#include "InputCommon/InputConfig.h"
|
#include "InputCommon/InputConfig.h"
|
||||||
|
|
||||||
using namespace ciface::ExpressionParser;
|
using namespace ciface::ExpressionParser;
|
||||||
|
@ -177,7 +177,7 @@ void PadSettingSpin::UpdateValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlDialog::ControlDialog(InputConfigDialog* const parent, InputConfig& config,
|
ControlDialog::ControlDialog(InputConfigDialog* const parent, InputConfig& config,
|
||||||
ControllerInterface::ControlReference* const ref)
|
ControlReference* const ref)
|
||||||
: wxDialog(parent, wxID_ANY, _("Configure Control"), wxDefaultPosition, wxDefaultSize,
|
: wxDialog(parent, wxID_ANY, _("Configure Control"), wxDefaultPosition, wxDefaultSize,
|
||||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
||||||
control_reference(ref), m_config(config), m_parent(parent)
|
control_reference(ref), m_config(config), m_parent(parent)
|
||||||
|
@ -220,8 +220,7 @@ ExtensionButton::ExtensionButton(wxWindow* const parent, ControllerEmu::Extensio
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlButton::ControlButton(wxWindow* const parent,
|
ControlButton::ControlButton(wxWindow* const parent, ControlReference* const _ref,
|
||||||
ControllerInterface::ControlReference* const _ref,
|
|
||||||
const std::string& name, const unsigned int width,
|
const std::string& name, const unsigned int width,
|
||||||
const std::string& label)
|
const std::string& label)
|
||||||
: wxButton(parent, wxID_ANY), control_reference(_ref), m_name(name),
|
: wxButton(parent, wxID_ANY), control_reference(_ref), m_name(name),
|
||||||
|
@ -387,8 +386,8 @@ bool ControlDialog::Validate()
|
||||||
control_reference->expression = WxStrToStr(textctrl->GetValue());
|
control_reference->expression = WxStrToStr(textctrl->GetValue());
|
||||||
|
|
||||||
auto lock = ControllerEmu::GetStateLock();
|
auto lock = ControllerEmu::GetStateLock();
|
||||||
g_controller_interface.UpdateReference(control_reference,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->default_device);
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
|
|
||||||
|
@ -426,8 +425,8 @@ void ControlDialog::ClearControl(wxCommandEvent&)
|
||||||
control_reference->expression.clear();
|
control_reference->expression.clear();
|
||||||
|
|
||||||
auto lock = ControllerEmu::GetStateLock();
|
auto lock = ControllerEmu::GetStateLock();
|
||||||
g_controller_interface.UpdateReference(control_reference,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->default_device);
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -485,8 +484,8 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&)
|
||||||
control_reference->expression = textctrl->GetValue();
|
control_reference->expression = textctrl->GetValue();
|
||||||
|
|
||||||
auto lock = ControllerEmu::GetStateLock();
|
auto lock = ControllerEmu::GetStateLock();
|
||||||
g_controller_interface.UpdateReference(control_reference,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->default_device);
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -521,8 +520,8 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
|
||||||
control_reference->expression = textctrl->GetValue();
|
control_reference->expression = textctrl->GetValue();
|
||||||
|
|
||||||
auto lock = ControllerEmu::GetStateLock();
|
auto lock = ControllerEmu::GetStateLock();
|
||||||
g_controller_interface.UpdateReference(control_reference,
|
control_reference->UpdateReference(g_controller_interface,
|
||||||
m_parent->GetController()->default_device);
|
m_parent->GetController()->default_device);
|
||||||
|
|
||||||
UpdateGUI();
|
UpdateGUI();
|
||||||
}
|
}
|
||||||
|
@ -703,7 +702,8 @@ bool InputConfigDialog::DetectButton(ControlButton* button)
|
||||||
GetExpressionForControl(expr, control_name);
|
GetExpressionForControl(expr, control_name);
|
||||||
button->control_reference->expression = expr;
|
button->control_reference->expression = expr;
|
||||||
auto lock = ControllerEmu::GetStateLock();
|
auto lock = ControllerEmu::GetStateLock();
|
||||||
g_controller_interface.UpdateReference(button->control_reference, controller->default_device);
|
button->control_reference->UpdateReference(g_controller_interface,
|
||||||
|
controller->default_device);
|
||||||
success = true;
|
success = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@
|
||||||
#include <wx/spinctrl.h>
|
#include <wx/spinctrl.h>
|
||||||
#include <wx/timer.h>
|
#include <wx/timer.h>
|
||||||
|
|
||||||
|
#include "InputCommon/ControlReference/ControlReference.h"
|
||||||
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
#include "InputCommon/ControllerEmu/ControllerEmu.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
|
||||||
#include "InputCommon/ControllerInterface/Device.h"
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
|
|
||||||
class DolphinSlider;
|
class DolphinSlider;
|
||||||
|
@ -100,14 +100,13 @@ class InputConfigDialog;
|
||||||
class ControlDialog : public wxDialog
|
class ControlDialog : public wxDialog
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlDialog(InputConfigDialog* const parent, InputConfig& config,
|
ControlDialog(InputConfigDialog* const parent, InputConfig& config, ControlReference* const ref);
|
||||||
ControllerInterface::ControlReference* const ref);
|
|
||||||
|
|
||||||
bool Validate() override;
|
bool Validate() override;
|
||||||
|
|
||||||
int GetRangeSliderValue() const;
|
int GetRangeSliderValue() const;
|
||||||
|
|
||||||
ControllerInterface::ControlReference* const control_reference;
|
ControlReference* const control_reference;
|
||||||
InputConfig& m_config;
|
InputConfig& m_config;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -151,10 +150,10 @@ public:
|
||||||
class ControlButton : public wxButton
|
class ControlButton : public wxButton
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ControlButton(wxWindow* const parent, ControllerInterface::ControlReference* const _ref,
|
ControlButton(wxWindow* const parent, ControlReference* const _ref, const std::string& name,
|
||||||
const std::string& name, const unsigned int width, const std::string& label = {});
|
const unsigned int width, const std::string& label = {});
|
||||||
|
|
||||||
ControllerInterface::ControlReference* const control_reference;
|
ControlReference* const control_reference;
|
||||||
const std::string m_name;
|
const std::string m_name;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -2,7 +2,9 @@ set(SRCS InputConfig.cpp
|
||||||
ControllerEmu/ControllerEmu.cpp
|
ControllerEmu/ControllerEmu.cpp
|
||||||
ControllerInterface/ControllerInterface.cpp
|
ControllerInterface/ControllerInterface.cpp
|
||||||
ControllerInterface/Device.cpp
|
ControllerInterface/Device.cpp
|
||||||
ControllerInterface/ExpressionParser.cpp)
|
ControlReference/ControlReference.cpp
|
||||||
|
ControlReference/ExpressionParser.cpp
|
||||||
|
)
|
||||||
set(LIBS common)
|
set(LIBS common)
|
||||||
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
// Copyright 2016 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#include "Common/Thread.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() || Host_UIHasFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// UpdateReference
|
||||||
|
//
|
||||||
|
// Updates a controlreference's binded devices/controls
|
||||||
|
// need to call this to re-parse a control reference's expression after changing it
|
||||||
|
//
|
||||||
|
void ControlReference::UpdateReference(ciface::Core::DeviceContainer& devices,
|
||||||
|
const ciface::Core::DeviceQualifier& default_device)
|
||||||
|
{
|
||||||
|
delete parsed_expression;
|
||||||
|
parsed_expression = nullptr;
|
||||||
|
|
||||||
|
ControlFinder finder(devices, default_device, is_input);
|
||||||
|
parse_error = ParseExpression(expression, finder, &parsed_expression);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// InputReference :: State
|
||||||
|
//
|
||||||
|
// Gets the state of an input reference
|
||||||
|
// override function for ControlReference::State ...
|
||||||
|
//
|
||||||
|
ControlState InputReference::State(const ControlState ignore)
|
||||||
|
{
|
||||||
|
if (parsed_expression && InputGateOn())
|
||||||
|
return parsed_expression->GetValue() * range;
|
||||||
|
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 OutputReference::State(const ControlState state)
|
||||||
|
{
|
||||||
|
if (parsed_expression && InputGateOn())
|
||||||
|
parsed_expression->SetValue(state);
|
||||||
|
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().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* 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;
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
// Copyright 2016 Dolphin Emulator Project
|
||||||
|
// Licensed under GPLv2+
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
||||||
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
|
|
||||||
|
// ControlReference
|
||||||
|
//
|
||||||
|
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
||||||
|
//
|
||||||
|
// After being bound to devices and controls with UpdateReference,
|
||||||
|
// each one can link to multiple devices and controls
|
||||||
|
// when you change a ControlReference's expression,
|
||||||
|
// you must use UpdateReference on it to rebind controls
|
||||||
|
//
|
||||||
|
|
||||||
|
class ControlReference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static bool InputGateOn();
|
||||||
|
|
||||||
|
virtual ControlState State(const ControlState state = 0) = 0;
|
||||||
|
virtual ciface::Core::Device::Control* Detect(const unsigned int ms,
|
||||||
|
ciface::Core::Device* const device) = 0;
|
||||||
|
|
||||||
|
void UpdateReference(ciface::Core::DeviceContainer& devices,
|
||||||
|
const ciface::Core::DeviceQualifier& default_device);
|
||||||
|
|
||||||
|
ControlState range;
|
||||||
|
std::string expression;
|
||||||
|
const bool is_input;
|
||||||
|
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
||||||
|
|
||||||
|
virtual ~ControlReference() { delete parsed_expression; }
|
||||||
|
int BoundCount()
|
||||||
|
{
|
||||||
|
if (parsed_expression)
|
||||||
|
return parsed_expression->num_controls;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
ControlReference(const bool _is_input) : range(1), is_input(_is_input), parsed_expression(nullptr)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
ciface::ExpressionParser::Expression* parsed_expression;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// InputReference
|
||||||
|
//
|
||||||
|
// Control reference for inputs
|
||||||
|
//
|
||||||
|
class InputReference : public ControlReference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InputReference() : ControlReference(true) {}
|
||||||
|
ControlState State(const ControlState state) override;
|
||||||
|
ciface::Core::Device::Control* Detect(const unsigned int ms,
|
||||||
|
ciface::Core::Device* const device) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// OutputReference
|
||||||
|
//
|
||||||
|
// Control reference for outputs
|
||||||
|
//
|
||||||
|
class OutputReference : public ControlReference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
OutputReference() : ControlReference(false) {}
|
||||||
|
ControlState State(const ControlState state) override;
|
||||||
|
ciface::Core::Device::Control* Detect(const unsigned int ms,
|
||||||
|
ciface::Core::Device* const device) override;
|
||||||
|
};
|
|
@ -10,7 +10,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
#include "InputCommon/ControlReference/ExpressionParser.h"
|
||||||
|
|
||||||
using namespace ciface::Core;
|
using namespace ciface::Core;
|
||||||
|
|
||||||
|
@ -241,8 +241,8 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ControlState GetValue() override { return control->ToInput()->GetGatedState(); }
|
ControlState GetValue() override { return control->ToInput()->GetState(); }
|
||||||
void SetValue(ControlState value) override { control->ToOutput()->SetGatedState(value); }
|
void SetValue(ControlState value) override { control->ToOutput()->SetState(value); }
|
||||||
int CountNumControls() override { return 1; }
|
int CountNumControls() override { return 1; }
|
||||||
operator std::string() override { return "`" + (std::string)qualifier + "`"; }
|
operator std::string() override { return "`" + (std::string)qualifier + "`"; }
|
||||||
private:
|
private:
|
|
@ -23,7 +23,7 @@ void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
||||||
for (auto& ctrlGroup : groups)
|
for (auto& ctrlGroup : groups)
|
||||||
{
|
{
|
||||||
for (auto& control : ctrlGroup->controls)
|
for (auto& control : ctrlGroup->controls)
|
||||||
devi.UpdateReference(control->control_ref.get(), default_device);
|
control->control_ref.get()->UpdateReference(devi, default_device);
|
||||||
|
|
||||||
// extension
|
// extension
|
||||||
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "Common/IniFile.h"
|
#include "Common/IniFile.h"
|
||||||
#include "Common/MathUtil.h"
|
#include "Common/MathUtil.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
#include "InputCommon/ControlReference/ControlReference.h"
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
#include "InputCommon/GCPadStatus.h"
|
#include "InputCommon/GCPadStatus.h"
|
||||||
|
|
||||||
|
@ -50,27 +51,27 @@ public:
|
||||||
class Control
|
class Control
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
Control(ControllerInterface::ControlReference* const _ref, const std::string& _name)
|
Control(ControlReference* const _ref, const std::string& _name)
|
||||||
: control_ref(_ref), name(_name)
|
: control_ref(_ref), name(_name)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual ~Control() {}
|
virtual ~Control() {}
|
||||||
std::unique_ptr<ControllerInterface::ControlReference> const control_ref;
|
std::unique_ptr<ControlReference> const control_ref;
|
||||||
const std::string name;
|
const std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Input : public Control
|
class Input : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Input(const std::string& _name) : Control(new ControllerInterface::InputReference, _name) {}
|
Input(const std::string& _name) : Control(new InputReference, _name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Output : public Control
|
class Output : public Control
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Output(const std::string& _name) : Control(new ControllerInterface::OutputReference, _name) {}
|
Output(const std::string& _name) : Control(new OutputReference, _name) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SettingType
|
enum class SettingType
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
|
||||||
#include "Common/Thread.h"
|
|
||||||
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
#include "InputCommon/ControllerInterface/ControllerInterface.h"
|
||||||
|
|
||||||
#ifdef CIFACE_USE_XINPUT
|
#ifdef CIFACE_USE_XINPUT
|
||||||
|
@ -33,13 +32,6 @@
|
||||||
#include "InputCommon/ControllerInterface/Pipes/Pipes.h"
|
#include "InputCommon/ControllerInterface/Pipes/Pipes.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace ciface::ExpressionParser;
|
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
const ControlState INPUT_DETECT_THRESHOLD = 0.55;
|
|
||||||
}
|
|
||||||
|
|
||||||
ControllerInterface g_controller_interface;
|
ControllerInterface g_controller_interface;
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -236,133 +228,3 @@ void ControllerInterface::InvokeHotplugCallbacks() const
|
||||||
for (const auto& callback : m_hotplug_callbacks)
|
for (const auto& callback : m_hotplug_callbacks)
|
||||||
callback();
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,9 +11,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Common/CommonTypes.h"
|
#include "Common/CommonTypes.h"
|
||||||
#include "Common/Thread.h"
|
|
||||||
#include "InputCommon/ControllerInterface/Device.h"
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
#include "InputCommon/ControllerInterface/ExpressionParser.h"
|
|
||||||
|
|
||||||
// enable disable sources
|
// enable disable sources
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -45,75 +43,6 @@
|
||||||
class ControllerInterface : public ciface::Core::DeviceContainer
|
class ControllerInterface : public ciface::Core::DeviceContainer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
//
|
|
||||||
// ControlReference
|
|
||||||
//
|
|
||||||
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
|
||||||
//
|
|
||||||
// After being bound to devices and controls with ControllerInterface::UpdateReference,
|
|
||||||
// each one can link to multiple devices and controls
|
|
||||||
// when you change a ControlReference's expression,
|
|
||||||
// you must use ControllerInterface::UpdateReference on it to rebind controls
|
|
||||||
//
|
|
||||||
class ControlReference
|
|
||||||
{
|
|
||||||
friend class ControllerInterface;
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ControlState State(const ControlState state = 0) = 0;
|
|
||||||
virtual ciface::Core::Device::Control* Detect(const unsigned int ms,
|
|
||||||
ciface::Core::Device* const device) = 0;
|
|
||||||
|
|
||||||
ControlState range;
|
|
||||||
std::string expression;
|
|
||||||
const bool is_input;
|
|
||||||
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
|
||||||
|
|
||||||
virtual ~ControlReference() { delete parsed_expression; }
|
|
||||||
int BoundCount()
|
|
||||||
{
|
|
||||||
if (parsed_expression)
|
|
||||||
return parsed_expression->num_controls;
|
|
||||||
else
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
ControlReference(const bool _is_input)
|
|
||||||
: range(1), is_input(_is_input), parsed_expression(nullptr)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
ciface::ExpressionParser::Expression* parsed_expression;
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// InputReference
|
|
||||||
//
|
|
||||||
// Control reference for inputs
|
|
||||||
//
|
|
||||||
class InputReference : public ControlReference
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
InputReference() : ControlReference(true) {}
|
|
||||||
ControlState State(const ControlState state) override;
|
|
||||||
ciface::Core::Device::Control* Detect(const unsigned int ms,
|
|
||||||
ciface::Core::Device* const device) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// OutputReference
|
|
||||||
//
|
|
||||||
// Control reference for outputs
|
|
||||||
//
|
|
||||||
class OutputReference : public ControlReference
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
OutputReference() : ControlReference(false) {}
|
|
||||||
ControlState State(const ControlState state) override;
|
|
||||||
ciface::Core::Device::Control* Detect(const unsigned int ms,
|
|
||||||
ciface::Core::Device* const device) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
|
ControllerInterface() : m_is_init(false), m_hwnd(nullptr) {}
|
||||||
void Initialize(void* const hwnd);
|
void Initialize(void* const hwnd);
|
||||||
void RefreshDevices();
|
void RefreshDevices();
|
||||||
|
@ -121,8 +50,6 @@ public:
|
||||||
void AddDevice(std::shared_ptr<ciface::Core::Device> device);
|
void AddDevice(std::shared_ptr<ciface::Core::Device> device);
|
||||||
void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback);
|
void RemoveDevice(std::function<bool(const ciface::Core::Device*)> callback);
|
||||||
bool IsInit() const { return m_is_init; }
|
bool IsInit() const { return m_is_init; }
|
||||||
void UpdateReference(ControlReference* control,
|
|
||||||
const ciface::Core::DeviceQualifier& default_device) const;
|
|
||||||
void UpdateInput();
|
void UpdateInput();
|
||||||
|
|
||||||
void RegisterHotplugCallback(std::function<void(void)> callback);
|
void RegisterHotplugCallback(std::function<void(void)> callback);
|
||||||
|
|
|
@ -7,12 +7,6 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
// For InputGateOn()
|
|
||||||
// This is a really 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/ControllerInterface/Device.h"
|
#include "InputCommon/ControllerInterface/Device.h"
|
||||||
|
|
||||||
namespace ciface
|
namespace ciface
|
||||||
|
@ -67,16 +61,6 @@ Device::Output* Device::FindOutput(const std::string& name) const
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Device::Control::InputGateOn()
|
|
||||||
{
|
|
||||||
if (SConfig::GetInstance().m_BackgroundInput)
|
|
||||||
return true;
|
|
||||||
else if (Host_RendererHasFocus() || Host_UIHasFocus())
|
|
||||||
return true;
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// DeviceQualifier :: ToString
|
// DeviceQualifier :: ToString
|
||||||
//
|
//
|
||||||
|
|
|
@ -42,8 +42,6 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual std::string GetName() const = 0;
|
virtual std::string GetName() const = 0;
|
||||||
virtual ~Control() {}
|
virtual ~Control() {}
|
||||||
bool InputGateOn();
|
|
||||||
|
|
||||||
virtual Input* ToInput() { return nullptr; }
|
virtual Input* ToInput() { return nullptr; }
|
||||||
virtual Output* ToOutput() { return nullptr; }
|
virtual Output* ToOutput() { return nullptr; }
|
||||||
};
|
};
|
||||||
|
@ -59,15 +57,6 @@ public:
|
||||||
// things like absolute axes/ absolute mouse position will override this
|
// things like absolute axes/ absolute mouse position will override this
|
||||||
virtual bool IsDetectable() { return true; }
|
virtual bool IsDetectable() { return true; }
|
||||||
virtual ControlState GetState() const = 0;
|
virtual ControlState GetState() const = 0;
|
||||||
|
|
||||||
ControlState GetGatedState()
|
|
||||||
{
|
|
||||||
if (InputGateOn())
|
|
||||||
return GetState();
|
|
||||||
else
|
|
||||||
return 0.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Input* ToInput() override { return this; }
|
Input* ToInput() override { return this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,13 +70,6 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual ~Output() {}
|
virtual ~Output() {}
|
||||||
virtual void SetState(ControlState state) = 0;
|
virtual void SetState(ControlState state) = 0;
|
||||||
|
|
||||||
void SetGatedState(ControlState state)
|
|
||||||
{
|
|
||||||
if (InputGateOn())
|
|
||||||
SetState(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
Output* ToOutput() override { return this; }
|
Output* ToOutput() override { return this; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
<ClCompile Include="ControllerInterface\DInput\DInputJoystick.cpp" />
|
<ClCompile Include="ControllerInterface\DInput\DInputJoystick.cpp" />
|
||||||
<ClCompile Include="ControllerInterface\DInput\DInputKeyboardMouse.cpp" />
|
<ClCompile Include="ControllerInterface\DInput\DInputKeyboardMouse.cpp" />
|
||||||
<ClCompile Include="ControllerInterface\DInput\XInputFilter.cpp" />
|
<ClCompile Include="ControllerInterface\DInput\XInputFilter.cpp" />
|
||||||
<ClCompile Include="ControllerInterface\ExpressionParser.cpp" />
|
<ClCompile Include="ControlReference\ControlReference.cpp" />
|
||||||
|
<ClCompile Include="ControlReference\ExpressionParser.cpp" />
|
||||||
<ClCompile Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.cpp" />
|
<ClCompile Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.cpp" />
|
||||||
<ClCompile Include="ControllerInterface\XInput\XInput.cpp" />
|
<ClCompile Include="ControllerInterface\XInput\XInput.cpp" />
|
||||||
<ClCompile Include="GCAdapter.cpp">
|
<ClCompile Include="GCAdapter.cpp">
|
||||||
|
@ -63,7 +64,8 @@
|
||||||
<ClInclude Include="ControllerInterface\DInput\DInputJoystick.h" />
|
<ClInclude Include="ControllerInterface\DInput\DInputJoystick.h" />
|
||||||
<ClInclude Include="ControllerInterface\DInput\DInputKeyboardMouse.h" />
|
<ClInclude Include="ControllerInterface\DInput\DInputKeyboardMouse.h" />
|
||||||
<ClInclude Include="ControllerInterface\DInput\XInputFilter.h" />
|
<ClInclude Include="ControllerInterface\DInput\XInputFilter.h" />
|
||||||
<ClInclude Include="ControllerInterface\ExpressionParser.h" />
|
<ClInclude Include="ControlReference\ControlReference.h" />
|
||||||
|
<ClInclude Include="ControlReference\ExpressionParser.h" />
|
||||||
<ClInclude Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.h" />
|
<ClInclude Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.h" />
|
||||||
<ClInclude Include="ControllerInterface\XInput\XInput.h" />
|
<ClInclude Include="ControllerInterface\XInput\XInput.h" />
|
||||||
<ClInclude Include="GCAdapter.h" />
|
<ClInclude Include="GCAdapter.h" />
|
||||||
|
|
|
@ -41,15 +41,18 @@
|
||||||
<ClCompile Include="ControllerInterface\ControllerInterface.cpp">
|
<ClCompile Include="ControllerInterface\ControllerInterface.cpp">
|
||||||
<Filter>ControllerInterface</Filter>
|
<Filter>ControllerInterface</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ControllerInterface\ExpressionParser.cpp">
|
|
||||||
<Filter>ControllerInterface</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.cpp">
|
<ClCompile Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.cpp">
|
||||||
<Filter>ControllerInterface\ForceFeedback</Filter>
|
<Filter>ControllerInterface\ForceFeedback</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="ControllerInterface\DInput\XInputFilter.cpp">
|
<ClCompile Include="ControllerInterface\DInput\XInputFilter.cpp">
|
||||||
<Filter>ControllerInterface\DInput</Filter>
|
<Filter>ControllerInterface\DInput</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="ControlReference\ExpressionParser.cpp">
|
||||||
|
<Filter>ControllerInterface</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="ControlReference\ControlReference.cpp">
|
||||||
|
<Filter>ControllerInterface</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="GCAdapter.h" />
|
<ClInclude Include="GCAdapter.h" />
|
||||||
|
@ -76,9 +79,6 @@
|
||||||
<ClInclude Include="ControllerInterface\Device.h">
|
<ClInclude Include="ControllerInterface\Device.h">
|
||||||
<Filter>ControllerInterface</Filter>
|
<Filter>ControllerInterface</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="ControllerInterface\ExpressionParser.h">
|
|
||||||
<Filter>ControllerInterface</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.h">
|
<ClInclude Include="ControllerInterface\ForceFeedback\ForceFeedbackDevice.h">
|
||||||
<Filter>ControllerInterface\ForceFeedback</Filter>
|
<Filter>ControllerInterface\ForceFeedback</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -88,6 +88,12 @@
|
||||||
<ClInclude Include="ControllerInterface\DInput\XInputFilter.h">
|
<ClInclude Include="ControllerInterface\DInput\XInputFilter.h">
|
||||||
<Filter>ControllerInterface\DInput</Filter>
|
<Filter>ControllerInterface\DInput</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="ControlReference\ExpressionParser.h">
|
||||||
|
<Filter>ControllerInterface</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="ControlReference\ControlReference.h">
|
||||||
|
<Filter>ControllerInterface</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="CMakeLists.txt" />
|
<Text Include="CMakeLists.txt" />
|
||||||
|
|
Loading…
Reference in New Issue