0

Lets say we have an input device which is a controller. In addition, lets say we also have some construct which checks for events using "SDL_PollEvent(...)".

In my tests, "SDL_PollEvent(...)" was checked every 3 seconds, if a button is tapped quickly just once or even tapped multiple times during the delay, SDL will not generate the button press nor the button release events. If the very same button which was tapped on the controller, is now pressed and held down, the SDL dose generated those events.

In addition to this very same test, if a keyboard key is tapped quickly just once during the very extreme "SDL_Delay(...)" test, a button pressed event is always generated.

Quick button press and release from the controller device will generate events with "SDL_WaitEvent(...)". But, SDL_INIT_VIDEO and SDL_INIT_EVENTTHREAD must be in the same thread as they can't be separated across multiple SDL_Thread[s] in my case.

Given the delay between event polling and how brief a button press is, my situation needs to know that the button was pressed at minimum once regardless.

What can be done in this situation? So that SDL would generate/poll controller events the very same way as it dose for the keyboard device?

Is SDL 1.2 not capable to do this? Are there other libraries which are better capable at guaranteeing that a button tap event is generated ? Thank you!

bool activity(1);

while(activity) // event polling used in testing
{
    std::cout << "\nWaiting...";
    SDL_Delay(3000U); // <--- simulating delay for purpose of test

    while(SDL_PollEvent(&event_))
    {
        switch(event_.type)
        {
            case SDL_JOYBUTTONDOWN :

                switch(event_.jbutton.button)
                {
                    case  0U :
                        ...
                        break;
                    case  1U :
                        ...
                        break;
                }

                break;
            case SDL_KEYDOWN :

                switch(event_.key.keysym.sym)
                {
                    case SDLK_a :
                        ...
                        break;
                }

                break;
        }
    }
}
3
  • Why do you need 3000ms between polls? If it's a hard constraint, you can use a separate thread that manages all SDL events and gives the main loop the info you need.
    – maxbc
    Sep 14, 2015 at 13:21
  • I used 3000ms to test if controller button press and keyboard key press behaved in the same way, in which case they don't. Events for the controller appear not to be polled in the same way as they are for the keyboard, controller events appear to be thrown away after the button has be released. Even at ~15ms input drop is surprisingly almost the same as with 3000ms... Sep 14, 2015 at 13:30
  • @maxbc Can you please expand on how to separate SDL events into another thread? Because my application dose crash if SDL events are running in thread A and SDL openGL is running in thread B. Sep 15, 2015 at 3:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.