onepad: plug uid instead of the index

ini must be recreated
This commit is contained in:
Gregory Hainaut 2017-04-16 17:49:05 +02:00
parent 3cff588eff
commit 31d8142a0d
5 changed files with 24 additions and 29 deletions

View File

@ -5,11 +5,6 @@
std::vector<std::unique_ptr<GamePad>> 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<std::unique_ptr<GamePad>> &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)

View File

@ -73,4 +73,3 @@ protected:
};
extern std::vector<std::unique_ptr<GamePad>> s_vgamePad;
extern bool GamePadIdWithinBounds(int joyid);

View File

@ -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;

View File

@ -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();

View File

@ -50,33 +50,34 @@ public:
};
u32 log;
u32 joyid_map;
map<u32, u32> keysym_map[GAMEPAD_NUMBER];
std::array<size_t, GAMEPAD_NUMBER> 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;
}
/**