Fix lint bugs

This commit is contained in:
iwubcode 2018-05-23 22:20:58 -05:00
parent b5db180ac4
commit 3b11066e61
11 changed files with 330 additions and 272 deletions

View File

@ -6,34 +6,48 @@
namespace Config namespace Config
{ {
// Configuration Information // Configuration Information
// WiimoteInput.Settings // WiimoteInput.Settings
const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_FAST{ { System::WiiPad, "Swing", "Fast" }, 4.5 }; const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_FAST{{System::WiiPad, "Swing", "Fast"}, 4.5};
const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM{ { System::WiiPad, "Swing", "Medium" }, 2.5 }; const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM{{System::WiiPad, "Swing", "Medium"},
const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_SLOW{ { System::WiiPad, "Swing", "Slow" }, 1.5 }; 2.5};
const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_SLOW{{System::WiiPad, "Swing", "Slow"}, 1.5};
const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_HARD{ { System::WiiPad, "Shake", "Hard" }, 5.0 }; const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_HARD{{System::WiiPad, "Shake", "Hard"}, 5.0};
const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM{ { System::WiiPad, "Shake", "Medium" }, 3.0 }; const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM{{System::WiiPad, "Shake", "Medium"},
const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT{ { System::WiiPad, "Shake", "Soft" }, 2.0 }; 3.0};
const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT{{System::WiiPad, "Shake", "Soft"}, 2.0};
// Dynamic settings // Dynamic settings
const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST{ { System::WiiPad, "Dynamic_Swing", "FramesHeldFast" }, 100 }; const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST{
const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW{ { System::WiiPad, "Dynamic_Swing", "FramesHeldSlow" }, 30 }; {System::WiiPad, "Dynamic_Swing", "FramesHeldFast"}, 100};
const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH{ { System::WiiPad, "Dynamic_Swing", "FrameCount" }, 30 }; const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW{
{System::WiiPad, "Dynamic_Swing", "FramesHeldSlow"}, 30};
const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH{
{System::WiiPad, "Dynamic_Swing", "FrameCount"}, 30};
const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD{ { System::WiiPad, "Dynamic_Shake", "FramesHeldHard" }, 45 }; const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD{
const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT{ { System::WiiPad, "Dynamic_Shake", "FramesHeldSoft" }, 15 }; {System::WiiPad, "Dynamic_Shake", "FramesHeldHard"}, 45};
const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH{ { System::WiiPad, "Dynamic_Shake", "FrameCount" }, 30 }; const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT{
{System::WiiPad, "Dynamic_Shake", "FramesHeldSoft"}, 15};
const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH{
{System::WiiPad, "Dynamic_Shake", "FrameCount"}, 30};
// NunchuckInput.Settings // NunchuckInput.Settings
const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_FAST{ { System::WiiPad, "Nunchuk_Swing", "Fast" }, 4.5 }; const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_FAST{
const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_MEDIUM{ { System::WiiPad, "Nunchuk_Swing", "Medium" }, 2.5 }; {System::WiiPad, "Nunchuk_Swing", "Fast"}, 4.5};
const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_SLOW{ { System::WiiPad, "Nunchuk_Swing", "Slow" }, 1.5 }; const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_MEDIUM{
{System::WiiPad, "Nunchuk_Swing", "Medium"}, 2.5};
const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_SLOW{
{System::WiiPad, "Nunchuk_Swing", "Slow"}, 1.5};
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_HARD{ { System::WiiPad, "Nunchuk_Shake", "Hard" }, 5.0 }; const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_HARD{
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM{ { System::WiiPad, "Nunchuk_Shake", "Medium" }, 3.0 }; {System::WiiPad, "Nunchuk_Shake", "Hard"}, 5.0};
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT{ { System::WiiPad, "Nunchuk_Shake", "Soft" }, 2.0 }; const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM{
{System::WiiPad, "Nunchuk_Shake", "Medium"}, 3.0};
const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT{
{System::WiiPad, "Nunchuk_Shake", "Soft"}, 2.0};
} }

View File

@ -8,36 +8,42 @@
namespace Config namespace Config
{ {
// Configuration Information // Configuration Information
// WiimoteInput.Settings // WiimoteInput.Settings
extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_FAST; extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_FAST;
extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM; extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM;
extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_SLOW; extern const ConfigInfo<double> WIIMOTE_INPUT_SWING_INTENSITY_SLOW;
extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_HARD; extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_HARD;
extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM; extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM;
extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT; extern const ConfigInfo<double> WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT;
// Below settings are for dynamic input only (based on how long the user holds a button) // Below settings are for dynamic input only (based on how long the user holds a button)
extern const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST; // How long button held constitutes a fast swing extern const ConfigInfo<int>
extern const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW; // How long button held constitutes a slow swing WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST; // How long button held constitutes a fast swing
extern const ConfigInfo<int> WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH; // How long to execute the swing extern const ConfigInfo<int>
WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW; // How long button held constitutes a slow swing
extern const ConfigInfo<int>
WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH; // How long to execute the swing
extern const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD; // How long button held constitutes a hard shake extern const ConfigInfo<int>
extern const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT; // How long button held constitutes a soft shake WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD; // How long button held constitutes a hard shake
extern const ConfigInfo<int> WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH; // How long to execute a shake extern const ConfigInfo<int>
WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT; // How long button held constitutes a soft shake
extern const ConfigInfo<int>
WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH; // How long to execute a shake
// NunchuckInput.Settings // NunchuckInput.Settings
extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_FAST; extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_FAST;
extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_MEDIUM; extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_MEDIUM;
extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_SLOW; extern const ConfigInfo<double> NUNCHUK_INPUT_SWING_INTENSITY_SLOW;
extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_HARD; extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_HARD;
extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM; extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM;
extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT; extern const ConfigInfo<double> NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT;
} // namespace Config } // namespace Config

View File

@ -109,9 +109,12 @@ void Nunchuk::GetState(u8* const data)
EmulateSwing(&accel, m_swing_fast, Config::Get(Config::NUNCHUK_INPUT_SWING_INTENSITY_FAST)); EmulateSwing(&accel, m_swing_fast, Config::Get(Config::NUNCHUK_INPUT_SWING_INTENSITY_FAST));
// shake // shake
EmulateShake(&accel, m_shake, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM), m_shake_step.data()); EmulateShake(&accel, m_shake, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_MEDIUM),
EmulateShake(&accel, m_shake_soft, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT), m_shake_soft_step.data()); m_shake_step.data());
EmulateShake(&accel, m_shake_hard, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_HARD), m_shake_hard_step.data()); EmulateShake(&accel, m_shake_soft, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_SOFT),
m_shake_soft_step.data());
EmulateShake(&accel, m_shake_hard, Config::Get(Config::NUNCHUK_INPUT_SHAKE_INTENSITY_HARD),
m_shake_hard_step.data());
// buttons // buttons
m_buttons->GetState(&nc_data.bt.hex, nunchuk_button_bitmasks.data()); m_buttons->GetState(&nc_data.bt.hex, nunchuk_button_bitmasks.data());

View File

@ -123,15 +123,16 @@ void EmulateShake(AccelData* const accel, ControllerEmu::Buttons* const buttons_
} }
} }
void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data, ControllerEmu::Buttons* const buttons_group, void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data,
const DynamicConfiguration& config, u8* const shake_step) ControllerEmu::Buttons* const buttons_group,
const DynamicConfiguration& config, u8* const shake_step)
{ {
// frame count of one up/down shake // frame count of one up/down shake
// < 9 no shake detection in "Wario Land: Shake It" // < 9 no shake detection in "Wario Land: Shake It"
auto const shake_step_max = 15; auto const shake_step_max = 15;
// shake is a bitfield of X,Y,Z shake button states // shake is a bitfield of X,Y,Z shake button states
static const unsigned int btns[] = { 0x01, 0x02, 0x04 }; static const unsigned int btns[] = {0x01, 0x02, 0x04};
unsigned int shake = 0; unsigned int shake = 0;
buttons_group->GetState(&shake, btns); buttons_group->GetState(&shake, btns);
@ -232,12 +233,14 @@ void EmulateSwing(AccelData* const accel, ControllerEmu::Force* const swing_grou
} }
void EmulateDynamicSwing(AccelData* const accel, DynamicData& dynamic_data, void EmulateDynamicSwing(AccelData* const accel, DynamicData& dynamic_data,
ControllerEmu::Force* const swing_group, const DynamicConfiguration& config, const bool sideways, const bool upright) ControllerEmu::Force* const swing_group,
const DynamicConfiguration& config, const bool sideways,
const bool upright)
{ {
ControlState swing[3]; ControlState swing[3];
swing_group->GetState(swing); swing_group->GetState(swing);
s8 g_dir[3] = { -1, -1, -1 }; s8 g_dir[3] = {-1, -1, -1};
u8 axis_map[3]; u8 axis_map[3];
// determine which axis is which direction // determine which axis is which direction
@ -398,9 +401,12 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), ir_sin(0), ir_cos(1
m_shake_hard->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z")); m_shake_hard->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z"));
groups.emplace_back(m_shake_dynamic = new ControllerEmu::Buttons("Shake Dynamic")); groups.emplace_back(m_shake_dynamic = new ControllerEmu::Buttons("Shake Dynamic"));
m_shake_dynamic->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "X")); m_shake_dynamic->controls.emplace_back(
m_shake_dynamic->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Y")); new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "X"));
m_shake_dynamic->controls.emplace_back(new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z")); m_shake_dynamic->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Y"));
m_shake_dynamic->controls.emplace_back(
new ControllerEmu::Input(ControllerEmu::DoNotTranslate, "Z"));
// extension // extension
groups.emplace_back(m_extension = new ControllerEmu::Extension(_trans("Extension"))); groups.emplace_back(m_extension = new ControllerEmu::Extension(_trans("Extension")));
@ -604,13 +610,18 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
swing_config.low_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_SLOW); swing_config.low_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_SLOW);
swing_config.med_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM); swing_config.med_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM);
swing_config.high_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_FAST); swing_config.high_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_FAST);
swing_config.frames_needed_for_high_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST); swing_config.frames_needed_for_high_intensity =
swing_config.frames_needed_for_low_intensity = Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW); Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_FAST);
swing_config.frames_needed_for_low_intensity =
Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_HELD_SLOW);
swing_config.frames_to_execute = Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH); swing_config.frames_to_execute = Config::Get(Config::WIIMOTE_INPUT_SWING_DYNAMIC_FRAMES_LENGTH);
EmulateSwing(&m_accel, m_swing, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM), is_sideways, is_upright); EmulateSwing(&m_accel, m_swing, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_MEDIUM),
EmulateSwing(&m_accel, m_swing_slow, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_SLOW), is_sideways, is_upright); is_sideways, is_upright);
EmulateSwing(&m_accel, m_swing_fast, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_FAST), is_sideways, is_upright); EmulateSwing(&m_accel, m_swing_slow, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_SLOW),
is_sideways, is_upright);
EmulateSwing(&m_accel, m_swing_fast, Config::Get(Config::WIIMOTE_INPUT_SWING_INTENSITY_FAST),
is_sideways, is_upright);
EmulateDynamicSwing(&m_accel, m_swing_dynamic_data, m_swing_dynamic, swing_config, is_sideways, EmulateDynamicSwing(&m_accel, m_swing_dynamic_data, m_swing_dynamic, swing_config, is_sideways,
is_upright); is_upright);
@ -618,17 +629,21 @@ void Wiimote::GetAccelData(u8* const data, const ReportFeatures& rptf)
shake_config.low_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT); shake_config.low_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT);
shake_config.med_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM); shake_config.med_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM);
shake_config.high_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_HARD); shake_config.high_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_HARD);
shake_config.frames_needed_for_high_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD); shake_config.frames_needed_for_high_intensity =
shake_config.frames_needed_for_low_intensity = Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT); Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_HARD);
shake_config.frames_needed_for_low_intensity =
Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_HELD_SOFT);
shake_config.frames_to_execute = Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH); shake_config.frames_to_execute = Config::Get(Config::WIIMOTE_INPUT_SHAKE_DYNAMIC_FRAMES_LENGTH);
EmulateShake(&m_accel, m_shake, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM), m_shake_step.data()); EmulateShake(&m_accel, m_shake, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_MEDIUM),
EmulateShake(&m_accel, m_shake_soft, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT), m_shake_soft_step.data()); m_shake_step.data());
EmulateShake(&m_accel, m_shake_hard, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_HARD), m_shake_hard_step.data()); EmulateShake(&m_accel, m_shake_soft, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_SOFT),
m_shake_soft_step.data());
EmulateShake(&m_accel, m_shake_hard, Config::Get(Config::WIIMOTE_INPUT_SHAKE_INTENSITY_HARD),
m_shake_hard_step.data());
EmulateDynamicShake(&m_accel, m_shake_dynamic_data, m_shake_dynamic, shake_config, EmulateDynamicShake(&m_accel, m_shake_dynamic_data, m_shake_dynamic, shake_config,
m_shake_dynamic_step.data()); m_shake_dynamic_step.data());
wm_accel& accel = *reinterpret_cast<wm_accel*>(data + rptf.accel); wm_accel& accel = *reinterpret_cast<wm_accel*>(data + rptf.accel);
wm_buttons& core = *reinterpret_cast<wm_buttons*>(data + rptf.core); wm_buttons& core = *reinterpret_cast<wm_buttons*>(data + rptf.core);

View File

@ -128,8 +128,8 @@ struct AccelData
// shake // shake
struct DynamicData struct DynamicData
{ {
std::array<int, 3> timing; // Hold length in frames for each axis std::array<int, 3> timing; // Hold length in frames for each axis
std::array<double, 3> intensity; // Swing or shake intensity std::array<double, 3> intensity; // Swing or shake intensity
std::array<int, 3> executing_frames_left; // Number of frames to execute the intensity operation std::array<int, 3> executing_frames_left; // Number of frames to execute the intensity operation
}; };
@ -186,8 +186,7 @@ void EmulateShake(AccelData* const accel_data, ControllerEmu::Buttons* const but
void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data, void EmulateDynamicShake(AccelData* const accel, DynamicData& dynamic_data,
ControllerEmu::Buttons* const buttons_group, ControllerEmu::Buttons* const buttons_group,
const DynamicConfiguration& config, const DynamicConfiguration& config, u8* const shake_step);
u8* const shake_step);
void EmulateTilt(AccelData* const accel, ControllerEmu::Tilt* const tilt_group, void EmulateTilt(AccelData* const accel, ControllerEmu::Tilt* const tilt_group,
const bool sideways = false, const bool upright = false); const bool sideways = false, const bool upright = false);
@ -197,8 +196,8 @@ void EmulateSwing(AccelData* const accel, ControllerEmu::Force* const tilt_group
void EmulateDynamicSwing(AccelData* const accel, DynamicData& dynamic_data, void EmulateDynamicSwing(AccelData* const accel, DynamicData& dynamic_data,
ControllerEmu::Force* const swing_group, ControllerEmu::Force* const swing_group,
const DynamicConfiguration& config, const DynamicConfiguration& config, const bool sideways = false,
const bool sideways = false, const bool upright = false); const bool upright = false);
enum enum
{ {

View File

@ -11,29 +11,30 @@
HotkeyControllerProfile::HotkeyControllerProfile(MappingWindow* window) : MappingWidget(window) HotkeyControllerProfile::HotkeyControllerProfile(MappingWindow* window) : MappingWidget(window)
{ {
CreateMainLayout(); CreateMainLayout();
} }
void HotkeyControllerProfile::CreateMainLayout() void HotkeyControllerProfile::CreateMainLayout()
{ {
m_main_layout = new QHBoxLayout(); m_main_layout = new QHBoxLayout();
m_main_layout->addWidget(CreateGroupBox(tr("Controller Profile"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_CONTROLLER_PROFILE))); m_main_layout->addWidget(CreateGroupBox(
tr("Controller Profile"), HotkeyManagerEmu::GetHotkeyGroup(HKGP_CONTROLLER_PROFILE)));
setLayout(m_main_layout); setLayout(m_main_layout);
} }
InputConfig* HotkeyControllerProfile::GetConfig() InputConfig* HotkeyControllerProfile::GetConfig()
{ {
return HotkeyManagerEmu::GetConfig(); return HotkeyManagerEmu::GetConfig();
} }
void HotkeyControllerProfile::LoadSettings() void HotkeyControllerProfile::LoadSettings()
{ {
HotkeyManagerEmu::LoadConfig(); HotkeyManagerEmu::LoadConfig();
} }
void HotkeyControllerProfile::SaveSettings() void HotkeyControllerProfile::SaveSettings()
{ {
HotkeyManagerEmu::GetConfig()->SaveConfig(); HotkeyManagerEmu::GetConfig()->SaveConfig();
} }

View File

@ -10,17 +10,17 @@ class QHBoxLayout;
class HotkeyControllerProfile final : public MappingWidget class HotkeyControllerProfile final : public MappingWidget
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit HotkeyControllerProfile(MappingWindow* window); explicit HotkeyControllerProfile(MappingWindow* window);
InputConfig* GetConfig() override; InputConfig* GetConfig() override;
private: private:
void LoadSettings() override; void LoadSettings() override;
void SaveSettings() override; void SaveSettings() override;
void CreateMainLayout(); void CreateMainLayout();
// Main // Main
QHBoxLayout* m_main_layout; QHBoxLayout* m_main_layout;
}; };

View File

@ -311,7 +311,7 @@ void MappingWindow::SetMappingType(MappingWindow::Type type)
AddWidget(tr("Debugging"), new HotkeyDebugging(this)); AddWidget(tr("Debugging"), new HotkeyDebugging(this));
AddWidget(tr("Wii and Wii Remote"), new HotkeyWii(this)); AddWidget(tr("Wii and Wii Remote"), new HotkeyWii(this));
AddWidget(tr("Controller Profile"), new HotkeyControllerProfile(this)); AddWidget(tr("Controller Profile"), new HotkeyControllerProfile(this));
AddWidget(tr("Graphics"), new HotkeyGraphics(this)); AddWidget(tr("Graphics"), new HotkeyGraphics(this));
AddWidget(tr("3D"), new Hotkey3D(this)); AddWidget(tr("3D"), new Hotkey3D(this));
AddWidget(tr("Save and Load State"), new HotkeyStates(this)); AddWidget(tr("Save and Load State"), new HotkeyStates(this));

View File

@ -87,8 +87,8 @@ bool InputConfig::LoadConfig(bool isGC)
{ {
std::string base; std::string base;
SplitPath(profile[n], nullptr, &base, nullptr); SplitPath(profile[n], nullptr, &base, nullptr);
Core::DisplayMessage("Loading game specific input profile '" + base + Core::DisplayMessage("Loading game specific input profile '" + base + "' for device '" +
"' for device '" + controller->GetName() + "'", controller->GetName() + "'",
6000); 6000);
IniFile profile_ini; IniFile profile_ini;

View File

@ -20,167 +20,179 @@
namespace InputProfile namespace InputProfile
{ {
namespace
{
constexpr int display_message_ms = 3000;
}
namespace std::vector<std::string> ProfileCycler::GetProfilesForDevice(InputConfig* device_configuration)
{
const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" +
device_configuration->GetProfileName());
return Common::DoFileSearch({device_profile_root_location}, {".ini"});
}
std::string ProfileCycler::GetProfile(CycleDirection cycle_direction, int& profile_index,
const std::vector<std::string>& profiles)
{
// update the index and bind it to the number of available strings
auto positive_modulo = [](int& i, int n) { i = (i % n + n) % n; };
profile_index += static_cast<int>(cycle_direction);
positive_modulo(profile_index, static_cast<int>(profiles.size()));
return profiles[profile_index];
}
void ProfileCycler::UpdateToProfile(const std::string& profile_filename,
ControllerEmu::EmulatedController* controller)
{
std::string base;
SplitPath(profile_filename, nullptr, &base, nullptr);
IniFile ini_file;
if (ini_file.Load(profile_filename))
{ {
constexpr int display_message_ms = 3000; Core::DisplayMessage("Loading input profile '" + base + "' for device '" +
controller->GetName() + "'",
display_message_ms);
controller->LoadConfig(ini_file.GetOrCreateSection("Profile"));
controller->UpdateReferences(g_controller_interface);
} }
else
std::vector<std::string> ProfileCycler::GetProfilesForDevice(InputConfig* device_configuration)
{ {
const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + device_configuration->GetProfileName()); Core::DisplayMessage("Unable to load input profile '" + base + "' for device '" +
return Common::DoFileSearch({ device_profile_root_location }, { ".ini" }); controller->GetName() + "'",
} display_message_ms);
std::string ProfileCycler::GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector<std::string>& profiles)
{
// update the index and bind it to the number of available strings
auto positive_modulo = [](int& i, int n) {i = (i % n + n) % n;};
profile_index += static_cast<int>(cycle_direction);
positive_modulo(profile_index, static_cast<int>(profiles.size()));
return profiles[profile_index];
}
void ProfileCycler::UpdateToProfile(const std::string& profile_filename, ControllerEmu::EmulatedController* controller)
{
std::string base;
SplitPath(profile_filename, nullptr, &base, nullptr);
IniFile ini_file;
if (ini_file.Load(profile_filename))
{
Core::DisplayMessage("Loading input profile '" + base + "' for device '" + controller->GetName() + "'", display_message_ms);
controller->LoadConfig(ini_file.GetOrCreateSection("Profile"));
controller->UpdateReferences(g_controller_interface);
}
else
{
Core::DisplayMessage("Unable to load input profile '" + base + "' for device '" + controller->GetName() + "'", display_message_ms);
}
}
std::vector<std::string> ProfileCycler::GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration)
{
const auto& profiles = SplitString(setting, ',');
const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" + device_configuration->GetProfileName());
std::vector<std::string> result(profiles.size());
std::transform(profiles.begin(), profiles.end(), result.begin(), [&device_profile_root_location](const std::string& profile)
{
return device_profile_root_location + "/" + StripSpaces(profile) + ".ini";
});
return result;
}
std::vector<std::string> ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting, const std::vector<std::string>& profiles, InputConfig* device_configuration)
{
const auto& profiles_from_setting = GetProfilesFromSetting(setting, device_configuration);
if (profiles_from_setting.empty())
{
return {};
}
std::vector<std::string> result;
std::set_intersection(profiles.begin(), profiles.end(), profiles_from_setting.begin(),
profiles_from_setting.end(), std::back_inserter(result));
return result;
}
void ProfileCycler::CycleProfile(CycleDirection cycle_direction,
InputConfig* device_configuration, int& profile_index,
int controller_index)
{
const auto& profiles = GetProfilesForDevice(device_configuration);
if (profiles.empty())
{
Core::DisplayMessage("No input profiles found", display_message_ms);
return;
}
const std::string profile = GetProfile(cycle_direction, profile_index, profiles);
auto* controller = device_configuration->GetController(controller_index);
if (controller)
{
UpdateToProfile(profile, controller);
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index), display_message_ms);
}
}
void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction,
InputConfig* device_configuration, int& profile_index,
const std::string& setting, int controller_index)
{
const auto& profiles = GetProfilesForDevice(device_configuration);
if (profiles.empty())
{
Core::DisplayMessage("No input profiles found", display_message_ms);
return;
}
if (setting.empty())
{
Core::DisplayMessage("No setting found for game", display_message_ms);
return;
}
const auto& profiles_for_game = GetMatchingProfilesFromSetting(setting, profiles,
device_configuration);
if (profiles_for_game.empty())
{
Core::DisplayMessage("No input profiles found for game", display_message_ms);
return;
}
const std::string profile = GetProfile(cycle_direction, profile_index, profiles_for_game);
auto* controller = device_configuration->GetController(controller_index);
if (controller)
{
UpdateToProfile(profile, controller);
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index), display_message_ms);
}
}
std::string ProfileCycler::GetWiimoteInputProfilesForGame(int controller_index)
{
IniFile game_ini = SConfig::GetInstance().LoadGameIni();
const IniFile::Section* const control_section = game_ini.GetOrCreateSection("Controls");
std::string result;
control_section->Get(StringFromFormat("WiimoteProfile%d", controller_index+1), &result);
return result;
}
void ProfileCycler::NextWiimoteProfile(int controller_index)
{
CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index,
controller_index);
}
void ProfileCycler::PreviousWiimoteProfile(int controller_index)
{
CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index,
controller_index);
}
void ProfileCycler::NextWiimoteProfileForGame(int controller_index)
{
CycleProfileForGame(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index,
GetWiimoteInputProfilesForGame(controller_index), controller_index);
}
void ProfileCycler::PreviousWiimoteProfileForGame(int controller_index)
{
CycleProfileForGame(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index,
GetWiimoteInputProfilesForGame(controller_index), controller_index);
} }
} }
std::vector<std::string> ProfileCycler::GetProfilesFromSetting(const std::string& setting,
InputConfig* device_configuration)
{
const auto& profiles = SplitString(setting, ',');
const std::string device_profile_root_location(File::GetUserPath(D_CONFIG_IDX) + "Profiles/" +
device_configuration->GetProfileName());
std::vector<std::string> result(profiles.size());
std::transform(profiles.begin(), profiles.end(), result.begin(),
[&device_profile_root_location](const std::string& profile) {
return device_profile_root_location + "/" + StripSpaces(profile) + ".ini";
});
return result;
}
std::vector<std::string>
ProfileCycler::GetMatchingProfilesFromSetting(const std::string& setting,
const std::vector<std::string>& profiles,
InputConfig* device_configuration)
{
const auto& profiles_from_setting = GetProfilesFromSetting(setting, device_configuration);
if (profiles_from_setting.empty())
{
return {};
}
std::vector<std::string> result;
std::set_intersection(profiles.begin(), profiles.end(), profiles_from_setting.begin(),
profiles_from_setting.end(), std::back_inserter(result));
return result;
}
void ProfileCycler::CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration,
int& profile_index, int controller_index)
{
const auto& profiles = GetProfilesForDevice(device_configuration);
if (profiles.empty())
{
Core::DisplayMessage("No input profiles found", display_message_ms);
return;
}
const std::string profile = GetProfile(cycle_direction, profile_index, profiles);
auto* controller = device_configuration->GetController(controller_index);
if (controller)
{
UpdateToProfile(profile, controller);
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index),
display_message_ms);
}
}
void ProfileCycler::CycleProfileForGame(CycleDirection cycle_direction,
InputConfig* device_configuration, int& profile_index,
const std::string& setting, int controller_index)
{
const auto& profiles = GetProfilesForDevice(device_configuration);
if (profiles.empty())
{
Core::DisplayMessage("No input profiles found", display_message_ms);
return;
}
if (setting.empty())
{
Core::DisplayMessage("No setting found for game", display_message_ms);
return;
}
const auto& profiles_for_game =
GetMatchingProfilesFromSetting(setting, profiles, device_configuration);
if (profiles_for_game.empty())
{
Core::DisplayMessage("No input profiles found for game", display_message_ms);
return;
}
const std::string profile = GetProfile(cycle_direction, profile_index, profiles_for_game);
auto* controller = device_configuration->GetController(controller_index);
if (controller)
{
UpdateToProfile(profile, controller);
}
else
{
Core::DisplayMessage("No controller found for index: " + std::to_string(controller_index),
display_message_ms);
}
}
std::string ProfileCycler::GetWiimoteInputProfilesForGame(int controller_index)
{
IniFile game_ini = SConfig::GetInstance().LoadGameIni();
const IniFile::Section* const control_section = game_ini.GetOrCreateSection("Controls");
std::string result;
control_section->Get(StringFromFormat("WiimoteProfile%d", controller_index + 1), &result);
return result;
}
void ProfileCycler::NextWiimoteProfile(int controller_index)
{
CycleProfile(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index,
controller_index);
}
void ProfileCycler::PreviousWiimoteProfile(int controller_index)
{
CycleProfile(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index,
controller_index);
}
void ProfileCycler::NextWiimoteProfileForGame(int controller_index)
{
CycleProfileForGame(CycleDirection::Forward, Wiimote::GetConfig(), m_wiimote_profile_index,
GetWiimoteInputProfilesForGame(controller_index), controller_index);
}
void ProfileCycler::PreviousWiimoteProfileForGame(int controller_index)
{
CycleProfileForGame(CycleDirection::Backward, Wiimote::GetConfig(), m_wiimote_profile_index,
GetWiimoteInputProfilesForGame(controller_index), controller_index);
}
}

View File

@ -8,7 +8,7 @@ class InputConfig;
namespace ControllerEmu namespace ControllerEmu
{ {
class EmulatedController; class EmulatedController;
} }
#include <string> #include <string>
@ -16,29 +16,37 @@ namespace ControllerEmu
namespace InputProfile namespace InputProfile
{ {
enum class CycleDirection : int enum class CycleDirection : int
{ {
Forward = 1, Forward = 1,
Backward = -1 Backward = -1
}; };
class ProfileCycler class ProfileCycler
{ {
public: public:
void NextWiimoteProfile(int controller_index); void NextWiimoteProfile(int controller_index);
void PreviousWiimoteProfile(int controller_index); void PreviousWiimoteProfile(int controller_index);
void NextWiimoteProfileForGame(int controller_index); void NextWiimoteProfileForGame(int controller_index);
void PreviousWiimoteProfileForGame(int controller_index); void PreviousWiimoteProfileForGame(int controller_index);
private:
void CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, int controller_index);
void CycleProfileForGame(CycleDirection cycle_direction, InputConfig* device_configuration, int& profile_index, const std::string& setting, int controller_index);
std::vector<std::string> GetProfilesForDevice(InputConfig* device_configuration);
std::vector<std::string> GetProfilesFromSetting(const std::string& setting, InputConfig* device_configuration);
std::string GetProfile(CycleDirection cycle_direction, int& profile_index, const std::vector<std::string>& profiles);
std::vector<std::string> GetMatchingProfilesFromSetting(const std::string& setting, const std::vector<std::string>& profiles, InputConfig* device_configuration);
void UpdateToProfile(const std::string& profile_filename, ControllerEmu::EmulatedController* controller);
std::string GetWiimoteInputProfilesForGame(int controller_index);
int m_wiimote_profile_index = 0; private:
}; void CycleProfile(CycleDirection cycle_direction, InputConfig* device_configuration,
int& profile_index, int controller_index);
void CycleProfileForGame(CycleDirection cycle_direction, InputConfig* device_configuration,
int& profile_index, const std::string& setting, int controller_index);
std::vector<std::string> GetProfilesForDevice(InputConfig* device_configuration);
std::vector<std::string> GetProfilesFromSetting(const std::string& setting,
InputConfig* device_configuration);
std::string GetProfile(CycleDirection cycle_direction, int& profile_index,
const std::vector<std::string>& profiles);
std::vector<std::string> GetMatchingProfilesFromSetting(const std::string& setting,
const std::vector<std::string>& profiles,
InputConfig* device_configuration);
void UpdateToProfile(const std::string& profile_filename,
ControllerEmu::EmulatedController* controller);
std::string GetWiimoteInputProfilesForGame(int controller_index);
int m_wiimote_profile_index = 0;
};
} }