I have a thread for handling events and works fine on the desktop.
When i run it on iphone the events don’t reach the thread unless i call SDL_PumpEvents() on the main thread, which is the same of not having a thread at all!
The code is like:
start handling input on a thread
while(!quit) {
physics()
render()
SDL_RenderPresent
}
Thread:
SDL_Event e;
while (SDL_WaitEvent(&e)) {
if mouse down ...
}
There is any specific way to use thread on iOS rather than
std::thread t1(inputEvents,…
t1.detach();
As long as you have a while-loop of SDL_PollEvent every frame, then you will receive all input events that happened since the last frame because the OS queues them up. You won’t miss any events that way even with really low framerate.
In theory yes. I have run two tests, one as you suggested with poll event loop on main thread and another with a separate thread, the first case is very slow, not responsice compared to the 2nd.
Most games and engines (including my own) use that approach regardless of whether they use SDL, with no problems. Do you mind sharing your code? Maybe there’s a bug in it somewhere.
Make sure that your event polling is running in its own while loop:
while(!quit) {
SDL_Event event;
while(SDL_PollEvent(&event)) {
switch(event.type) {
// set flags based on events here
}
}
// Respond to event flags here
}