Merge pull request #4873 from lioncash/controller-emu

ControllerEmu: Separate ControlGroup from ControllerEmu
This commit is contained in:
Mat M 2017-02-10 13:50:33 -05:00 committed by GitHub
commit f6d364e37b
69 changed files with 1807 additions and 971 deletions

View File

@ -1,3 +1,5 @@
#include "Core/Analytics.h"
#include <cinttypes> #include <cinttypes>
#include <mbedtls/sha1.h> #include <mbedtls/sha1.h>
#include <memory> #include <memory>
@ -16,12 +18,10 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Analytics.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HW/GCPad.h" #include "Core/HW/GCPad.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "Core/NetPlayProto.h" #include "Core/NetPlayProto.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/GCAdapter.h" #include "InputCommon/GCAdapter.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
#include "VideoCommon/VideoBackendBase.h" #include "VideoCommon/VideoBackendBase.h"

View File

@ -6,6 +6,7 @@
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string>
#include "Common/Analytics.h" #include "Common/Analytics.h"

View File

@ -2,12 +2,16 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/GCKeyboard.h"
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCKeyboardEmu.h" #include "Core/HW/GCKeyboardEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
#include "InputCommon/KeyboardStatus.h" #include "InputCommon/KeyboardStatus.h"

View File

@ -5,12 +5,16 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
class InputConfig; class InputConfig;
enum class KeyboardGroup; enum class KeyboardGroup;
struct KeyboardStatus; struct KeyboardStatus;
namespace ControllerEmu
{
class ControlGroup;
}
namespace Keyboard namespace Keyboard
{ {
void Shutdown(); void Shutdown();

View File

@ -3,7 +3,12 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/GCKeyboardEmu.h" #include "Core/HW/GCKeyboardEmu.h"
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/KeyboardStatus.h" #include "InputCommon/KeyboardStatus.h"
@ -48,36 +53,38 @@ static const char* const named_keys5[] = {"LEFT", "DOWN", "UP", "RIGHT", "ENTER"
GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index) GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index)
{ {
// buttons // buttons
groups.emplace_back(m_keys0x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys0x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys0) for (const char* key : named_keys0)
m_keys0x->controls.emplace_back(new ControlGroup::Input(key)); m_keys0x->controls.emplace_back(new ControllerEmu::Input(key));
groups.emplace_back(m_keys1x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys1x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys1) for (const char* key : named_keys1)
m_keys1x->controls.emplace_back(new ControlGroup::Input(key)); m_keys1x->controls.emplace_back(new ControllerEmu::Input(key));
groups.emplace_back(m_keys2x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys2x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys2) for (const char* key : named_keys2)
m_keys2x->controls.emplace_back(new ControlGroup::Input(key)); m_keys2x->controls.emplace_back(new ControllerEmu::Input(key));
groups.emplace_back(m_keys3x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys3x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys3) for (const char* key : named_keys3)
m_keys3x->controls.emplace_back(new ControlGroup::Input(key)); m_keys3x->controls.emplace_back(new ControllerEmu::Input(key));
groups.emplace_back(m_keys4x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys4x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys4) for (const char* key : named_keys4)
m_keys4x->controls.emplace_back(new ControlGroup::Input(key)); m_keys4x->controls.emplace_back(new ControllerEmu::Input(key));
groups.emplace_back(m_keys5x = new Buttons(_trans("Keys"))); groups.emplace_back(m_keys5x = new ControllerEmu::Buttons(_trans("Keys")));
for (const char* key : named_keys5) for (const char* key : named_keys5)
m_keys5x->controls.emplace_back(new ControlGroup::Input(key)); m_keys5x->controls.emplace_back(new ControllerEmu::Input(key));
// options // options
groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input"))); std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>( _trans("Background Input")));
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); m_options->boolean_settings.emplace_back(
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
} }
std::string GCKeyboard::GetName() const std::string GCKeyboard::GetName() const
@ -110,7 +117,7 @@ ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group)
KeyboardStatus GCKeyboard::GetInput() const KeyboardStatus GCKeyboard::GetInput() const
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
KeyboardStatus kb = {}; KeyboardStatus kb = {};
@ -126,7 +133,7 @@ KeyboardStatus GCKeyboard::GetInput() const
void GCKeyboard::LoadDefaults(const ControllerInterface& ciface) void GCKeyboard::LoadDefaults(const ControllerInterface& ciface)
{ {
ControllerEmu::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
// Buttons // Buttons
m_keys0x->SetControlExpression(5, "A"); m_keys0x->SetControlExpression(5, "A");

View File

@ -10,6 +10,12 @@
struct KeyboardStatus; struct KeyboardStatus;
namespace ControllerEmu
{
class ControlGroup;
class Buttons;
}
enum class KeyboardGroup enum class KeyboardGroup
{ {
Kb0x, Kb0x,
@ -22,23 +28,23 @@ enum class KeyboardGroup
Options Options
}; };
class GCKeyboard : public ControllerEmu class GCKeyboard : public ControllerEmu::EmulatedController
{ {
public: public:
explicit GCKeyboard(unsigned int index); explicit GCKeyboard(unsigned int index);
KeyboardStatus GetInput() const; KeyboardStatus GetInput() const;
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetGroup(KeyboardGroup group); ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:
Buttons* m_keys0x; ControllerEmu::Buttons* m_keys0x;
Buttons* m_keys1x; ControllerEmu::Buttons* m_keys1x;
Buttons* m_keys2x; ControllerEmu::Buttons* m_keys2x;
Buttons* m_keys3x; ControllerEmu::Buttons* m_keys3x;
Buttons* m_keys4x; ControllerEmu::Buttons* m_keys4x;
Buttons* m_keys5x; ControllerEmu::Buttons* m_keys5x;
ControlGroup* m_options; ControllerEmu::ControlGroup* m_options;
const unsigned int m_index; const unsigned int m_index;
}; };

View File

@ -2,11 +2,14 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/GCPad.h"
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/GCPadEmu.h" #include "Core/HW/GCPadEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"

View File

@ -5,13 +5,17 @@
#pragma once #pragma once
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerInterface/Device.h" #include "InputCommon/ControllerInterface/Device.h"
class InputConfig; class InputConfig;
enum class PadGroup; enum class PadGroup;
struct GCPadStatus; struct GCPadStatus;
namespace ControllerEmu
{
class ControlGroup;
}
namespace Pad namespace Pad
{ {
void Shutdown(); void Shutdown();

View File

@ -3,9 +3,17 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/GCPadEmu.h" #include "Core/HW/GCPadEmu.h"
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/Host.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
#include "InputCommon/GCPadStatus.h"
static const u16 button_bitmasks[] = { static const u16 button_bitmasks[] = {
PAD_BUTTON_A, PAD_BUTTON_A,
@ -39,40 +47,42 @@ static const char* const named_triggers[] = {
GCPad::GCPad(const unsigned int index) : m_index(index) GCPad::GCPad(const unsigned int index) : m_index(index)
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons(_trans("Buttons"))); groups.emplace_back(m_buttons = new ControllerEmu::Buttons(_trans("Buttons")));
for (unsigned int i = 0; i < sizeof(named_buttons) / sizeof(*named_buttons); ++i) for (unsigned int i = 0; i < sizeof(named_buttons) / sizeof(*named_buttons); ++i)
m_buttons->controls.emplace_back(new ControlGroup::Input(named_buttons[i])); m_buttons->controls.emplace_back(new ControllerEmu::Input(named_buttons[i]));
// sticks // sticks
groups.emplace_back(m_main_stick = new AnalogStick("Main Stick", _trans("Control Stick"), groups.emplace_back(m_main_stick = new ControllerEmu::AnalogStick(
DEFAULT_PAD_STICK_RADIUS)); "Main Stick", _trans("Control Stick"), DEFAULT_PAD_STICK_RADIUS));
groups.emplace_back(m_c_stick = groups.emplace_back(m_c_stick = new ControllerEmu::AnalogStick("C-Stick", _trans("C Stick"),
new AnalogStick("C-Stick", _trans("C Stick"), DEFAULT_PAD_STICK_RADIUS)); DEFAULT_PAD_STICK_RADIUS));
// triggers // triggers
groups.emplace_back(m_triggers = new MixedTriggers(_trans("Triggers"))); groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers(_trans("Triggers")));
for (auto& named_trigger : named_triggers) for (auto& named_trigger : named_triggers)
m_triggers->controls.emplace_back(new ControlGroup::Input(named_trigger)); m_triggers->controls.emplace_back(new ControllerEmu::Input(named_trigger));
// rumble // rumble
groups.emplace_back(m_rumble = new ControlGroup(_trans("Rumble"))); groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(new ControlGroup::Output(_trans("Motor"))); m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor")));
// Microphone // Microphone
groups.emplace_back(m_mic = new Buttons(_trans("Microphone"))); groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
m_mic->controls.emplace_back(new ControlGroup::Input(_trans("Button"))); m_mic->controls.emplace_back(new ControllerEmu::Input(_trans("Button")));
// dpad // dpad
groups.emplace_back(m_dpad = new Buttons(_trans("D-Pad"))); groups.emplace_back(m_dpad = new ControllerEmu::Buttons(_trans("D-Pad")));
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction));
// options // options
groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input"))); std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>( _trans("Background Input")));
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); m_options->boolean_settings.emplace_back(
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
} }
std::string GCPad::GetName() const std::string GCPad::GetName() const
@ -107,7 +117,7 @@ ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group)
GCPadStatus GCPad::GetInput() const GCPadStatus GCPad::GetInput() const
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
ControlState x, y, triggers[2]; ControlState x, y, triggers[2];
GCPadStatus pad = {}; GCPadStatus pad = {};
@ -147,13 +157,13 @@ GCPadStatus GCPad::GetInput() const
void GCPad::SetOutput(const ControlState strength) void GCPad::SetOutput(const ControlState strength)
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
m_rumble->controls[0]->control_ref->State(strength); m_rumble->controls[0]->control_ref->State(strength);
} }
void GCPad::LoadDefaults(const ControllerInterface& ciface) void GCPad::LoadDefaults(const ControllerInterface& ciface)
{ {
ControllerEmu::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
// Buttons // Buttons
m_buttons->SetControlExpression(0, "X"); // A m_buttons->SetControlExpression(0, "X"); // A
@ -222,6 +232,6 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)
bool GCPad::GetMicButton() const bool GCPad::GetMicButton() const
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
return (0.0f != m_mic->controls.back()->control_ref->State()); return (0.0f != m_mic->controls.back()->control_ref->State());
} }

View File

@ -8,7 +8,15 @@
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
struct GCPadStatus;
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup; class ControlGroup;
class MixedTriggers;
}
enum class PadGroup enum class PadGroup
{ {
@ -22,7 +30,7 @@ enum class PadGroup
Options Options
}; };
class GCPad : public ControllerEmu class GCPad : public ControllerEmu::EmulatedController
{ {
public: public:
explicit GCPad(unsigned int index); explicit GCPad(unsigned int index);
@ -33,19 +41,19 @@ public:
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetGroup(PadGroup group); ControllerEmu::ControlGroup* GetGroup(PadGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
AnalogStick* m_main_stick; ControllerEmu::AnalogStick* m_main_stick;
AnalogStick* m_c_stick; ControllerEmu::AnalogStick* m_c_stick;
Buttons* m_dpad; ControllerEmu::Buttons* m_dpad;
MixedTriggers* m_triggers; ControllerEmu::MixedTriggers* m_triggers;
ControlGroup* m_rumble; ControllerEmu::ControlGroup* m_rumble;
Buttons* m_mic; ControllerEmu::Buttons* m_mic;
ControlGroup* m_options; ControllerEmu::ControlGroup* m_options;
const unsigned int m_index; const unsigned int m_index;

View File

@ -3,10 +3,15 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "Common/ChunkFile.h" #include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"

View File

@ -6,10 +6,15 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
class InputConfig; class InputConfig;
class PointerWrap; class PointerWrap;
namespace ControllerEmu
{
class ControlGroup;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class WiimoteGroup; enum class WiimoteGroup;

View File

@ -11,6 +11,7 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
@ -53,12 +54,14 @@ void Attachment::Reset()
} }
} // namespace WiimoteEmu } // namespace WiimoteEmu
void ControllerEmu::Extension::GetState(u8* const data) namespace ControllerEmu
{
void Extension::GetState(u8* const data)
{ {
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data); ((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState(data);
} }
bool ControllerEmu::Extension::IsButtonPressed() const bool Extension::IsButtonPressed() const
{ {
// Extension == 0 means no Extension, > 0 means one is connected // Extension == 0 means no Extension, > 0 means one is connected
// Since we want to use this to know if disconnected Wiimotes want to be connected, and // Since we want to use this to know if disconnected Wiimotes want to be connected, and
@ -71,3 +74,4 @@ bool ControllerEmu::Extension::IsButtonPressed() const
return ((WiimoteEmu::Attachment*)attachments[switch_extension].get())->IsButtonPressed(); return ((WiimoteEmu::Attachment*)attachments[switch_extension].get())->IsButtonPressed();
return false; return false;
} }
} // namespace ControllerEmu

View File

@ -13,7 +13,7 @@ namespace WiimoteEmu
{ {
struct ExtensionReg; struct ExtensionReg;
class Attachment : public ControllerEmu class Attachment : public ControllerEmu::EmulatedController
{ {
public: public:
Attachment(const char* const name, ExtensionReg& reg); Attachment(const char* const name, ExtensionReg& reg);

View File

@ -11,6 +11,12 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr std::array<u8, 6> classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}}; constexpr std::array<u8, 6> classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}};
@ -49,25 +55,25 @@ constexpr std::array<u16, 4> classic_dpad_bitmasks{{
Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg) Classic::Classic(ExtensionReg& reg) : Attachment(_trans("Classic"), reg)
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
for (auto& classic_button_name : classic_button_names) for (auto& classic_button_name : classic_button_names)
m_buttons->controls.emplace_back(new ControlGroup::Input(classic_button_name)); m_buttons->controls.emplace_back(new ControllerEmu::Input(classic_button_name));
// sticks // sticks
groups.emplace_back(m_left_stick = groups.emplace_back(m_left_stick = new ControllerEmu::AnalogStick(
new AnalogStick(_trans("Left Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); _trans("Left Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
groups.emplace_back(m_right_stick = groups.emplace_back(m_right_stick = new ControllerEmu::AnalogStick(
new AnalogStick(_trans("Right Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); _trans("Right Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
// triggers // triggers
groups.emplace_back(m_triggers = new MixedTriggers("Triggers")); groups.emplace_back(m_triggers = new ControllerEmu::MixedTriggers("Triggers"));
for (auto& classic_trigger_name : classic_trigger_names) for (auto& classic_trigger_name : classic_trigger_names)
m_triggers->controls.emplace_back(new ControlGroup::Input(classic_trigger_name)); m_triggers->controls.emplace_back(new ControllerEmu::Input(classic_trigger_name));
// dpad // dpad
groups.emplace_back(m_dpad = new Buttons("D-Pad")); groups.emplace_back(m_dpad = new ControllerEmu::Buttons("D-Pad"));
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction));
// Set up register // Set up register
m_calibration = classic_calibration; m_calibration = classic_calibration;

View File

@ -6,6 +6,14 @@
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
class MixedTriggers;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class ClassicGroup; enum class ClassicGroup;
@ -18,7 +26,7 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(ClassicGroup group); ControllerEmu::ControlGroup* GetGroup(ClassicGroup group);
enum enum
{ {
@ -52,10 +60,10 @@ public:
static const u8 RIGHT_TRIGGER_RANGE = 0x1F; static const u8 RIGHT_TRIGGER_RANGE = 0x1F;
private: private:
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
MixedTriggers* m_triggers; ControllerEmu::MixedTriggers* m_triggers;
Buttons* m_dpad; ControllerEmu::Buttons* m_dpad;
AnalogStick* m_left_stick; ControllerEmu::AnalogStick* m_left_stick;
AnalogStick* m_right_stick; ControllerEmu::AnalogStick* m_right_stick;
}; };
} }

View File

@ -11,6 +11,10 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr std::array<u8, 6> drums_id{{0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}}; constexpr std::array<u8, 6> drums_id{{0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}};
@ -32,17 +36,18 @@ constexpr std::array<u16, 2> drum_button_bitmasks{{
Drums::Drums(ExtensionReg& reg) : Attachment(_trans("Drums"), reg) Drums::Drums(ExtensionReg& reg) : Attachment(_trans("Drums"), reg)
{ {
// pads // pads
groups.emplace_back(m_pads = new Buttons(_trans("Pads"))); groups.emplace_back(m_pads = new ControllerEmu::Buttons(_trans("Pads")));
for (auto& drum_pad_name : drum_pad_names) for (auto& drum_pad_name : drum_pad_names)
m_pads->controls.emplace_back(new ControlGroup::Input(drum_pad_name)); m_pads->controls.emplace_back(new ControllerEmu::Input(drum_pad_name));
// stick // stick
groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); groups.emplace_back(m_stick =
new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS));
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("-")); m_buttons->controls.emplace_back(new ControllerEmu::Input("-"));
m_buttons->controls.emplace_back(new ControlGroup::Input("+")); m_buttons->controls.emplace_back(new ControllerEmu::Input("+"));
// set up register // set up register
m_id = drums_id; m_id = drums_id;

View File

@ -6,6 +6,13 @@
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class DrumsGroup; enum class DrumsGroup;
@ -18,7 +25,7 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(DrumsGroup group); ControllerEmu::ControlGroup* GetGroup(DrumsGroup group);
enum enum
{ {
@ -34,8 +41,8 @@ public:
}; };
private: private:
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
Buttons* m_pads; ControllerEmu::Buttons* m_pads;
AnalogStick* m_stick; ControllerEmu::AnalogStick* m_stick;
}; };
} }

View File

@ -11,6 +11,12 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr std::array<u8, 6> guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}}; constexpr std::array<u8, 6> guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}};
@ -35,26 +41,27 @@ constexpr std::array<u16, 2> guitar_strum_bitmasks{{
Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg) Guitar::Guitar(ExtensionReg& reg) : Attachment(_trans("Guitar"), reg)
{ {
// frets // frets
groups.emplace_back(m_frets = new Buttons(_trans("Frets"))); groups.emplace_back(m_frets = new ControllerEmu::Buttons(_trans("Frets")));
for (auto& guitar_fret_name : guitar_fret_names) for (auto& guitar_fret_name : guitar_fret_names)
m_frets->controls.emplace_back(new ControlGroup::Input(guitar_fret_name)); m_frets->controls.emplace_back(new ControllerEmu::Input(guitar_fret_name));
// strum // strum
groups.emplace_back(m_strum = new Buttons(_trans("Strum"))); groups.emplace_back(m_strum = new ControllerEmu::Buttons(_trans("Strum")));
m_strum->controls.emplace_back(new ControlGroup::Input("Up")); m_strum->controls.emplace_back(new ControllerEmu::Input("Up"));
m_strum->controls.emplace_back(new ControlGroup::Input("Down")); m_strum->controls.emplace_back(new ControllerEmu::Input("Down"));
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("-")); m_buttons->controls.emplace_back(new ControllerEmu::Input("-"));
m_buttons->controls.emplace_back(new ControlGroup::Input("+")); m_buttons->controls.emplace_back(new ControllerEmu::Input("+"));
// stick // stick
groups.emplace_back(m_stick = new AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS)); groups.emplace_back(
m_stick = new ControllerEmu::AnalogStick(_trans("Stick"), DEFAULT_ATTACHMENT_STICK_RADIUS));
// whammy // whammy
groups.emplace_back(m_whammy = new Triggers(_trans("Whammy"))); groups.emplace_back(m_whammy = new ControllerEmu::Triggers(_trans("Whammy")));
m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar"))); m_whammy->controls.emplace_back(new ControllerEmu::Input(_trans("Bar")));
// set up register // set up register
m_id = guitar_id; m_id = guitar_id;

View File

@ -6,6 +6,14 @@
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
class Triggers;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class GuitarGroup; enum class GuitarGroup;
@ -18,7 +26,7 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(GuitarGroup group); ControllerEmu::ControlGroup* GetGroup(GuitarGroup group);
enum enum
{ {
@ -35,10 +43,10 @@ public:
}; };
private: private:
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
Buttons* m_frets; ControllerEmu::Buttons* m_frets;
Buttons* m_strum; ControllerEmu::Buttons* m_strum;
Triggers* m_whammy; ControllerEmu::Triggers* m_whammy;
AnalogStick* m_stick; ControllerEmu::AnalogStick* m_stick;
}; };
} }

View File

@ -12,6 +12,13 @@
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr std::array<u8, 6> nunchuk_id{{0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}}; constexpr std::array<u8, 6> nunchuk_id{{0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}};
@ -23,24 +30,25 @@ constexpr std::array<u8, 2> nunchuk_button_bitmasks{{
Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg) Nunchuk::Nunchuk(ExtensionReg& reg) : Attachment(_trans("Nunchuk"), reg)
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("C")); m_buttons->controls.emplace_back(new ControllerEmu::Input("C"));
m_buttons->controls.emplace_back(new ControlGroup::Input("Z")); m_buttons->controls.emplace_back(new ControllerEmu::Input("Z"));
// stick // stick
groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); groups.emplace_back(m_stick =
new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS));
// swing // swing
groups.emplace_back(m_swing = new Force("Swing")); groups.emplace_back(m_swing = new ControllerEmu::Force("Swing"));
// tilt // tilt
groups.emplace_back(m_tilt = new Tilt("Tilt")); groups.emplace_back(m_tilt = new ControllerEmu::Tilt("Tilt"));
// shake // shake
groups.emplace_back(m_shake = new Buttons("Shake")); groups.emplace_back(m_shake = new ControllerEmu::Buttons("Shake"));
m_shake->controls.emplace_back(new ControlGroup::Input("X")); m_shake->controls.emplace_back(new ControllerEmu::Input("X"));
m_shake->controls.emplace_back(new ControlGroup::Input("Y")); m_shake->controls.emplace_back(new ControllerEmu::Input("Y"));
m_shake->controls.emplace_back(new ControlGroup::Input("Z")); m_shake->controls.emplace_back(new ControllerEmu::Input("Z"));
m_id = nunchuk_id; m_id = nunchuk_id;
} }

View File

@ -7,6 +7,15 @@
#include <array> #include <array>
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
class Force;
class Tilt;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class NunchukGroup; enum class NunchukGroup;
@ -20,7 +29,7 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(NunchukGroup group); ControllerEmu::ControlGroup* GetGroup(NunchukGroup group);
enum enum
{ {
@ -44,13 +53,13 @@ public:
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:
Tilt* m_tilt; ControllerEmu::Tilt* m_tilt;
Force* m_swing; ControllerEmu::Force* m_swing;
Buttons* m_shake; ControllerEmu::Buttons* m_shake;
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
AnalogStick* m_stick; ControllerEmu::AnalogStick* m_stick;
std::array<u8, 3> m_shake_step{}; std::array<u8, 3> m_shake_step{};
}; };

View File

@ -11,6 +11,13 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
constexpr std::array<u8, 6> turntable_id{{0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}}; constexpr std::array<u8, 6> turntable_id{{0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}};
@ -29,23 +36,24 @@ constexpr std::array<const char*, 9> turntable_button_names{{
Turntable::Turntable(ExtensionReg& reg) : Attachment(_trans("Turntable"), reg) Turntable::Turntable(ExtensionReg& reg) : Attachment(_trans("Turntable"), reg)
{ {
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
for (auto& turntable_button_name : turntable_button_names) for (auto& turntable_button_name : turntable_button_names)
m_buttons->controls.emplace_back(new ControlGroup::Input(turntable_button_name)); m_buttons->controls.emplace_back(new ControllerEmu::Input(turntable_button_name));
// turntables // turntables
groups.emplace_back(m_left_table = new Slider(_trans("Table Left"))); groups.emplace_back(m_left_table = new ControllerEmu::Slider(_trans("Table Left")));
groups.emplace_back(m_right_table = new Slider(_trans("Table Right"))); groups.emplace_back(m_right_table = new ControllerEmu::Slider(_trans("Table Right")));
// stick // stick
groups.emplace_back(m_stick = new AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS)); groups.emplace_back(m_stick =
new ControllerEmu::AnalogStick("Stick", DEFAULT_ATTACHMENT_STICK_RADIUS));
// effect dial // effect dial
groups.emplace_back(m_effect_dial = new Triggers(_trans("Effect"))); groups.emplace_back(m_effect_dial = new ControllerEmu::Triggers(_trans("Effect")));
m_effect_dial->controls.emplace_back(new ControlGroup::Input(_trans("Dial"))); m_effect_dial->controls.emplace_back(new ControllerEmu::Input(_trans("Dial")));
// crossfade // crossfade
groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade"))); groups.emplace_back(m_crossfade = new ControllerEmu::Slider(_trans("Crossfade")));
// set up register // set up register
m_id = turntable_id; m_id = turntable_id;

View File

@ -6,6 +6,15 @@
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
class Slider;
class Triggers;
}
namespace WiimoteEmu namespace WiimoteEmu
{ {
enum class TurntableGroup; enum class TurntableGroup;
@ -18,7 +27,7 @@ public:
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
ControlGroup* GetGroup(TurntableGroup group); ControllerEmu::ControlGroup* GetGroup(TurntableGroup group);
enum enum
{ {
@ -37,11 +46,11 @@ public:
}; };
private: private:
Buttons* m_buttons; ControllerEmu::Buttons* m_buttons;
AnalogStick* m_stick; ControllerEmu::AnalogStick* m_stick;
Triggers* m_effect_dial; ControllerEmu::Triggers* m_effect_dial;
Slider* m_left_table; ControllerEmu::Slider* m_left_table;
Slider* m_right_table; ControllerEmu::Slider* m_right_table;
Slider* m_crossfade; ControllerEmu::Slider* m_crossfade;
}; };
} }

View File

@ -30,6 +30,7 @@
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {

View File

@ -7,7 +7,9 @@
#include "AudioCommon/AudioCommon.h" #include "AudioCommon/AudioCommon.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Core/ConfigManager.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
//#define WIIMOTE_SPEAKER_DUMP //#define WIIMOTE_SPEAKER_DUMP
#ifdef WIIMOTE_SPEAKER_DUMP #ifdef WIIMOTE_SPEAKER_DUMP

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include <cassert> #include <cassert>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
@ -10,6 +12,7 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/WiimoteEmu/Attachment/Classic.h" #include "Core/HW/WiimoteEmu/Attachment/Classic.h"
@ -18,13 +21,22 @@
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h" #include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h" #include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
#include "Core/HW/WiimoteEmu/MatrixMath.h" #include "Core/HW/WiimoteEmu/MatrixMath.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HW/WiimoteEmu/WiimoteHid.h" #include "Core/HW/WiimoteEmu/WiimoteHid.h"
#include "Core/HW/WiimoteReal/WiimoteReal.h" #include "Core/HW/WiimoteReal/WiimoteReal.h"
#include "Core/Host.h" #include "Core/Host.h"
#include "Core/Movie.h" #include "Core/Movie.h"
#include "Core/NetPlayClient.h" #include "Core/NetPlayClient.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
namespace namespace
{ {
// :) // :)
@ -239,27 +251,27 @@ Wiimote::Wiimote(const unsigned int index)
// ---- set up all the controls ---- // ---- set up all the controls ----
// buttons // buttons
groups.emplace_back(m_buttons = new Buttons("Buttons")); groups.emplace_back(m_buttons = new ControllerEmu::Buttons("Buttons"));
for (auto& named_button : named_buttons) for (auto& named_button : named_buttons)
m_buttons->controls.emplace_back(new ControlGroup::Input(named_button)); m_buttons->controls.emplace_back(new ControllerEmu::Input(named_button));
// ir // ir
groups.emplace_back(m_ir = new Cursor(_trans("IR"))); groups.emplace_back(m_ir = new ControllerEmu::Cursor(_trans("IR")));
// swing // swing
groups.emplace_back(m_swing = new Force(_trans("Swing"))); groups.emplace_back(m_swing = new ControllerEmu::Force(_trans("Swing")));
// tilt // tilt
groups.emplace_back(m_tilt = new Tilt(_trans("Tilt"))); groups.emplace_back(m_tilt = new ControllerEmu::Tilt(_trans("Tilt")));
// shake // shake
groups.emplace_back(m_shake = new Buttons(_trans("Shake"))); groups.emplace_back(m_shake = new ControllerEmu::Buttons(_trans("Shake")));
m_shake->controls.emplace_back(new ControlGroup::Input("X")); m_shake->controls.emplace_back(new ControllerEmu::Input("X"));
m_shake->controls.emplace_back(new ControlGroup::Input("Y")); m_shake->controls.emplace_back(new ControllerEmu::Input("Y"));
m_shake->controls.emplace_back(new ControlGroup::Input("Z")); m_shake->controls.emplace_back(new ControllerEmu::Input("Z"));
// extension // extension
groups.emplace_back(m_extension = new Extension(_trans("Extension"))); groups.emplace_back(m_extension = new ControllerEmu::Extension(_trans("Extension")));
m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_reg_ext));
m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext));
@ -268,34 +280,40 @@ Wiimote::Wiimote(const unsigned int index)
m_extension->attachments.emplace_back(new WiimoteEmu::Turntable(m_reg_ext)); m_extension->attachments.emplace_back(new WiimoteEmu::Turntable(m_reg_ext));
m_extension->boolean_settings.emplace_back( m_extension->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BooleanSetting>(_trans("Motion Plus"), false)); std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(_trans("Motion Plus"), false));
// rumble // rumble
groups.emplace_back(m_rumble = new ControlGroup(_trans("Rumble"))); groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(new ControlGroup::Output(_trans("Motor"))); m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor")));
// dpad // dpad
groups.emplace_back(m_dpad = new Buttons("D-Pad")); groups.emplace_back(m_dpad = new ControllerEmu::Buttons("D-Pad"));
for (auto& named_direction : named_directions) for (auto& named_direction : named_directions)
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction)); m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction));
// options // options
groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input"))); std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
_trans("Background Input")));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BooleanSetting>(_trans("Sideways Wii Remote"), false)); std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(_trans("Sideways Wii Remote"),
false));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BooleanSetting>(_trans("Upright Wii Remote"), false)); std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(_trans("Upright Wii Remote"),
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>( false));
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); m_options->boolean_settings.emplace_back(
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
m_options->numeric_settings.emplace_back( m_options->numeric_settings.emplace_back(
std::make_unique<ControlGroup::NumericSetting>(_trans("Speaker Pan"), 0, -127, 127)); std::make_unique<ControllerEmu::ControlGroup::NumericSetting>(_trans("Speaker Pan"), 0, -127,
127));
m_options->numeric_settings.emplace_back( m_options->numeric_settings.emplace_back(
std::make_unique<ControlGroup::NumericSetting>(_trans("Battery"), 95.0 / 100, 0, 255)); std::make_unique<ControllerEmu::ControlGroup::NumericSetting>(_trans("Battery"), 95.0 / 100,
0, 255));
// hotkeys // hotkeys
groups.emplace_back(m_hotkeys = new ModifySettingsButton(_trans("Hotkeys"))); groups.emplace_back(m_hotkeys = new ControllerEmu::ModifySettingsButton(_trans("Hotkeys")));
// hotkeys to temporarily modify the Wii Remote orientation (sideways, upright) // hotkeys to temporarily modify the Wii Remote orientation (sideways, upright)
// this setting modifier is toggled // this setting modifier is toggled
m_hotkeys->AddInput(_trans("Sideways Toggle"), true); m_hotkeys->AddInput(_trans("Sideways Toggle"), true);
@ -699,7 +717,7 @@ void Wiimote::Update()
// returns true if a report was sent // returns true if a report was sent
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
if (Step()) if (Step())
return; return;
} }
@ -724,7 +742,7 @@ void Wiimote::Update()
data[0] = 0xA1; data[0] = 0xA1;
data[1] = m_reporting_mode; data[1] = m_reporting_mode;
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
// hotkey/settings modifier // hotkey/settings modifier
m_hotkeys->GetState(); // data is later accessed in UpdateButtonsStatus and GetAccelData m_hotkeys->GetState(); // data is later accessed in UpdateButtonsStatus and GetAccelData
@ -959,7 +977,7 @@ void Wiimote::ConnectOnInput()
} }
u16 buttons = 0; u16 buttons = 0;
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
m_buttons->GetState(&buttons, button_bitmasks); m_buttons->GetState(&buttons, button_bitmasks);
m_dpad->GetState(&buttons, dpad_bitmasks); m_dpad->GetState(&buttons, dpad_bitmasks);
@ -974,7 +992,7 @@ void Wiimote::ConnectOnInput()
void Wiimote::LoadDefaults(const ControllerInterface& ciface) void Wiimote::LoadDefaults(const ControllerInterface& ciface)
{ {
ControllerEmu::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
// Buttons // Buttons
#if defined HAVE_X11 && HAVE_X11 #if defined HAVE_X11 && HAVE_X11
@ -1030,4 +1048,19 @@ void Wiimote::LoadDefaults(const ControllerInterface& ciface)
// set nunchuk defaults // set nunchuk defaults
m_extension->attachments[1]->LoadDefaults(ciface); m_extension->attachments[1]->LoadDefaults(ciface);
} }
int Wiimote::CurrentExtension() const
{
return m_extension->active_extension;
} }
bool Wiimote::HaveExtension() const
{
return m_extension->active_extension > 0;
}
bool Wiimote::WantExtension() const
{
return m_extension->switch_extension != 0;
}
} // namespace WiimoteEmu

View File

@ -20,6 +20,17 @@
class PointerWrap; class PointerWrap;
namespace ControllerEmu
{
class Buttons;
class ControlGroup;
class Cursor;
class Extension;
class Force;
class ModifySettingsButton;
class Tilt;
}
namespace WiimoteReal namespace WiimoteReal
{ {
class Wiimote; class Wiimote;
@ -152,7 +163,7 @@ enum
ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G), ACCEL_RANGE = (ACCEL_ONE_G - ACCEL_ZERO_G),
}; };
class Wiimote : public ControllerEmu class Wiimote : public ControllerEmu::EmulatedController
{ {
friend class WiimoteReal::Wiimote; friend class WiimoteReal::Wiimote;
@ -175,8 +186,8 @@ public:
Wiimote(const unsigned int index); Wiimote(const unsigned int index);
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetWiimoteGroup(WiimoteGroup group); ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group);
ControlGroup* GetNunchukGroup(NunchukGroup group); ControllerEmu::ControlGroup* GetNunchukGroup(NunchukGroup group);
ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group); ControllerEmu::ControlGroup* GetClassicGroup(ClassicGroup group);
ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group); ControllerEmu::ControlGroup* GetGuitarGroup(GuitarGroup group);
ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group); ControllerEmu::ControlGroup* GetDrumsGroup(DrumsGroup group);
@ -193,7 +204,8 @@ public:
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
int CurrentExtension() const { return m_extension->active_extension; } int CurrentExtension() const;
protected: protected:
bool Step(); bool Step();
void HidOutputReport(const wm_report* const sr, const bool send_ack = true); void HidOutputReport(const wm_report* const sr, const bool send_ack = true);
@ -205,8 +217,9 @@ protected:
void GetIRData(u8* const data, bool use_accel); void GetIRData(u8* const data, bool use_accel);
void GetExtData(u8* const data); void GetExtData(u8* const data);
bool HaveExtension() const { return m_extension->active_extension > 0; } bool HaveExtension() const;
bool WantExtension() const { return m_extension->switch_extension != 0; } bool WantExtension() const;
private: private:
struct ReadRequest struct ReadRequest
{ {
@ -225,14 +238,16 @@ private:
bool NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode); bool NetPlay_GetWiimoteData(int wiimote, u8* data, u8 size, u8 reporting_mode);
// control groups // control groups
Buttons *m_buttons, *m_dpad, *m_shake; ControllerEmu::Buttons* m_buttons;
Cursor* m_ir; ControllerEmu::Buttons* m_dpad;
Tilt* m_tilt; ControllerEmu::Buttons* m_shake;
Force* m_swing; ControllerEmu::Cursor* m_ir;
ControlGroup* m_rumble; ControllerEmu::Tilt* m_tilt;
Extension* m_extension; ControllerEmu::Force* m_swing;
ControlGroup* m_options; ControllerEmu::ControlGroup* m_rumble;
ModifySettingsButton* m_hotkeys; ControllerEmu::Extension* m_extension;
ControllerEmu::ControlGroup* m_options;
ControllerEmu::ModifySettingsButton* m_hotkeys;
// Wiimote accel data // Wiimote accel data
AccelData m_accel; AccelData m_accel;

View File

@ -2,11 +2,17 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HotkeyManager.h"
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/Common.h" #include "Common/Common.h"
#include "Core/HotkeyManager.h" #include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
const std::string hotkey_labels[] = { const std::string hotkey_labels[] = {
@ -255,19 +261,22 @@ HotkeyManager::HotkeyManager()
{ {
for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) for (int group = 0; group < NUM_HOTKEY_GROUPS; group++)
{ {
m_hotkey_groups[group] = (m_keys[group] = new Buttons("Keys", groups_info[group].name)); m_hotkey_groups[group] =
(m_keys[group] = new ControllerEmu::Buttons("Keys", groups_info[group].name));
groups.emplace_back(m_hotkey_groups[group]); groups.emplace_back(m_hotkey_groups[group]);
for (int key = groups_info[group].first; key <= groups_info[group].last; key++) for (int key = groups_info[group].first; key <= groups_info[group].last; key++)
{ {
m_keys[group]->controls.emplace_back(new ControlGroup::Input(hotkey_labels[key])); m_keys[group]->controls.emplace_back(new ControllerEmu::Input(hotkey_labels[key]));
} }
} }
groups.emplace_back(m_options = new ControlGroup(_trans("Options"))); groups.emplace_back(m_options = new ControllerEmu::ControlGroup(_trans("Options")));
m_options->boolean_settings.emplace_back( m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input"))); std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>( _trans("Background Input")));
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL)); m_options->boolean_settings.emplace_back(
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
} }
HotkeyManager::~HotkeyManager() HotkeyManager::~HotkeyManager()
@ -281,7 +290,7 @@ std::string HotkeyManager::GetName() const
void HotkeyManager::GetInput(HotkeyStatus* const kb) void HotkeyManager::GetInput(HotkeyStatus* const kb)
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
for (int group = 0; group < NUM_HOTKEY_GROUPS; group++) for (int group = 0; group < NUM_HOTKEY_GROUPS; group++)
{ {
const int group_count = (groups_info[group].last - groups_info[group].first) + 1; const int group_count = (groups_info[group].last - groups_info[group].first) + 1;
@ -319,7 +328,7 @@ int HotkeyManager::GetIndexForGroup(int group, int id) const
void HotkeyManager::LoadDefaults(const ControllerInterface& ciface) void HotkeyManager::LoadDefaults(const ControllerInterface& ciface)
{ {
ControllerEmu::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);
#ifdef _WIN32 #ifdef _WIN32
const std::string NON = "(!(LMENU | RMENU) & !(LSHIFT | RSHIFT) & !(LCONTROL | RCONTROL))"; const std::string NON = "(!(LMENU | RMENU) & !(LSHIFT | RSHIFT) & !(LCONTROL | RCONTROL))";

View File

@ -7,9 +7,16 @@
#include <array> #include <array>
#include <string> #include <string>
#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
namespace ControllerEmu
{
class ControllerEmu;
class Buttons;
}
enum Hotkey enum Hotkey
{ {
HK_OPEN, HK_OPEN,
@ -183,7 +190,7 @@ struct HotkeyStatus
s8 err; s8 err;
}; };
class HotkeyManager : public ControllerEmu class HotkeyManager : public ControllerEmu::EmulatedController
{ {
public: public:
HotkeyManager(); HotkeyManager();
@ -191,16 +198,16 @@ public:
void GetInput(HotkeyStatus* const hk); void GetInput(HotkeyStatus* const hk);
std::string GetName() const override; std::string GetName() const override;
ControlGroup* GetHotkeyGroup(HotkeyGroup group) const; ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) const;
ControlGroup* GetOptionsGroup() const; ControllerEmu::ControlGroup* GetOptionsGroup() const;
int FindGroupByID(int id) const; int FindGroupByID(int id) const;
int GetIndexForGroup(int group, int id) const; int GetIndexForGroup(int group, int id) const;
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
private: private:
Buttons* m_keys[NUM_HOTKEY_GROUPS]; ControllerEmu::Buttons* m_keys[NUM_HOTKEY_GROUPS];
std::array<ControlGroup*, NUM_HOTKEY_GROUPS> m_hotkey_groups; std::array<ControllerEmu::ControlGroup*, NUM_HOTKEY_GROUPS> m_hotkey_groups;
ControlGroup* m_options; ControllerEmu::ControlGroup* m_options;
}; };
namespace HotkeyManagerEmu namespace HotkeyManagerEmu

View File

@ -28,13 +28,11 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/SymbolDB.h" #include "Common/SymbolDB.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/Debugger/Debugger_SymbolMap.h" #include "Core/Debugger/Debugger_SymbolMap.h"
#include "Core/Debugger/PPCDebugInterface.h" #include "Core/Debugger/PPCDebugInterface.h"
#include "Core/HW/CPU.h" #include "Core/HW/CPU.h"
#include "Core/HW/Memmap.h"
#include "Core/HW/SystemTimers.h"
#include "Core/Host.h"
#include "Core/PowerPC/BreakPoints.h" #include "Core/PowerPC/BreakPoints.h"
#include "Core/PowerPC/Gekko.h" #include "Core/PowerPC/Gekko.h"
#include "Core/PowerPC/JitInterface.h" #include "Core/PowerPC/JitInterface.h"

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "DolphinWX/Input/InputConfigDiag.h"
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cctype> #include <cctype>
@ -38,21 +40,27 @@
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Core/Core.h" #include "Core/Core.h"
#include "Core/HW/GCKeyboard.h" #include "Core/HW/GCKeyboard.h"
#include "Core/HW/GCPad.h" #include "Core/HW/GCPad.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
#include "Core/HotkeyManager.h" #include "Core/HotkeyManager.h"
#include "DolphinWX/DolphinSlider.h" #include "DolphinWX/DolphinSlider.h"
#include "DolphinWX/Input/ClassicInputConfigDiag.h" #include "DolphinWX/Input/ClassicInputConfigDiag.h"
#include "DolphinWX/Input/DrumsInputConfigDiag.h" #include "DolphinWX/Input/DrumsInputConfigDiag.h"
#include "DolphinWX/Input/GuitarInputConfigDiag.h" #include "DolphinWX/Input/GuitarInputConfigDiag.h"
#include "DolphinWX/Input/InputConfigDiag.h"
#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/ControlReference.h"
#include "InputCommon/ControlReference/ExpressionParser.h" #include "InputCommon/ControlReference/ExpressionParser.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.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"
@ -388,7 +396,7 @@ bool ControlDialog::Validate()
{ {
control_reference->expression = WxStrToStr(textctrl->GetValue()); control_reference->expression = WxStrToStr(textctrl->GetValue());
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
control_reference->UpdateReference(g_controller_interface, control_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->default_device); m_parent->GetController()->default_device);
@ -427,7 +435,7 @@ void ControlDialog::ClearControl(wxCommandEvent&)
{ {
control_reference->expression.clear(); control_reference->expression.clear();
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
control_reference->UpdateReference(g_controller_interface, control_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->default_device); m_parent->GetController()->default_device);
@ -486,7 +494,7 @@ void ControlDialog::SetSelectedControl(wxCommandEvent&)
textctrl->WriteText(expr); textctrl->WriteText(expr);
control_reference->expression = textctrl->GetValue(); control_reference->expression = textctrl->GetValue();
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
control_reference->UpdateReference(g_controller_interface, control_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->default_device); m_parent->GetController()->default_device);
@ -522,7 +530,7 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
textctrl->WriteText(expr); textctrl->WriteText(expr);
control_reference->expression = textctrl->GetValue(); control_reference->expression = textctrl->GetValue();
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
control_reference->UpdateReference(g_controller_interface, control_reference->UpdateReference(g_controller_interface,
m_parent->GetController()->default_device); m_parent->GetController()->default_device);
@ -704,7 +712,7 @@ bool InputConfigDialog::DetectButton(ControlButton* button)
wxString expr; wxString expr;
GetExpressionForControl(expr, control_name); GetExpressionForControl(expr, control_name);
button->control_reference->expression = expr; button->control_reference->expression = expr;
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
button->control_reference->UpdateReference(g_controller_interface, button->control_reference->UpdateReference(g_controller_interface,
controller->default_device); controller->default_device);
success = true; success = true;
@ -834,7 +842,7 @@ void InputConfigDialog::GetProfilePath(std::string& path)
} }
} }
ControllerEmu* InputConfigDialog::GetController() const ControllerEmu::EmulatedController* InputConfigDialog::GetController() const
{ {
return controller; return controller;
} }
@ -933,8 +941,10 @@ ControlGroupBox::~ControlGroupBox()
bool ControlGroupBox::HasBitmapHeading() const bool ControlGroupBox::HasBitmapHeading() const
{ {
return control_group->type == GROUP_TYPE_STICK || control_group->type == GROUP_TYPE_TILT || return control_group->type == ControllerEmu::GROUP_TYPE_STICK ||
control_group->type == GROUP_TYPE_CURSOR || control_group->type == GROUP_TYPE_FORCE; control_group->type == ControllerEmu::GROUP_TYPE_TILT ||
control_group->type == ControllerEmu::GROUP_TYPE_CURSOR ||
control_group->type == ControllerEmu::GROUP_TYPE_FORCE;
} }
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent,
@ -989,10 +999,10 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
switch (group->type) switch (group->type)
{ {
case GROUP_TYPE_STICK: case ControllerEmu::GROUP_TYPE_STICK:
case GROUP_TYPE_TILT: case ControllerEmu::GROUP_TYPE_TILT:
case GROUP_TYPE_CURSOR: case ControllerEmu::GROUP_TYPE_CURSOR:
case GROUP_TYPE_FORCE: case ControllerEmu::GROUP_TYPE_FORCE:
{ {
wxSize bitmap_size = parent->FromDIP(wxSize(64, 64)); wxSize bitmap_size = parent->FromDIP(wxSize(64, 64));
m_scale = bitmap_size.GetWidth() / 64.0; m_scale = bitmap_size.GetWidth() / 64.0;
@ -1034,7 +1044,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3); Add(h_szr, 0, wxEXPAND | wxLEFT | wxRIGHT, space3);
} }
break; break;
case GROUP_TYPE_BUTTONS: case ControllerEmu::GROUP_TYPE_BUTTONS:
{ {
// Draw buttons in rows of 8 // Draw buttons in rows of 8
unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size(); unsigned int button_cols = group->controls.size() > 8 ? 8 : group->controls.size();
@ -1072,17 +1082,17 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
} }
break; break;
case GROUP_TYPE_MIXED_TRIGGERS: case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS:
case GROUP_TYPE_TRIGGERS: case ControllerEmu::GROUP_TYPE_TRIGGERS:
case GROUP_TYPE_SLIDER: case ControllerEmu::GROUP_TYPE_SLIDER:
{ {
int height = (int)(12 * group->controls.size()); int height = (int)(12 * group->controls.size());
int width = 64; int width = 64;
if (GROUP_TYPE_MIXED_TRIGGERS == group->type) if (ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS == group->type)
width = 64 + 12 + 1; width = 64 + 12 + 1;
if (GROUP_TYPE_TRIGGERS != group->type) if (ControllerEmu::GROUP_TYPE_TRIGGERS != group->type)
height /= 2; height /= 2;
height += 1; height += 1;
@ -1116,7 +1126,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3); Add(static_bitmap, 0, wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT, space3);
} }
break; break;
case GROUP_TYPE_EXTENSION: case ControllerEmu::GROUP_TYPE_EXTENSION:
{ {
PadSettingExtension* const attachments = PadSettingExtension* const attachments =
new PadSettingExtension(parent, (ControllerEmu::Extension*)group); new PadSettingExtension(parent, (ControllerEmu::Extension*)group);

View File

@ -23,10 +23,10 @@
#include <wx/spinctrl.h> #include <wx/spinctrl.h>
#include <wx/timer.h> #include <wx/timer.h>
#include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerInterface/Device.h" #include "InputCommon/ControllerInterface/Device.h"
class ControlReference;
class DolphinSlider; class DolphinSlider;
class InputConfig; class InputConfig;
class wxComboBox; class wxComboBox;
@ -35,6 +35,12 @@ class wxStaticBitmap;
class wxStaticText; class wxStaticText;
class wxTextCtrl; class wxTextCtrl;
namespace ControllerEmu
{
class EmulatedController;
class Extension;
}
class PadSetting class PadSetting
{ {
protected: protected:
@ -221,7 +227,7 @@ public:
void AdjustBooleanSetting(wxCommandEvent& event); void AdjustBooleanSetting(wxCommandEvent& event);
void GetProfilePath(std::string& path); void GetProfilePath(std::string& path);
ControllerEmu* GetController() const; ControllerEmu::EmulatedController* GetController() const;
wxComboBox* profile_cbox = nullptr; wxComboBox* profile_cbox = nullptr;
wxComboBox* device_cbox = nullptr; wxComboBox* device_cbox = nullptr;
@ -234,7 +240,7 @@ protected:
wxBoxSizer* CreaterResetGroupBox(wxOrientation orientation); wxBoxSizer* CreaterResetGroupBox(wxOrientation orientation);
wxBoxSizer* CreateProfileChooserGroupBox(); wxBoxSizer* CreateProfileChooserGroupBox();
ControllerEmu* const controller; ControllerEmu::EmulatedController* const controller;
wxTimer m_update_timer; wxTimer m_update_timer;

View File

@ -22,6 +22,15 @@
#include "DolphinWX/Input/InputConfigDiag.h" #include "DolphinWX/Input/InputConfigDiag.h"
#include "DolphinWX/WxUtils.h" #include "DolphinWX/WxUtils.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h"
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.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"
@ -150,9 +159,9 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
switch (g->control_group->type) switch (g->control_group->type)
{ {
case GROUP_TYPE_TILT: case ControllerEmu::GROUP_TYPE_TILT:
case GROUP_TYPE_STICK: case ControllerEmu::GROUP_TYPE_STICK:
case GROUP_TYPE_CURSOR: case ControllerEmu::GROUP_TYPE_CURSOR:
{ {
// this is starting to be a mess combining all these in one case // this is starting to be a mess combining all these in one case
@ -160,19 +169,19 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
switch (g->control_group->type) switch (g->control_group->type)
{ {
case GROUP_TYPE_STICK: case ControllerEmu::GROUP_TYPE_STICK:
((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y); ((ControllerEmu::AnalogStick*)g->control_group)->GetState(&x, &y);
break; break;
case GROUP_TYPE_TILT: case ControllerEmu::GROUP_TYPE_TILT:
((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y); ((ControllerEmu::Tilt*)g->control_group)->GetState(&x, &y);
break; break;
case GROUP_TYPE_CURSOR: case ControllerEmu::GROUP_TYPE_CURSOR:
((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z); ((ControllerEmu::Cursor*)g->control_group)->GetState(&x, &y, &z);
break; break;
} }
// ir cursor forward movement // ir cursor forward movement
if (GROUP_TYPE_CURSOR == g->control_group->type) if (ControllerEmu::GROUP_TYPE_CURSOR == g->control_group->type)
{ {
gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH); gc->SetBrush(z ? *wxRED_BRUSH : *wxGREY_BRUSH);
wxGraphicsPath path = gc->CreatePath(); wxGraphicsPath path = gc->CreatePath();
@ -182,7 +191,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
// input zone // input zone
gc->SetPen(*wxLIGHT_GREY_PEN); gc->SetPen(*wxLIGHT_GREY_PEN);
if (GROUP_TYPE_STICK == g->control_group->type) if (ControllerEmu::GROUP_TYPE_STICK == g->control_group->type)
{ {
gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray gc->SetBrush(wxColour(0xDDDDDD)); // Light Gray
@ -222,9 +231,12 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
gc->DrawRectangle(16, 16, 32, 32); gc->DrawRectangle(16, 16, 32, 32);
} }
if (GROUP_TYPE_CURSOR != g->control_group->type) if (ControllerEmu::GROUP_TYPE_CURSOR != g->control_group->type)
{ {
int deadzone_idx = g->control_group->type == GROUP_TYPE_STICK ? SETTING_DEADZONE : 0; const int deadzone_idx = g->control_group->type == ControllerEmu::GROUP_TYPE_STICK ?
ControllerEmu::AnalogStick::SETTING_DEADZONE :
0;
wxGraphicsPath path = gc->CreatePath(); wxGraphicsPath path = gc->CreatePath();
path.AddCircle(VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2, path.AddCircle(VIS_BITMAP_SIZE / 2, VIS_BITMAP_SIZE / 2,
g->control_group->numeric_settings[deadzone_idx]->GetValue() * g->control_group->numeric_settings[deadzone_idx]->GetValue() *
@ -255,7 +267,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case GROUP_TYPE_FORCE: case ControllerEmu::GROUP_TYPE_FORCE:
{ {
ControlState raw_dot[3]; ControlState raw_dot[3];
ControlState adj_dot[3]; ControlState adj_dot[3];
@ -320,7 +332,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case GROUP_TYPE_BUTTONS: case ControllerEmu::GROUP_TYPE_BUTTONS:
{ {
const unsigned int button_count = static_cast<unsigned int>(g->control_group->controls.size()); const unsigned int button_count = static_cast<unsigned int>(g->control_group->controls.size());
std::vector<unsigned int> bitmasks(button_count); std::vector<unsigned int> bitmasks(button_count);
@ -349,7 +361,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case GROUP_TYPE_TRIGGERS: case ControllerEmu::GROUP_TYPE_TRIGGERS:
{ {
const unsigned int trigger_count = static_cast<unsigned int>(g->control_group->controls.size()); const unsigned int trigger_count = static_cast<unsigned int>(g->control_group->controls.size());
std::vector<ControlState> trigs(trigger_count); std::vector<ControlState> trigs(trigger_count);
@ -391,7 +403,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case GROUP_TYPE_MIXED_TRIGGERS: case ControllerEmu::GROUP_TYPE_MIXED_TRIGGERS:
{ {
const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2)); const unsigned int trigger_count = ((unsigned int)(g->control_group->controls.size() / 2));
@ -431,7 +443,7 @@ static void DrawControlGroupBox(wxGraphicsContext* gc, ControlGroupBox* g)
} }
break; break;
case GROUP_TYPE_SLIDER: case ControllerEmu::GROUP_TYPE_SLIDER:
{ {
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue(); const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
@ -488,7 +500,7 @@ void InputConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
g_controller_interface.UpdateInput(); g_controller_interface.UpdateInput();
wxMemoryDC dc; wxMemoryDC dc;
auto lock = ControllerEmu::GetStateLock(); const auto lock = ControllerEmu::EmulatedController::GetStateLock();
for (ControlGroupBox* g : control_groups) for (ControlGroupBox* g : control_groups)
{ {
// Only if this control group has a bitmap // Only if this control group has a bitmap

View File

@ -1,5 +1,19 @@
set(SRCS InputConfig.cpp set(SRCS InputConfig.cpp
ControllerEmu/ControllerEmu.cpp ControllerEmu/ControllerEmu.cpp
ControllerEmu/Control/Control.cpp
ControllerEmu/Control/Input.cpp
ControllerEmu/Control/Output.cpp
ControllerEmu/ControlGroup/AnalogStick.cpp
ControllerEmu/ControlGroup/Buttons.cpp
ControllerEmu/ControlGroup/ControlGroup.cpp
ControllerEmu/ControlGroup/Cursor.cpp
ControllerEmu/ControlGroup/Extension.cpp
ControllerEmu/ControlGroup/Force.cpp
ControllerEmu/ControlGroup/MixedTriggers.cpp
ControllerEmu/ControlGroup/ModifySettingsButton.cpp
ControllerEmu/ControlGroup/Slider.cpp
ControllerEmu/ControlGroup/Tilt.cpp
ControllerEmu/ControlGroup/Triggers.cpp
ControllerInterface/ControllerInterface.cpp ControllerInterface/ControllerInterface.cpp
ControllerInterface/Device.cpp ControllerInterface/Device.cpp
ControlReference/ControlReference.cpp ControlReference/ControlReference.cpp

View File

@ -0,0 +1,15 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControlReference/ControlReference.h"
namespace ControllerEmu
{
Control::Control(ControlReference* ref, const std::string& name_) : control_ref(ref), name(name_)
{
}
Control::~Control() = default;
} // namespace ControllerEmu

View File

@ -0,0 +1,25 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
class ControlReference;
namespace ControllerEmu
{
class Control
{
public:
virtual ~Control();
std::unique_ptr<ControlReference> const control_ref;
const std::string name;
protected:
Control(ControlReference* ref, const std::string& name);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,15 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/Control/Input.h"
#include <string>
#include "InputCommon/ControlReference/ControlReference.h"
namespace ControllerEmu
{
Input::Input(const std::string& name_) : Control(new InputReference, name_)
{
}
} // namespace ControllerEmu

View File

@ -0,0 +1,17 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
class Input : public Control
{
public:
explicit Input(const std::string& name);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,15 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/Control/Output.h"
#include <string>
#include "InputCommon/ControlReference/ControlReference.h"
namespace ControllerEmu
{
Output::Output(const std::string& name_) : Control(new OutputReference, name_)
{
}
} // namespace ControllerEmu

View File

@ -0,0 +1,17 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
class Output : public Control
{
public:
explicit Output(const std::string& name);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,71 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
AnalogStick::AnalogStick(const char* const name_, ControlState default_radius)
: AnalogStick(name_, name_, default_radius)
{
}
AnalogStick::AnalogStick(const char* const name_, const char* const ui_name_,
ControlState default_radius)
: ControlGroup(name_, ui_name_, GROUP_TYPE_STICK)
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction));
controls.emplace_back(std::make_unique<Input>(_trans("Modifier")));
numeric_settings.emplace_back(
std::make_unique<NumericSetting>(_trans("Radius"), default_radius, 0, 100));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
void AnalogStick::GetState(ControlState* const x, ControlState* const y)
{
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue();
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
ControlState m = controls[4]->control_ref->State();
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
ControlState ang_cos = cos(ang);
ControlState dist = sqrt(xx * xx + yy * yy);
// dead zone code
dist = std::max(0.0, dist - deadzone);
dist /= (1 - deadzone);
// radius
dist *= radius;
// The modifier halves the distance by 50%, which is useful
// for keyboard controls.
if (m)
dist *= 0.5;
yy = std::max(-1.0, std::min(1.0, ang_sin * dist));
xx = std::max(-1.0, std::min(1.0, ang_cos * dist));
*y = yy;
*x = xx;
}
} // namespace ControllerEmu

View File

@ -0,0 +1,26 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class AnalogStick : public ControlGroup
{
public:
enum
{
SETTING_RADIUS,
SETTING_DEADZONE,
};
// The GameCube controller and Wiimote attachments have a different default radius
AnalogStick(const char* name, ControlState default_radius);
AnalogStick(const char* name, const char* ui_name, ControlState default_radius);
void GetState(ControlState* x, ControlState* y);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,24 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include <memory>
#include <string>
#include "Common/Common.h"
namespace ControllerEmu
{
Buttons::Buttons(const std::string& name_) : ControlGroup(name_, name_, GROUP_TYPE_BUTTONS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
Buttons::Buttons(const std::string& ini_name, const std::string& group_name)
: ControlGroup(ini_name, group_name, GROUP_TYPE_BUTTONS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
} // namespace ControllerEmu

View File

@ -0,0 +1,33 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Buttons : public ControlGroup
{
public:
explicit Buttons(const std::string& name_);
Buttons(const std::string& ini_name, const std::string& group_name);
template <typename C>
void GetState(C* const buttons, const C* bitmasks)
{
for (auto& control : controls)
{
if (control->control_ref->State() > numeric_settings[0]->GetValue()) // threshold
*buttons |= *bitmasks;
bitmasks++;
}
}
};
} // namespace ControllerEmu

View File

@ -0,0 +1,132 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
ControlGroup::ControlGroup(const std::string& name_, const u32 type_)
: name(name_), ui_name(name_), type(type_)
{
}
ControlGroup::ControlGroup(const std::string& name_, const std::string& ui_name_, const u32 type_)
: name(name_), ui_name(ui_name_), type(type_)
{
}
ControlGroup::~ControlGroup() = default;
ControlGroup::BooleanSetting::~BooleanSetting() = default;
void ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev,
const std::string& base)
{
std::string group(base + name + "/");
// settings
for (auto& s : numeric_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Get(group + s->m_name, &s->m_value, s->m_default_value * 100);
s->m_value /= 100;
}
for (auto& s : boolean_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Get(group + s->m_name, &s->m_value, s->m_default_value);
}
for (auto& c : controls)
{
// control expression
sec->Get(group + c->name, &c->control_ref->expression, "");
// range
sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0);
c->control_ref->range /= 100;
}
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = (Extension*)this;
ext->switch_extension = 0;
u32 n = 0;
std::string extname;
sec->Get(base + name, &extname, "");
for (auto& ai : ext->attachments)
{
ai->default_device.FromString(defdev);
ai->LoadConfig(sec, base + ai->GetName() + "/");
if (ai->GetName() == extname)
ext->switch_extension = n;
n++;
}
}
}
void ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev,
const std::string& base)
{
std::string group(base + name + "/");
for (auto& s : numeric_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Set(group + s->m_name, s->m_value * 100.0, s->m_default_value * 100.0);
}
for (auto& s : boolean_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Set(group + s->m_name, s->m_value, s->m_default_value);
}
for (auto& c : controls)
{
// control expression
sec->Set(group + c->name, c->control_ref->expression, "");
// range
sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0);
}
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = (Extension*)this;
sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");
for (auto& ai : ext->attachments)
ai->SaveConfig(sec, base + ai->GetName() + "/");
}
}
void ControlGroup::SetControlExpression(int index, const std::string& expression)
{
controls.at(index)->control_ref->expression = expression;
}
} // namespace ControllerEmu

View File

@ -0,0 +1,117 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/IniFile.h"
#include "Core/ConfigManager.h"
#include "InputCommon/ControllerInterface/Device.h"
namespace ControllerEmu
{
class Control;
enum
{
GROUP_TYPE_OTHER,
GROUP_TYPE_STICK,
GROUP_TYPE_MIXED_TRIGGERS,
GROUP_TYPE_BUTTONS,
GROUP_TYPE_FORCE,
GROUP_TYPE_EXTENSION,
GROUP_TYPE_TILT,
GROUP_TYPE_CURSOR,
GROUP_TYPE_TRIGGERS,
GROUP_TYPE_SLIDER
};
class ControlGroup
{
public:
enum class SettingType
{
NORMAL, // normal settings are saved to configuration files
VIRTUAL, // virtual settings are not saved at all
};
class NumericSetting
{
public:
NumericSetting(const std::string& setting_name, const ControlState default_value,
const u32 low = 0, const u32 high = 100,
const SettingType setting_type = SettingType::NORMAL)
: m_type(setting_type), m_name(setting_name), m_default_value(default_value), m_low(low),
m_high(high)
{
}
ControlState GetValue() const { return m_value; }
void SetValue(ControlState value) { m_value = value; }
const SettingType m_type;
const std::string m_name;
const ControlState m_default_value;
const u32 m_low;
const u32 m_high;
ControlState m_value;
};
class BooleanSetting
{
public:
BooleanSetting(const std::string& setting_name, const bool default_value,
const SettingType setting_type = SettingType::NORMAL)
: m_type(setting_type), m_name(setting_name), m_default_value(default_value)
{
}
virtual ~BooleanSetting();
virtual bool GetValue() const { return m_value; }
virtual void SetValue(bool value) { m_value = value; }
const SettingType m_type;
const std::string m_name;
const bool m_default_value;
bool m_value;
};
class BackgroundInputSetting : public BooleanSetting
{
public:
BackgroundInputSetting(const std::string& setting_name)
: BooleanSetting(setting_name, false, SettingType::VIRTUAL)
{
}
bool GetValue() const override { return SConfig::GetInstance().m_BackgroundInput; }
void SetValue(bool value) override
{
m_value = value;
SConfig::GetInstance().m_BackgroundInput = value;
}
};
explicit ControlGroup(const std::string& name, u32 type = GROUP_TYPE_OTHER);
ControlGroup(const std::string& name, const std::string& ui_name, u32 type = GROUP_TYPE_OTHER);
virtual ~ControlGroup();
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
void SetControlExpression(int index, const std::string& expression);
const std::string name;
const std::string ui_name;
const u32 type;
std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSetting>> numeric_settings;
std::vector<std::unique_ptr<BooleanSetting>> boolean_settings;
};
} // namespace ControllerEmu

View File

@ -0,0 +1,98 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Cursor.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "Common/MathUtil.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
Cursor::Cursor(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_CURSOR)
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction));
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
controls.emplace_back(std::make_unique<Input>("Recenter"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Height"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 20));
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Relative Input"), false));
}
void Cursor::GetState(ControlState* const x, ControlState* const y, ControlState* const z,
const bool adjusted)
{
const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
// silly being here
if (zz > m_z)
m_z = std::min(m_z + 0.1, zz);
else if (zz < m_z)
m_z = std::max(m_z - 0.1, zz);
*z = m_z;
// hide
if (controls[6]->control_ref->State() > 0.5)
{
*x = 10000;
*y = 0;
}
else
{
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
// adjust cursor according to settings
if (adjusted)
{
xx *= (numeric_settings[1]->GetValue() * 2);
yy *= (numeric_settings[2]->GetValue() * 2);
yy += (numeric_settings[0]->GetValue() - 0.5);
}
// relative input
if (boolean_settings[0]->GetValue())
{
const ControlState deadzone = numeric_settings[3]->GetValue();
// deadzone to avoid the cursor slowly drifting
if (std::abs(xx) > deadzone)
m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
if (std::abs(yy) > deadzone)
m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
// recenter
if (controls[7]->control_ref->State() > 0.5)
{
m_x = 0.0;
m_y = 0.0;
}
}
else
{
m_x = xx;
m_y = yy;
}
*x = m_x;
*y = m_y;
}
}
} // namespace ControllerEmu

View File

@ -0,0 +1,29 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Cursor : public ControlGroup
{
public:
explicit Cursor(const std::string& name);
void GetState(ControlState* x, ControlState* y, ControlState* z, bool adjusted = false);
ControlState m_z = 0.0;
private:
// This is used to reduce the cursor speed for relative input
// to something that makes sense with the default range.
static constexpr double SPEED_MULTIPLIER = 0.04;
ControlState m_x = 0.0;
ControlState m_y = 0.0;
};
} // namespace ControllerEmu

View File

@ -0,0 +1,16 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
#include <string>
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
Extension::Extension(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_EXTENSION)
{
}
} // namespace ControllerEmu

View File

@ -0,0 +1,31 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <memory>
#include <string>
#include <vector>
#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class EmulatedController;
class Extension : public ControlGroup
{
public:
explicit Extension(const std::string& name);
void GetState(u8* data);
bool IsButtonPressed() const;
std::vector<std::unique_ptr<EmulatedController>> attachments;
int switch_extension = 0;
int active_extension = 0;
};
} // namespace ControllerEmu

View File

@ -0,0 +1,51 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Force.h"
#include <cmath>
#include <cstring>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
Force::Force(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_FORCE)
{
memset(m_swing, 0, sizeof(m_swing));
controls.emplace_back(std::make_unique<Input>(_trans("Up")));
controls.emplace_back(std::make_unique<Input>(_trans("Down")));
controls.emplace_back(std::make_unique<Input>(_trans("Left")));
controls.emplace_back(std::make_unique<Input>(_trans("Right")));
controls.emplace_back(std::make_unique<Input>(_trans("Forward")));
controls.emplace_back(std::make_unique<Input>(_trans("Backward")));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
void Force::GetState(ControlState* axis)
{
const ControlState deadzone = numeric_settings[0]->GetValue();
for (u32 i = 0; i < 6; i += 2)
{
ControlState tmpf = 0;
const ControlState state =
controls[i + 1]->control_ref->State() - controls[i]->control_ref->State();
if (fabs(state) > deadzone)
tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone));
ControlState& ax = m_swing[i >> 1];
*axis++ = (tmpf - ax);
ax = tmpf;
}
}
} // namespace ControllerEmu

View File

@ -0,0 +1,22 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Force : public ControlGroup
{
public:
explicit Force(const std::string& name);
void GetState(ControlState* axis);
private:
ControlState m_swing[3];
};
} // namespace ControllerEmu

View File

@ -0,0 +1,42 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
#include <cstddef>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
MixedTriggers::MixedTriggers(const std::string& name_)
: ControlGroup(name_, GROUP_TYPE_MIXED_TRIGGERS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9));
}
void MixedTriggers::GetState(u16* const digital, const u16* bitmasks, ControlState* analog)
{
const size_t trigger_count = controls.size() / 2;
for (size_t i = 0; i < trigger_count; ++i, ++bitmasks, ++analog)
{
if (controls[i]->control_ref->State() > numeric_settings[0]->GetValue()) // threshold
{
*analog = 1.0;
*digital |= *bitmasks;
}
else
{
*analog = controls[i + trigger_count]->control_ref->State();
}
}
}
} // namespace ControllerEmu

View File

@ -0,0 +1,19 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class MixedTriggers : public ControlGroup
{
public:
explicit MixedTriggers(const std::string& name);
void GetState(u16* digital, const u16* bitmasks, ControlState* analog);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,77 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/ModifySettingsButton.h"
#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "VideoCommon/OnScreenDisplay.h"
namespace ControllerEmu
{
ModifySettingsButton::ModifySettingsButton(std::string button_name)
: Buttons(std::move(button_name))
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
void ModifySettingsButton::AddInput(std::string button_name, bool toggle)
{
controls.emplace_back(new Input(std::move(button_name)));
threshold_exceeded.emplace_back(false);
associated_settings.emplace_back(false);
associated_settings_toggle.emplace_back(toggle);
}
void ModifySettingsButton::GetState()
{
for (size_t i = 0; i < controls.size(); ++i)
{
ControlState state = controls[i]->control_ref->State();
if (!associated_settings_toggle[i])
{
// not toggled
associated_settings[i] = state > numeric_settings[0]->GetValue();
}
else
{
// toggle (loading savestates does not en-/disable toggle)
// after we passed the threshold, we en-/disable. but after that, we don't change it
// anymore
if (!threshold_exceeded[i] && state > numeric_settings[0]->GetValue())
{
associated_settings[i] = !associated_settings[i];
if (associated_settings[i])
OSD::AddMessage(controls[i]->name + ": " + _trans("on"));
else
OSD::AddMessage(controls[i]->name + ": " + _trans("off"));
threshold_exceeded[i] = true;
}
if (state < numeric_settings[0]->GetValue())
threshold_exceeded[i] = false;
}
}
}
const std::vector<bool>& ModifySettingsButton::isSettingToggled() const
{
return associated_settings_toggle;
}
const std::vector<bool>& ModifySettingsButton::getSettingsModifier() const
{
return associated_settings;
}
} // namespace ControllerEmu

View File

@ -0,0 +1,31 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include <vector>
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
namespace ControllerEmu
{
class ModifySettingsButton : public Buttons
{
public:
explicit ModifySettingsButton(std::string button_name);
void AddInput(std::string button_name, bool toggle = false);
void GetState();
const std::vector<bool>& isSettingToggled() const;
const std::vector<bool>& getSettingsModifier() const;
private:
std::vector<bool> threshold_exceeded; // internal calculation (if "state" was above threshold)
std::vector<bool> associated_settings_toggle; // is setting toggled or hold?
std::vector<bool> associated_settings; // result
};
} // namespace ControllerEmu

View File

@ -0,0 +1,37 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Slider.h"
#include <cmath>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
namespace ControllerEmu
{
Slider::Slider(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_SLIDER)
{
controls.emplace_back(std::make_unique<Input>("Left"));
controls.emplace_back(std::make_unique<Input>("Right"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
void Slider::GetState(ControlState* const slider)
{
const ControlState deadzone = numeric_settings[0]->GetValue();
const ControlState state = controls[1]->control_ref->State() - controls[0]->control_ref->State();
if (fabs(state) > deadzone)
*slider = (state - (deadzone * sign(state))) / (1 - deadzone);
else
*slider = 0;
}
} // namespace ControllerEmu

View File

@ -0,0 +1,19 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Slider : public ControlGroup
{
public:
explicit Slider(const std::string& name);
void GetState(ControlState* slider);
};
} // namespace ControllerEmu

View File

@ -0,0 +1,99 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Tilt.h"
#include <algorithm>
#include <cmath>
#include <cstring>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/Control/Input.h"
namespace ControllerEmu
{
Tilt::Tilt(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TILT)
{
memset(m_tilt, 0, sizeof(m_tilt));
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>("Left"));
controls.emplace_back(std::make_unique<Input>("Right"));
controls.emplace_back(std::make_unique<Input>(_trans("Modifier")));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Circle Stick"), 0));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Angle"), 0.9, 0, 180));
}
void Tilt::GetState(ControlState* const x, ControlState* const y, const bool step)
{
// this is all a mess
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
ControlState deadzone = numeric_settings[0]->GetValue();
ControlState circle = numeric_settings[1]->GetValue();
auto const angle = numeric_settings[2]->GetValue() / 1.8;
ControlState m = controls[4]->control_ref->State();
// deadzone / circle stick code
// this section might be all wrong, but its working good enough, I think
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
ControlState ang_cos = cos(ang);
// the amt a full square stick would have at current angle
ControlState square_full =
std::min(ang_sin ? 1 / fabs(ang_sin) : 2, ang_cos ? 1 / fabs(ang_cos) : 2);
// the amt a full stick would have that was (user setting circular) at current angle
// I think this is more like a pointed circle rather than a rounded square like it should be
ControlState stick_full = (square_full * (1 - circle)) + (circle);
ControlState dist = sqrt(xx * xx + yy * yy);
// dead zone code
dist = std::max(0.0, dist - deadzone * stick_full);
dist /= (1 - deadzone);
// circle stick code
ControlState amt = dist / stick_full;
dist += (square_full - 1) * amt * circle;
if (m)
dist *= 0.5;
yy = std::max(-1.0, std::min(1.0, ang_sin * dist));
xx = std::max(-1.0, std::min(1.0, ang_cos * dist));
// this is kinda silly here
// gui being open will make this happen 2x as fast, o well
// silly
if (step)
{
if (xx > m_tilt[0])
m_tilt[0] = std::min(m_tilt[0] + 0.1, xx);
else if (xx < m_tilt[0])
m_tilt[0] = std::max(m_tilt[0] - 0.1, xx);
if (yy > m_tilt[1])
m_tilt[1] = std::min(m_tilt[1] + 0.1, yy);
else if (yy < m_tilt[1])
m_tilt[1] = std::max(m_tilt[1] - 0.1, yy);
}
*y = m_tilt[1] * angle;
*x = m_tilt[0] * angle;
}
} // namespace ControllerEmu

View File

@ -0,0 +1,22 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Tilt : public ControlGroup
{
public:
explicit Tilt(const std::string& name);
void GetState(ControlState* x, ControlState* y, bool step = true);
private:
ControlState m_tilt[2];
};
} // namespace ControllerEmu

View File

@ -0,0 +1,31 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControlGroup/Triggers.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <string>
#include "Common/Common.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
namespace ControllerEmu
{
Triggers::Triggers(const std::string& name_) : ControlGroup(name_, GROUP_TYPE_TRIGGERS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
void Triggers::GetState(ControlState* analog)
{
const size_t trigger_count = controls.size();
const ControlState deadzone = numeric_settings[0]->GetValue();
for (size_t i = 0; i < trigger_count; ++i, ++analog)
*analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone);
}
} // namespace ControllerEmu

View File

@ -0,0 +1,19 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <string>
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
namespace ControllerEmu
{
class Triggers : public ControlGroup
{
public:
explicit Triggers(const std::string& name);
void GetState(ControlState* analog);
};
} // namespace ControllerEmu

View File

@ -3,23 +3,36 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
#include <memory> #include <memory>
#include "Common/Common.h" #include <mutex>
#include "VideoCommon/OnScreenDisplay.h" #include <string>
#include "Common/IniFile.h"
#include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerEmu/Control/Control.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/Extension.h"
namespace ControllerEmu
{
static std::recursive_mutex s_get_state_mutex;
EmulatedController::~EmulatedController() = default;
// This should be called before calling GetState() or State() on a control reference // This should be called before calling GetState() or State() on a control reference
// to prevent a race condition. // to prevent a race condition.
// This is a recursive mutex because UpdateReferences is recursive. // This is a recursive mutex because UpdateReferences is recursive.
static std::recursive_mutex s_get_state_mutex; std::unique_lock<std::recursive_mutex> EmulatedController::GetStateLock()
std::unique_lock<std::recursive_mutex> ControllerEmu::GetStateLock()
{ {
std::unique_lock<std::recursive_mutex> lock(s_get_state_mutex); std::unique_lock<std::recursive_mutex> lock(s_get_state_mutex);
return lock; return lock;
} }
void ControllerEmu::UpdateReferences(ControllerInterface& devi) void EmulatedController::UpdateReferences(ControllerInterface& devi)
{ {
auto lock = ControllerEmu::GetStateLock(); const auto lock = GetStateLock();
for (auto& ctrlGroup : groups) for (auto& ctrlGroup : groups)
{ {
for (auto& control : ctrlGroup->controls) for (auto& control : ctrlGroup->controls)
@ -34,7 +47,7 @@ void ControllerEmu::UpdateReferences(ControllerInterface& devi)
} }
} }
void ControllerEmu::UpdateDefaultDevice() void EmulatedController::UpdateDefaultDevice()
{ {
for (auto& ctrlGroup : groups) for (auto& ctrlGroup : groups)
{ {
@ -50,62 +63,7 @@ void ControllerEmu::UpdateDefaultDevice()
} }
} }
void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section* sec, const std::string& defdev, void EmulatedController::LoadConfig(IniFile::Section* sec, const std::string& base)
const std::string& base)
{
std::string group(base + name + "/");
// settings
for (auto& s : numeric_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Get(group + s->m_name, &s->m_value, s->m_default_value * 100);
s->m_value /= 100;
}
for (auto& s : boolean_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Get(group + s->m_name, &s->m_value, s->m_default_value);
}
for (auto& c : controls)
{
// control expression
sec->Get(group + c->name, &c->control_ref->expression, "");
// range
sec->Get(group + c->name + "/Range", &c->control_ref->range, 100.0);
c->control_ref->range /= 100;
}
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = (Extension*)this;
ext->switch_extension = 0;
unsigned int n = 0;
std::string extname;
sec->Get(base + name, &extname, "");
for (auto& ai : ext->attachments)
{
ai->default_device.FromString(defdev);
ai->LoadConfig(sec, base + ai->GetName() + "/");
if (ai->GetName() == extname)
ext->switch_extension = n;
n++;
}
}
}
ControllerEmu::ControlGroup::BooleanSetting::~BooleanSetting() = default;
void ControllerEmu::LoadConfig(IniFile::Section* sec, const std::string& base)
{ {
std::string defdev = default_device.ToString(); std::string defdev = default_device.ToString();
if (base.empty()) if (base.empty())
@ -118,45 +76,7 @@ void ControllerEmu::LoadConfig(IniFile::Section* sec, const std::string& base)
cg->LoadConfig(sec, defdev, base); cg->LoadConfig(sec, defdev, base);
} }
void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section* sec, const std::string& defdev, void EmulatedController::SaveConfig(IniFile::Section* sec, const std::string& base)
const std::string& base)
{
std::string group(base + name + "/");
for (auto& s : numeric_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Set(group + s->m_name, s->m_value * 100.0, s->m_default_value * 100.0);
}
for (auto& s : boolean_settings)
{
if (s->m_type == SettingType::VIRTUAL)
continue;
sec->Set(group + s->m_name, s->m_value, s->m_default_value);
}
for (auto& c : controls)
{
// control expression
sec->Set(group + c->name, c->control_ref->expression, "");
// range
sec->Set(group + c->name + "/Range", c->control_ref->range * 100.0, 100.0);
}
// extensions
if (type == GROUP_TYPE_EXTENSION)
{
Extension* const ext = (Extension*)this;
sec->Set(base + name, ext->attachments[ext->switch_extension]->GetName(), "None");
for (auto& ai : ext->attachments)
ai->SaveConfig(sec, base + ai->GetName() + "/");
}
}
void ControllerEmu::SaveConfig(IniFile::Section* sec, const std::string& base)
{ {
const std::string defdev = default_device.ToString(); const std::string defdev = default_device.ToString();
if (base.empty()) if (base.empty())
@ -166,154 +86,7 @@ void ControllerEmu::SaveConfig(IniFile::Section* sec, const std::string& base)
ctrlGroup->SaveConfig(sec, defdev, base); ctrlGroup->SaveConfig(sec, defdev, base);
} }
void ControllerEmu::ControlGroup::SetControlExpression(int index, const std::string& expression) void EmulatedController::LoadDefaults(const ControllerInterface& ciface)
{
controls.at(index)->control_ref->expression = expression;
}
ControllerEmu::AnalogStick::AnalogStick(const char* const _name, ControlState default_radius)
: AnalogStick(_name, _name, default_radius)
{
}
ControllerEmu::AnalogStick::AnalogStick(const char* const _name, const char* const _ui_name,
ControlState default_radius)
: ControlGroup(_name, _ui_name, GROUP_TYPE_STICK)
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction));
controls.emplace_back(std::make_unique<Input>(_trans("Modifier")));
numeric_settings.emplace_back(
std::make_unique<NumericSetting>(_trans("Radius"), default_radius, 0, 100));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
ControllerEmu::Buttons::Buttons(const std::string& _name)
: ControlGroup(_name, _name, GROUP_TYPE_BUTTONS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
ControllerEmu::Buttons::Buttons(const std::string& ini_name, const std::string& group_name)
: ControlGroup(ini_name, group_name, GROUP_TYPE_BUTTONS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
ControllerEmu::ModifySettingsButton::ModifySettingsButton(std::string button_name)
: Buttons(std::move(button_name))
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.5));
}
void ControllerEmu::ModifySettingsButton::AddInput(std::string button_name, bool toggle)
{
controls.emplace_back(new ControlGroup::Input(std::move(button_name)));
threshold_exceeded.emplace_back(false);
associated_settings.emplace_back(false);
associated_settings_toggle.emplace_back(toggle);
}
void ControllerEmu::ModifySettingsButton::GetState()
{
for (size_t i = 0; i < controls.size(); ++i)
{
ControlState state = controls[i]->control_ref->State();
if (!associated_settings_toggle[i])
{
// not toggled
associated_settings[i] = state > numeric_settings[0]->GetValue();
}
else
{
// toggle (loading savestates does not en-/disable toggle)
// after we passed the threshold, we en-/disable. but after that, we don't change it
// anymore
if (!threshold_exceeded[i] && state > numeric_settings[0]->GetValue())
{
associated_settings[i] = !associated_settings[i];
if (associated_settings[i])
OSD::AddMessage(controls[i]->name + ": " + _trans("on"));
else
OSD::AddMessage(controls[i]->name + ": " + _trans("off"));
threshold_exceeded[i] = true;
}
if (state < numeric_settings[0]->GetValue())
threshold_exceeded[i] = false;
}
}
}
ControllerEmu::MixedTriggers::MixedTriggers(const std::string& _name)
: ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Threshold"), 0.9));
}
ControllerEmu::Triggers::Triggers(const std::string& _name)
: ControlGroup(_name, GROUP_TYPE_TRIGGERS)
{
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
ControllerEmu::Slider::Slider(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_SLIDER)
{
controls.emplace_back(std::make_unique<Input>("Left"));
controls.emplace_back(std::make_unique<Input>("Right"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
ControllerEmu::Force::Force(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_FORCE)
{
memset(m_swing, 0, sizeof(m_swing));
controls.emplace_back(std::make_unique<Input>(_trans("Up")));
controls.emplace_back(std::make_unique<Input>(_trans("Down")));
controls.emplace_back(std::make_unique<Input>(_trans("Left")));
controls.emplace_back(std::make_unique<Input>(_trans("Right")));
controls.emplace_back(std::make_unique<Input>(_trans("Forward")));
controls.emplace_back(std::make_unique<Input>(_trans("Backward")));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
}
ControllerEmu::Tilt::Tilt(const std::string& _name) : ControlGroup(_name, GROUP_TYPE_TILT)
{
memset(m_tilt, 0, sizeof(m_tilt));
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>("Left"));
controls.emplace_back(std::make_unique<Input>("Right"));
controls.emplace_back(std::make_unique<Input>(_trans("Modifier")));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 50));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Circle Stick"), 0));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Angle"), 0.9, 0, 180));
}
ControllerEmu::Cursor::Cursor(const std::string& _name)
: ControlGroup(_name, GROUP_TYPE_CURSOR), m_z(0)
{
for (auto& named_direction : named_directions)
controls.emplace_back(std::make_unique<Input>(named_direction));
controls.emplace_back(std::make_unique<Input>("Forward"));
controls.emplace_back(std::make_unique<Input>("Backward"));
controls.emplace_back(std::make_unique<Input>(_trans("Hide")));
controls.emplace_back(std::make_unique<Input>("Recenter"));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Center"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Width"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Height"), 0.5));
numeric_settings.emplace_back(std::make_unique<NumericSetting>(_trans("Dead Zone"), 0, 0, 20));
boolean_settings.emplace_back(std::make_unique<BooleanSetting>(_trans("Relative Input"), false));
}
void ControllerEmu::LoadDefaults(const ControllerInterface& ciface)
{ {
// load an empty inifile section, clears everything // load an empty inifile section, clears everything
IniFile::Section sec; IniFile::Section sec;
@ -326,3 +99,4 @@ void ControllerEmu::LoadDefaults(const ControllerInterface& ciface)
UpdateDefaultDevice(); UpdateDefaultDevice();
} }
} }
} // namespace ControllerEmu

View File

@ -4,488 +4,27 @@
#pragma once #pragma once
#include <algorithm>
#include <cmath>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <string> #include <string>
#include <vector> #include <vector>
#include "Common/IniFile.h" #include "Common/IniFile.h"
#include "Common/MathUtil.h"
#include "Core/ConfigManager.h"
#include "InputCommon/ControlReference/ControlReference.h" #include "InputCommon/ControlReference/ControlReference.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/GCPadStatus.h"
#define sign(x) ((x) ? (x) < 0 ? -1 : 1 : 0) #define sign(x) ((x) ? (x) < 0 ? -1 : 1 : 0)
enum
{
GROUP_TYPE_OTHER,
GROUP_TYPE_STICK,
GROUP_TYPE_MIXED_TRIGGERS,
GROUP_TYPE_BUTTONS,
GROUP_TYPE_FORCE,
GROUP_TYPE_EXTENSION,
GROUP_TYPE_TILT,
GROUP_TYPE_CURSOR,
GROUP_TYPE_TRIGGERS,
GROUP_TYPE_SLIDER
};
enum
{
SETTING_RADIUS,
SETTING_DEADZONE,
};
const char* const named_directions[] = {"Up", "Down", "Left", "Right"}; const char* const named_directions[] = {"Up", "Down", "Left", "Right"};
class ControllerEmu namespace ControllerEmu
{
class ControlGroup;
class EmulatedController
{ {
public: public:
class ControlGroup virtual ~EmulatedController();
{
public:
class Control
{
protected:
Control(ControlReference* const _ref, const std::string& _name)
: control_ref(_ref), name(_name)
{
}
public:
virtual ~Control() {}
std::unique_ptr<ControlReference> const control_ref;
const std::string name;
};
class Input : public Control
{
public:
Input(const std::string& _name) : Control(new InputReference, _name) {}
};
class Output : public Control
{
public:
Output(const std::string& _name) : Control(new OutputReference, _name) {}
};
enum class SettingType
{
NORMAL, // normal settings are saved to configuration files
VIRTUAL, // virtual settings are not saved at all
};
class NumericSetting
{
public:
NumericSetting(const std::string& setting_name, const ControlState default_value,
const unsigned int low = 0, const unsigned int high = 100,
const SettingType setting_type = SettingType::NORMAL)
: m_type(setting_type), m_name(setting_name), m_default_value(default_value), m_low(low),
m_high(high)
{
}
ControlState GetValue() const { return m_value; }
void SetValue(ControlState value) { m_value = value; }
const SettingType m_type;
const std::string m_name;
const ControlState m_default_value;
const unsigned int m_low, m_high;
ControlState m_value;
};
class BooleanSetting
{
public:
BooleanSetting(const std::string& setting_name, const bool default_value,
const SettingType setting_type = SettingType::NORMAL)
: m_type(setting_type), m_name(setting_name), m_default_value(default_value)
{
}
virtual ~BooleanSetting();
virtual bool GetValue() const { return m_value; }
virtual void SetValue(bool value) { m_value = value; }
const SettingType m_type;
const std::string m_name;
const bool m_default_value;
bool m_value;
};
class BackgroundInputSetting : public BooleanSetting
{
public:
BackgroundInputSetting(const std::string& setting_name)
: BooleanSetting(setting_name, false, SettingType::VIRTUAL)
{
}
bool GetValue() const override { return SConfig::GetInstance().m_BackgroundInput; }
void SetValue(bool value) override
{
m_value = value;
SConfig::GetInstance().m_BackgroundInput = value;
}
};
ControlGroup(const std::string& _name, const unsigned int _type = GROUP_TYPE_OTHER)
: name(_name), ui_name(_name), type(_type)
{
}
ControlGroup(const std::string& _name, const std::string& _ui_name,
const unsigned int _type = GROUP_TYPE_OTHER)
: name(_name), ui_name(_ui_name), type(_type)
{
}
virtual ~ControlGroup() {}
virtual void LoadConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
virtual void SaveConfig(IniFile::Section* sec, const std::string& defdev = "",
const std::string& base = "");
void SetControlExpression(int index, const std::string& expression);
const std::string name;
const std::string ui_name;
const unsigned int type;
std::vector<std::unique_ptr<Control>> controls;
std::vector<std::unique_ptr<NumericSetting>> numeric_settings;
std::vector<std::unique_ptr<BooleanSetting>> boolean_settings;
};
class AnalogStick : public ControlGroup
{
public:
// The GameCube controller and Wiimote attachments have a different default radius
AnalogStick(const char* const _name, ControlState default_radius);
AnalogStick(const char* const _name, const char* const _ui_name, ControlState default_radius);
void GetState(ControlState* const x, ControlState* const y)
{
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
ControlState radius = numeric_settings[SETTING_RADIUS]->GetValue();
ControlState deadzone = numeric_settings[SETTING_DEADZONE]->GetValue();
ControlState m = controls[4]->control_ref->State();
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
ControlState ang_cos = cos(ang);
ControlState dist = sqrt(xx * xx + yy * yy);
// dead zone code
dist = std::max(0.0, dist - deadzone);
dist /= (1 - deadzone);
// radius
dist *= radius;
// The modifier halves the distance by 50%, which is useful
// for keyboard controls.
if (m)
dist *= 0.5;
yy = std::max(-1.0, std::min(1.0, ang_sin * dist));
xx = std::max(-1.0, std::min(1.0, ang_cos * dist));
*y = yy;
*x = xx;
}
};
class Buttons : public ControlGroup
{
public:
Buttons(const std::string& _name);
Buttons(const std::string& ini_name, const std::string& group_name);
template <typename C>
void GetState(C* const buttons, const C* bitmasks)
{
for (auto& control : controls)
{
if (control->control_ref->State() > numeric_settings[0]->GetValue()) // threshold
*buttons |= *bitmasks;
bitmasks++;
}
}
};
class ModifySettingsButton : public Buttons
{
public:
ModifySettingsButton(std::string button_name);
void AddInput(std::string button_name, bool toggle = false);
void GetState();
const std::vector<bool>& isSettingToggled() const { return associated_settings_toggle; }
const std::vector<bool>& getSettingsModifier() const { return associated_settings; }
private:
std::vector<bool> threshold_exceeded; // internal calculation (if "state" was above threshold)
std::vector<bool> associated_settings_toggle; // is setting toggled or hold?
std::vector<bool> associated_settings; // result
};
class MixedTriggers : public ControlGroup
{
public:
MixedTriggers(const std::string& _name);
void GetState(u16* const digital, const u16* bitmasks, ControlState* analog)
{
const unsigned int trig_count = ((unsigned int)(controls.size() / 2));
for (unsigned int i = 0; i < trig_count; ++i, ++bitmasks, ++analog)
{
if (controls[i]->control_ref->State() > numeric_settings[0]->GetValue()) // threshold
{
*analog = 1.0;
*digital |= *bitmasks;
}
else
{
*analog = controls[i + trig_count]->control_ref->State();
}
}
}
};
class Triggers : public ControlGroup
{
public:
Triggers(const std::string& _name);
void GetState(ControlState* analog)
{
const unsigned int trig_count = ((unsigned int)(controls.size()));
const ControlState deadzone = numeric_settings[0]->GetValue();
for (unsigned int i = 0; i < trig_count; ++i, ++analog)
*analog = std::max(controls[i]->control_ref->State() - deadzone, 0.0) / (1 - deadzone);
}
};
class Slider : public ControlGroup
{
public:
Slider(const std::string& _name);
void GetState(ControlState* const slider)
{
const ControlState deadzone = numeric_settings[0]->GetValue();
const ControlState state =
controls[1]->control_ref->State() - controls[0]->control_ref->State();
if (fabs(state) > deadzone)
*slider = (state - (deadzone * sign(state))) / (1 - deadzone);
else
*slider = 0;
}
};
class Force : public ControlGroup
{
public:
Force(const std::string& _name);
void GetState(ControlState* axis)
{
const ControlState deadzone = numeric_settings[0]->GetValue();
for (unsigned int i = 0; i < 6; i += 2)
{
ControlState tmpf = 0;
const ControlState state =
controls[i + 1]->control_ref->State() - controls[i]->control_ref->State();
if (fabs(state) > deadzone)
tmpf = ((state - (deadzone * sign(state))) / (1 - deadzone));
ControlState& ax = m_swing[i >> 1];
*axis++ = (tmpf - ax);
ax = tmpf;
}
}
private:
ControlState m_swing[3];
};
class Tilt : public ControlGroup
{
public:
Tilt(const std::string& _name);
void GetState(ControlState* const x, ControlState* const y, const bool step = true)
{
// this is all a mess
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
ControlState deadzone = numeric_settings[0]->GetValue();
ControlState circle = numeric_settings[1]->GetValue();
auto const angle = numeric_settings[2]->GetValue() / 1.8;
ControlState m = controls[4]->control_ref->State();
// deadzone / circle stick code
// this section might be all wrong, but its working good enough, I think
ControlState ang = atan2(yy, xx);
ControlState ang_sin = sin(ang);
ControlState ang_cos = cos(ang);
// the amt a full square stick would have at current angle
ControlState square_full =
std::min(ang_sin ? 1 / fabs(ang_sin) : 2, ang_cos ? 1 / fabs(ang_cos) : 2);
// the amt a full stick would have that was (user setting circular) at current angle
// I think this is more like a pointed circle rather than a rounded square like it should be
ControlState stick_full = (square_full * (1 - circle)) + (circle);
ControlState dist = sqrt(xx * xx + yy * yy);
// dead zone code
dist = std::max(0.0, dist - deadzone * stick_full);
dist /= (1 - deadzone);
// circle stick code
ControlState amt = dist / stick_full;
dist += (square_full - 1) * amt * circle;
if (m)
dist *= 0.5;
yy = std::max(-1.0, std::min(1.0, ang_sin * dist));
xx = std::max(-1.0, std::min(1.0, ang_cos * dist));
// this is kinda silly here
// gui being open will make this happen 2x as fast, o well
// silly
if (step)
{
if (xx > m_tilt[0])
m_tilt[0] = std::min(m_tilt[0] + 0.1, xx);
else if (xx < m_tilt[0])
m_tilt[0] = std::max(m_tilt[0] - 0.1, xx);
if (yy > m_tilt[1])
m_tilt[1] = std::min(m_tilt[1] + 0.1, yy);
else if (yy < m_tilt[1])
m_tilt[1] = std::max(m_tilt[1] - 0.1, yy);
}
*y = m_tilt[1] * angle;
*x = m_tilt[0] * angle;
}
private:
ControlState m_tilt[2];
};
class Cursor : public ControlGroup
{
public:
Cursor(const std::string& _name);
void GetState(ControlState* const x, ControlState* const y, ControlState* const z,
const bool adjusted = false)
{
const ControlState zz = controls[4]->control_ref->State() - controls[5]->control_ref->State();
// silly being here
if (zz > m_z)
m_z = std::min(m_z + 0.1, zz);
else if (zz < m_z)
m_z = std::max(m_z - 0.1, zz);
*z = m_z;
// hide
if (controls[6]->control_ref->State() > 0.5)
{
*x = 10000;
*y = 0;
}
else
{
ControlState yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
ControlState xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
// adjust cursor according to settings
if (adjusted)
{
xx *= (numeric_settings[1]->GetValue() * 2);
yy *= (numeric_settings[2]->GetValue() * 2);
yy += (numeric_settings[0]->GetValue() - 0.5);
}
// relative input
if (boolean_settings[0]->GetValue())
{
const ControlState deadzone = numeric_settings[3]->GetValue();
// deadzone to avoid the cursor slowly drifting
if (std::abs(xx) > deadzone)
m_x = MathUtil::Clamp(m_x + xx * SPEED_MULTIPLIER, -1.0, 1.0);
if (std::abs(yy) > deadzone)
m_y = MathUtil::Clamp(m_y + yy * SPEED_MULTIPLIER, -1.0, 1.0);
// recenter
if (controls[7]->control_ref->State() > 0.5)
{
m_x = 0.0;
m_y = 0.0;
}
}
else
{
m_x = xx;
m_y = yy;
}
*x = m_x;
*y = m_y;
}
}
ControlState m_z;
private:
// This is used to reduce the cursor speed for relative input
// to something that makes sense with the default range.
static constexpr double SPEED_MULTIPLIER = 0.04;
ControlState m_x = 0.0;
ControlState m_y = 0.0;
};
class Extension : public ControlGroup
{
public:
Extension(const std::string& _name)
: ControlGroup(_name, GROUP_TYPE_EXTENSION), switch_extension(0), active_extension(0)
{
}
~Extension() {}
void GetState(u8* const data);
bool IsButtonPressed() const;
std::vector<std::unique_ptr<ControllerEmu>> attachments;
int switch_extension;
int active_extension;
};
virtual ~ControllerEmu() {}
virtual std::string GetName() const = 0; virtual std::string GetName() const = 0;
virtual void LoadDefaults(const ControllerInterface& ciface); virtual void LoadDefaults(const ControllerInterface& ciface);
@ -506,3 +45,4 @@ public:
ciface::Core::DeviceQualifier default_device; ciface::Core::DeviceQualifier default_device;
}; };
} // namespace ControllerEmu

View File

@ -36,6 +36,20 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<ItemGroup> <ItemGroup>
<ClCompile Include="ControllerEmu\ControllerEmu.cpp" /> <ClCompile Include="ControllerEmu\ControllerEmu.cpp" />
<ClCompile Include="ControllerEmu\Control\Control.cpp" />
<ClCompile Include="ControllerEmu\Control\Input.cpp" />
<ClCompile Include="ControllerEmu\Control\Output.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\AnalogStick.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Buttons.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\ControlGroup.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Cursor.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Extension.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Force.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\MixedTriggers.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\ModifySettingsButton.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Slider.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Tilt.cpp" />
<ClCompile Include="ControllerEmu\ControlGroup\Triggers.cpp" />
<ClCompile Include="ControllerInterface\ControllerInterface.cpp" /> <ClCompile Include="ControllerInterface\ControllerInterface.cpp" />
<ClCompile Include="ControllerInterface\Device.cpp" /> <ClCompile Include="ControllerInterface\Device.cpp" />
<ClCompile Include="ControllerInterface\DInput\DInput.cpp" /> <ClCompile Include="ControllerInterface\DInput\DInput.cpp" />
@ -57,6 +71,20 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="ControllerEmu\ControllerEmu.h" /> <ClInclude Include="ControllerEmu\ControllerEmu.h" />
<ClInclude Include="ControllerEmu\Control\Control.h" />
<ClInclude Include="ControllerEmu\Control\Input.h" />
<ClInclude Include="ControllerEmu\Control\Output.h" />
<ClInclude Include="ControllerEmu\ControlGroup\AnalogStick.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Buttons.h" />
<ClInclude Include="ControllerEmu\ControlGroup\ControlGroup.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Cursor.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Extension.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Force.h" />
<ClInclude Include="ControllerEmu\ControlGroup\MixedTriggers.h" />
<ClInclude Include="ControllerEmu\ControlGroup\ModifySettingsButton.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Slider.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Tilt.h" />
<ClInclude Include="ControllerEmu\ControlGroup\Triggers.h" />
<ClInclude Include="ControllerInterface\ControllerInterface.h" /> <ClInclude Include="ControllerInterface\ControllerInterface.h" />
<ClInclude Include="ControllerInterface\Device.h" /> <ClInclude Include="ControllerInterface\Device.h" />
<ClInclude Include="ControllerInterface\DInput\DInput.h" /> <ClInclude Include="ControllerInterface\DInput\DInput.h" />

View File

@ -16,6 +16,12 @@
<Filter Include="ControllerEmu"> <Filter Include="ControllerEmu">
<UniqueIdentifier>{4c839215-4085-4e34-a960-7960986ad015}</UniqueIdentifier> <UniqueIdentifier>{4c839215-4085-4e34-a960-7960986ad015}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="ControllerEmu\Control">
<UniqueIdentifier>{19ddd862-a1e3-479b-b638-bb31700c5171}</UniqueIdentifier>
</Filter>
<Filter Include="ControllerEmu\ControlGroup">
<UniqueIdentifier>{e805231c-dc4e-4540-8bf8-8c567f3d00ae}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="GCAdapter.cpp" /> <ClCompile Include="GCAdapter.cpp" />
@ -23,6 +29,48 @@
<ClCompile Include="ControllerEmu\ControllerEmu.cpp"> <ClCompile Include="ControllerEmu\ControllerEmu.cpp">
<Filter>ControllerEmu</Filter> <Filter>ControllerEmu</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ControllerEmu\Control\Control.cpp">
<Filter>ControllerEmu\Control</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\Control\Input.cpp">
<Filter>ControllerEmu\Control</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\Control\Output.cpp">
<Filter>ControllerEmu\Control</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\AnalogStick.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Buttons.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\ControlGroup.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Cursor.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Extension.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Force.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\MixedTriggers.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\ModifySettingsButton.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Slider.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Tilt.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerEmu\ControlGroup\Triggers.cpp">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClCompile>
<ClCompile Include="ControllerInterface\DInput\DInput.cpp"> <ClCompile Include="ControllerInterface\DInput\DInput.cpp">
<Filter>ControllerInterface\DInput</Filter> <Filter>ControllerInterface\DInput</Filter>
</ClCompile> </ClCompile>
@ -61,6 +109,48 @@
<ClInclude Include="ControllerEmu\ControllerEmu.h"> <ClInclude Include="ControllerEmu\ControllerEmu.h">
<Filter>ControllerEmu</Filter> <Filter>ControllerEmu</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="ControllerEmu\Control\Control.h">
<Filter>ControllerEmu\Control</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\Control\Input.h">
<Filter>ControllerEmu\Control</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\Control\Output.h">
<Filter>ControllerEmu\Control</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\AnalogStick.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Buttons.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\ControlGroup.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Cursor.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Extension.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Force.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\MixedTriggers.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\ModifySettingsButton.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Slider.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Tilt.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerEmu\ControlGroup\Triggers.h">
<Filter>ControllerEmu\ControlGroup</Filter>
</ClInclude>
<ClInclude Include="ControllerInterface\DInput\DInput.h"> <ClInclude Include="ControllerInterface\DInput\DInput.h">
<Filter>ControllerInterface\DInput</Filter> <Filter>ControllerInterface\DInput</Filter>
</ClInclude> </ClInclude>
@ -98,4 +188,4 @@
<ItemGroup> <ItemGroup>
<Text Include="CMakeLists.txt" /> <Text Include="CMakeLists.txt" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -9,10 +9,19 @@
#include "Common/MsgHandler.h" #include "Common/MsgHandler.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h" #include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h" #include "InputCommon/ControllerInterface/ControllerInterface.h"
#include "InputCommon/InputConfig.h" #include "InputCommon/InputConfig.h"
InputConfig::InputConfig(const std::string& ini_name, const std::string& gui_name,
const std::string& profile_name)
: m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name)
{
}
InputConfig::~InputConfig() = default;
bool InputConfig::LoadConfig(bool isGC) bool InputConfig::LoadConfig(bool isGC)
{ {
IniFile inifile; IniFile inifile;
@ -104,7 +113,7 @@ void InputConfig::SaveConfig()
inifile.Save(ini_filename); inifile.Save(ini_filename);
} }
ControllerEmu* InputConfig::GetController(int index) ControllerEmu::EmulatedController* InputConfig::GetController(int index)
{ {
return m_controllers.at(index).get(); return m_controllers.at(index).get();
} }

View File

@ -9,16 +9,18 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
class ControllerEmu; namespace ControllerEmu
{
class EmulatedController;
}
class InputConfig class InputConfig
{ {
public: public:
InputConfig(const std::string& ini_name, const std::string& gui_name, InputConfig(const std::string& ini_name, const std::string& gui_name,
const std::string& profile_name) const std::string& profile_name);
: m_ini_name(ini_name), m_gui_name(gui_name), m_profile_name(profile_name)
{ ~InputConfig();
}
bool LoadConfig(bool isGC); bool LoadConfig(bool isGC);
void SaveConfig(); void SaveConfig();
@ -29,7 +31,7 @@ public:
m_controllers.emplace_back(std::make_unique<T>(std::forward<Args>(args)...)); m_controllers.emplace_back(std::make_unique<T>(std::forward<Args>(args)...));
} }
ControllerEmu* GetController(int index); ControllerEmu::EmulatedController* GetController(int index);
void ClearControllers(); void ClearControllers();
bool ControllersNeedToBeCreated() const; bool ControllersNeedToBeCreated() const;
bool IsControllerControlledByGamepadDevice(int index) const; bool IsControllerControlledByGamepadDevice(int index) const;
@ -37,7 +39,7 @@ public:
std::string GetGUIName() const { return m_gui_name; } std::string GetGUIName() const { return m_gui_name; }
std::string GetProfileName() const { return m_profile_name; } std::string GetProfileName() const { return m_profile_name; }
private: private:
std::vector<std::unique_ptr<ControllerEmu>> m_controllers; std::vector<std::unique_ptr<ControllerEmu::EmulatedController>> m_controllers;
const std::string m_ini_name; const std::string m_ini_name;
const std::string m_gui_name; const std::string m_gui_name;
const std::string m_profile_name; const std::string m_profile_name;