diff --git a/plugins/onepad/GamePad.cpp b/plugins/onepad/GamePad.cpp index 21aa77c0a6..bfa504c237 100644 --- a/plugins/onepad/GamePad.cpp +++ b/plugins/onepad/GamePad.cpp @@ -5,11 +5,6 @@ std::vector> s_vgamePad; -bool GamePadIdWithinBounds(int GamePadId) -{ - return ((GamePadId >= 0) && (GamePadId < (int)s_vgamePad.size())); -} - /** * Following static methods are just forwarders to their backend * This is where link between agnostic and specific code is done @@ -30,10 +25,9 @@ void GamePad::EnumerateGamePads(std::vector> &vgamePad) **/ void GamePad::DoRumble(unsigned type, unsigned pad) { - u32 id = conf->get_joyid(pad); - if (GamePadIdWithinBounds(id)) { - s_vgamePad[id]->Rumble(type, pad); - } + int index = uid_to_index(conf->get_joy_uid(pad)); + if (index >= 0) + s_vgamePad[index]->Rumble(type, pad); } size_t GamePad::index_to_uid(int index) diff --git a/plugins/onepad/GamePad.h b/plugins/onepad/GamePad.h index 4b37dca9eb..39adf81a05 100644 --- a/plugins/onepad/GamePad.h +++ b/plugins/onepad/GamePad.h @@ -73,4 +73,3 @@ protected: }; extern std::vector> s_vgamePad; -extern bool GamePadIdWithinBounds(int joyid); diff --git a/plugins/onepad/Linux/ini.cpp b/plugins/onepad/Linux/ini.cpp index 3df948afad..ccc3526ed6 100644 --- a/plugins/onepad/Linux/ini.cpp +++ b/plugins/onepad/Linux/ini.cpp @@ -92,8 +92,9 @@ void SaveConfig() fprintf(f, "log = %d\n", conf->log); fprintf(f, "options = %d\n", conf->packed_options); fprintf(f, "mouse_sensibility = %d\n", conf->get_sensibility()); - fprintf(f, "joy_pad_map = %d\n", conf->joyid_map); fprintf(f, "ff_intensity = %d\n", conf->get_ff_intensity()); + fprintf(f, "uid[0] = %zu\n", conf->get_joy_uid(0)); + fprintf(f, "uid[1] = %zu\n", conf->get_joy_uid(1)); for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) for (auto const &it : conf->keysym_map[pad]) @@ -130,15 +131,15 @@ void LoadConfig() if (fscanf(f, "mouse_sensibility = %u\n", &value) == 0) goto error; conf->set_sensibility(value); - if (fscanf(f, "joy_pad_map = %u\n", &value) == 0) - goto error; - // Value is now hardcoded in controller.h avoid to reload a bad - // value from an old ini file. - //conf->joyid_map = value; if (fscanf(f, "ff_intensity = %u\n", &value) == 0) goto error; conf->set_ff_intensity(value); + size_t uid; + if (fscanf(f, "uid[0] = %zu\n", &uid) == 1) + conf->set_joy_uid(0, uid); + if (fscanf(f, "uid[1] = %zu\n", &uid) == 1) + conf->set_joy_uid(1, uid); u32 pad; u32 keysym; diff --git a/plugins/onepad/Linux/linux.cpp b/plugins/onepad/Linux/linux.cpp index e729027b52..30e9e3745a 100644 --- a/plugins/onepad/Linux/linux.cpp +++ b/plugins/onepad/Linux/linux.cpp @@ -83,11 +83,11 @@ void _PADclose() void PollForJoystickInput(int cpad) { - int joyid = conf->get_joyid(cpad); - if (!GamePadIdWithinBounds(joyid)) + int index = GamePad::uid_to_index(conf->get_joy_uid(cpad)); + if (index < 0) return; - auto &gamePad = s_vgamePad[joyid]; + auto &gamePad = s_vgamePad[index]; gamePad->UpdateGamePadState(); diff --git a/plugins/onepad/controller.h b/plugins/onepad/controller.h index 84adb9941b..9496f5c50e 100644 --- a/plugins/onepad/controller.h +++ b/plugins/onepad/controller.h @@ -50,33 +50,34 @@ public: }; u32 log; - u32 joyid_map; map keysym_map[GAMEPAD_NUMBER]; + std::array unique_id; PADconf() { init(); } void init() { - log = packed_options = joyid_map = 0; + log = packed_options = 0; ff_intensity = 0x7FFF; // set it at max value by default sensibility = 500; for (int pad = 0; pad < GAMEPAD_NUMBER; pad++) { keysym_map[pad].clear(); - set_joyid((u32)pad, (u32)pad); // define id mapping for each gamepad } + unique_id.fill(0); } - void set_joyid(u32 pad, u32 joy_id) + void set_joy_uid(u32 pad, size_t uid) { - int shift = 8 * pad; - joyid_map &= ~(0xFF << shift); // clear - joyid_map |= (joy_id & 0xFF) << shift; // set + if (pad < GAMEPAD_NUMBER) + unique_id[pad] = uid; } - u32 get_joyid(u32 pad) + size_t get_joy_uid(u32 pad) { - int shift = 8 * pad; - return ((joyid_map >> shift) & 0xFF); + if (pad < GAMEPAD_NUMBER) + return unique_id[pad]; + else + return 0; } /**