[SDL] SDL_Event threading all backwards?

Torsten Giebl wizard at syntheticsw.com
Mon Feb 25 21:45:20 PST 2008


Hello !


> 2. The most efficient way to manage SDL_Events is with the   
> SDL_WaitEvent function.


Most games use SDL_PollEvent to get their events :

SDL_Event event; /* Event structure */

.
.
.
/* Check for events */
while(SDL_PollEvent(&event)) {  /* Loop until there are no events left  
on the queue */
   switch(event.type) { /* Process the appropiate event type */
     case SDL_KEYDOWN:  /* Handle a KEYDOWN event */
       printf("Oh! Key press\n");
       break;
     case SDL_MOUSEMOTION:
       .
       .
       .
     default: /* Report an unhandled event */
       printf("I don't know what this event is!\n");
   }
}

SDL_WaitEvent is usefull when your app only does something
after an event, but most game loops should also run when
the user has not pressed a key or moved the mouse.


CU




More information about the SDL mailing list