diff --git a/desmume/src/frontend/posix/shared/ctrlssdl.cpp b/desmume/src/frontend/posix/shared/ctrlssdl.cpp index acccc13fb..416f4650b 100644 --- a/desmume/src/frontend/posix/shared/ctrlssdl.cpp +++ b/desmume/src/frontend/posix/shared/ctrlssdl.cpp @@ -23,8 +23,6 @@ #include "NDSSystem.h" #include "frontend/modules/osd/agg/agg_osd.h" #include "driver.h" -#include -#include #ifdef FAKE_MIC #include "mic.h" @@ -42,7 +40,7 @@ mouse_status mouse; static int fullscreen; //List of currently connected joysticks (key - instance id, value - SDL_Joystick structure, joystick number) -static std::unordered_map > open_joysticks; +static std::pair open_joysticks[MAX_JOYSTICKS]; /* Keypad key names */ const char *key_names[NB_KEYS] = @@ -118,8 +116,11 @@ BOOL init_joy( void) { SDL_GetError()); return FALSE; } + + for(i=0; i 0) { printf("Found %d joysticks\n", nbr_joy); @@ -132,14 +133,13 @@ BOOL init_joy( void) { printf("Buttons: %d\n", SDL_JoystickNumButtons(joy)); printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy)); printf("Hats: %d\n\n", SDL_JoystickNumHats(joy)); - open_joysticks.insert(std::make_pair(SDL_JoystickInstanceID(joy), std::make_pair(joy, i))); + open_joysticks[i]=std::make_pair(joy, SDL_JoystickInstanceID(joy)); } else { fprintf(stderr, "Failed to open joystick %d: %s\n", i, SDL_GetError()); joy_init_good = FALSE; } } - nbr_joy = open_joysticks.size(); } return joy_init_good; @@ -148,12 +148,14 @@ BOOL init_joy( void) { /* Unload joysticks */ void uninit_joy( void) { - for (auto & it: open_joysticks) { - if(it.second.first) - SDL_JoystickClose(it.second.first); + int i; + for (i=0; itype) { /* Joystick disconnected */ case SDL_JOYDEVICEREMOVED: - { - auto it = open_joysticks.find(event->jdevice.which); - if(it != open_joysticks.cend()) { - printf("Joystick with instance %d disconnected\n", event->jdevice.which); - SDL_JoystickClose(it->second.first); - open_joysticks.erase(it); - } - nbr_joy = open_joysticks.size(); + n=get_joystick_number_by_id(event->jdevice.which); + if(n != -1) { + printf("Joystick %d disconnected\n", n); + SDL_JoystickClose(open_joysticks[n].first); + open_joysticks[n]=std::make_pair((SDL_Joystick*)NULL, 0); } break; /* Joystick connected */ case SDL_JOYDEVICEADDED: - { - if(get_joystick_number_by_id(SDL_JoystickGetDeviceInstanceID(event->jdevice.which))==-1) { + if(event->jdevice.whichjdevice.which].first) { SDL_Joystick* joy = SDL_JoystickOpen(event->jdevice.which); if(joy) { printf("Joystick %d %s\n", event->jdevice.which, SDL_JoystickNameForIndex(event->jdevice.which)); @@ -485,13 +485,15 @@ do_process_joystick_device_events(SDL_Event* event) { printf("Buttons: %d\n", SDL_JoystickNumButtons(joy)); printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy)); printf("Hats: %d\n\n", SDL_JoystickNumHats(joy)); - open_joysticks.insert(std::make_pair(SDL_JoystickInstanceID(joy), std::make_pair(joy, event->jdevice.which))); - nbr_joy = open_joysticks.size(); + open_joysticks[event->jdevice.which]=std::make_pair(joy, SDL_JoystickInstanceID(joy)); } else fprintf(stderr, "Failed to open joystick %d: %s\n", event->jdevice.which, SDL_GetError()); } } + else + printf("Joystick %d connected to the system, but maximum supported joystick index is %d, ignoring\n", + event->jdevice.which, MAX_JOYSTICKS-1); break; default: @@ -537,9 +539,11 @@ void process_joystick_device_events() { int get_joystick_number_by_id(SDL_JoystickID id) { - auto it = open_joysticks.find(id); - if(it != open_joysticks.cend()) - return it->second.second; + int i; + for(i=0; i