Sign in to follow this  
Kalazart

SDL event loop

Recommended Posts

Just be careful you don't ignore all events but the last one to be seen by the while loop or you will end up with dropped events.

ie: deal with all events, or manage the events yourself somehow that makes sense for your application... But don't do the while loop and then process only the last event because you'll have missed all the other ones for the sake of emptying the SDL event queue.

Typically how I handle it is I have at the top of my game loop the sdl event loop (the while loop) which grabs all events, interprets them in some form for my own event manager and then each frame I process events from my event manager as required. Some events are dealt with immediately while others can acceptably be left for a frame or two and so it isn't just a dumb event queue like you get from SDL, though I do maintain order of recieved events when necessary...

Hopefully that explains my view at least... It may not be the best way of handling things, it's just how I do.

Share this post


Link to post
Share on other sites
The while loop. When I first started with SDL I read a book that showed the IF method. It caused a lot of slowdown with handling events. Just changing to the while loops sped up the event handling.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this