Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9688 from Filoppi/input_cleanup
Input cleanup
  • Loading branch information
phire committed May 14, 2021
2 parents 099bf16 + f3ffac0 commit 9f91fb6
Show file tree
Hide file tree
Showing 47 changed files with 239 additions and 185 deletions.
1 change: 1 addition & 0 deletions Source/Core/Common/Logging/Log.h
Expand Up @@ -20,6 +20,7 @@ enum LOG_TYPE
COMMANDPROCESSOR,
COMMON,
CONSOLE,
CONTROLLERINTERFACE,
CORE,
DISCIO,
DSPHLE,
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Common/Logging/LogManager.cpp
Expand Up @@ -123,6 +123,7 @@ LogManager::LogManager()
m_log[COMMANDPROCESSOR] = {"CP", "Command Processor"};
m_log[COMMON] = {"COMMON", "Common"};
m_log[CONSOLE] = {"CONSOLE", "Dolphin Console"};
m_log[CONTROLLERINTERFACE] = {"CI", "Controller Interface"};
m_log[CORE] = {"CORE", "Core"};
m_log[DISCIO] = {"DIO", "Disc IO"};
m_log[DSPHLE] = {"DSPHLE", "DSP HLE"};
Expand Down
67 changes: 36 additions & 31 deletions Source/Core/Core/HW/GCPadEmu.cpp
Expand Up @@ -93,10 +93,15 @@ GCPad::GCPad(const unsigned int index) : m_index(index)

// options
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->AddSetting(&m_always_connected_setting,
// i18n: Treat a controller as always being connected regardless of what
// devices the user actually has plugged in
_trans("Always Connected"), false);
m_options->AddSetting(
&m_always_connected_setting,
// i18n: Treat a controller as always being connected regardless of what
// devices the user actually has plugged in
{_trans("Always Connected"), _trans(""),
_trans("Always connected if checked.\n"
"If unchecked, it will link the emulated controller connection state\n"
"to the real default device connection state (if there is one).")},
false);
}

std::string GCPad::GetName() const
Expand Down Expand Up @@ -181,64 +186,64 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
EmulatedController::LoadDefaults(ciface);

// Buttons
m_buttons->SetControlExpression(0, "X"); // A
m_buttons->SetControlExpression(1, "Z"); // B
m_buttons->SetControlExpression(2, "C"); // X
m_buttons->SetControlExpression(3, "S"); // Y
m_buttons->SetControlExpression(4, "D"); // Z
m_buttons->SetControlExpression(0, "`X`"); // A
m_buttons->SetControlExpression(1, "`Z`"); // B
m_buttons->SetControlExpression(2, "`C`"); // X
m_buttons->SetControlExpression(3, "`S`"); // Y
m_buttons->SetControlExpression(4, "`D`"); // Z
#ifdef _WIN32
m_buttons->SetControlExpression(5, "RETURN"); // Start
m_buttons->SetControlExpression(5, "`RETURN`"); // Start
#else
// OS X/Linux
// Start
m_buttons->SetControlExpression(5, "Return");
m_buttons->SetControlExpression(5, "`Return`");
#endif

// stick modifiers to 50 %
m_main_stick->controls[4]->control_ref->range = 0.5f;
m_c_stick->controls[4]->control_ref->range = 0.5f;

// D-Pad
m_dpad->SetControlExpression(0, "T"); // Up
m_dpad->SetControlExpression(1, "G"); // Down
m_dpad->SetControlExpression(2, "F"); // Left
m_dpad->SetControlExpression(3, "H"); // Right
m_dpad->SetControlExpression(0, "`T`"); // Up
m_dpad->SetControlExpression(1, "`G`"); // Down
m_dpad->SetControlExpression(2, "`F`"); // Left
m_dpad->SetControlExpression(3, "`H`"); // Right

// C Stick
m_c_stick->SetControlExpression(0, "I"); // Up
m_c_stick->SetControlExpression(1, "K"); // Down
m_c_stick->SetControlExpression(2, "J"); // Left
m_c_stick->SetControlExpression(3, "L"); // Right
m_c_stick->SetControlExpression(0, "`I`"); // Up
m_c_stick->SetControlExpression(1, "`K`"); // Down
m_c_stick->SetControlExpression(2, "`J`"); // Left
m_c_stick->SetControlExpression(3, "`L`"); // Right
// Modifier
m_c_stick->SetControlExpression(4, "Ctrl");
m_c_stick->SetControlExpression(4, "`Ctrl`");

// Control Stick
#ifdef _WIN32
m_main_stick->SetControlExpression(0, "UP"); // Up
m_main_stick->SetControlExpression(1, "DOWN"); // Down
m_main_stick->SetControlExpression(2, "LEFT"); // Left
m_main_stick->SetControlExpression(3, "RIGHT"); // Right
m_main_stick->SetControlExpression(0, "`UP`"); // Up
m_main_stick->SetControlExpression(1, "`DOWN`"); // Down
m_main_stick->SetControlExpression(2, "`LEFT`"); // Left
m_main_stick->SetControlExpression(3, "`RIGHT`"); // Right
#elif __APPLE__
m_main_stick->SetControlExpression(0, "`Up Arrow`"); // Up
m_main_stick->SetControlExpression(1, "`Down Arrow`"); // Down
m_main_stick->SetControlExpression(2, "`Left Arrow`"); // Left
m_main_stick->SetControlExpression(3, "`Right Arrow`"); // Right
#else
m_main_stick->SetControlExpression(0, "Up"); // Up
m_main_stick->SetControlExpression(1, "Down"); // Down
m_main_stick->SetControlExpression(2, "Left"); // Left
m_main_stick->SetControlExpression(3, "Right"); // Right
m_main_stick->SetControlExpression(0, "`Up`"); // Up
m_main_stick->SetControlExpression(1, "`Down`"); // Down
m_main_stick->SetControlExpression(2, "`Left`"); // Left
m_main_stick->SetControlExpression(3, "`Right`"); // Right
#endif
// Modifier
m_main_stick->SetControlExpression(4, "Shift");
m_main_stick->SetControlExpression(4, "`Shift`");

// Because our defaults use keyboard input, set calibration shapes to squares.
m_c_stick->SetCalibrationFromGate(ControllerEmu::SquareStickGate(1.0));
m_main_stick->SetCalibrationFromGate(ControllerEmu::SquareStickGate(1.0));

// Triggers
m_triggers->SetControlExpression(0, "Q"); // L
m_triggers->SetControlExpression(1, "W"); // R
m_triggers->SetControlExpression(0, "`Q`"); // L
m_triggers->SetControlExpression(1, "`W`"); // R
}

bool GCPad::GetMicButton() const
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/EmuSubroutines.cpp
Expand Up @@ -19,7 +19,6 @@
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "InputCommon/ControllerEmu/ControlGroup/Attachments.h"
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"

namespace WiimoteEmu
{
Expand Down
1 change: 0 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/ExtensionPort.cpp
Expand Up @@ -23,7 +23,6 @@ void ExtensionPort::AttachExtension(Extension* ext)

m_extension = ext;
m_i2c_bus.AddSlave(m_extension);
;
}

} // namespace WiimoteEmu
2 changes: 2 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/ExtensionPort.h
Expand Up @@ -22,6 +22,8 @@ enum ExtensionNumber : u8
UDRAW_TABLET,
DRAWSOME_TABLET,
TATACON,

MAX
};

// FYI: An extension must be attached.
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Expand Up @@ -428,7 +428,7 @@ void Wiimote::Update()

// Hotkey / settings modifier
// Data is later accessed in IsSideways and IsUpright
m_hotkeys->GetState();
m_hotkeys->UpdateState();

// Update our motion simulations.
StepDynamics();
Expand Down Expand Up @@ -700,15 +700,15 @@ EncryptionKey Wiimote::GetExtensionEncryptionKey() const

bool Wiimote::IsSideways() const
{
const bool sideways_modifier_toggle = m_hotkeys->getSettingsModifier()[0];
const bool sideways_modifier_switch = m_hotkeys->getSettingsModifier()[2];
const bool sideways_modifier_toggle = m_hotkeys->GetSettingsModifier()[0];
const bool sideways_modifier_switch = m_hotkeys->GetSettingsModifier()[2];
return m_sideways_setting.GetValue() ^ sideways_modifier_toggle ^ sideways_modifier_switch;
}

bool Wiimote::IsUpright() const
{
const bool upright_modifier_toggle = m_hotkeys->getSettingsModifier()[1];
const bool upright_modifier_switch = m_hotkeys->getSettingsModifier()[3];
const bool upright_modifier_toggle = m_hotkeys->GetSettingsModifier()[1];
const bool upright_modifier_switch = m_hotkeys->GetSettingsModifier()[3];
return m_upright_setting.GetValue() ^ upright_modifier_toggle ^ upright_modifier_switch;
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/DolphinQt/Config/Mapping/MappingNumeric.cpp
Expand Up @@ -75,6 +75,9 @@ void MappingDouble::Update()
MappingBool::MappingBool(MappingWidget* parent, ControllerEmu::NumericSetting<bool>* setting)
: QCheckBox(parent), m_setting(*setting)
{
if (const auto ui_description = m_setting.GetUIDescription())
setToolTip(tr(ui_description));

connect(this, &QCheckBox::stateChanged, this, [this, parent](int value) {
m_setting.SetValue(value != 0);
ConfigChanged();
Expand Down
4 changes: 3 additions & 1 deletion Source/Core/DolphinQt/Config/ToolTipControls/ToolTipWidget.h
Expand Up @@ -10,6 +10,8 @@

#include "DolphinQt/Config/Graphics/BalloonTip.h"

constexpr int TOOLTIP_DELAY = 300;

template <class Derived>
class ToolTipWidget : public Derived
{
Expand All @@ -25,7 +27,7 @@ class ToolTipWidget : public Derived
{
if (m_timer_id)
return;
m_timer_id = this->startTimer(300);
m_timer_id = this->startTimer(TOOLTIP_DELAY);
}

void leaveEvent(QEvent* event) override
Expand Down
41 changes: 22 additions & 19 deletions Source/Core/InputCommon/ControlReference/ExpressionParser.cpp
Expand Up @@ -247,22 +247,18 @@ ParseStatus Lexer::Tokenize(std::vector<Token>& tokens)
class ControlExpression : public Expression
{
public:
// Keep a shared_ptr to the device so the control pointer doesn't become invalid.
std::shared_ptr<Device> m_device;

explicit ControlExpression(ControlQualifier qualifier_) : qualifier(qualifier_) {}
explicit ControlExpression(ControlQualifier qualifier) : m_qualifier(qualifier) {}

ControlState GetValue() const override
{
if (s_hotkey_suppressions.IsSuppressed(input))
if (s_hotkey_suppressions.IsSuppressed(m_input))
return 0;
else
return GetValueIgnoringSuppression();
return GetValueIgnoringSuppression();
}

ControlState GetValueIgnoringSuppression() const
{
if (!input)
if (!m_input)
return 0.0;

// Note: Inputs may return negative values in situations where opposing directions are
Expand All @@ -271,27 +267,29 @@ class ControlExpression : public Expression
// 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, input->GetState());
return std::max(0.0, m_input->GetState());
}
void SetValue(ControlState value) override
{
if (output)
output->SetState(value);
if (m_output)
m_output->SetState(value);
}
int CountNumControls() const override { return (input || output) ? 1 : 0; }
int CountNumControls() const override { return (m_input || m_output) ? 1 : 0; }
void UpdateReferences(ControlEnvironment& env) override
{
m_device = env.FindDevice(qualifier);
input = env.FindInput(qualifier);
output = env.FindOutput(qualifier);
m_device = env.FindDevice(m_qualifier);
m_input = env.FindInput(m_qualifier);
m_output = env.FindOutput(m_qualifier);
}

Device::Input* GetInput() const { return input; };
Device::Input* GetInput() const { return m_input; };

private:
ControlQualifier qualifier;
Device::Input* input = nullptr;
Device::Output* output = nullptr;
// Keep a shared_ptr to the device so the control pointer doesn't become invalid.
std::shared_ptr<Device> m_device;
ControlQualifier m_qualifier;
Device::Input* m_input = nullptr;
Device::Output* m_output = nullptr;
};

bool HotkeySuppressions::IsSuppressedIgnoringModifiers(Device::Input* input,
Expand Down Expand Up @@ -371,6 +369,7 @@ class BinaryExpression : public Expression
}
case TOK_ASSIGN:
{
// Use this carefully as it's extremely powerful and can end up in unforeseen situations
lhs->SetValue(rhs->GetValue());
return lhs->GetValue();
}
Expand Down Expand Up @@ -565,6 +564,9 @@ class HotkeyExpression : public Expression

// This class proxies all methods to its either left-hand child if it has bound controls, or its
// right-hand child. Its intended use is for supporting old-style barewords expressions.
// Note that if you have a keyboard device as default device and the expression is a single digit
// number, this will usually resolve in a numerical key instead of a numerical value.
// Though if this expression belongs to NumericSetting, it will likely be simplifed back to a value.
class CoalesceExpression : public Expression
{
public:
Expand Down Expand Up @@ -945,6 +947,7 @@ static std::unique_ptr<Expression> ParseBarewordExpression(const std::string& st
qualifier.control_name = str;
qualifier.has_device = false;

// This control expression will only work (find the specified control) with the default device.
return std::make_unique<ControlExpression>(qualifier);
}

Expand Down
3 changes: 3 additions & 0 deletions Source/Core/InputCommon/ControlReference/ExpressionParser.h
Expand Up @@ -63,7 +63,9 @@ class Token
enum class ParseStatus
{
Successful,
// Note that the expression could still work in this case (be valid and return a value)
SyntaxError,
// Will return the default value
EmptyExpression,
};

Expand Down Expand Up @@ -107,6 +109,7 @@ class ControlQualifier
public:
bool has_device;
Core::DeviceQualifier device_qualifier;
// Makes no distinction between input and output
std::string control_name;

ControlQualifier() : has_device(false) {}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/InputCommon/ControllerEmu/Control/Control.h
Expand Up @@ -23,7 +23,7 @@ class Control
virtual ~Control();

template <typename T = ControlState>
T GetState()
T GetState() const
{
return control_ref->GetState<T>();
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
AddInput(Translate, _trans("Modifier"));
}

AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted) const
{
const ControlState y = controls[0]->GetState() - controls[1]->GetState();
const ControlState x = controls[3]->GetState() - controls[2]->GetState();
Expand All @@ -46,7 +46,7 @@ AnalogStick::ReshapeData AnalogStick::GetReshapableState(bool adjusted)
return Reshape(x, y, modifier);
}

AnalogStick::StateData AnalogStick::GetState()
AnalogStick::StateData AnalogStick::GetState() const
{
return GetReshapableState(true);
}
Expand Down
Expand Up @@ -18,10 +18,10 @@ class AnalogStick : public ReshapableInput
AnalogStick(const char* name, std::unique_ptr<StickGate>&& stick_gate);
AnalogStick(const char* name, const char* ui_name, std::unique_ptr<StickGate>&& stick_gate);

ReshapeData GetReshapableState(bool adjusted) final override;
ReshapeData GetReshapableState(bool adjusted) const final override;
ControlState GetGateRadiusAtAngle(double ang) const override;

StateData GetState();
StateData GetState() const;

private:
std::unique_ptr<StickGate> m_stick_gate;
Expand Down
Expand Up @@ -10,6 +10,7 @@
#include <vector>

#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/ExtensionPort.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
Expand All @@ -34,7 +35,11 @@ class Attachments : public ControlGroup

private:
SettingValue<int> m_selection_value;
NumericSetting<int> m_selection_setting = {&m_selection_value, {""}, 0, 0, 0};
// This is here and not added to the list of numeric_settings because it's serialized differently,
// by string (to be independent from the enum), and visualized differently in the UI.
// For the rest, it's treated similarly to other numeric_settings in the group.
NumericSetting<int> m_selection_setting = {
&m_selection_value, {""}, 0, 0, WiimoteEmu::ExtensionNumber::MAX - 1};

std::vector<std::unique_ptr<EmulatedController>> m_attachments;
};
Expand Down
Expand Up @@ -20,7 +20,7 @@ class Buttons : public ControlGroup
Buttons(const std::string& ini_name, const std::string& group_name);

template <typename C>
void GetState(C* const buttons, const C* bitmasks)
void GetState(C* const buttons, const C* bitmasks) const
{
for (auto& control : controls)
*buttons |= *(bitmasks++) * control->GetState<bool>();
Expand Down

0 comments on commit 9f91fb6

Please sign in to comment.