mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-10 14:39:01 +01:00
Merge pull request #23 from lioncash/sorta-large-input-cleanup
Larger cleanup to input-related source files (this time using unique_ptr).
This commit is contained in:
commit
3363b396af
@ -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
|
||||
|
@ -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 );
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ 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;
|
||||
|
||||
@ -30,7 +30,7 @@ public:
|
||||
class None : public Attachment
|
||||
{
|
||||
public:
|
||||
None( WiimoteEmu::ExtensionReg& _reg );
|
||||
None(WiimoteEmu::ExtensionReg& _reg);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@ 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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@ 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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@ 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
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -17,7 +17,7 @@ class Nunchuk : public Attachment
|
||||
public:
|
||||
Nunchuk(UDPWrapper * wrp, WiimoteEmu::ExtensionReg& _reg);
|
||||
|
||||
virtual void GetState( u8* const data, const bool focus ) override;
|
||||
virtual void GetState(u8* const data, const bool focus) override;
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -33,23 +33,23 @@ static const char* const turntable_button_names[] =
|
||||
Turntable::Turntable(WiimoteEmu::ExtensionReg& _reg) : Attachment(_trans("Turntable"), _reg)
|
||||
{
|
||||
// buttons
|
||||
groups.push_back(m_buttons = new Buttons("Buttons"));
|
||||
groups.emplace_back(m_buttons = new Buttons("Buttons"));
|
||||
for (auto& turntable_button_name : turntable_button_names)
|
||||
m_buttons->controls.push_back(new ControlGroup::Input(turntable_button_name));
|
||||
m_buttons->controls.emplace_back(new ControlGroup::Input(turntable_button_name));
|
||||
|
||||
// turntables
|
||||
groups.push_back(m_left_table = new Slider(_trans("Table Left")));
|
||||
groups.push_back(m_right_table = new Slider(_trans("Table Right")));
|
||||
groups.emplace_back(m_left_table = new Slider(_trans("Table Left")));
|
||||
groups.emplace_back(m_right_table = new Slider(_trans("Table Right")));
|
||||
|
||||
// stick
|
||||
groups.push_back(m_stick = new AnalogStick("Stick"));
|
||||
groups.emplace_back(m_stick = new AnalogStick("Stick"));
|
||||
|
||||
// effect dial
|
||||
groups.push_back(m_effect_dial = new Triggers(_trans("Effect")));
|
||||
m_effect_dial->controls.push_back(new ControlGroup::Input(_trans("Dial")));
|
||||
groups.emplace_back(m_effect_dial = new Triggers(_trans("Effect")));
|
||||
m_effect_dial->controls.emplace_back(new ControlGroup::Input(_trans("Dial")));
|
||||
|
||||
// crossfade
|
||||
groups.push_back(m_crossfade = new Slider(_trans("Crossfade")));
|
||||
groups.emplace_back(m_crossfade = new Slider(_trans("Crossfade")));
|
||||
|
||||
// set up register
|
||||
// id
|
||||
|
@ -32,8 +32,10 @@ public:
|
||||
private:
|
||||
Buttons* m_buttons;
|
||||
AnalogStick* m_stick;
|
||||
Triggers *m_effect_dial;
|
||||
Slider *m_left_table, *m_right_table, *m_crossfade;
|
||||
Triggers* m_effect_dial;
|
||||
Slider* m_left_table;
|
||||
Slider* m_right_table;
|
||||
Slider* m_crossfade;
|
||||
};
|
||||
|
||||
|
||||
|
@ -852,7 +852,7 @@ void Wiimote::HandleExtensionSwap()
|
||||
m_extension->active_extension = m_extension->switch_extension;
|
||||
|
||||
// reset register
|
||||
((WiimoteEmu::Attachment*)m_extension->attachments[m_extension->active_extension])->Reset();
|
||||
((WiimoteEmu::Attachment*)m_extension->attachments[m_extension->active_extension].get())->Reset();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,53 +268,53 @@ Wiimote::Wiimote( const unsigned int index )
|
||||
// ---- set up all the controls ----
|
||||
|
||||
// buttons
|
||||
groups.push_back(m_buttons = new Buttons("Buttons"));
|
||||
groups.emplace_back(m_buttons = new Buttons("Buttons"));
|
||||
for (auto& named_button : named_buttons)
|
||||
m_buttons->controls.push_back(new ControlGroup::Input( named_button));
|
||||
m_buttons->controls.emplace_back(new ControlGroup::Input( named_button));
|
||||
|
||||
// udp
|
||||
groups.push_back(m_udp = new UDPWrapper(m_index, _trans("UDP Wiimote")));
|
||||
groups.emplace_back(m_udp = new UDPWrapper(m_index, _trans("UDP Wiimote")));
|
||||
|
||||
// ir
|
||||
groups.push_back(m_ir = new Cursor(_trans("IR")));
|
||||
groups.emplace_back(m_ir = new Cursor(_trans("IR")));
|
||||
|
||||
// swing
|
||||
groups.push_back(m_swing = new Force(_trans("Swing")));
|
||||
groups.emplace_back(m_swing = new Force(_trans("Swing")));
|
||||
|
||||
// tilt
|
||||
groups.push_back(m_tilt = new Tilt(_trans("Tilt")));
|
||||
groups.emplace_back(m_tilt = new Tilt(_trans("Tilt")));
|
||||
|
||||
// shake
|
||||
groups.push_back(m_shake = new Buttons(_trans("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(_trans("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"));
|
||||
|
||||
// extension
|
||||
groups.push_back(m_extension = new Extension(_trans("Extension")));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::None(m_reg_ext));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::Nunchuk(m_udp, m_reg_ext));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::Classic(m_reg_ext));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::Guitar(m_reg_ext));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::Drums(m_reg_ext));
|
||||
m_extension->attachments.push_back(new WiimoteEmu::Turntable(m_reg_ext));
|
||||
groups.emplace_back(m_extension = new Extension(_trans("Extension")));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::None(m_reg_ext));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::Nunchuk(m_udp, m_reg_ext));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::Classic(m_reg_ext));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::Guitar(m_reg_ext));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::Drums(m_reg_ext));
|
||||
m_extension->attachments.emplace_back(new WiimoteEmu::Turntable(m_reg_ext));
|
||||
|
||||
m_extension->settings.push_back(new ControlGroup::Setting(_trans("Motion Plus"), 0, 0, 1));
|
||||
m_extension->settings.emplace_back(new ControlGroup::Setting(_trans("Motion Plus"), 0, 0, 1));
|
||||
|
||||
// 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("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));
|
||||
|
||||
// options
|
||||
groups.push_back( m_options = new ControlGroup(_trans("Options")));
|
||||
m_options->settings.push_back(new ControlGroup::Setting(_trans("Background Input"), false));
|
||||
m_options->settings.push_back(new ControlGroup::Setting(_trans("Sideways Wiimote"), false));
|
||||
m_options->settings.push_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false));
|
||||
groups.emplace_back( m_options = new ControlGroup(_trans("Options")));
|
||||
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Background Input"), false));
|
||||
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Sideways Wiimote"), false));
|
||||
m_options->settings.emplace_back(new ControlGroup::Setting(_trans("Upright Wiimote"), false));
|
||||
|
||||
// TODO: This value should probably be re-read if SYSCONF gets changed
|
||||
m_sensor_bar_on_top = SConfig::GetInstance().m_SYSCONF->GetData<u8>("BT.BAR") != 0;
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
BUTTON_HOME = 0x8000,
|
||||
};
|
||||
|
||||
Wiimote( const unsigned int index );
|
||||
Wiimote(const unsigned int index);
|
||||
std::string GetName() const;
|
||||
|
||||
void Update();
|
||||
@ -148,7 +148,7 @@ private:
|
||||
struct ReadRequest
|
||||
{
|
||||
//u16 channel;
|
||||
unsigned int address, size, position;
|
||||
u32 address, size, position;
|
||||
u8* data;
|
||||
};
|
||||
|
||||
@ -202,7 +202,7 @@ private:
|
||||
// read data request queue
|
||||
// maybe it isn't actually a queue
|
||||
// maybe read requests cancel any current requests
|
||||
std::queue< ReadRequest > m_read_requests;
|
||||
std::queue<ReadRequest> m_read_requests;
|
||||
|
||||
wiimote_key m_ext_key;
|
||||
|
||||
@ -219,14 +219,12 @@ private:
|
||||
|
||||
// address 0xFA
|
||||
u8 ext_identifier[6];
|
||||
|
||||
} m_reg_motion_plus;
|
||||
|
||||
struct IrReg
|
||||
{
|
||||
u8 data[0x33];
|
||||
u8 mode;
|
||||
|
||||
} m_reg_ir;
|
||||
|
||||
ExtensionReg m_reg_ext;
|
||||
@ -244,7 +242,6 @@ private:
|
||||
u8 unk_7;
|
||||
u8 play;
|
||||
u8 unk_9;
|
||||
|
||||
} m_reg_speaker;
|
||||
};
|
||||
|
||||
|
@ -31,8 +31,7 @@ void GamepadPage::ConfigExtension(wxCommandEvent& event)
|
||||
wxBoxSizer* const main_szr = new wxBoxSizer(wxVERTICAL);
|
||||
const std::size_t orig_size = control_groups.size();
|
||||
|
||||
ControlGroupsSizer* const szr =
|
||||
new ControlGroupsSizer(ex->attachments[ex->switch_extension], &dlg, this, &control_groups);
|
||||
ControlGroupsSizer* const szr = new ControlGroupsSizer(ex->attachments[ex->switch_extension].get(), &dlg, this, &control_groups);
|
||||
main_szr->Add(szr, 0, wxLEFT, 5);
|
||||
main_szr->Add(dlg.CreateButtonSizer(wxOK), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 5);
|
||||
dlg.SetSizerAndFit(main_szr);
|
||||
@ -49,13 +48,10 @@ PadSettingExtension::PadSettingExtension(wxWindow* const parent, ControllerEmu::
|
||||
: PadSetting(new wxChoice(parent, -1))
|
||||
, extension(ext)
|
||||
{
|
||||
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
i = extension->attachments.begin(),
|
||||
e = extension->attachments.end();
|
||||
|
||||
for (; i!=e; ++i)
|
||||
((wxChoice*)wxcontrol)->Append(wxGetTranslation(StrToWxStr((*i)->GetName())));
|
||||
for (auto& attachment : extension->attachments)
|
||||
{
|
||||
((wxChoice*)wxcontrol)->Append(wxGetTranslation(StrToWxStr(attachment->GetName())));
|
||||
}
|
||||
|
||||
UpdateGUI();
|
||||
}
|
||||
@ -152,29 +148,25 @@ void InputConfigDialog::UpdateProfileComboBox()
|
||||
const CFileSearch::XStringVector& sv = cfs.GetFileNames();
|
||||
|
||||
wxArrayString strs;
|
||||
CFileSearch::XStringVector::const_iterator si = sv.begin(),
|
||||
se = sv.end();
|
||||
for (; si!=se; ++si)
|
||||
for (auto si = sv.cbegin(); si != sv.cend(); ++si)
|
||||
{
|
||||
std::string str(si->begin() + si->find_last_of('/') + 1 , si->end() - 4) ;
|
||||
strs.push_back(StrToWxStr(str));
|
||||
}
|
||||
|
||||
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
|
||||
e = m_padpages.end();
|
||||
for (; i != e; ++i)
|
||||
for (GamepadPage* page : m_padpages)
|
||||
{
|
||||
(*i)->profile_cbox->Clear();
|
||||
(*i)->profile_cbox->Append(strs);
|
||||
page->profile_cbox->Clear();
|
||||
page->profile_cbox->Append(strs);
|
||||
}
|
||||
}
|
||||
|
||||
void InputConfigDialog::UpdateControlReferences()
|
||||
{
|
||||
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
|
||||
e = m_padpages.end();
|
||||
for (; i != e; ++i)
|
||||
(*i)->controller->UpdateReferences(g_controller_interface);
|
||||
for (GamepadPage* page : m_padpages)
|
||||
{
|
||||
page->controller->UpdateReferences(g_controller_interface);
|
||||
}
|
||||
}
|
||||
|
||||
void InputConfigDialog::ClickSave(wxCommandEvent& event)
|
||||
@ -192,21 +184,17 @@ void ControlDialog::UpdateListContents()
|
||||
{
|
||||
if (control_reference->is_input)
|
||||
{
|
||||
// for inputs
|
||||
std::vector<Device::Input*>::const_iterator
|
||||
i = dev->Inputs().begin(),
|
||||
e = dev->Inputs().end();
|
||||
for (; i!=e; ++i)
|
||||
control_lbox->Append(StrToWxStr((*i)->GetName()));
|
||||
}
|
||||
else
|
||||
for (Device::Input* input : dev->Inputs())
|
||||
{
|
||||
// for outputs
|
||||
std::vector<Device::Output*>::const_iterator
|
||||
i = dev->Outputs().begin(),
|
||||
e = dev->Outputs().end();
|
||||
for (; i!=e; ++i)
|
||||
control_lbox->Append(StrToWxStr((*i)->GetName()));
|
||||
control_lbox->Append(StrToWxStr(input->GetName()));
|
||||
}
|
||||
}
|
||||
else // It's an output
|
||||
{
|
||||
for (Device::Output* output : dev->Outputs())
|
||||
{
|
||||
control_lbox->Append(StrToWxStr(output->GetName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -246,24 +234,19 @@ void GamepadPage::UpdateGUI()
|
||||
{
|
||||
device_cbox->SetValue(StrToWxStr(controller->default_device.ToString()));
|
||||
|
||||
std::vector< ControlGroupBox* >::const_iterator g = control_groups.begin(),
|
||||
ge = control_groups.end();
|
||||
for (; g!=ge; ++g)
|
||||
for (ControlGroupBox* cgBox : control_groups)
|
||||
{
|
||||
// buttons
|
||||
std::vector<ControlButton*>::const_iterator i = (*g)->control_buttons.begin()
|
||||
, e = (*g)->control_buttons.end();
|
||||
for (; i!=e; ++i) {
|
||||
wxString expr = StrToWxStr((*i)->control_reference->expression);
|
||||
for (ControlButton* button : cgBox->control_buttons)
|
||||
{
|
||||
wxString expr = StrToWxStr(button->control_reference->expression);
|
||||
expr.Replace("&", "&&");
|
||||
(*i)->SetLabel(expr);
|
||||
button->SetLabel(expr);
|
||||
}
|
||||
|
||||
// cboxes
|
||||
std::vector<PadSetting*>::const_iterator si = (*g)->options.begin()
|
||||
, se = (*g)->options.end();
|
||||
for (; si!=se; ++si)
|
||||
(*si)->UpdateGUI();
|
||||
for (PadSetting* padSetting : cgBox->options)
|
||||
{
|
||||
padSetting->UpdateGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,9 +325,10 @@ void ControlDialog::ClearControl(wxCommandEvent&)
|
||||
|
||||
inline bool IsAlphabetic(wxString &str)
|
||||
{
|
||||
for (wxString::const_iterator it = str.begin(); it != str.end(); ++it)
|
||||
if (!isalpha(*it))
|
||||
for (wxUniChar c : str)
|
||||
if (!isalpha(c))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -423,7 +407,9 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
|
||||
expr = wxString::Format("%c(%s)", op, selection);
|
||||
}
|
||||
else
|
||||
{
|
||||
expr = wxString::Format(" %c %s", op, device_expr);
|
||||
}
|
||||
|
||||
textctrl->WriteText(expr);
|
||||
control_reference->expression = textctrl->GetValue();
|
||||
@ -605,7 +591,7 @@ wxStaticBoxSizer* ControlDialog::CreateControlChooser(GamepadPage* const parent)
|
||||
void GamepadPage::GetProfilePath(std::string& path)
|
||||
{
|
||||
const wxString& name = profile_cbox->GetValue();
|
||||
if (false == name.empty())
|
||||
if (!name.empty())
|
||||
{
|
||||
// TODO: check for dumb characters maybe
|
||||
|
||||
@ -623,7 +609,7 @@ void GamepadPage::LoadProfile(wxCommandEvent&)
|
||||
std::string fname;
|
||||
GamepadPage::GetProfilePath(fname);
|
||||
|
||||
if (false == File::Exists(fname))
|
||||
if (!File::Exists(fname))
|
||||
return;
|
||||
|
||||
IniFile inifile;
|
||||
@ -642,7 +628,7 @@ void GamepadPage::SaveProfile(wxCommandEvent&)
|
||||
GamepadPage::GetProfilePath(fname);
|
||||
File::CreateFullPath(fname);
|
||||
|
||||
if (false == fname.empty())
|
||||
if (!fname.empty())
|
||||
{
|
||||
IniFile inifile;
|
||||
controller->SaveConfig(inifile.GetOrCreateSection("Profile"));
|
||||
@ -675,21 +661,18 @@ void GamepadPage::DeleteProfile(wxCommandEvent&)
|
||||
|
||||
void InputConfigDialog::UpdateDeviceComboBox()
|
||||
{
|
||||
std::vector< GamepadPage* >::iterator i = m_padpages.begin(),
|
||||
e = m_padpages.end();
|
||||
DeviceQualifier dq;
|
||||
for (; i != e; ++i)
|
||||
for (GamepadPage* page : m_padpages)
|
||||
{
|
||||
(*i)->device_cbox->Clear();
|
||||
std::vector<Device*>::const_iterator
|
||||
di = g_controller_interface.Devices().begin(),
|
||||
de = g_controller_interface.Devices().end();
|
||||
for (; di!=de; ++di)
|
||||
page->device_cbox->Clear();
|
||||
|
||||
for (Device* d : g_controller_interface.Devices())
|
||||
{
|
||||
dq.FromDevice(*di);
|
||||
(*i)->device_cbox->Append(StrToWxStr(dq.ToString()));
|
||||
dq.FromDevice(d);
|
||||
page->device_cbox->Append(StrToWxStr(dq.ToString()));
|
||||
}
|
||||
(*i)->device_cbox->SetValue(StrToWxStr((*i)->controller->default_device.ToString()));
|
||||
|
||||
page->device_cbox->SetValue(StrToWxStr(page->controller->default_device.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -710,11 +693,8 @@ void GamepadPage::RefreshDevices(wxCommandEvent&)
|
||||
|
||||
ControlGroupBox::~ControlGroupBox()
|
||||
{
|
||||
std::vector<PadSetting*>::const_iterator
|
||||
i = options.begin(),
|
||||
e = options.end();
|
||||
for (; i!=e; ++i)
|
||||
delete *i;
|
||||
for (PadSetting* padSetting : options)
|
||||
delete padSetting;
|
||||
}
|
||||
|
||||
ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWindow* const parent, GamepadPage* const eventsink)
|
||||
@ -724,20 +704,16 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
static_bitmap = NULL;
|
||||
|
||||
wxFont m_SmallFont(7, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
||||
std::vector<ControllerEmu::ControlGroup::Control*>::iterator
|
||||
ci = group->controls.begin(),
|
||||
ce = group->controls.end();
|
||||
for (; ci != ce; ++ci)
|
||||
for (auto& control : group->controls)
|
||||
{
|
||||
wxStaticText* const label = new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr(control->name)));
|
||||
|
||||
wxStaticText* const label = new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr((*ci)->name)));
|
||||
|
||||
ControlButton* const control_button = new ControlButton(parent, (*ci)->control_ref, 80);
|
||||
ControlButton* const control_button = new ControlButton(parent, control->control_ref.get(), 80);
|
||||
control_button->SetFont(m_SmallFont);
|
||||
|
||||
control_buttons.push_back(control_button);
|
||||
|
||||
if ((*ci)->control_ref->is_input)
|
||||
if (control->control_ref->is_input)
|
||||
{
|
||||
control_button->SetToolTip(_("Left-click to detect input.\nMiddle-click to clear.\nRight-click for more options."));
|
||||
control_button->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &GamepadPage::DetectControl, eventsink);
|
||||
@ -774,17 +750,13 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
dc.Clear();
|
||||
static_bitmap = new wxStaticBitmap(parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
||||
|
||||
std::vector< ControllerEmu::ControlGroup::Setting* >::const_iterator
|
||||
i = group->settings.begin(),
|
||||
e = group->settings.end();
|
||||
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
||||
for (; i!=e; ++i)
|
||||
for (auto& groupSetting : group->settings)
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, *i);
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
szr->Add(new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr((*i)->name))));
|
||||
szr->Add(new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr(groupSetting->name))));
|
||||
szr->Add(setting->wxcontrol, 0, wxLEFT, 0);
|
||||
}
|
||||
|
||||
@ -802,7 +774,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
dc.Clear();
|
||||
static_bitmap = new wxStaticBitmap(parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
||||
|
||||
PadSettingSpin* const threshold_cbox = new PadSettingSpin(parent, group->settings[0]);
|
||||
PadSettingSpin* const threshold_cbox = new PadSettingSpin(parent, group->settings[0].get());
|
||||
threshold_cbox->wxcontrol->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &GamepadPage::AdjustSetting, eventsink);
|
||||
|
||||
threshold_cbox->wxcontrol->SetToolTip(_("Adjust the analog control pressure required to activate buttons."));
|
||||
@ -836,16 +808,13 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
dc.Clear();
|
||||
static_bitmap = new wxStaticBitmap(parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP);
|
||||
|
||||
std::vector<ControllerEmu::ControlGroup::Setting*>::const_iterator
|
||||
i = group->settings.begin(),
|
||||
e = group->settings.end();
|
||||
for (; i!=e; ++i)
|
||||
for (auto& groupSetting : group->settings)
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, *i);
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_COMMAND_SPINCTRL_UPDATED, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
szr->Add(new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr((*i)->name))), 0, wxCENTER|wxRIGHT, 3);
|
||||
szr->Add(new wxStaticText(parent, -1, wxGetTranslation(StrToWxStr(groupSetting->name))), 0, wxCENTER|wxRIGHT, 3);
|
||||
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
||||
Add(szr, 0, wxALL|wxCENTER, 3);
|
||||
}
|
||||
@ -877,18 +846,13 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
default:
|
||||
{
|
||||
//options
|
||||
|
||||
std::vector<ControllerEmu::ControlGroup::Setting*>::const_iterator
|
||||
i = group->settings.begin(),
|
||||
e = group->settings.end();
|
||||
for (; i!=e; ++i)
|
||||
for (auto& groupSetting : group->settings)
|
||||
{
|
||||
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, (*i)->value, (*i)->name);
|
||||
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting->value, groupSetting->name);
|
||||
setting_cbox->wxcontrol->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting_cbox);
|
||||
|
||||
Add(setting_cbox->wxcontrol, 0, wxALL|wxLEFT, 5);
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -905,9 +869,9 @@ ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow
|
||||
size_t col_size = 0;
|
||||
|
||||
wxBoxSizer* stacked_groups = NULL;
|
||||
for (ControllerEmu::ControlGroup* group : controller->groups)
|
||||
for (auto& group : controller->groups)
|
||||
{
|
||||
ControlGroupBox* control_group_box = new ControlGroupBox(group, parent, eventsink);
|
||||
ControlGroupBox* control_group_box = new ControlGroupBox(group.get(), parent, eventsink);
|
||||
wxStaticBoxSizer *control_group =
|
||||
new wxStaticBoxSizer(wxVERTICAL, parent, wxGetTranslation(StrToWxStr(group->name)));
|
||||
control_group->Add(control_group_box);
|
||||
|
@ -8,95 +8,33 @@
|
||||
#include <X11/Xlib.h>
|
||||
#endif
|
||||
|
||||
ControllerEmu::~ControllerEmu()
|
||||
{
|
||||
// control groups
|
||||
std::vector<ControlGroup*>::const_iterator
|
||||
i = groups.begin(),
|
||||
e = groups.end();
|
||||
for (; i!=e; ++i)
|
||||
delete *i;
|
||||
}
|
||||
|
||||
ControllerEmu::ControlGroup::~ControlGroup()
|
||||
{
|
||||
// controls
|
||||
std::vector<Control*>::const_iterator
|
||||
ci = controls.begin(),
|
||||
ce = controls.end();
|
||||
for (; ci!=ce; ++ci)
|
||||
delete *ci;
|
||||
|
||||
// settings
|
||||
std::vector<Setting*>::const_iterator
|
||||
si = settings.begin(),
|
||||
se = settings.end();
|
||||
for (; si!=se; ++si)
|
||||
delete *si;
|
||||
}
|
||||
|
||||
ControllerEmu::Extension::~Extension()
|
||||
{
|
||||
// attachments
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
ai = attachments.begin(),
|
||||
ae = attachments.end();
|
||||
for (; ai!=ae; ++ai)
|
||||
delete *ai;
|
||||
}
|
||||
ControllerEmu::ControlGroup::Control::~Control()
|
||||
{
|
||||
delete control_ref;
|
||||
}
|
||||
|
||||
void ControllerEmu::UpdateReferences(ControllerInterface& devi)
|
||||
{
|
||||
std::vector<ControlGroup*>::const_iterator
|
||||
i = groups.begin(),
|
||||
e = groups.end();
|
||||
for (; i!=e; ++i)
|
||||
for (auto& ctrlGroup : groups)
|
||||
{
|
||||
std::vector<ControlGroup::Control*>::const_iterator
|
||||
ci = (*i)->controls.begin(),
|
||||
ce = (*i)->controls.end();
|
||||
for (; ci!=ce; ++ci)
|
||||
devi.UpdateReference((*ci)->control_ref, default_device);
|
||||
for (auto& control : ctrlGroup->controls)
|
||||
devi.UpdateReference(control->control_ref.get(), default_device);
|
||||
|
||||
// extension
|
||||
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
||||
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
ai = ((Extension*)*i)->attachments.begin(),
|
||||
ae = ((Extension*)*i)->attachments.end();
|
||||
for (; ai!=ae; ++ai)
|
||||
(*ai)->UpdateReferences(devi);
|
||||
for (auto& attachment : ((Extension*)ctrlGroup.get())->attachments)
|
||||
attachment->UpdateReferences(devi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ControllerEmu::UpdateDefaultDevice()
|
||||
{
|
||||
std::vector<ControlGroup*>::const_iterator
|
||||
i = groups.begin(),
|
||||
e = groups.end();
|
||||
for (; i!=e; ++i)
|
||||
for (auto& ctrlGroup : groups)
|
||||
{
|
||||
//std::vector<ControlGroup::Control*>::const_iterator
|
||||
//ci = (*i)->controls.begin(),
|
||||
//ce = (*i)->controls.end();
|
||||
//for (; ci!=ce; ++ci)
|
||||
//(*ci)->control_ref->device_qualifier = default_device;
|
||||
|
||||
// extension
|
||||
if (GROUP_TYPE_EXTENSION == (*i)->type)
|
||||
if (ctrlGroup->type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
ai = ((Extension*)*i)->attachments.begin(),
|
||||
ae = ((Extension*)*i)->attachments.end();
|
||||
for (; ai!=ae; ++ai)
|
||||
for (auto& ai : ((Extension*)ctrlGroup.get())->attachments)
|
||||
{
|
||||
(*ai)->default_device = default_device;
|
||||
(*ai)->UpdateDefaultDevice();
|
||||
ai->default_device = default_device;
|
||||
ai->UpdateDefaultDevice();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,50 +45,42 @@ void ControllerEmu::ControlGroup::LoadConfig(IniFile::Section *sec, const std::s
|
||||
std::string group(base + name); group += "/";
|
||||
|
||||
// settings
|
||||
std::vector<ControlGroup::Setting*>::const_iterator
|
||||
si = settings.begin(),
|
||||
se = settings.end();
|
||||
for (; si!=se; ++si)
|
||||
for (auto& s : settings)
|
||||
{
|
||||
sec->Get((group+(*si)->name).c_str(), &(*si)->value, (*si)->default_value*100);
|
||||
(*si)->value /= 100;
|
||||
sec->Get((group + s->name).c_str(), &s->value, s->default_value * 100);
|
||||
s->value /= 100;
|
||||
}
|
||||
|
||||
// controls
|
||||
std::vector<ControlGroup::Control*>::const_iterator
|
||||
ci = controls.begin(),
|
||||
ce = controls.end();
|
||||
for (; ci!=ce; ++ci)
|
||||
for (auto& c : controls)
|
||||
{
|
||||
// control expression
|
||||
sec->Get((group + (*ci)->name).c_str(), &(*ci)->control_ref->expression, "");
|
||||
sec->Get((group + c->name).c_str(), &c->control_ref->expression, "");
|
||||
|
||||
// range
|
||||
sec->Get((group+(*ci)->name+"/Range").c_str(), &(*ci)->control_ref->range, 100.0f);
|
||||
(*ci)->control_ref->range /= 100;
|
||||
sec->Get((group + c->name + "/Range").c_str(), &c->control_ref->range, 100.0f);
|
||||
c->control_ref->range /= 100;
|
||||
|
||||
}
|
||||
|
||||
// extensions
|
||||
if (GROUP_TYPE_EXTENSION == type)
|
||||
if (type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
Extension* const ex = ((Extension*)this);
|
||||
Extension* const ext = ((Extension*)this);
|
||||
|
||||
ex->switch_extension = 0;
|
||||
ext->switch_extension = 0;
|
||||
unsigned int n = 0;
|
||||
std::string extname;
|
||||
sec->Get((base + name).c_str(), &extname, "");
|
||||
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
ai = ((Extension*)this)->attachments.begin(),
|
||||
ae = ((Extension*)this)->attachments.end();
|
||||
for (; ai!=ae; ++ai,++n)
|
||||
for (auto& ai : ext->attachments)
|
||||
{
|
||||
(*ai)->default_device.FromString(defdev);
|
||||
(*ai)->LoadConfig(sec, base + (*ai)->GetName() + "/");
|
||||
ai->default_device.FromString(defdev);
|
||||
ai->LoadConfig(sec, base + ai->GetName() + "/");
|
||||
|
||||
if ((*ai)->GetName() == extname)
|
||||
ex->switch_extension = n;
|
||||
if (ai->GetName() == extname)
|
||||
ext->switch_extension = n;
|
||||
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,47 +93,35 @@ void ControllerEmu::LoadConfig(IniFile::Section *sec, const std::string& base)
|
||||
sec->Get((base + "Device").c_str(), &defdev, "");
|
||||
default_device.FromString(defdev);
|
||||
}
|
||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
||||
e = groups.end();
|
||||
for (; i!=e; ++i)
|
||||
(*i)->LoadConfig(sec, defdev, base);
|
||||
|
||||
for (auto& cg : groups)
|
||||
cg->LoadConfig(sec, defdev, base);
|
||||
}
|
||||
|
||||
void ControllerEmu::ControlGroup::SaveConfig(IniFile::Section *sec, const std::string& defdev, const std::string& base)
|
||||
{
|
||||
std::string group(base + name); group += "/";
|
||||
|
||||
// settings
|
||||
std::vector<ControlGroup::Setting*>::const_iterator
|
||||
si = settings.begin(),
|
||||
se = settings.end();
|
||||
for (; si!=se; ++si)
|
||||
sec->Set((group+(*si)->name).c_str(), (*si)->value*100.0f, (*si)->default_value*100.0f);
|
||||
for (auto& s : settings)
|
||||
sec->Set((group + s->name).c_str(), s->value*100.0f, s->default_value*100.0f);
|
||||
|
||||
// controls
|
||||
std::vector<ControlGroup::Control*>::const_iterator
|
||||
ci = controls.begin(),
|
||||
ce = controls.end();
|
||||
for (; ci!=ce; ++ci)
|
||||
for (auto& c : controls)
|
||||
{
|
||||
// control expression
|
||||
sec->Set((group+(*ci)->name).c_str(), (*ci)->control_ref->expression, "");
|
||||
sec->Set((group + c->name).c_str(), c->control_ref->expression, "");
|
||||
|
||||
// range
|
||||
sec->Set((group+(*ci)->name+"/Range").c_str(), (*ci)->control_ref->range*100.0f, 100.0f);
|
||||
sec->Set((group + c->name + "/Range").c_str(), c->control_ref->range*100.0f, 100.0f);
|
||||
}
|
||||
|
||||
// extensions
|
||||
if (GROUP_TYPE_EXTENSION == type)
|
||||
if (type == GROUP_TYPE_EXTENSION)
|
||||
{
|
||||
Extension* const ext = ((Extension*)this);
|
||||
sec->Set((base + name).c_str(), ext->attachments[ext->switch_extension]->GetName(), "None");
|
||||
|
||||
std::vector<ControllerEmu*>::const_iterator
|
||||
ai = ((Extension*)this)->attachments.begin(),
|
||||
ae = ((Extension*)this)->attachments.end();
|
||||
for (; ai!=ae; ++ai)
|
||||
(*ai)->SaveConfig(sec, base + (*ai)->GetName() + "/");
|
||||
for (auto& ai : ext->attachments)
|
||||
ai->SaveConfig(sec, base + ai->GetName() + "/");
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,60 +131,58 @@ void ControllerEmu::SaveConfig(IniFile::Section *sec, const std::string& base)
|
||||
if (base.empty())
|
||||
sec->Set((/*std::string(" ") +*/ base + "Device").c_str(), defdev, "");
|
||||
|
||||
std::vector<ControlGroup*>::const_iterator i = groups.begin(),
|
||||
e = groups.end();
|
||||
for (; i!=e; ++i)
|
||||
(*i)->SaveConfig(sec, defdev, base);
|
||||
for (auto& ctrlGroup : groups)
|
||||
ctrlGroup->SaveConfig(sec, defdev, base);
|
||||
}
|
||||
|
||||
ControllerEmu::AnalogStick::AnalogStick(const char* const _name) : ControlGroup(_name, GROUP_TYPE_STICK)
|
||||
{
|
||||
for (auto& named_direction : named_directions)
|
||||
controls.push_back(new Input(named_direction));
|
||||
controls.emplace_back(new Input(named_direction));
|
||||
|
||||
controls.push_back(new Input(_trans("Modifier")));
|
||||
controls.emplace_back(new Input(_trans("Modifier")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Radius"), 0.7f, 0, 100));
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.push_back(new Setting(_trans("Square Stick"), 0));
|
||||
settings.emplace_back(new Setting(_trans("Radius"), 0.7f, 0, 100));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Square Stick"), 0));
|
||||
|
||||
}
|
||||
|
||||
ControllerEmu::Buttons::Buttons(const char* const _name) : ControlGroup(_name, GROUP_TYPE_BUTTONS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Threshold"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Threshold"), 0.5f));
|
||||
}
|
||||
|
||||
ControllerEmu::MixedTriggers::MixedTriggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_MIXED_TRIGGERS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Threshold"), 0.9f));
|
||||
settings.emplace_back(new Setting(_trans("Threshold"), 0.9f));
|
||||
}
|
||||
|
||||
ControllerEmu::Triggers::Triggers(const char* const _name) : ControlGroup(_name, GROUP_TYPE_TRIGGERS)
|
||||
{
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Slider::Slider(const char* const _name) : ControlGroup(_name, GROUP_TYPE_SLIDER)
|
||||
{
|
||||
controls.push_back(new Input("Left"));
|
||||
controls.push_back(new Input("Right"));
|
||||
controls.emplace_back(new Input("Left"));
|
||||
controls.emplace_back(new Input("Right"));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Force::Force(const char* const _name) : ControlGroup(_name, GROUP_TYPE_FORCE)
|
||||
{
|
||||
memset(m_swing, 0, sizeof(m_swing));
|
||||
|
||||
controls.push_back(new Input(_trans("Up")));
|
||||
controls.push_back(new Input(_trans("Down")));
|
||||
controls.push_back(new Input(_trans("Left")));
|
||||
controls.push_back(new Input(_trans("Right")));
|
||||
controls.push_back(new Input(_trans("Forward")));
|
||||
controls.push_back(new Input(_trans("Backward")));
|
||||
controls.emplace_back(new Input(_trans("Up")));
|
||||
controls.emplace_back(new Input(_trans("Down")));
|
||||
controls.emplace_back(new Input(_trans("Left")));
|
||||
controls.emplace_back(new Input(_trans("Right")));
|
||||
controls.emplace_back(new Input(_trans("Forward")));
|
||||
controls.emplace_back(new Input(_trans("Backward")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
}
|
||||
|
||||
ControllerEmu::Tilt::Tilt(const char* const _name)
|
||||
@ -274,16 +190,16 @@ ControllerEmu::Tilt::Tilt(const char* const _name)
|
||||
{
|
||||
memset(m_tilt, 0, sizeof(m_tilt));
|
||||
|
||||
controls.push_back(new Input("Forward"));
|
||||
controls.push_back(new Input("Backward"));
|
||||
controls.push_back(new Input("Left"));
|
||||
controls.push_back(new Input("Right"));
|
||||
controls.emplace_back(new Input("Forward"));
|
||||
controls.emplace_back(new Input("Backward"));
|
||||
controls.emplace_back(new Input("Left"));
|
||||
controls.emplace_back(new Input("Right"));
|
||||
|
||||
controls.push_back(new Input(_trans("Modifier")));
|
||||
controls.emplace_back(new Input(_trans("Modifier")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.push_back(new Setting(_trans("Circle Stick"), 0));
|
||||
settings.push_back(new Setting(_trans("Angle"), 0.9f, 0, 180));
|
||||
settings.emplace_back(new Setting(_trans("Dead Zone"), 0, 0, 50));
|
||||
settings.emplace_back(new Setting(_trans("Circle Stick"), 0));
|
||||
settings.emplace_back(new Setting(_trans("Angle"), 0.9f, 0, 180));
|
||||
}
|
||||
|
||||
ControllerEmu::Cursor::Cursor(const char* const _name)
|
||||
@ -291,14 +207,14 @@ ControllerEmu::Cursor::Cursor(const char* const _name)
|
||||
, m_z(0)
|
||||
{
|
||||
for (auto& named_direction : named_directions)
|
||||
controls.push_back(new Input(named_direction));
|
||||
controls.push_back(new Input("Forward"));
|
||||
controls.push_back(new Input("Backward"));
|
||||
controls.push_back(new Input(_trans("Hide")));
|
||||
controls.emplace_back(new Input(named_direction));
|
||||
controls.emplace_back(new Input("Forward"));
|
||||
controls.emplace_back(new Input("Backward"));
|
||||
controls.emplace_back(new Input(_trans("Hide")));
|
||||
|
||||
settings.push_back(new Setting(_trans("Center"), 0.5f));
|
||||
settings.push_back(new Setting(_trans("Width"), 0.5f));
|
||||
settings.push_back(new Setting(_trans("Height"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Center"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Width"), 0.5f));
|
||||
settings.emplace_back(new Setting(_trans("Height"), 0.5f));
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define NOMINMAX
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
@ -42,7 +43,7 @@ enum
|
||||
SETTING_SQUARE,
|
||||
};
|
||||
|
||||
const char * const named_directions[] =
|
||||
const char* const named_directions[] =
|
||||
{
|
||||
"Up",
|
||||
"Down",
|
||||
@ -61,13 +62,13 @@ public:
|
||||
class Control
|
||||
{
|
||||
protected:
|
||||
Control(ControllerInterface::ControlReference* const _ref, const char * const _name)
|
||||
: control_ref(_ref), name(_name){}
|
||||
public:
|
||||
Control(ControllerInterface::ControlReference* const _ref, const char* const _name)
|
||||
: control_ref(_ref), name(_name) {}
|
||||
|
||||
virtual ~Control();
|
||||
ControllerInterface::ControlReference* const control_ref;
|
||||
const char * const name;
|
||||
public:
|
||||
virtual ~Control() {}
|
||||
std::unique_ptr<ControllerInterface::ControlReference> const control_ref;
|
||||
const char* const name;
|
||||
|
||||
};
|
||||
|
||||
@ -75,18 +76,16 @@ public:
|
||||
{
|
||||
public:
|
||||
|
||||
Input(const char * const _name)
|
||||
Input(const char* const _name)
|
||||
: Control(new ControllerInterface::InputReference, _name) {}
|
||||
|
||||
};
|
||||
|
||||
class Output : public Control
|
||||
{
|
||||
public:
|
||||
|
||||
Output(const char * const _name)
|
||||
Output(const char* const _name)
|
||||
: Control(new ControllerInterface::OutputReference, _name) {}
|
||||
|
||||
};
|
||||
|
||||
class Setting
|
||||
@ -94,7 +93,7 @@ public:
|
||||
public:
|
||||
|
||||
Setting(const char* const _name, const ControlState def_value
|
||||
, const unsigned int _low = 0, const unsigned int _high = 100 )
|
||||
, const unsigned int _low = 0, const unsigned int _high = 100)
|
||||
: name(_name)
|
||||
, value(def_value)
|
||||
, default_value(def_value)
|
||||
@ -108,7 +107,7 @@ public:
|
||||
};
|
||||
|
||||
ControlGroup(const char* const _name, const unsigned int _type = GROUP_TYPE_OTHER) : name(_name), type(_type) {}
|
||||
virtual ~ControlGroup();
|
||||
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 = "" );
|
||||
@ -116,8 +115,8 @@ public:
|
||||
const char* const name;
|
||||
const unsigned int type;
|
||||
|
||||
std::vector< Control* > controls;
|
||||
std::vector< Setting* > settings;
|
||||
std::vector<std::unique_ptr<Control>> controls;
|
||||
std::vector<std::unique_ptr<Setting>> settings;
|
||||
|
||||
};
|
||||
|
||||
@ -194,14 +193,12 @@ public:
|
||||
template <typename C>
|
||||
void GetState(C* const buttons, const C* bitmasks)
|
||||
{
|
||||
std::vector<Control*>::iterator
|
||||
i = controls.begin(),
|
||||
e = controls.end();
|
||||
|
||||
for (; i!=e; ++i, ++bitmasks)
|
||||
for (auto& control : controls)
|
||||
{
|
||||
if ((*i)->control_ref->State() > settings[0]->value) // threshold
|
||||
if (control->control_ref->State() > settings[0]->value) // threshold
|
||||
*buttons |= *bitmasks;
|
||||
|
||||
bitmasks++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,6 +288,7 @@ public:
|
||||
ax = tmpf;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
float m_swing[3];
|
||||
};
|
||||
@ -370,6 +368,7 @@ public:
|
||||
*y = C(m_tilt[1] * angle * range + base);
|
||||
*x = C(m_tilt[0] * angle * range + base);
|
||||
}
|
||||
|
||||
private:
|
||||
float m_tilt[2];
|
||||
};
|
||||
@ -425,17 +424,18 @@ public:
|
||||
: ControlGroup(_name, GROUP_TYPE_EXTENSION)
|
||||
, switch_extension(0)
|
||||
, active_extension(0) {}
|
||||
~Extension();
|
||||
|
||||
~Extension() {}
|
||||
|
||||
void GetState(u8* const data, const bool focus = true);
|
||||
|
||||
std::vector<ControllerEmu*> attachments;
|
||||
std::vector<std::unique_ptr<ControllerEmu>> attachments;
|
||||
|
||||
int switch_extension;
|
||||
int active_extension;
|
||||
};
|
||||
|
||||
virtual ~ControllerEmu();
|
||||
virtual ~ControllerEmu() {}
|
||||
|
||||
virtual std::string GetName() const = 0;
|
||||
|
||||
@ -447,7 +447,7 @@ public:
|
||||
|
||||
void UpdateReferences(ControllerInterface& devi);
|
||||
|
||||
std::vector< ControlGroup* > groups;
|
||||
std::vector<std::unique_ptr<ControlGroup>> groups;
|
||||
|
||||
DeviceQualifier default_device;
|
||||
};
|
||||
|
@ -40,7 +40,7 @@ ControllerInterface g_controller_interface;
|
||||
//
|
||||
// Init
|
||||
//
|
||||
// detect devices and inputs outputs / will make refresh function later
|
||||
// Detect devices and inputs outputs / will make refresh function later
|
||||
//
|
||||
void ControllerInterface::Initialize()
|
||||
{
|
||||
@ -81,29 +81,24 @@ if (GLWin.platform == EGL_PLATFORM_X11) {
|
||||
//
|
||||
// DeInit
|
||||
//
|
||||
// remove all devices/ call library cleanup functions
|
||||
// Remove all devices/ call library cleanup functions
|
||||
//
|
||||
void ControllerInterface::Shutdown()
|
||||
{
|
||||
if (false == m_is_init)
|
||||
if (!m_is_init)
|
||||
return;
|
||||
|
||||
std::vector<Device*>::const_iterator
|
||||
d = m_devices.begin(),
|
||||
de = m_devices.end();
|
||||
for ( ;d != de; ++d )
|
||||
for (Device* d : m_devices)
|
||||
{
|
||||
std::vector<Device::Output*>::const_iterator
|
||||
o = (*d)->Outputs().begin(),
|
||||
oe = (*d)->Outputs().end();
|
||||
// set outputs to ZERO before destroying device
|
||||
for ( ;o!=oe; ++o)
|
||||
(*o)->SetState(0);
|
||||
// update output
|
||||
(*d)->UpdateOutput();
|
||||
// Set outputs to ZERO before destroying device
|
||||
for (Device::Output* o : d->Outputs())
|
||||
o->SetState(0);
|
||||
|
||||
//delete device
|
||||
delete *d;
|
||||
// Update output
|
||||
d->UpdateOutput();
|
||||
|
||||
// Delete device
|
||||
delete d;
|
||||
}
|
||||
|
||||
m_devices.clear();
|
||||
@ -134,7 +129,7 @@ void ControllerInterface::Shutdown()
|
||||
//
|
||||
// SetHwnd
|
||||
//
|
||||
// sets the hwnd used for some crap when initializing, use before calling Init
|
||||
// Sets the hwnd used for some crap when initializing, use before calling Init
|
||||
//
|
||||
void ControllerInterface::SetHwnd( void* const hwnd )
|
||||
{
|
||||
@ -144,7 +139,7 @@ void ControllerInterface::SetHwnd( void* const hwnd )
|
||||
//
|
||||
// UpdateInput
|
||||
//
|
||||
// update input for all devices, return true if all devices returned successful
|
||||
// Update input for all devices, return true if all devices returned successful
|
||||
//
|
||||
bool ControllerInterface::UpdateInput(const bool force)
|
||||
{
|
||||
@ -157,12 +152,9 @@ bool ControllerInterface::UpdateInput(const bool force)
|
||||
|
||||
size_t ok_count = 0;
|
||||
|
||||
std::vector<Device*>::const_iterator
|
||||
d = m_devices.begin(),
|
||||
e = m_devices.end();
|
||||
for ( ;d != e; ++d )
|
||||
for (Device* d : m_devices)
|
||||
{
|
||||
if ((*d)->UpdateInput())
|
||||
if (d->UpdateInput())
|
||||
++ok_count;
|
||||
//else
|
||||
// disabled. it might be causing problems
|
||||
@ -175,7 +167,7 @@ bool ControllerInterface::UpdateInput(const bool force)
|
||||
//
|
||||
// UpdateOutput
|
||||
//
|
||||
// update output for all devices, return true if all devices returned successful
|
||||
// Update output for all devices, return true if all devices returned successful
|
||||
//
|
||||
bool ControllerInterface::UpdateOutput(const bool force)
|
||||
{
|
||||
@ -188,9 +180,9 @@ bool ControllerInterface::UpdateOutput(const bool force)
|
||||
|
||||
size_t ok_count = 0;
|
||||
|
||||
for (auto d = m_devices.cbegin(); d != m_devices.cend(); ++d)
|
||||
for (Device* d : m_devices)
|
||||
{
|
||||
if ((*d)->UpdateOutput())
|
||||
if (d->UpdateOutput())
|
||||
++ok_count;
|
||||
}
|
||||
|
||||
@ -200,7 +192,7 @@ bool ControllerInterface::UpdateOutput(const bool force)
|
||||
//
|
||||
// InputReference :: State
|
||||
//
|
||||
// get the state of an input reference
|
||||
// Gets the state of an input reference
|
||||
// override function for ControlReference::State ...
|
||||
//
|
||||
ControlState ControllerInterface::InputReference::State( const ControlState ignore )
|
||||
@ -214,9 +206,9 @@ ControlState ControllerInterface::InputReference::State( const ControlState igno
|
||||
//
|
||||
// OutputReference :: State
|
||||
//
|
||||
// set the state of all binded outputs
|
||||
// overrides ControlReference::State .. combined them so i could make the gui simple / inputs == same as outputs one list
|
||||
// i was lazy and it works so watever
|
||||
// Set the state of all binded outputs
|
||||
// overrides ControlReference::State .. combined them so I could make the GUI simple / inputs == same as outputs one list
|
||||
// I was lazy and it works so watever
|
||||
//
|
||||
ControlState ControllerInterface::OutputReference::State(const ControlState state)
|
||||
{
|
||||
@ -228,7 +220,7 @@ ControlState ControllerInterface::OutputReference::State(const ControlState stat
|
||||
//
|
||||
// UpdateReference
|
||||
//
|
||||
// updates a controlreference's binded devices/controls
|
||||
// Updates a controlreference's binded devices/controls
|
||||
// need to call this to re-parse a control reference's expression after changing it
|
||||
//
|
||||
void ControllerInterface::UpdateReference(ControllerInterface::ControlReference* ref
|
||||
@ -244,7 +236,7 @@ void ControllerInterface::UpdateReference(ControllerInterface::ControlReference*
|
||||
//
|
||||
// InputReference :: Detect
|
||||
//
|
||||
// wait for input on all binded devices
|
||||
// Wait for input on all binded devices
|
||||
// supports not detecting inputs that were held down at the time of Detect start,
|
||||
// which is useful for those crazy flightsticks that have certain buttons that are always held down
|
||||
// or some crazy axes or something
|
||||
|
@ -37,8 +37,8 @@ using namespace ciface::Core;
|
||||
//
|
||||
// ControllerInterface
|
||||
//
|
||||
// some crazy shit I made to control different device inputs and outputs
|
||||
// from lots of different sources, hopefully more easily
|
||||
// Some crazy shit I made to control different device inputs and outputs
|
||||
// from lots of different sources, hopefully more easily.
|
||||
//
|
||||
class ControllerInterface : public DeviceContainer
|
||||
{
|
||||
@ -47,9 +47,9 @@ public:
|
||||
//
|
||||
// ControlReference
|
||||
//
|
||||
// these are what you create to actually use the inputs, InputReference or OutputReference
|
||||
// These are what you create to actually use the inputs, InputReference or OutputReference.
|
||||
//
|
||||
// after being bound to devices and controls with ControllerInterface::UpdateReference,
|
||||
// After being bound to devices and controls with ControllerInterface::UpdateReference,
|
||||
// each one can link to multiple devices and controls
|
||||
// when you change a ControlReference's expression,
|
||||
// you must use ControllerInterface::UpdateReference on it to rebind controls
|
||||
@ -66,11 +66,13 @@ public:
|
||||
const bool is_input;
|
||||
ciface::ExpressionParser::ExpressionParseStatus parse_error;
|
||||
|
||||
virtual ~ControlReference() {
|
||||
virtual ~ControlReference()
|
||||
{
|
||||
delete parsed_expression;
|
||||
}
|
||||
|
||||
int BoundCount() {
|
||||
int BoundCount()
|
||||
{
|
||||
if (parsed_expression)
|
||||
return parsed_expression->num_controls;
|
||||
else
|
||||
@ -85,7 +87,7 @@ public:
|
||||
//
|
||||
// InputReference
|
||||
//
|
||||
// control reference for inputs
|
||||
// Control reference for inputs
|
||||
//
|
||||
class InputReference : public ControlReference
|
||||
{
|
||||
@ -98,7 +100,7 @@ public:
|
||||
//
|
||||
// OutputReference
|
||||
//
|
||||
// control reference for outputs
|
||||
// Control reference for outputs
|
||||
//
|
||||
class OutputReference : public ControlReference
|
||||
{
|
||||
|
@ -65,65 +65,65 @@ void GetXInputGUIDS( std::vector<DWORD>& guids )
|
||||
bool bCleanupCOM = SUCCEEDED(hr);
|
||||
|
||||
// Create WMI
|
||||
hr = CoCreateInstance( __uuidof(WbemLocator),
|
||||
hr = CoCreateInstance(__uuidof(WbemLocator),
|
||||
NULL,
|
||||
CLSCTX_INPROC_SERVER,
|
||||
__uuidof(IWbemLocator),
|
||||
(LPVOID*) &pIWbemLocator);
|
||||
if( FAILED(hr) || pIWbemLocator == NULL )
|
||||
if (FAILED(hr) || pIWbemLocator == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
bstrNamespace = SysAllocString( L"\\\\.\\root\\cimv2" );if( bstrNamespace == NULL ) goto LCleanup;
|
||||
bstrClassName = SysAllocString( L"Win32_PNPEntity" ); if( bstrClassName == NULL ) goto LCleanup;
|
||||
bstrDeviceID = SysAllocString( L"DeviceID" ); if( bstrDeviceID == NULL ) goto LCleanup;
|
||||
bstrNamespace = SysAllocString(L"\\\\.\\root\\cimv2");if(bstrNamespace == NULL) goto LCleanup;
|
||||
bstrClassName = SysAllocString(L"Win32_PNPEntity"); if(bstrClassName == NULL) goto LCleanup;
|
||||
bstrDeviceID = SysAllocString(L"DeviceID"); if(bstrDeviceID == NULL) goto LCleanup;
|
||||
|
||||
// Connect to WMI
|
||||
hr = pIWbemLocator->ConnectServer( bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices );
|
||||
if( FAILED(hr) || pIWbemServices == NULL )
|
||||
hr = pIWbemLocator->ConnectServer(bstrNamespace, NULL, NULL, 0L, 0L, NULL, NULL, &pIWbemServices);
|
||||
if (FAILED(hr) || pIWbemServices == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
// Switch security level to IMPERSONATE.
|
||||
CoSetProxyBlanket( pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
||||
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE );
|
||||
CoSetProxyBlanket(pIWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
|
||||
RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);
|
||||
|
||||
hr = pIWbemServices->CreateInstanceEnum( bstrClassName, 0, NULL, &pEnumDevices );
|
||||
if( FAILED(hr) || pEnumDevices == NULL )
|
||||
hr = pIWbemServices->CreateInstanceEnum(bstrClassName, 0, NULL, &pEnumDevices);
|
||||
if (FAILED(hr) || pEnumDevices == NULL)
|
||||
goto LCleanup;
|
||||
|
||||
// Loop over all devices
|
||||
while( true )
|
||||
while (true)
|
||||
{
|
||||
// Get 20 at a time
|
||||
hr = pEnumDevices->Next( 10000, 20, pDevices, &uReturned );
|
||||
if( FAILED(hr) || uReturned == 0 )
|
||||
hr = pEnumDevices->Next(10000, 20, pDevices, &uReturned);
|
||||
if (FAILED(hr) || uReturned == 0)
|
||||
break;
|
||||
|
||||
for( UINT iDevice=0; iDevice<uReturned; ++iDevice )
|
||||
for (UINT iDevice = 0; iDevice < uReturned; ++iDevice)
|
||||
{
|
||||
// For each device, get its device ID
|
||||
hr = pDevices[iDevice]->Get( bstrDeviceID, 0L, &var, NULL, NULL );
|
||||
if( SUCCEEDED( hr ) && var.vt == VT_BSTR && var.bstrVal != NULL )
|
||||
hr = pDevices[iDevice]->Get(bstrDeviceID, 0L, &var, NULL, NULL);
|
||||
if (SUCCEEDED(hr) && var.vt == VT_BSTR && var.bstrVal != NULL)
|
||||
{
|
||||
// Check if the device ID contains "IG_". If it does, then it's an XInput device
|
||||
// This information can not be found from DirectInput
|
||||
if( wcsstr( var.bstrVal, L"IG_" ) )
|
||||
if (wcsstr(var.bstrVal, L"IG_"))
|
||||
{
|
||||
// If it does, then get the VID/PID from var.bstrVal
|
||||
DWORD dwPid = 0, dwVid = 0;
|
||||
WCHAR* strVid = wcsstr( var.bstrVal, L"VID_" );
|
||||
if( strVid && swscanf( strVid, L"VID_%4X", &dwVid ) != 1 )
|
||||
WCHAR* strVid = wcsstr(var.bstrVal, L"VID_");
|
||||
if (strVid && swscanf(strVid, L"VID_%4X", &dwVid) != 1)
|
||||
dwVid = 0;
|
||||
WCHAR* strPid = wcsstr( var.bstrVal, L"PID_" );
|
||||
if( strPid && swscanf( strPid, L"PID_%4X", &dwPid ) != 1 )
|
||||
WCHAR* strPid = wcsstr(var.bstrVal, L"PID_");
|
||||
if (strPid && swscanf(strPid, L"PID_%4X", &dwPid) != 1)
|
||||
dwPid = 0;
|
||||
|
||||
// Compare the VID/PID to the DInput device
|
||||
DWORD dwVidPid = MAKELONG( dwVid, dwPid );
|
||||
guids.push_back( dwVidPid );
|
||||
DWORD dwVidPid = MAKELONG(dwVid, dwPid);
|
||||
guids.push_back(dwVidPid);
|
||||
//bIsXinputDevice = true;
|
||||
}
|
||||
}
|
||||
SAFE_RELEASE( pDevices[iDevice] );
|
||||
SAFE_RELEASE(pDevices[iDevice]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,13 +134,13 @@ LCleanup:
|
||||
SysFreeString(bstrDeviceID);
|
||||
if(bstrClassName)
|
||||
SysFreeString(bstrClassName);
|
||||
for( UINT iDevice=0; iDevice<20; iDevice++ )
|
||||
SAFE_RELEASE( pDevices[iDevice] );
|
||||
SAFE_RELEASE( pEnumDevices );
|
||||
SAFE_RELEASE( pIWbemLocator );
|
||||
SAFE_RELEASE( pIWbemServices );
|
||||
for (UINT iDevice = 0; iDevice < 20; iDevice++)
|
||||
SAFE_RELEASE(pDevices[iDevice]);
|
||||
SAFE_RELEASE(pEnumDevices);
|
||||
SAFE_RELEASE(pIWbemLocator);
|
||||
SAFE_RELEASE(pIWbemServices);
|
||||
|
||||
if( bCleanupCOM )
|
||||
if (bCleanupCOM)
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
@ -156,17 +156,14 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
||||
std::vector<DWORD> xinput_guids;
|
||||
GetXInputGUIDS( xinput_guids );
|
||||
|
||||
std::list<DIDEVICEINSTANCE>::iterator
|
||||
i = joysticks.begin(),
|
||||
e = joysticks.end();
|
||||
for ( ; i!=e; ++i )
|
||||
for (DIDEVICEINSTANCE& joystick : joysticks)
|
||||
{
|
||||
// skip XInput Devices
|
||||
if ( std::find( xinput_guids.begin(), xinput_guids.end(), i->guidProduct.Data1 ) != xinput_guids.end() )
|
||||
if (std::find(xinput_guids.begin(), xinput_guids.end(), joystick.guidProduct.Data1) != xinput_guids.end())
|
||||
continue;
|
||||
|
||||
LPDIRECTINPUTDEVICE8 js_device;
|
||||
if (SUCCEEDED(idi8->CreateDevice(i->guidInstance, &js_device, NULL)))
|
||||
if (SUCCEEDED(idi8->CreateDevice(joystick.guidInstance, &js_device, NULL)))
|
||||
{
|
||||
if (SUCCEEDED(js_device->SetDataFormat(&c_dfDIJoystick)))
|
||||
{
|
||||
@ -182,7 +179,7 @@ void InitJoystick(IDirectInput8* const idi8, std::vector<Core::Device*>& devices
|
||||
}
|
||||
}
|
||||
|
||||
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[i->tszInstanceName]++);
|
||||
Joystick* js = new Joystick(/*&*i, */js_device, name_counts[joystick.tszInstanceName]++);
|
||||
// only add if it has some inputs/outputs
|
||||
if (js->Inputs().size() || js->Outputs().size())
|
||||
devices.push_back(js);
|
||||
@ -359,14 +356,11 @@ Joystick::Joystick( /*const LPCDIDEVICEINSTANCE lpddi, */const LPDIRECTINPUTDEVI
|
||||
Joystick::~Joystick()
|
||||
{
|
||||
// release the ff effect iface's
|
||||
std::list<EffectState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for (; i!=e; ++i)
|
||||
for (EffectState& state : m_state_out)
|
||||
{
|
||||
i->iface->Stop();
|
||||
i->iface->Unload();
|
||||
i->iface->Release();
|
||||
state.iface->Stop();
|
||||
state.iface->Unload();
|
||||
state.iface->Release();
|
||||
}
|
||||
|
||||
m_device->Unacquire();
|
||||
@ -377,7 +371,7 @@ void Joystick::ClearInputState()
|
||||
{
|
||||
ZeroMemory(&m_state_in, sizeof(m_state_in));
|
||||
// set hats to center
|
||||
memset( m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV) );
|
||||
memset(m_state_in.rgdwPOV, 0xFF, sizeof(m_state_in.rgdwPOV));
|
||||
}
|
||||
|
||||
std::string Joystick::GetName() const
|
||||
@ -449,26 +443,23 @@ bool Joystick::UpdateOutput()
|
||||
eff.dwSize = sizeof(DIEFFECT);
|
||||
eff.dwFlags = DIEFF_CARTESIAN | DIEFF_OBJECTOFFSETS;
|
||||
|
||||
std::list<EffectState>::iterator
|
||||
i = m_state_out.begin(),
|
||||
e = m_state_out.end();
|
||||
for (; i!=e; ++i)
|
||||
for (EffectState& state : m_state_out)
|
||||
{
|
||||
if (i->params)
|
||||
if (state.params)
|
||||
{
|
||||
if (i->size)
|
||||
if (state.size)
|
||||
{
|
||||
eff.cbTypeSpecificParams = i->size;
|
||||
eff.lpvTypeSpecificParams = i->params;
|
||||
eff.cbTypeSpecificParams = state.size;
|
||||
eff.lpvTypeSpecificParams = state.params;
|
||||
// set params and start effect
|
||||
ok_count += SUCCEEDED(i->iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
||||
ok_count += SUCCEEDED(state.iface->SetParameters(&eff, DIEP_TYPESPECIFICPARAMS | DIEP_START));
|
||||
}
|
||||
else
|
||||
{
|
||||
ok_count += SUCCEEDED(i->iface->Stop());
|
||||
ok_count += SUCCEEDED(state.iface->Stop());
|
||||
}
|
||||
|
||||
i->params = NULL;
|
||||
state.params = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -540,6 +531,7 @@ ControlState Joystick::Hat::GetState() const
|
||||
// hat centered code from MSDN
|
||||
if (0xFFFF == LOWORD(m_hat))
|
||||
return 0;
|
||||
|
||||
return (abs((int)(m_hat / 4500 - m_direction * 2 + 8) % 8 - 4) > 2);
|
||||
}
|
||||
|
||||
|
@ -16,23 +16,13 @@ namespace Core
|
||||
//
|
||||
Device::~Device()
|
||||
{
|
||||
{
|
||||
// delete inputs
|
||||
std::vector<Device::Input*>::iterator
|
||||
i = m_inputs.begin(),
|
||||
e = m_inputs.end();
|
||||
for ( ;i!=e; ++i)
|
||||
delete *i;
|
||||
}
|
||||
for (Device::Input* input : m_inputs)
|
||||
delete input;
|
||||
|
||||
{
|
||||
// delete outputs
|
||||
std::vector<Device::Output*>::iterator
|
||||
o = m_outputs.begin(),
|
||||
e = m_outputs.end();
|
||||
for ( ;o!=e; ++o)
|
||||
delete *o;
|
||||
}
|
||||
for (Device::Output* output: m_outputs)
|
||||
delete output;
|
||||
}
|
||||
|
||||
void Device::AddInput(Device::Input* const i)
|
||||
@ -47,24 +37,22 @@ void Device::AddOutput(Device::Output* const o)
|
||||
|
||||
Device::Input* Device::FindInput(const std::string &name) const
|
||||
{
|
||||
std::vector<Input*>::const_iterator
|
||||
it = m_inputs.begin(),
|
||||
itend = m_inputs.end();
|
||||
for (; it != itend; ++it)
|
||||
if ((*it)->GetName() == name)
|
||||
return *it;
|
||||
for (Input* input : m_inputs)
|
||||
{
|
||||
if (input->GetName() == name)
|
||||
return input;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Device::Output* Device::FindOutput(const std::string &name) const
|
||||
{
|
||||
std::vector<Output*>::const_iterator
|
||||
it = m_outputs.begin(),
|
||||
itend = m_outputs.end();
|
||||
for (; it != itend; ++it)
|
||||
if ((*it)->GetName() == name)
|
||||
return *it;
|
||||
for (Output* output : m_outputs)
|
||||
{
|
||||
if (output->GetName() == name)
|
||||
return output;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -86,24 +74,26 @@ void Device::ClearInputState()
|
||||
//
|
||||
// DeviceQualifier :: ToString
|
||||
//
|
||||
// get string from a device qualifier / serialize
|
||||
// Get string from a device qualifier / serialize
|
||||
//
|
||||
std::string DeviceQualifier::ToString() const
|
||||
{
|
||||
if (source.empty() && (cid < 0) && name.empty())
|
||||
return "";
|
||||
|
||||
std::ostringstream ss;
|
||||
ss << source << '/';
|
||||
if ( cid > -1 )
|
||||
if (cid > -1)
|
||||
ss << cid;
|
||||
ss << '/' << name;
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
//
|
||||
// DeviceQualifier :: FromString
|
||||
//
|
||||
// set a device qualifier from a string / unserialize
|
||||
// Set a device qualifier from a string / unserialize
|
||||
//
|
||||
void DeviceQualifier::FromString(const std::string& str)
|
||||
{
|
||||
@ -121,7 +111,7 @@ void DeviceQualifier::FromString(const std::string& str)
|
||||
//
|
||||
// DeviceQualifier :: FromDevice
|
||||
//
|
||||
// set a device qualifier from a device
|
||||
// Set a device qualifier from a device
|
||||
//
|
||||
void DeviceQualifier::FromDevice(const Device* const dev)
|
||||
{
|
||||
@ -136,6 +126,7 @@ bool DeviceQualifier::operator==(const Device* const dev) const
|
||||
if (dev->GetName() == name)
|
||||
if (dev->GetSource() == source)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -151,12 +142,11 @@ bool DeviceQualifier::operator==(const DeviceQualifier& devq) const
|
||||
|
||||
Device* DeviceContainer::FindDevice(const DeviceQualifier& devq) const
|
||||
{
|
||||
std::vector<Device*>::const_iterator
|
||||
di = m_devices.begin(),
|
||||
de = m_devices.end();
|
||||
for (; di!=de; ++di)
|
||||
if (devq == *di)
|
||||
return *di;
|
||||
for (Device* d : m_devices)
|
||||
{
|
||||
if (devq == d)
|
||||
return d;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -170,12 +160,9 @@ Device::Input* DeviceContainer::FindInput(const std::string& name, const Device*
|
||||
return inp;
|
||||
}
|
||||
|
||||
std::vector<Device*>::const_iterator
|
||||
di = m_devices.begin(),
|
||||
de = m_devices.end();
|
||||
for (; di != de; ++di)
|
||||
for (Device* d : m_devices)
|
||||
{
|
||||
Device::Input* const i = (*di)->FindInput(name);
|
||||
Device::Input* const i = d->FindInput(name);
|
||||
|
||||
if (i)
|
||||
return i;
|
||||
|
@ -21,7 +21,7 @@ class DeviceQualifier;
|
||||
//
|
||||
// Device
|
||||
//
|
||||
// a device class
|
||||
// A device class
|
||||
//
|
||||
class Device
|
||||
{
|
||||
@ -32,7 +32,7 @@ public:
|
||||
//
|
||||
// Control
|
||||
//
|
||||
// control includes inputs and outputs
|
||||
// Control includes inputs and outputs
|
||||
//
|
||||
class Control // input or output
|
||||
{
|
||||
@ -47,7 +47,7 @@ public:
|
||||
//
|
||||
// Input
|
||||
//
|
||||
// an input on a device
|
||||
// An input on a device
|
||||
//
|
||||
class Input : public Control
|
||||
{
|
||||
@ -63,7 +63,7 @@ public:
|
||||
//
|
||||
// Output
|
||||
//
|
||||
// an output on a device
|
||||
// An output on a device
|
||||
//
|
||||
class Output : public Control
|
||||
{
|
||||
@ -133,8 +133,8 @@ private:
|
||||
//
|
||||
// DeviceQualifier
|
||||
//
|
||||
// device qualifier used to match devices
|
||||
// currently has ( source, id, name ) properties which match a device
|
||||
// Device qualifier used to match devices.
|
||||
// Currently has ( source, id, name ) properties which match a device
|
||||
//
|
||||
class DeviceQualifier
|
||||
{
|
||||
|
@ -10,10 +10,8 @@
|
||||
InputPlugin::~InputPlugin()
|
||||
{
|
||||
// delete pads
|
||||
std::vector<ControllerEmu*>::const_iterator i = controllers.begin(),
|
||||
e = controllers.end();
|
||||
for ( ; i != e; ++i )
|
||||
delete *i;
|
||||
for (ControllerEmu* pad : controllers)
|
||||
delete pad;
|
||||
}
|
||||
|
||||
bool InputPlugin::LoadConfig(bool isGC)
|
||||
@ -58,25 +56,26 @@ bool InputPlugin::LoadConfig(bool isGC)
|
||||
|
||||
if (inifile.Load(File::GetUserPath(D_CONFIG_IDX) + ini_name + ".ini"))
|
||||
{
|
||||
std::vector< ControllerEmu* >::const_iterator
|
||||
i = controllers.begin(),
|
||||
e = controllers.end();
|
||||
for (int n = 0; i!=e; ++i, ++n)
|
||||
int n = 0;
|
||||
for (ControllerEmu* pad : controllers)
|
||||
{
|
||||
// load settings from ini
|
||||
// Load settings from ini
|
||||
if (useProfile[n])
|
||||
{
|
||||
IniFile profile_ini;
|
||||
profile_ini.Load(File::GetUserPath(D_CONFIG_IDX) + path + profile[n] + ".ini");
|
||||
(*i)->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
||||
pad->LoadConfig(profile_ini.GetOrCreateSection("Profile"));
|
||||
}
|
||||
else
|
||||
{
|
||||
(*i)->LoadConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
|
||||
pad->LoadConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
|
||||
}
|
||||
|
||||
// update refs
|
||||
(*i)->UpdateReferences(g_controller_interface);
|
||||
// Update refs
|
||||
pad->UpdateReferences(g_controller_interface);
|
||||
|
||||
// Next profile
|
||||
n++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -95,10 +94,8 @@ void InputPlugin::SaveConfig()
|
||||
IniFile inifile;
|
||||
inifile.Load(ini_filename);
|
||||
|
||||
std::vector< ControllerEmu* >::const_iterator i = controllers.begin(),
|
||||
e = controllers.end();
|
||||
for ( ; i!=e; ++i )
|
||||
(*i)->SaveConfig(inifile.GetOrCreateSection((*i)->GetName().c_str()));
|
||||
for (ControllerEmu* pad : controllers)
|
||||
pad->SaveConfig(inifile.GetOrCreateSection(pad->GetName().c_str()));
|
||||
|
||||
inifile.Save(ini_filename);
|
||||
}
|
||||
|
@ -30,13 +30,13 @@ public:
|
||||
bool LoadConfig(bool isGC);
|
||||
void SaveConfig();
|
||||
|
||||
std::vector< ControllerEmu* > controllers;
|
||||
std::vector<ControllerEmu*> controllers;
|
||||
|
||||
std::recursive_mutex controls_lock; // for changing any control references
|
||||
|
||||
const char * const ini_name;
|
||||
const char * const gui_name;
|
||||
const char * const profile_name;
|
||||
const char* const ini_name;
|
||||
const char* const gui_name;
|
||||
const char* const profile_name;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user