Attachment: Use std::array over C arrays

This commit is contained in:
Lioncash 2017-01-23 00:10:25 -05:00
parent 4b2f40a634
commit c87ee2a00e
12 changed files with 131 additions and 131 deletions

View File

@ -2,45 +2,45 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
#include <algorithm>
#include <array>
#include <cstring> #include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
// Extension device IDs to be written to the last bytes of the extension reg // Extension device IDs to be written to the last bytes of the extension reg
// The id for nothing inserted // The id for nothing inserted
static const u8 nothing_id[] = {0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e}; constexpr std::array<u8, 6> nothing_id{{0x00, 0x00, 0x00, 0x00, 0x2e, 0x2e}};
// The id for a partially inserted extension (currently unused) // The id for a partially inserted extension (currently unused)
UNUSED static const u8 partially_id[] = {0x00, 0x00, 0x00, 0x00, 0xff, 0xff}; UNUSED constexpr std::array<u8, 6> partially_id{{0x00, 0x00, 0x00, 0x00, 0xff, 0xff}};
Attachment::Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg) Attachment::Attachment(const char* const name, ExtensionReg& reg) : m_name(name), m_reg(reg)
: name(_name), reg(_reg)
{ {
memset(id, 0, sizeof(id));
memset(calibration, 0, sizeof(calibration));
} }
None::None(WiimoteEmu::ExtensionReg& _reg) : Attachment("None", _reg) None::None(ExtensionReg& reg) : Attachment("None", reg)
{ {
// set up register // set up register
memcpy(&id, nothing_id, sizeof(nothing_id)); m_id = nothing_id;
} }
std::string Attachment::GetName() const std::string Attachment::GetName() const
{ {
return name; return m_name;
} }
void Attachment::Reset() void Attachment::Reset()
{ {
// set up register // set up register
memset(&reg, 0, WIIMOTE_REG_EXT_SIZE); m_reg = {};
memcpy(&reg.constant_id, id, sizeof(id)); std::copy(m_id.cbegin(), m_id.cend(), m_reg.constant_id);
memcpy(&reg.calibration, calibration, sizeof(calibration)); std::copy(m_calibration.cbegin(), m_calibration.cend(), m_reg.calibration);
} }
} }

View File

@ -4,6 +4,9 @@
#pragma once #pragma once
#include <array>
#include <string>
#include "Common/CommonTypes.h"
#include "InputCommon/ControllerEmu.h" #include "InputCommon/ControllerEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
@ -13,7 +16,7 @@ struct ExtensionReg;
class Attachment : public ControllerEmu class Attachment : public ControllerEmu
{ {
public: public:
Attachment(const char* const _name, WiimoteEmu::ExtensionReg& _reg); Attachment(const char* const name, ExtensionReg& reg);
virtual void GetState(u8* const data) {} virtual void GetState(u8* const data) {}
virtual bool IsButtonPressed() const { return false; } virtual bool IsButtonPressed() const { return false; }
@ -24,17 +27,17 @@ protected:
// Default radius for attachment analog sticks. // Default radius for attachment analog sticks.
static constexpr ControlState DEFAULT_ATTACHMENT_STICK_RADIUS = 1.0; static constexpr ControlState DEFAULT_ATTACHMENT_STICK_RADIUS = 1.0;
u8 id[6]; std::array<u8, 6> m_id{};
u8 calibration[0x10]; std::array<u8, 0x10> m_calibration{};
private: private:
const char* const name; const char* const m_name;
WiimoteEmu::ExtensionReg& reg; ExtensionReg& m_reg;
}; };
class None : public Attachment class None : public Attachment
{ {
public: public:
None(WiimoteEmu::ExtensionReg& _reg); None(ExtensionReg& reg);
}; };
} }

View File

@ -2,45 +2,51 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
#include <array>
#include <cassert> #include <cassert>
#include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Classic.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
static const u8 classic_id[] = {0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}; constexpr std::array<u8, 6> classic_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x01}};
/* Classic Controller calibration */
static const u8 classic_calibration[] = {0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00,
0x80, 0xff, 0x00, 0x80, 0x00, 0x00, 0x51, 0xa6};
static const u16 classic_button_bitmasks[] = { // Classic Controller calibration
Classic::BUTTON_A, Classic::BUTTON_B, Classic::BUTTON_X, Classic::BUTTON_Y, constexpr std::array<u8, 0x10> classic_calibration{{
0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0xff, 0x00, 0x80, 0x00, 0x00, 0x51, 0xa6,
}};
Classic::BUTTON_ZL, Classic::BUTTON_ZR, constexpr std::array<u16, 9> classic_button_bitmasks{{
Classic::BUTTON_A, Classic::BUTTON_B, Classic::BUTTON_X, Classic::BUTTON_Y,
Classic::BUTTON_ZL, Classic::BUTTON_ZR,
Classic::BUTTON_MINUS, Classic::BUTTON_PLUS, Classic::BUTTON_MINUS, Classic::BUTTON_PLUS,
Classic::BUTTON_HOME, Classic::BUTTON_HOME,
}; }};
static const char* const classic_button_names[] = { constexpr std::array<const char*, 9> classic_button_names{{
"A", "B", "X", "Y", "ZL", "ZR", "-", "+", "Home", "A", "B", "X", "Y", "ZL", "ZR", "-", "+", "Home",
}; }};
static const u16 classic_trigger_bitmasks[] = { constexpr std::array<u16, 2> classic_trigger_bitmasks{{
Classic::TRIGGER_L, Classic::TRIGGER_R, Classic::TRIGGER_L, Classic::TRIGGER_R,
}; }};
static const char* const classic_trigger_names[] = {"L", "R", "L-Analog", "R-Analog"}; constexpr std::array<const char*, 4> classic_trigger_names{{
"L", "R", "L-Analog", "R-Analog",
}};
static const u16 classic_dpad_bitmasks[] = {Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, constexpr std::array<u16, 4> classic_dpad_bitmasks{{
Classic::PAD_RIGHT}; Classic::PAD_UP, Classic::PAD_DOWN, Classic::PAD_LEFT, Classic::PAD_RIGHT,
}};
Classic::Classic(WiimoteEmu::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 Buttons("Buttons"));
@ -63,11 +69,9 @@ Classic::Classic(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Classic"),
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 ControlGroup::Input(named_direction));
// set up register // Set up register
// calibration m_calibration = classic_calibration;
memcpy(&calibration, classic_calibration, sizeof(classic_calibration)); m_id = classic_id;
// id
memcpy(&id, classic_id, sizeof(classic_id));
} }
void Classic::GetState(u8* const data) void Classic::GetState(u8* const data)
@ -107,7 +111,7 @@ void Classic::GetState(u8* const data)
{ {
ControlState trigs[2] = {0, 0}; ControlState trigs[2] = {0, 0};
u8 lt, rt; u8 lt, rt;
m_triggers->GetState(&ccdata->bt.hex, classic_trigger_bitmasks, trigs); m_triggers->GetState(&ccdata->bt.hex, classic_trigger_bitmasks.data(), trigs);
lt = static_cast<u8>(trigs[0] * Classic::LEFT_TRIGGER_RANGE); lt = static_cast<u8>(trigs[0] * Classic::LEFT_TRIGGER_RANGE);
rt = static_cast<u8>(trigs[1] * Classic::RIGHT_TRIGGER_RANGE); rt = static_cast<u8>(trigs[1] * Classic::RIGHT_TRIGGER_RANGE);
@ -118,9 +122,9 @@ void Classic::GetState(u8* const data)
} }
// buttons // buttons
m_buttons->GetState(&ccdata->bt.hex, classic_button_bitmasks); m_buttons->GetState(&ccdata->bt.hex, classic_button_bitmasks.data());
// dpad // dpad
m_dpad->GetState(&ccdata->bt.hex, classic_dpad_bitmasks); m_dpad->GetState(&ccdata->bt.hex, classic_dpad_bitmasks.data());
// flip button bits // flip button bits
ccdata->bt.hex ^= 0xFFFF; ccdata->bt.hex ^= 0xFFFF;
@ -129,10 +133,10 @@ void Classic::GetState(u8* const data)
bool Classic::IsButtonPressed() const bool Classic::IsButtonPressed() const
{ {
u16 buttons = 0; u16 buttons = 0;
ControlState trigs[2] = {0, 0}; std::array<ControlState, 2> trigs{};
m_buttons->GetState(&buttons, classic_button_bitmasks); m_buttons->GetState(&buttons, classic_button_bitmasks.data());
m_dpad->GetState(&buttons, classic_dpad_bitmasks); m_dpad->GetState(&buttons, classic_dpad_bitmasks.data());
m_triggers->GetState(&buttons, classic_trigger_bitmasks, trigs); m_triggers->GetState(&buttons, classic_trigger_bitmasks.data(), trigs.data());
return buttons != 0; return buttons != 0;
} }

View File

@ -14,7 +14,7 @@ struct ExtensionReg;
class Classic : public Attachment class Classic : public Attachment
{ {
public: public:
Classic(WiimoteEmu::ExtensionReg& _reg); Classic(ExtensionReg& reg);
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;

View File

@ -2,31 +2,34 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Drums.h"
#include <array>
#include <cassert> #include <cassert>
#include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Drums.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
static const u8 drums_id[] = {0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}; constexpr std::array<u8, 6> drums_id{{0x01, 0x00, 0xa4, 0x20, 0x01, 0x03}};
static const u16 drum_pad_bitmasks[] = { constexpr std::array<u16, 6> drum_pad_bitmasks{{
Drums::PAD_RED, Drums::PAD_YELLOW, Drums::PAD_BLUE, Drums::PAD_RED, Drums::PAD_YELLOW, Drums::PAD_BLUE, Drums::PAD_GREEN, Drums::PAD_ORANGE,
Drums::PAD_GREEN, Drums::PAD_ORANGE, Drums::PAD_BASS, Drums::PAD_BASS,
}; }};
static const char* const drum_pad_names[] = {_trans("Red"), _trans("Yellow"), _trans("Blue"), constexpr std::array<const char*, 6> drum_pad_names{{
_trans("Green"), _trans("Orange"), _trans("Bass")}; _trans("Red"), _trans("Yellow"), _trans("Blue"), _trans("Green"), _trans("Orange"),
_trans("Bass"),
}};
static const u16 drum_button_bitmasks[] = { constexpr std::array<u16, 2> drum_button_bitmasks{{
Drums::BUTTON_MINUS, Drums::BUTTON_PLUS, Drums::BUTTON_MINUS, Drums::BUTTON_PLUS,
}; }};
Drums::Drums(WiimoteEmu::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 Buttons(_trans("Pads")));
@ -42,8 +45,7 @@ Drums::Drums(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Drums"), _reg)
m_buttons->controls.emplace_back(new ControlGroup::Input("+")); m_buttons->controls.emplace_back(new ControlGroup::Input("+"));
// set up register // set up register
// id m_id = drums_id;
memcpy(&id, drums_id, sizeof(drums_id));
} }
void Drums::GetState(u8* const data) void Drums::GetState(u8* const data)
@ -67,9 +69,9 @@ void Drums::GetState(u8* const data)
data[3] = 0xFF; data[3] = 0xFF;
// buttons // buttons
m_buttons->GetState(&ddata->bt, drum_button_bitmasks); m_buttons->GetState(&ddata->bt, drum_button_bitmasks.data());
// pads // pads
m_pads->GetState(&ddata->bt, drum_pad_bitmasks); m_pads->GetState(&ddata->bt, drum_pad_bitmasks.data());
// flip button bits // flip button bits
ddata->bt ^= 0xFFFF; ddata->bt ^= 0xFFFF;
@ -78,8 +80,8 @@ void Drums::GetState(u8* const data)
bool Drums::IsButtonPressed() const bool Drums::IsButtonPressed() const
{ {
u16 buttons = 0; u16 buttons = 0;
m_buttons->GetState(&buttons, drum_button_bitmasks); m_buttons->GetState(&buttons, drum_button_bitmasks.data());
m_pads->GetState(&buttons, drum_pad_bitmasks); m_pads->GetState(&buttons, drum_pad_bitmasks.data());
return buttons != 0; return buttons != 0;
} }

View File

@ -14,7 +14,7 @@ struct ExtensionReg;
class Drums : public Attachment class Drums : public Attachment
{ {
public: public:
Drums(WiimoteEmu::ExtensionReg& _reg); Drums(ExtensionReg& reg);
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;

View File

@ -2,36 +2,37 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Guitar.h"
#include <array>
#include <cassert> #include <cassert>
#include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Guitar.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
static const u8 guitar_id[] = {0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}; constexpr std::array<u8, 6> guitar_id{{0x00, 0x00, 0xa4, 0x20, 0x01, 0x03}};
static const u16 guitar_fret_bitmasks[] = { constexpr std::array<u16, 5> guitar_fret_bitmasks{{
Guitar::FRET_GREEN, Guitar::FRET_RED, Guitar::FRET_YELLOW, Guitar::FRET_GREEN, Guitar::FRET_RED, Guitar::FRET_YELLOW, Guitar::FRET_BLUE,
Guitar::FRET_BLUE, Guitar::FRET_ORANGE, Guitar::FRET_ORANGE,
}; }};
static const char* const guitar_fret_names[] = { constexpr std::array<const char*, 5> guitar_fret_names{{
"Green", "Red", "Yellow", "Blue", "Orange", "Green", "Red", "Yellow", "Blue", "Orange",
}; }};
static const u16 guitar_button_bitmasks[] = { constexpr std::array<u16, 2> guitar_button_bitmasks{{
Guitar::BUTTON_MINUS, Guitar::BUTTON_PLUS, Guitar::BUTTON_MINUS, Guitar::BUTTON_PLUS,
}; }};
static const u16 guitar_strum_bitmasks[] = { constexpr std::array<u16, 2> guitar_strum_bitmasks{{
Guitar::BAR_UP, Guitar::BAR_DOWN, Guitar::BAR_UP, Guitar::BAR_DOWN,
}; }};
Guitar::Guitar(WiimoteEmu::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 Buttons(_trans("Frets")));
@ -56,8 +57,7 @@ Guitar::Guitar(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Guitar"), _r
m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar"))); m_whammy->controls.emplace_back(new ControlGroup::Input(_trans("Bar")));
// set up register // set up register
// id m_id = guitar_id;
memcpy(&id, guitar_id, sizeof(guitar_id));
} }
void Guitar::GetState(u8* const data) void Guitar::GetState(u8* const data)
@ -85,11 +85,11 @@ void Guitar::GetState(u8* const data)
gdata->whammy = static_cast<u8>(whammy * 0x1F); gdata->whammy = static_cast<u8>(whammy * 0x1F);
// buttons // buttons
m_buttons->GetState(&gdata->bt, guitar_button_bitmasks); m_buttons->GetState(&gdata->bt, guitar_button_bitmasks.data());
// frets // frets
m_frets->GetState(&gdata->bt, guitar_fret_bitmasks); m_frets->GetState(&gdata->bt, guitar_fret_bitmasks.data());
// strum // strum
m_strum->GetState(&gdata->bt, guitar_strum_bitmasks); m_strum->GetState(&gdata->bt, guitar_strum_bitmasks.data());
// flip button bits // flip button bits
gdata->bt ^= 0xFFFF; gdata->bt ^= 0xFFFF;
@ -98,9 +98,9 @@ void Guitar::GetState(u8* const data)
bool Guitar::IsButtonPressed() const bool Guitar::IsButtonPressed() const
{ {
u16 buttons = 0; u16 buttons = 0;
m_buttons->GetState(&buttons, guitar_button_bitmasks); m_buttons->GetState(&buttons, guitar_button_bitmasks.data());
m_frets->GetState(&buttons, guitar_fret_bitmasks); m_frets->GetState(&buttons, guitar_fret_bitmasks.data());
m_strum->GetState(&buttons, guitar_strum_bitmasks); m_strum->GetState(&buttons, guitar_strum_bitmasks.data());
return buttons != 0; return buttons != 0;
} }

View File

@ -14,7 +14,7 @@ struct ExtensionReg;
class Guitar : public Attachment class Guitar : public Attachment
{ {
public: public:
Guitar(WiimoteEmu::ExtensionReg& _reg); Guitar(ExtensionReg& reg);
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;

View File

@ -2,24 +2,25 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include <array>
#include <cassert> #include <cassert>
#include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/MathUtil.h" #include "Common/MathUtil.h"
#include "Core/HW/WiimoteEmu/Attachment/Nunchuk.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
static const u8 nunchuk_id[] = {0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}; constexpr std::array<u8, 6> nunchuk_id{{0x00, 0x00, 0xa4, 0x20, 0x00, 0x00}};
static const u8 nunchuk_button_bitmasks[] = { constexpr std::array<u8, 2> nunchuk_button_bitmasks{{
Nunchuk::BUTTON_C, Nunchuk::BUTTON_Z, Nunchuk::BUTTON_C, Nunchuk::BUTTON_Z,
}; }};
Nunchuk::Nunchuk(WiimoteEmu::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 Buttons("Buttons"));
@ -41,11 +42,7 @@ Nunchuk::Nunchuk(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Nunchuk"),
m_shake->controls.emplace_back(new ControlGroup::Input("Y")); m_shake->controls.emplace_back(new ControlGroup::Input("Y"));
m_shake->controls.emplace_back(new ControlGroup::Input("Z")); m_shake->controls.emplace_back(new ControlGroup::Input("Z"));
// id m_id = nunchuk_id;
memcpy(&id, nunchuk_id, sizeof(nunchuk_id));
// this should get set to 0 on disconnect, but it isn't, o well
memset(m_shake_step, 0, sizeof(m_shake_step));
} }
void Nunchuk::GetState(u8* const data) void Nunchuk::GetState(u8* const data)
@ -84,9 +81,9 @@ void Nunchuk::GetState(u8* const data)
// swing // swing
EmulateSwing(&accel, m_swing); EmulateSwing(&accel, m_swing);
// shake // shake
EmulateShake(&accel, m_shake, m_shake_step); EmulateShake(&accel, m_shake, m_shake_step.data());
// buttons // buttons
m_buttons->GetState(&ncdata->bt.hex, nunchuk_button_bitmasks); m_buttons->GetState(&ncdata->bt.hex, nunchuk_button_bitmasks.data());
// flip the button bits :/ // flip the button bits :/
ncdata->bt.hex ^= 0x03; ncdata->bt.hex ^= 0x03;
@ -111,7 +108,7 @@ void Nunchuk::GetState(u8* const data)
bool Nunchuk::IsButtonPressed() const bool Nunchuk::IsButtonPressed() const
{ {
u8 buttons = 0; u8 buttons = 0;
m_buttons->GetState(&buttons, nunchuk_button_bitmasks); m_buttons->GetState(&buttons, nunchuk_button_bitmasks.data());
return buttons != 0; return buttons != 0;
} }

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <array>
#include "Core/HW/WiimoteEmu/Attachment/Attachment.h" #include "Core/HW/WiimoteEmu/Attachment/Attachment.h"
namespace WiimoteEmu namespace WiimoteEmu
@ -14,7 +15,7 @@ struct ExtensionReg;
class Nunchuk : public Attachment class Nunchuk : public Attachment
{ {
public: public:
Nunchuk(WiimoteEmu::ExtensionReg& _reg); Nunchuk(ExtensionReg& reg);
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;
@ -51,6 +52,6 @@ private:
Buttons* m_buttons; Buttons* m_buttons;
AnalogStick* m_stick; AnalogStick* m_stick;
u8 m_shake_step[3]; std::array<u8, 3> m_shake_step{};
}; };
} }

View File

@ -2,37 +2,31 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
#include <array>
#include <cassert> #include <cassert>
#include <cstring>
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/WiimoteEmu/Attachment/Turntable.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
namespace WiimoteEmu namespace WiimoteEmu
{ {
static const u8 turntable_id[] = {0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}; constexpr std::array<u8, 6> turntable_id{{0x03, 0x00, 0xa4, 0x20, 0x01, 0x03}};
static const u16 turntable_button_bitmasks[] = { constexpr std::array<u16, 9> turntable_button_bitmasks{{
Turntable::BUTTON_L_GREEN, Turntable::BUTTON_L_RED, Turntable::BUTTON_L_BLUE, Turntable::BUTTON_L_GREEN, Turntable::BUTTON_L_RED, Turntable::BUTTON_L_BLUE,
Turntable::BUTTON_R_GREEN, Turntable::BUTTON_R_RED, Turntable::BUTTON_R_BLUE, Turntable::BUTTON_R_GREEN, Turntable::BUTTON_R_RED, Turntable::BUTTON_R_BLUE,
Turntable::BUTTON_MINUS, Turntable::BUTTON_PLUS, Turntable::BUTTON_EUPHORIA, Turntable::BUTTON_MINUS, Turntable::BUTTON_PLUS, Turntable::BUTTON_EUPHORIA,
}; }};
static const char* const turntable_button_names[] = { constexpr std::array<const char*, 9> turntable_button_names{{
_trans("Green Left"), _trans("Green Left"), _trans("Red Left"), _trans("Blue Left"), _trans("Green Right"),
_trans("Red Left"), _trans("Red Right"), _trans("Blue Right"), "-", "+", _trans("Euphoria"),
_trans("Blue Left"), }};
_trans("Green Right"),
_trans("Red Right"),
_trans("Blue Right"),
"-",
"+",
_trans("Euphoria"),
};
Turntable::Turntable(WiimoteEmu::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 Buttons("Buttons"));
@ -54,8 +48,7 @@ Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turnta
groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade"))); groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade")));
// set up register // set up register
// id m_id = turntable_id;
memcpy(&id, turntable_id, sizeof(turntable_id));
} }
void Turntable::GetState(u8* const data) void Turntable::GetState(u8* const data)
@ -119,7 +112,7 @@ void Turntable::GetState(u8* const data)
} }
// buttons // buttons
m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks); m_buttons->GetState(&ttdata->bt, turntable_button_bitmasks.data());
// flip button bits :/ // flip button bits :/
ttdata->bt ^= (BUTTON_L_GREEN | BUTTON_L_RED | BUTTON_L_BLUE | BUTTON_R_GREEN | BUTTON_R_RED | ttdata->bt ^= (BUTTON_L_GREEN | BUTTON_L_RED | BUTTON_L_BLUE | BUTTON_R_GREEN | BUTTON_R_RED |
@ -129,7 +122,7 @@ void Turntable::GetState(u8* const data)
bool Turntable::IsButtonPressed() const bool Turntable::IsButtonPressed() const
{ {
u16 buttons = 0; u16 buttons = 0;
m_buttons->GetState(&buttons, turntable_button_bitmasks); m_buttons->GetState(&buttons, turntable_button_bitmasks.data());
return buttons != 0; return buttons != 0;
} }

View File

@ -14,7 +14,7 @@ struct ExtensionReg;
class Turntable : public Attachment class Turntable : public Attachment
{ {
public: public:
Turntable(WiimoteEmu::ExtensionReg& _reg); Turntable(ExtensionReg& reg);
void GetState(u8* const data) override; void GetState(u8* const data) override;
bool IsButtonPressed() const override; bool IsButtonPressed() const override;