954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

simple sdl question

So i just started learning SDL and came across "Event driven programming", just wanted to be sure if i understood the tutorial correcly. So lets say by adding:

SDL_Event event;


i add lets say a container that keeps track of every event i do? After that i start using:

while ( program == true )
{
	while(SDL_PollEvent(&event)
	{
		if ( event.type == SDL_QUIT )
		{
			program = false;
		}
	}
}


If i understand correcly, in the second loop we say that while theres some sort of event ( and we send a list of events ) do the loop and if it happens that one of those events type is SDL_QUIT then the program will terminate. I think i understand it good enough but would like to hear something about the event handling in the SDL that i dont know about or correct me if im wrong.

nuclear
Junior Poster in Training
94 posts since Aug 2011
Reputation Points: 2
Solved Threads: 3
 

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

raptr_dflo
Practically a Master Poster
602 posts since Aug 2010
Reputation Points: 76
Solved Threads: 82
 

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

Thanks, all i wanted to know.

nuclear
Junior Poster in Training
94 posts since Aug 2011
Reputation Points: 2
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: