Skip to content

Commit

Permalink
DolphinQt: Use input override system for TAS input windows
Browse files Browse the repository at this point in the history
This lets the TAS input code use a higher-level interface for
overriding inputs instead of having to fiddle with raw bits.
WiiTASInputWindow in particular was messy with how much
controller code it had to re-implement.
  • Loading branch information
JosJuice committed Sep 29, 2022
1 parent 6c8cfcb commit f90ca1b
Show file tree
Hide file tree
Showing 21 changed files with 553 additions and 503 deletions.
41 changes: 13 additions & 28 deletions Source/Core/Core/HW/GCPadEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,62 +36,47 @@ static const u16 trigger_bitmasks[] = {
static const u16 dpad_bitmasks[] = {PAD_BUTTON_UP, PAD_BUTTON_DOWN, PAD_BUTTON_LEFT,
PAD_BUTTON_RIGHT};

static const char* const named_buttons[] = {"A", "B", "X", "Y", "Z", "Start"};

static const char* const named_triggers[] = {
// i18n: The left trigger button (labeled L on real controllers)
_trans("L"),
// i18n: The right trigger button (labeled R on real controllers)
_trans("R"),
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
_trans("L-Analog"),
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
_trans("R-Analog")};

GCPad::GCPad(const unsigned int index) : m_index(index)
{
// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (const char* named_button : named_buttons)
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
for (const char* named_button : {A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, Z_BUTTON})
{
const bool is_start = named_button == std::string("Start");
const ControllerEmu::Translatability translate =
is_start ? ControllerEmu::Translate : ControllerEmu::DoNotTranslate;
// i18n: The START/PAUSE button on GameCube controllers
std::string ui_name = is_start ? _trans("START") : named_button;
m_buttons->AddInput(translate, named_button, std::move(ui_name));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button);
}
// i18n: The START/PAUSE button on GameCube controllers
m_buttons->AddInput(ControllerEmu::Translate, START_BUTTON, _trans("START"));

// sticks
groups.emplace_back(m_main_stick = new ControllerEmu::OctagonAnalogStick(
"Main Stick", _trans("Control Stick"), MAIN_STICK_GATE_RADIUS));
MAIN_STICK_GROUP, _trans("Control Stick"), MAIN_STICK_GATE_RADIUS));
groups.emplace_back(m_c_stick = new ControllerEmu::OctagonAnalogStick(
"C-Stick", _trans("C Stick"), C_STICK_GATE_RADIUS));
C_STICK_GROUP, _trans("C Stick"), C_STICK_GATE_RADIUS));

// triggers
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* named_trigger : named_triggers)
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP));
for (const char* named_trigger : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG})
{
m_triggers->AddInput(ControllerEmu::Translate, named_trigger);
}

// rumble
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(RUMBLE_GROUP));
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));

// Microphone
groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
groups.emplace_back(m_mic = new ControllerEmu::Buttons(MIC_GROUP));
m_mic->AddInput(ControllerEmu::Translate, _trans("Button"));

// dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
for (const char* named_direction : named_directions)
{
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
}

// options
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
groups.emplace_back(m_options = new ControllerEmu::ControlGroup(OPTIONS_GROUP));
m_options->AddSetting(
&m_always_connected_setting,
// i18n: Treat a controller as always being connected regardless of what
Expand Down
27 changes: 27 additions & 0 deletions Source/Core/Core/HW/GCPadEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <string>

#include "Common/Common.h"

#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/Setting/NumericSetting.h"
Expand Down Expand Up @@ -49,6 +51,31 @@ class GCPad : public ControllerEmu::EmulatedController
static constexpr ControlState MAIN_STICK_GATE_RADIUS = 0.7937125;
static constexpr ControlState C_STICK_GATE_RADIUS = 0.7221375;

static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
static constexpr const char* MAIN_STICK_GROUP = "Main Stick";
static constexpr const char* C_STICK_GROUP = "C-Stick";
static constexpr const char* DPAD_GROUP = _trans("D-Pad");
static constexpr const char* TRIGGERS_GROUP = _trans("Triggers");
static constexpr const char* RUMBLE_GROUP = _trans("Rumble");
static constexpr const char* MIC_GROUP = _trans("Microphone");
static constexpr const char* OPTIONS_GROUP = _trans("Options");

static constexpr const char* A_BUTTON = "A";
static constexpr const char* B_BUTTON = "B";
static constexpr const char* X_BUTTON = "X";
static constexpr const char* Y_BUTTON = "Y";
static constexpr const char* Z_BUTTON = "Z";
static constexpr const char* START_BUTTON = "Start";

// i18n: The left trigger button (labeled L on real controllers)
static constexpr const char* L_DIGITAL = _trans("L");
// i18n: The right trigger button (labeled R on real controllers)
static constexpr const char* R_DIGITAL = _trans("R");
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
static constexpr const char* L_ANALOG = _trans("L-Analog");
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
static constexpr const char* R_ANALOG = _trans("R-Analog");

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::AnalogStick* m_main_stick;
Expand Down
2 changes: 0 additions & 2 deletions Source/Core/Core/HW/SI/SI_DeviceGCController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ int CSIDevice_GCController::RunBuffer(u8* buffer, int request_length)

void CSIDevice_GCController::HandleMoviePadStatus(int device_number, GCPadStatus* pad_status)
{
Movie::CallGCInputManip(pad_status, device_number);

Movie::SetPolledDevice();
if (NetPlay_GetInput(device_number, pad_status))
{
Expand Down
45 changes: 11 additions & 34 deletions Source/Core/Core/HW/WiimoteEmu/Extension/Classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,11 @@ constexpr std::array<u16, 9> classic_button_bitmasks{{
Classic::BUTTON_HOME,
}};

constexpr std::array<std::string_view, 9> classic_button_names{{
"A",
"B",
"X",
"Y",
"ZL",
"ZR",
"-",
"+",
"Home",
}};

constexpr std::array<u16, 2> classic_trigger_bitmasks{{
Classic::TRIGGER_L,
Classic::TRIGGER_R,
}};

constexpr std::array<const char*, 4> classic_trigger_names{{
// i18n: The left trigger button (labeled L on real controllers)
_trans("L"),
// i18n: The right trigger button (labeled R on real controllers)
_trans("R"),
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
_trans("L-Analog"),
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
_trans("R-Analog"),
}};

constexpr std::array<u16, 4> classic_dpad_bitmasks{{
Classic::PAD_UP,
Classic::PAD_DOWN,
Expand All @@ -75,30 +52,30 @@ constexpr std::array<u16, 4> classic_dpad_bitmasks{{
Classic::Classic() : Extension1stParty("Classic", _trans("Classic Controller"))
{
// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& button_name : classic_button_names)
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
for (auto& button_name :
{A_BUTTON, B_BUTTON, X_BUTTON, Y_BUTTON, ZL_BUTTON, ZR_BUTTON, MINUS_BUTTON, PLUS_BUTTON})
{
std::string_view ui_name = (button_name == "Home") ? "HOME" : button_name;
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(button_name),
std::string(ui_name));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, button_name);
}
m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME");

// sticks
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / CAL_STICK_RADIUS;
groups.emplace_back(m_left_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Left Stick"), gate_radius));
groups.emplace_back(
m_right_stick = new ControllerEmu::OctagonAnalogStick(_trans("Right Stick"), gate_radius));
new ControllerEmu::OctagonAnalogStick(LEFT_STICK_GROUP, gate_radius));
groups.emplace_back(m_right_stick =
new ControllerEmu::OctagonAnalogStick(RIGHT_STICK_GROUP, gate_radius));

// triggers
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (const char* trigger_name : classic_trigger_names)
groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(TRIGGERS_GROUP));
for (const char* trigger_name : {L_DIGITAL, R_DIGITAL, L_ANALOG, R_ANALOG})
{
m_triggers->AddInput(ControllerEmu::Translate, trigger_name);
}

// dpad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
for (const char* named_direction : named_directions)
{
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
Expand Down
25 changes: 25 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/Extension/Classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ class Classic : public Extension1stParty

static constexpr u8 TRIGGER_RANGE = 0x1F;

static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
static constexpr const char* LEFT_STICK_GROUP = _trans("Left Stick");
static constexpr const char* RIGHT_STICK_GROUP = _trans("Right Stick");
static constexpr const char* TRIGGERS_GROUP = _trans("Triggers");
static constexpr const char* DPAD_GROUP = _trans("D-Pad");

static constexpr const char* A_BUTTON = "A";
static constexpr const char* B_BUTTON = "B";
static constexpr const char* X_BUTTON = "X";
static constexpr const char* Y_BUTTON = "Y";
static constexpr const char* ZL_BUTTON = "ZL";
static constexpr const char* ZR_BUTTON = "ZR";
static constexpr const char* MINUS_BUTTON = "-";
static constexpr const char* PLUS_BUTTON = "+";
static constexpr const char* HOME_BUTTON = "Home";

// i18n: The left trigger button (labeled L on real controllers)
static constexpr const char* L_DIGITAL = _trans("L");
// i18n: The right trigger button (labeled R on real controllers)
static constexpr const char* R_DIGITAL = _trans("R");
// i18n: The left trigger button (labeled L on real controllers) used as an analog input
static constexpr const char* L_ANALOG = _trans("L-Analog");
// i18n: The right trigger button (labeled R on real controllers) used as an analog input
static constexpr const char* R_ANALOG = _trans("R-Analog");

private:
ControllerEmu::Buttons* m_buttons;
ControllerEmu::MixedTriggers* m_triggers;
Expand Down
11 changes: 5 additions & 6 deletions Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ constexpr std::array<u8, 2> nunchuk_button_bitmasks{{
Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))
{
// buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "C");
m_buttons->AddInput(ControllerEmu::DoNotTranslate, "Z");
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, C_BUTTON);
m_buttons->AddInput(ControllerEmu::DoNotTranslate, Z_BUTTON);

// stick
constexpr auto gate_radius = ControlState(STICK_GATE_RADIUS) / STICK_RADIUS;
groups.emplace_back(m_stick =
new ControllerEmu::OctagonAnalogStick(_trans("Stick"), gate_radius));
groups.emplace_back(m_stick = new ControllerEmu::OctagonAnalogStick(STICK_GROUP, gate_radius));

// swing
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
Expand All @@ -57,7 +56,7 @@ Nunchuk::Nunchuk() : Extension1stParty(_trans("Nunchuk"))

// accelerometer
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
"IMUAccelerometer", _trans("Accelerometer")));
ACCELEROMETER_GROUP, _trans("Accelerometer")));
}

void Nunchuk::Update()
Expand Down
11 changes: 10 additions & 1 deletion Source/Core/Core/HW/WiimoteEmu/Extension/Nunchuk.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <array>

#include "Common/Common.h"

#include "Core/HW/WiimoteCommon/WiimoteReport.h"
#include "Core/HW/WiimoteEmu/Dynamics.h"
#include "Core/HW/WiimoteEmu/Extension/Extension.h"
Expand Down Expand Up @@ -155,6 +157,8 @@ class Nunchuk : public Extension1stParty

ControllerEmu::ControlGroup* GetGroup(NunchukGroup group);

void LoadDefaults(const ControllerInterface& ciface) override;

static constexpr u8 BUTTON_C = 0x02;
static constexpr u8 BUTTON_Z = 0x01;

Expand All @@ -167,7 +171,12 @@ class Nunchuk : public Extension1stParty
static constexpr u8 STICK_RADIUS = 0x7F;
static constexpr u8 STICK_RANGE = 0xFF;

void LoadDefaults(const ControllerInterface& ciface) override;
static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
static constexpr const char* STICK_GROUP = _trans("Stick");
static constexpr const char* ACCELEROMETER_GROUP = "IMUAccelerometer";

static constexpr const char* C_BUTTON = "C";
static constexpr const char* Z_BUTTON = "Z";

private:
ControllerEmu::Tilt* m_tilt;
Expand Down
22 changes: 9 additions & 13 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <fmt/format.h>

#include "Common/Assert.h"
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/FileUtil.h"
Expand Down Expand Up @@ -63,10 +64,6 @@ static const u16 dpad_bitmasks[] = {Wiimote::PAD_UP, Wiimote::PAD_DOWN, Wiimote:
static const u16 dpad_sideways_bitmasks[] = {Wiimote::PAD_RIGHT, Wiimote::PAD_LEFT, Wiimote::PAD_UP,
Wiimote::PAD_DOWN};

constexpr std::array<std::string_view, 7> named_buttons{
"A", "B", "1", "2", "-", "+", "Home",
};

void Wiimote::Reset()
{
SetRumble(false);
Expand Down Expand Up @@ -197,24 +194,23 @@ void Wiimote::Reset()
Wiimote::Wiimote(const unsigned int index) : m_index(index)
{
// Buttons
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (auto& named_button : named_buttons)
groups.emplace_back(m_buttons = new ControllerEmu::Buttons(BUTTONS_GROUP));
for (auto& named_button : {A_BUTTON, B_BUTTON, ONE_BUTTON, TWO_BUTTON, MINUS_BUTTON, PLUS_BUTTON})
{
std::string_view ui_name = (named_button == "Home") ? "HOME" : named_button;
m_buttons->AddInput(ControllerEmu::DoNotTranslate, std::string(named_button),
std::string(ui_name));
m_buttons->AddInput(ControllerEmu::DoNotTranslate, named_button);
}
m_buttons->AddInput(ControllerEmu::DoNotTranslate, HOME_BUTTON, "HOME");

// Pointing (IR)
// i18n: "Point" refers to the action of pointing a Wii Remote.
groups.emplace_back(m_ir = new ControllerEmu::Cursor("IR", _trans("Point")));
groups.emplace_back(m_ir = new ControllerEmu::Cursor(IR_GROUP, _trans("Point")));
groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt")));
groups.emplace_back(m_shake = new ControllerEmu::Shake(_trans("Shake")));
groups.emplace_back(m_imu_accelerometer = new ControllerEmu::IMUAccelerometer(
"IMUAccelerometer", _trans("Accelerometer")));
ACCELEROMETER_GROUP, _trans("Accelerometer")));
groups.emplace_back(m_imu_gyroscope =
new ControllerEmu::IMUGyroscope("IMUGyroscope", _trans("Gyroscope")));
new ControllerEmu::IMUGyroscope(GYROSCOPE_GROUP, _trans("Gyroscope")));
groups.emplace_back(m_imu_ir = new ControllerEmu::IMUCursor("IMUIR", _trans("Point")));

const auto fov_default =
Expand Down Expand Up @@ -258,7 +254,7 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index)
m_rumble->AddOutput(ControllerEmu::Translate, _trans("Motor"));

// D-Pad
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
groups.emplace_back(m_dpad = new ControllerEmu::Buttons(DPAD_GROUP));
for (const char* named_direction : named_directions)
{
m_dpad->AddInput(ControllerEmu::Translate, named_direction);
Expand Down
16 changes: 16 additions & 0 deletions Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <optional>
#include <string>

#include "Common/Common.h"

#include "Core/HW/WiimoteCommon/WiimoteReport.h"

#include "Core/HW/WiimoteEmu/Camera.h"
Expand Down Expand Up @@ -110,6 +112,20 @@ class Wiimote : public ControllerEmu::EmulatedController, public WiimoteCommon::
static constexpr u16 BUTTON_MINUS = 0x1000;
static constexpr u16 BUTTON_HOME = 0x8000;

static constexpr const char* BUTTONS_GROUP = _trans("Buttons");
static constexpr const char* DPAD_GROUP = _trans("D-Pad");
static constexpr const char* ACCELEROMETER_GROUP = "IMUAccelerometer";
static constexpr const char* GYROSCOPE_GROUP = "IMUGyroscope";
static constexpr const char* IR_GROUP = "IR";

static constexpr const char* A_BUTTON = "A";
static constexpr const char* B_BUTTON = "B";
static constexpr const char* ONE_BUTTON = "1";
static constexpr const char* TWO_BUTTON = "2";
static constexpr const char* MINUS_BUTTON = "-";
static constexpr const char* PLUS_BUTTON = "+";
static constexpr const char* HOME_BUTTON = "Home";

explicit Wiimote(unsigned int index);
~Wiimote();

Expand Down
Loading

0 comments on commit f90ca1b

Please sign in to comment.