Retain SDL joystick IDs
This commit is contained in:
@@ -6,18 +6,21 @@ namespace lime {
|
|||||||
|
|
||||||
static SDL_Joystick* accelerometer = 0;
|
static SDL_Joystick* accelerometer = 0;
|
||||||
static SDL_JoystickID accelerometerID = -1;
|
static SDL_JoystickID accelerometerID = -1;
|
||||||
|
std::map<int, int> joystickIDs = std::map<int, int> ();
|
||||||
std::map<int, SDL_Joystick*> joysticks = std::map<int, SDL_Joystick*> ();
|
std::map<int, SDL_Joystick*> joysticks = std::map<int, SDL_Joystick*> ();
|
||||||
|
|
||||||
|
|
||||||
bool SDLJoystick::Connect (int id) {
|
bool SDLJoystick::Connect (int deviceID) {
|
||||||
|
|
||||||
if (id != accelerometerID) {
|
if (deviceID != accelerometerID) {
|
||||||
|
|
||||||
SDL_Joystick* joystick = SDL_JoystickOpen (id);
|
SDL_Joystick* joystick = SDL_JoystickOpen (deviceID);
|
||||||
|
int id = SDL_JoystickInstanceID (joystick);
|
||||||
|
|
||||||
if (joystick) {
|
if (joystick) {
|
||||||
|
|
||||||
joysticks[id] = joystick;
|
joysticks[id] = joystick;
|
||||||
|
joystickIDs[deviceID] = id;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -36,7 +39,6 @@ namespace lime {
|
|||||||
SDL_Joystick* joystick = joysticks[id];
|
SDL_Joystick* joystick = joysticks[id];
|
||||||
SDL_JoystickClose (joystick);
|
SDL_JoystickClose (joystick);
|
||||||
joysticks.erase (id);
|
joysticks.erase (id);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -48,7 +50,7 @@ namespace lime {
|
|||||||
|
|
||||||
int SDLJoystick::GetInstanceID (int deviceID) {
|
int SDLJoystick::GetInstanceID (int deviceID) {
|
||||||
|
|
||||||
return SDL_JoystickInstanceID (joysticks[deviceID]);
|
return joystickIDs[deviceID];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user