Fix ES freezing without input

And also hook up SDL joystick reinit when device removal or insertion is
detected.
This commit is contained in:
Bim Overbohm 2013-06-27 10:26:56 +02:00
parent e809414558
commit 887a1e00f8
2 changed files with 23 additions and 20 deletions

View file

@ -58,7 +58,7 @@ std::vector<InputDevice> InputManager::getInputDevices() const
//looks like a joystick. add to devices.
currentDevices.push_back(InputDevice(deviceName, 0, 0));
}
dirIt++;
++dirIt;
}
//or dump /proc/bus/input/devices anbd search for a Handler=..."js"... entry
#elif defined(WIN32) || defined(_WIN32)
@ -122,14 +122,13 @@ Uint32 InputManager::devicePollingCallback(Uint32 interval, void* param)
//this thing my be running in a different thread, so we're not allowed to call
//any functions or change/allocate/delete stuff, but can send a user event
SDL_Event event;
SDL_UserEvent userevent;
userevent.type = SDL_USEREVENT_POLLDEVICES;
userevent.code = 0;
userevent.data1 = nullptr;
userevent.data2 = nullptr;
event.type = SDL_USEREVENT;
event.user = userevent;
SDL_PushEvent(&event);
event.user.type = SDL_USEREVENT;
event.user.code = SDL_USEREVENT_POLLDEVICES;
event.user.data1 = nullptr;
event.user.data2 = nullptr;
if (SDL_PushEvent(&event) != 0) {
LOG(LogError) << "InputManager::devicePollingCallback - SDL event queue is full!";
}
return interval;
}
@ -290,15 +289,20 @@ bool InputManager::parseEvent(const SDL_Event& ev)
mWindow->input(getInputConfigByDevice(DEVICE_KEYBOARD), Input(DEVICE_KEYBOARD, TYPE_KEY, ev.key.keysym.sym, 0, false));
return true;
case SDL_USEREVENT_POLLDEVICES:
//poll joystick / HID again
std::vector<InputDevice> currentDevices = getInputDevices();
//compare device lists to see if devices were added/deleted
if (currentDevices != inputDevices) {
LOG(LogInfo) << "Device configuration changed!";
inputDevices = currentDevices;
case SDL_USEREVENT:
if (ev.user.code == SDL_USEREVENT_POLLDEVICES) {
//poll joystick / HID again
std::vector<InputDevice> currentDevices = getInputDevices();
//compare device lists to see if devices were added/deleted
if (currentDevices != inputDevices) {
LOG(LogInfo) << "Device configuration changed!";
inputDevices = currentDevices;
//deinit and reinit InputManager
deinit();
init();
}
return true;
}
return true;
}
return false;

View file

@ -168,7 +168,7 @@ int main(int argc, char* argv[])
timeSinceLastEvent = 0;
}
break;
case InputManager::SDL_USEREVENT_POLLDEVICES:
case SDL_USEREVENT:
//try to poll input devices, but do not necessarily wake up...
window.getInputManager()->parseEvent(event);
break;
@ -181,7 +181,7 @@ int main(int argc, char* argv[])
if(sleeping)
{
lastTime = SDL_GetTicks();
sleep(1); //this doesn't need to accurate
SDL_Delay(1); //this doesn't need to be accurate
continue;
}
@ -225,7 +225,6 @@ int main(int argc, char* argv[])
Renderer::swapBuffers();
}
Log::flush();
}