Jump to content
  • Advertisement
Sign in to follow this  
gapern

[SDL] Event queue question

This topic is 2617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm just wondering if the event queue ever needs to be cleared and if so how do I do it? I'm seeing the SDL_FlushEvent function and I'm assuming that's how clearing the queue would be done but I'm not sure if I need too or not. Consider this example code.


while(key.a != pressed)
{
dostuff();
}

while(key.b != pressed)
{
domorestuff();
}
endprogram();



The first loop runs until I hit a. While in the first loop I hit the b key. Assume b is not used in the first loop so it's just stored in the event queue. Now I hit a and break out of the first loop. The program immediately finds b and ends the program but I didn't want the program to end yet.

Is the problem I just pointed out valid?

Share this post


Link to post
Share on other sites
Advertisement
If you use SDL_PollEvent or SDL_WaitEvent the events are removed from the event queue and there is no need to clear the queue yourself.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!