Skip to main content
gamedev.net
🔒 Locked

SDL C++ (while loop)

Started by retroworld 2 replies 1.1k views
Original Post
retroworld
retroworld
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]
kirsis
kirsis
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.