Skip to content

Commit

Permalink
ControllerEmu: Separate ControlGroup from ControllerEmu
Browse files Browse the repository at this point in the history
ControllerEmu, the class, is essentially acting like a namespace for
ControlGroup. This makes it impossible to forward declare any of the
internals. It also globs a bunch of classes together which is kind of a
pain to manage.

This splits ControlGroup and the classes it contains into their own source
files and situates them all within a namespace, which gets them out of
global scope.

Since this allows forward declarations for the once-internal classes, it
now requires significantly less files to be rebuilt if anything is changed
in the ControllerEmu portion of code.

It does not split out the settings classes yet, however, as it
would be preferable to make a settings base class that all settings derive
from, but this would be a functional change -- this commit only intends to
move around existing code. Extracting the settings class will be done in
another commit.
  • Loading branch information
lioncash committed Feb 9, 2017
1 parent 1385a01 commit e6df5f2
Show file tree
Hide file tree
Showing 69 changed files with 1,807 additions and 971 deletions.
5 changes: 3 additions & 2 deletions Source/Core/Core/Analytics.cpp
@@ -1,3 +1,5 @@
#include "Core/Analytics.h"

#include <cinttypes>
#include <mbedtls/sha1.h>
#include <memory>
Expand All @@ -16,12 +18,11 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "Core/Analytics.h"
#include "Core/ConfigManager.h"
#include "Core/HW/GCPad.h"
#include "Core/Movie.h"
#include "Core/NetPlayProto.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/GCAdapter.h"
#include "InputCommon/InputConfig.h"
#include "VideoCommon/VideoBackendBase.h"
Expand Down
1 change: 1 addition & 0 deletions Source/Core/Core/Analytics.h
Expand Up @@ -6,6 +6,7 @@

#include <memory>
#include <mutex>
#include <string>

#include "Common/Analytics.h"

Expand Down
7 changes: 5 additions & 2 deletions Source/Core/Core/HW/GCKeyboard.cpp
Expand Up @@ -2,13 +2,16 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Core/HW/GCKeyboard.h"

#include <cstring>

#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Core/HW/GCKeyboard.h"

#include "Core/HW/GCKeyboardEmu.h"
#include "InputCommon/ControllerInterface/ControllerInterface.h"

#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/InputConfig.h"
#include "InputCommon/KeyboardStatus.h"

Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/HW/GCKeyboard.h
Expand Up @@ -5,12 +5,16 @@
#pragma once

#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"

class InputConfig;
enum class KeyboardGroup;
struct KeyboardStatus;

namespace ControllerEmu
{
class ControlGroup;
}

namespace Keyboard
{
void Shutdown();
Expand Down
43 changes: 25 additions & 18 deletions Source/Core/Core/HW/GCKeyboardEmu.cpp
Expand Up @@ -3,7 +3,12 @@
// Refer to the license.txt file included.

#include "Core/HW/GCKeyboardEmu.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/KeyboardStatus.h"

Expand Down Expand Up @@ -48,36 +53,38 @@ static const char* const named_keys5[] = {"LEFT", "DOWN", "UP", "RIGHT", "ENTER"
GCKeyboard::GCKeyboard(const unsigned int index) : m_index(index)
{
// 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)
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)
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)
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)
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)
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)
m_keys5x->controls.emplace_back(new ControlGroup::Input(key));
m_keys5x->controls.emplace_back(new ControllerEmu::Input(key));

// 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(
std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
_trans("Background Input")));
m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input")));
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL));
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
}

std::string GCKeyboard::GetName() const
Expand Down Expand Up @@ -110,7 +117,7 @@ ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group)

KeyboardStatus GCKeyboard::GetInput() const
{
auto lock = ControllerEmu::GetStateLock();
const auto lock = GetStateLock();

KeyboardStatus kb = {};

Expand All @@ -126,7 +133,7 @@ KeyboardStatus GCKeyboard::GetInput() const

void GCKeyboard::LoadDefaults(const ControllerInterface& ciface)
{
ControllerEmu::LoadDefaults(ciface);
EmulatedController::LoadDefaults(ciface);

// Buttons
m_keys0x->SetControlExpression(5, "A");
Expand Down
24 changes: 15 additions & 9 deletions Source/Core/Core/HW/GCKeyboardEmu.h
Expand Up @@ -10,6 +10,12 @@

struct KeyboardStatus;

namespace ControllerEmu
{
class ControlGroup;
class Buttons;
}

enum class KeyboardGroup
{
Kb0x,
Expand All @@ -22,23 +28,23 @@ enum class KeyboardGroup
Options
};

class GCKeyboard : public ControllerEmu
class GCKeyboard : public ControllerEmu::EmulatedController
{
public:
explicit GCKeyboard(unsigned int index);
KeyboardStatus GetInput() const;
std::string GetName() const override;
ControlGroup* GetGroup(KeyboardGroup group);
ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group);
void LoadDefaults(const ControllerInterface& ciface) override;

private:
Buttons* m_keys0x;
Buttons* m_keys1x;
Buttons* m_keys2x;
Buttons* m_keys3x;
Buttons* m_keys4x;
Buttons* m_keys5x;
ControlGroup* m_options;
ControllerEmu::Buttons* m_keys0x;
ControllerEmu::Buttons* m_keys1x;
ControllerEmu::Buttons* m_keys2x;
ControllerEmu::Buttons* m_keys3x;
ControllerEmu::Buttons* m_keys4x;
ControllerEmu::Buttons* m_keys5x;
ControllerEmu::ControlGroup* m_options;

const unsigned int m_index;
};
4 changes: 3 additions & 1 deletion Source/Core/Core/HW/GCPad.cpp
Expand Up @@ -2,11 +2,13 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Core/HW/GCPad.h"

#include <cstring>

#include "Common/Common.h"
#include "Core/HW/GCPad.h"
#include "Core/HW/GCPadEmu.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/GCPadStatus.h"
#include "InputCommon/InputConfig.h"

Expand Down
6 changes: 5 additions & 1 deletion Source/Core/Core/HW/GCPad.h
Expand Up @@ -5,13 +5,17 @@
#pragma once

#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu/ControllerEmu.h"
#include "InputCommon/ControllerInterface/Device.h"

class InputConfig;
enum class PadGroup;
struct GCPadStatus;

namespace ControllerEmu
{
class ControlGroup;
}

namespace Pad
{
void Shutdown();
Expand Down
56 changes: 33 additions & 23 deletions Source/Core/Core/HW/GCPadEmu.cpp
Expand Up @@ -3,9 +3,17 @@
// Refer to the license.txt file included.

#include "Core/HW/GCPadEmu.h"

#include "Common/Common.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[] = {
PAD_BUTTON_A,
Expand Down Expand Up @@ -39,40 +47,42 @@ static const char* const named_triggers[] = {
GCPad::GCPad(const unsigned int index) : m_index(index)
{
// 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)
m_buttons->controls.emplace_back(new ControlGroup::Input(named_buttons[i]));
m_buttons->controls.emplace_back(new ControllerEmu::Input(named_buttons[i]));

// sticks
groups.emplace_back(m_main_stick = new AnalogStick("Main Stick", _trans("Control Stick"),
DEFAULT_PAD_STICK_RADIUS));
groups.emplace_back(m_c_stick =
new AnalogStick("C-Stick", _trans("C Stick"), DEFAULT_PAD_STICK_RADIUS));
groups.emplace_back(m_main_stick = new ControllerEmu::AnalogStick(
"Main Stick", _trans("Control Stick"), DEFAULT_PAD_STICK_RADIUS));
groups.emplace_back(m_c_stick = new ControllerEmu::AnalogStick("C-Stick", _trans("C Stick"),
DEFAULT_PAD_STICK_RADIUS));

// 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)
m_triggers->controls.emplace_back(new ControlGroup::Input(named_trigger));
m_triggers->controls.emplace_back(new ControllerEmu::Input(named_trigger));

// rumble
groups.emplace_back(m_rumble = new ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(new ControlGroup::Output(_trans("Motor")));
groups.emplace_back(m_rumble = new ControllerEmu::ControlGroup(_trans("Rumble")));
m_rumble->controls.emplace_back(new ControllerEmu::Output(_trans("Motor")));

// Microphone
groups.emplace_back(m_mic = new Buttons(_trans("Microphone")));
m_mic->controls.emplace_back(new ControlGroup::Input(_trans("Button")));
groups.emplace_back(m_mic = new ControllerEmu::Buttons(_trans("Microphone")));
m_mic->controls.emplace_back(new ControllerEmu::Input(_trans("Button")));

// 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)
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction));
m_dpad->controls.emplace_back(new ControllerEmu::Input(named_direction));

// 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(
std::make_unique<ControllerEmu::ControlGroup::BackgroundInputSetting>(
_trans("Background Input")));
m_options->boolean_settings.emplace_back(
std::make_unique<ControlGroup::BackgroundInputSetting>(_trans("Background Input")));
m_options->boolean_settings.emplace_back(std::make_unique<ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControlGroup::SettingType::VIRTUAL));
std::make_unique<ControllerEmu::ControlGroup::BooleanSetting>(
_trans("Iterative Input"), false, ControllerEmu::ControlGroup::SettingType::VIRTUAL));
}

std::string GCPad::GetName() const
Expand Down Expand Up @@ -107,7 +117,7 @@ ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group)

GCPadStatus GCPad::GetInput() const
{
auto lock = ControllerEmu::GetStateLock();
const auto lock = GetStateLock();

ControlState x, y, triggers[2];
GCPadStatus pad = {};
Expand Down Expand Up @@ -147,13 +157,13 @@ GCPadStatus GCPad::GetInput() const

void GCPad::SetOutput(const ControlState strength)
{
auto lock = ControllerEmu::GetStateLock();
const auto lock = GetStateLock();
m_rumble->controls[0]->control_ref->State(strength);
}

void GCPad::LoadDefaults(const ControllerInterface& ciface)
{
ControllerEmu::LoadDefaults(ciface);
EmulatedController::LoadDefaults(ciface);

// Buttons
m_buttons->SetControlExpression(0, "X"); // A
Expand Down Expand Up @@ -222,6 +232,6 @@ void GCPad::LoadDefaults(const ControllerInterface& ciface)

bool GCPad::GetMicButton() const
{
auto lock = ControllerEmu::GetStateLock();
const auto lock = GetStateLock();
return (0.0f != m_mic->controls.back()->control_ref->State());
}
28 changes: 18 additions & 10 deletions Source/Core/Core/HW/GCPadEmu.h
Expand Up @@ -8,7 +8,15 @@

#include "InputCommon/ControllerEmu/ControllerEmu.h"

struct GCPadStatus;

namespace ControllerEmu
{
class AnalogStick;
class Buttons;
class ControlGroup;
class MixedTriggers;
}

enum class PadGroup
{
Expand All @@ -22,7 +30,7 @@ enum class PadGroup
Options
};

class GCPad : public ControllerEmu
class GCPad : public ControllerEmu::EmulatedController
{
public:
explicit GCPad(unsigned int index);
Expand All @@ -33,19 +41,19 @@ class GCPad : public ControllerEmu

std::string GetName() const override;

ControlGroup* GetGroup(PadGroup group);
ControllerEmu::ControlGroup* GetGroup(PadGroup group);

void LoadDefaults(const ControllerInterface& ciface) override;

private:
Buttons* m_buttons;
AnalogStick* m_main_stick;
AnalogStick* m_c_stick;
Buttons* m_dpad;
MixedTriggers* m_triggers;
ControlGroup* m_rumble;
Buttons* m_mic;
ControlGroup* m_options;
ControllerEmu::Buttons* m_buttons;
ControllerEmu::AnalogStick* m_main_stick;
ControllerEmu::AnalogStick* m_c_stick;
ControllerEmu::Buttons* m_dpad;
ControllerEmu::MixedTriggers* m_triggers;
ControllerEmu::ControlGroup* m_rumble;
ControllerEmu::Buttons* m_mic;
ControllerEmu::ControlGroup* m_options;

const unsigned int m_index;

Expand Down

0 comments on commit e6df5f2

Please sign in to comment.