SDL C++ (while loop)

Started by
2 comments, last by retroworld 13 years, 9 months ago
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]
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.
It would be great if you could close your code-blocks using (without the whitespace). Horizontal scrolling chills away :)
I thought that would be the reason why but now I am sure it is ;) thanks for clarifying that for me mate.

This topic is closed to new replies.

Advertisement