Jump to content
  • Advertisement
Sign in to follow this  
retroworld

SDL C++ (while loop)

This topic is 3091 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

Okay so I started learning SDL as I am already fluint in C++. so I have a question that got me confused; when you are polling in SDL to see if there are any events you do it like:


while(!quit)
{
while(SDL_PollEvents(event)
{
//check for events
}
// render stuff here

}


this is just to show you what I mean.

my question is, when the second while loop executes, why doesn't it stop the rendering stuff from working or delay it. I thought it should because the second while loop will always be true since you are moving your mouse or pressing buttons but it actually doesn't effect it.

I hope you understand what I mean.

[Edited by - retroworld on July 2, 2010 9:00:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
SDL_PollEvents returns true once per every event in the queue.

If you press a key, it pushes one event on the queue. If you move the mouse, it pushes one (or maybe multiple) events on the queue. These events get handled in the next frame and removed from the queue.

The reason why it does not affect the rendering loop is that the event queue is mostly empty. The rendering loop would only be blocked, if the user could generate events faster than your application can process them, which is usually not a problem.

Share this post


Link to post
Share on other sites
It would be great if you could close your code-blocks using [/ code] (without the whitespace). Horizontal scrolling chills away :)

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!