Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #23 from lioncash/sorta-large-input-cleanup
Larger cleanup to input-related source files (this time using unique_ptr).
  • Loading branch information
delroth committed Feb 2, 2014
2 parents 70f66ad + 3efb0aa commit 3363b39
Show file tree
Hide file tree
Showing 30 changed files with 640 additions and 791 deletions.
24 changes: 12 additions & 12 deletions Source/Core/Core/HW/GCPadEmu.cpp
Expand Up @@ -55,31 +55,31 @@ GCPad::GCPad(const unsigned int index) : m_index(index)
int const mic_hax = index > 1;

// buttons
groups.push_back(m_buttons = new Buttons(_trans("Buttons")));
groups.emplace_back(m_buttons = new Buttons(_trans("Buttons")));
for (unsigned int i=0; i < sizeof(named_buttons)/sizeof(*named_buttons) - mic_hax; ++i)
m_buttons->controls.push_back(new ControlGroup::Input(named_buttons[i]));
m_buttons->controls.emplace_back(new ControlGroup::Input(named_buttons[i]));

// sticks
groups.push_back(m_main_stick = new AnalogStick(_trans("Main Stick")));
groups.push_back(m_c_stick = new AnalogStick(_trans("C-Stick")));
groups.emplace_back(m_main_stick = new AnalogStick(_trans("Main Stick")));
groups.emplace_back(m_c_stick = new AnalogStick(_trans("C-Stick")));

// triggers
groups.push_back(m_triggers = new MixedTriggers(_trans("Triggers")));
groups.emplace_back(m_triggers = new MixedTriggers(_trans("Triggers")));
for (auto& named_trigger : named_triggers)
m_triggers->controls.push_back(new ControlGroup::Input(named_trigger));
m_triggers->controls.emplace_back(new ControlGroup::Input(named_trigger));

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

// dpad
groups.push_back(m_dpad = new Buttons(_trans("D-Pad")));
groups.emplace_back(m_dpad = new Buttons(_trans("D-Pad")));
for (auto& named_direction : named_directions)
m_dpad->controls.push_back(new ControlGroup::Input(named_direction));
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction));

// options
groups.push_back(m_options = new ControlGroup(_trans("Options")));
m_options->settings.push_back(new ControlGroup::Setting(_trans("Background Input"), false));
groups.emplace_back(m_options = new ControlGroup(_trans("Options")));
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Background Input"), false));
}

std::string GCPad::GetName() const
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.cpp
Expand Up @@ -43,5 +43,5 @@ void Attachment::Reset()

void ControllerEmu::Extension::GetState( u8* const data, const bool focus )
{
((WiimoteEmu::Attachment*)attachments[ active_extension ])->GetState( data, focus );
((WiimoteEmu::Attachment*)attachments[active_extension].get())->GetState( data, focus );
}
10 changes: 5 additions & 5 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Attachment.h
Expand Up @@ -14,14 +14,14 @@ namespace WiimoteEmu
class Attachment : public ControllerEmu
{
public:
Attachment( const char* const _name, WiimoteEmu::ExtensionReg& _reg );
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg);

virtual void GetState( u8* const data, const bool focus = true ) {}
virtual void GetState(u8* const data, const bool focus = true) {}
void Reset();
std::string GetName() const override;

const char* const name;
WiimoteEmu::ExtensionReg& reg;
const char* const name;
WiimoteEmu::ExtensionReg& reg;

u8 id[6];
u8 calibration[0x10];
Expand All @@ -30,7 +30,7 @@ class Attachment : public ControllerEmu
class None : public Attachment
{
public:
None( WiimoteEmu::ExtensionReg& _reg );
None(WiimoteEmu::ExtensionReg& _reg);
};

}
Expand Down
16 changes: 8 additions & 8 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.cpp
Expand Up @@ -56,23 +56,23 @@ static const u16 classic_dpad_bitmasks[] =
Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"), _reg)
{
// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
groups.emplace_back(m_buttons = new Buttons("Buttons"));
for (auto& classic_button_name : classic_button_names)
m_buttons->controls.push_back(new ControlGroup::Input(classic_button_name));
m_buttons->controls.emplace_back(new ControlGroup::Input(classic_button_name));

// sticks
groups.push_back(m_left_stick = new AnalogStick(_trans("Left Stick")));
groups.push_back(m_right_stick = new AnalogStick(_trans("Right Stick")));
groups.emplace_back(m_left_stick = new AnalogStick(_trans("Left Stick")));
groups.emplace_back(m_right_stick = new AnalogStick(_trans("Right Stick")));

// triggers
groups.push_back(m_triggers = new MixedTriggers("Triggers"));
groups.emplace_back(m_triggers = new MixedTriggers("Triggers"));
for (auto& classic_trigger_name : classic_trigger_names)
m_triggers->controls.push_back(new ControlGroup::Input(classic_trigger_name));
m_triggers->controls.emplace_back(new ControlGroup::Input(classic_trigger_name));

// dpad
groups.push_back(m_dpad = new Buttons("D-Pad"));
groups.emplace_back(m_dpad = new Buttons("D-Pad"));
for (auto& named_direction : named_directions)
m_dpad->controls.push_back(new ControlGroup::Input(named_direction));
m_dpad->controls.emplace_back(new ControlGroup::Input(named_direction));

// set up register
// calibration
Expand Down
42 changes: 21 additions & 21 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Classic.h
Expand Up @@ -11,34 +11,34 @@ class Classic : public Attachment
{
public:
Classic(WiimoteEmu::ExtensionReg& _reg);
void GetState( u8* const data, const bool focus );
void GetState(u8* const data, const bool focus) override;

enum
{
PAD_RIGHT = 0x80,
PAD_DOWN = 0x40,
TRIGGER_L = 0x20,
PAD_RIGHT = 0x80,
PAD_DOWN = 0x40,
TRIGGER_L = 0x20,
BUTTON_MINUS = 0x10,
BUTTON_HOME = 0x08,
BUTTON_PLUS = 0x04,
TRIGGER_R = 0x02,
NOTHING = 0x01,
BUTTON_ZL = 0x8000,
BUTTON_B = 0x4000,
BUTTON_Y = 0x2000,
BUTTON_A = 0x1000,
BUTTON_X = 0x0800,
BUTTON_ZR = 0x0400,
PAD_LEFT = 0x0200,
PAD_UP = 0x0100,
BUTTON_HOME = 0x08,
BUTTON_PLUS = 0x04,
TRIGGER_R = 0x02,
NOTHING = 0x01,
BUTTON_ZL = 0x8000,
BUTTON_B = 0x4000,
BUTTON_Y = 0x2000,
BUTTON_A = 0x1000,
BUTTON_X = 0x0800,
BUTTON_ZR = 0x0400,
PAD_LEFT = 0x0200,
PAD_UP = 0x0100,
};

private:
Buttons* m_buttons;
MixedTriggers* m_triggers;
Buttons* m_dpad;
AnalogStick* m_left_stick;
AnalogStick* m_right_stick;
Buttons* m_buttons;
MixedTriggers* m_triggers;
Buttons* m_dpad;
AnalogStick* m_left_stick;
AnalogStick* m_right_stick;
};


Expand Down
12 changes: 6 additions & 6 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.cpp
Expand Up @@ -35,17 +35,17 @@ static const u16 drum_button_bitmasks[] =
Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
{
// pads
groups.push_back(m_pads = new Buttons(_trans("Pads")));
groups.emplace_back(m_pads = new Buttons(_trans("Pads")));
for (auto& drum_pad_name : drum_pad_names)
m_pads->controls.push_back(new ControlGroup::Input(drum_pad_name));
m_pads->controls.emplace_back(new ControlGroup::Input(drum_pad_name));

// stick
groups.push_back(m_stick = new AnalogStick("Stick"));
groups.emplace_back(m_stick = new AnalogStick("Stick"));

// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.push_back(new ControlGroup::Input("-"));
m_buttons->controls.push_back(new ControlGroup::Input("+"));
groups.emplace_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("-"));
m_buttons->controls.emplace_back(new ControlGroup::Input("+"));

// set up register
// id
Expand Down
22 changes: 11 additions & 11 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Drums.h
Expand Up @@ -11,25 +11,25 @@ class Drums : public Attachment
{
public:
Drums(WiimoteEmu::ExtensionReg& _reg);
void GetState( u8* const data, const bool focus );
void GetState(u8* const data, const bool focus) override;

enum
{
BUTTON_PLUS = 0x04,
BUTTON_PLUS = 0x04,
BUTTON_MINUS = 0x10,

PAD_BASS = 0x0400,
PAD_BLUE = 0x0800,
PAD_GREEN = 0x1000,
PAD_YELLOW = 0x2000,
PAD_RED = 0x4000,
PAD_ORANGE = 0x8000,
PAD_BASS = 0x0400,
PAD_BLUE = 0x0800,
PAD_GREEN = 0x1000,
PAD_YELLOW = 0x2000,
PAD_RED = 0x4000,
PAD_ORANGE = 0x8000,
};

private:
Buttons* m_buttons;
Buttons* m_pads;
AnalogStick* m_stick;
Buttons* m_buttons;
Buttons* m_pads;
AnalogStick* m_stick;
};


Expand Down
22 changes: 11 additions & 11 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.cpp
Expand Up @@ -39,26 +39,26 @@ static const u16 guitar_strum_bitmasks[] =
Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _reg)
{
// frets
groups.push_back(m_frets = new Buttons(_trans("Frets")));
groups.emplace_back(m_frets = new Buttons(_trans("Frets")));
for (auto& guitar_fret_name : guitar_fret_names)
m_frets->controls.push_back(new ControlGroup::Input(guitar_fret_name));
m_frets->controls.emplace_back(new ControlGroup::Input(guitar_fret_name));

// strum
groups.push_back(m_strum = new Buttons(_trans("Strum")));
m_strum->controls.push_back(new ControlGroup::Input("Up"));
m_strum->controls.push_back(new ControlGroup::Input("Down"));
groups.emplace_back(m_strum = new Buttons(_trans("Strum")));
m_strum->controls.emplace_back(new ControlGroup::Input("Up"));
m_strum->controls.emplace_back(new ControlGroup::Input("Down"));

// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.push_back(new ControlGroup::Input("-"));
m_buttons->controls.push_back(new ControlGroup::Input("+"));
groups.emplace_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("-"));
m_buttons->controls.emplace_back(new ControlGroup::Input("+"));

// stick
groups.push_back(m_stick = new AnalogStick(_trans("Stick")));
groups.emplace_back(m_stick = new AnalogStick(_trans("Stick")));

// whammy
groups.push_back(m_whammy = new Triggers(_trans("Whammy")));
m_whammy->controls.push_back(new ControlGroup::Input(_trans("Bar")));
groups.emplace_back(m_whammy = new Triggers(_trans("Whammy")));
m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar")));

// set up register
// id
Expand Down
30 changes: 15 additions & 15 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Guitar.h
Expand Up @@ -11,28 +11,28 @@ class Guitar : public Attachment
{
public:
Guitar(WiimoteEmu::ExtensionReg& _reg);
void GetState( u8* const data, const bool focus ) override;
void GetState(u8* const data, const bool focus) override;

enum
{
BUTTON_PLUS = 0x04,
BUTTON_PLUS = 0x04,
BUTTON_MINUS = 0x10,
BAR_DOWN = 0x40,

BAR_UP = 0x0100,
FRET_YELLOW = 0x0800,
FRET_GREEN = 0x1000,
FRET_BLUE = 0x2000,
FRET_RED = 0x4000,
FRET_ORANGE = 0x8000,
BAR_DOWN = 0x40,

BAR_UP = 0x0100,
FRET_YELLOW = 0x0800,
FRET_GREEN = 0x1000,
FRET_BLUE = 0x2000,
FRET_RED = 0x4000,
FRET_ORANGE = 0x8000,
};

private:
Buttons* m_buttons;
Buttons* m_frets;
Buttons* m_strum;
Triggers* m_whammy;
AnalogStick* m_stick;
Buttons* m_buttons;
Buttons* m_frets;
Buttons* m_strum;
Triggers* m_whammy;
AnalogStick* m_stick;
};


Expand Down
42 changes: 21 additions & 21 deletions Source/Core/Core/HW/WiimoteEmu/Attachment/Nunchuk.cpp
Expand Up @@ -35,24 +35,24 @@ Nunchuk::Nunchuk(UDPWrapper *wrp, WiimoteEmu::ExtensionReg& _reg)
: Attachment(_trans("Nunchuk"), _reg) , m_udpWrap(wrp)
{
// buttons
groups.push_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.push_back(new ControlGroup::Input("C"));
m_buttons->controls.push_back(new ControlGroup::Input("Z"));
groups.emplace_back(m_buttons = new Buttons("Buttons"));
m_buttons->controls.emplace_back(new ControlGroup::Input("C"));
m_buttons->controls.emplace_back(new ControlGroup::Input("Z"));

// stick
groups.push_back(m_stick = new AnalogStick("Stick"));
groups.emplace_back(m_stick = new AnalogStick("Stick"));

// swing
groups.push_back(m_swing = new Force("Swing"));
groups.emplace_back(m_swing = new Force("Swing"));

// tilt
groups.push_back(m_tilt = new Tilt("Tilt"));
groups.emplace_back(m_tilt = new Tilt("Tilt"));

// shake
groups.push_back(m_shake = new Buttons("Shake"));
m_shake->controls.push_back(new ControlGroup::Input("X"));
m_shake->controls.push_back(new ControlGroup::Input("Y"));
m_shake->controls.push_back(new ControlGroup::Input("Z"));
groups.emplace_back(m_shake = new Buttons("Shake"));
m_shake->controls.emplace_back(new ControlGroup::Input("X"));
m_shake->controls.emplace_back(new ControlGroup::Input("Y"));
m_shake->controls.emplace_back(new ControlGroup::Input("Z"));

// set up register
// calibration
Expand Down Expand Up @@ -159,24 +159,24 @@ void Nunchuk::GetState(u8* const data, const bool focus)
void Nunchuk::LoadDefaults(const ControllerInterface& ciface)
{
// ugly macroooo
#define set_control(group, num, str) (group)->controls[num]->control_ref->expression = (str)
#define set_control(group, num, str) (group)->controls[num]->control_ref->expression = (str)

// Stick
set_control(m_stick, 0, "W"); // up
set_control(m_stick, 1, "S"); // down
set_control(m_stick, 2, "A"); // left
set_control(m_stick, 3, "D"); // right
set_control(m_stick, 0, "W"); // up
set_control(m_stick, 1, "S"); // down
set_control(m_stick, 2, "A"); // left
set_control(m_stick, 3, "D"); // right

// Buttons
#ifdef _WIN32
set_control(m_buttons, 0, "LCONTROL"); // C
set_control(m_buttons, 1, "LSHIFT"); // Z
set_control(m_buttons, 0, "LCONTROL"); // C
set_control(m_buttons, 1, "LSHIFT"); // Z
#elif __APPLE__
set_control(m_buttons, 0, "Left Control"); // C
set_control(m_buttons, 1, "Left Shift"); // Z
set_control(m_buttons, 0, "Left Control"); // C
set_control(m_buttons, 1, "Left Shift"); // Z
#else
set_control(m_buttons, 0, "Control_L"); // C
set_control(m_buttons, 1, "Shift_L"); // Z
set_control(m_buttons, 0, "Control_L"); // C
set_control(m_buttons, 1, "Shift_L"); // Z
#endif
}

Expand Down

0 comments on commit 3363b39

Please sign in to comment.