it was confusing me how the snippet below worked, i have stepped through it and would like to know if i am now right about how it works >
Code:
while(Mainloop == 0)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT ) { Mainloop = 1; }
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { Mainloop = 1; }
}
if( event.type == SDL_MOUSEBUTTONDOWN ) { newscene = true; }
}
newscene = DrawScene(screen, newscene);
}
as i understand it >
control enters the 1st while loop, an object 'event' is created,
the second while loop condition is tested by calling function SDL_PollEvent() to see if any event has occured,
if true it checks to see if the event is any of the kinds i have included.
it then drops back into the first while loop, if no event occurs the second while loop is ignored, etc etc.
my problem understanding really is that when an event occurs i watch the inner loop go around a few times before exiting, whether a condition in the loop is met or not, why does this happen? How come it does not just drop out straight away once the IF statements are checked ?
the description in the header file for this function is as follows >
extern DECLSPEC int SDLCALL SDL_PollEvent(SDL_Event *event);
Polls for currently pending events, and returns 1 if there are any pending
events, or 0 if there are none available. If 'event' is not NULL, the next
event is removed from the queue and stored in that area.
i mean if it finds an event has occured the condition is 'true', fair enough, but i dont see how that condition lasts for more than one iteration, because next time around it again calls SDL_PollEvent(); but nothing will have happend that time?