How to ignore the pending events?

I am trying to write a simple program (maybe it is a game… :wink: to practice
programming using SDL. Here is the segment for process events:


while (SDL_WaitEvent(&event) != 0){
switch (event.type){
case SDL_KEYDOWN:{
if (event.key.keysym.sym == SDLK_ESCAPE)
gWoofClientQuit();

		if (gMotionControlThread != NULL)
			SDL_WaitThread(gMotionControlThread, NULL);

		/* Open a new thread so that gClient can process next request */
		gMotionControlThread =
			SDL_CreateThread(gMotionControlThreadEntryPoint, &event.key);
		break;
	}
	case SDL_MOUSEMOTION:{
		if (SDL_GetMouseState(NULL, NULL)&SDL_BUTTON(1)){
			if (gHeadControlThread != NULL)
				SDL_WaitThread(gHeadControlThread, NULL);
			
			gHeadControlThread =
				SDL_CreateThread(gHeadControlThreadEntryPoint, &event.motion);
		}
		break;
	}
	case SDL_QUIT:{
		gWoofClientQuit();
		break;
	}
}

}

The problem I am having now is that, If I keep pressing a key or moving the
mouse w/ button 1 pressed, all the events will be queued and processed later.
This is not what I want. I want all the other events, generated during the
processing of the current event, to be totally ignored.

How can I do that?

Thanks a lot!

Yu

I want all the other events, generated during the
processing of the current event, to be totally ignored.

Once you accomplish this you may find that this is in fact NOT what you
want, but here are some simple steps to accomplish that.

First you need a function that returns zero all the time, and accepts a
specific parameter list:

int WeaponsOfMassDestruction ( const SDL_Event *event ) { return 0; }

Well that was easy.

Next you need to insert some code at the point in your program where
you begin processing events, and some code where you are done
processing events. The first code will cause your program to ignore all
events before they are even added to the event queue. The second code
will bring event queuing back.

// Disable event queuing, do this after you retrieve an event from the
queue
SDL_SetEventFilter( WeaponsOfMassDestruction );

// Enable event queuing, do this after you are done handling an event
SDL_SetEventFilter( NULL );

Here is an excerpt from the doc page for SDL_SetEventFilter that will
probably be of interest to you.

There is one caveat when dealing with the SDL_QUITEVENT event type. The
event filter is only called when the window manager desires to close
the application window. If the event filter returns 1, then the window
will be closed, otherwise the window will remain open if possible. If
the quit event is generated by an interrupt signal, it will bypass the
internal queue and be delivered to the application at the next event
poll.

Good luck.

ps. There is probably a better design solution than ignoring events
that happen during event handling. Think about your design some more.On Jul 28, 2004, at 10:24 PM, Yu Wang wrote: