[SDL] 1.3 Event source addition

Vassilis Virvilis vasvir at iit.demokritos.gr
Thu Jun 29 08:02:24 PDT 2006


Olivier Delannoy wrote:
> I like the event loop of SDL and my only problem with 1.2 series is
> that the Event subsystem is completly hidden and close. There is no
> way to extends this part of the library that I know. It would really
> interesting to be able to register new event source that are triggered
> by SDL automatically.

seconded. fully agreed!

....

> 
> It would be cool to be able to register our own source of event using
> an API call
> similar to
> 
> struct SDLEventSource
> {
>    void (*pushEvents)(void* userdata);
>    void* userdata;
> };
> 
> SDL_EventRegisterSource(SDL_EventSource* source);
> 
> SDL_EventUnregisterSource(SDL_EventSource* source);
> 

There are user events in SDL. Look for SDL_UserEvent in the doc.

The problem IMHO is that the event id (type) is not handled by SDL but
by the user. This way if you use two SDL libraries let's say
SDL_lib1 and SDL_lib2 and they need user events you have to
tweak their source code in order to have non overlapping user events' ids.

What I would like to see is something like this.

int SDL_RegisterUserEvent();  /* SDL returns the next free event id (e.g. SDL_USEREVENT)*/
void SDL_UnRegisterUserEvent(int id) /* SDL unregister a previously given user event id */

if you try to unregister a system event (e.g. like mouseMove)
you should and will be shot.

I think the reason is done this way is for writing the switch case more easily

switch (event.type) {
	case SDL_MOUSEMOTION:
	.
	.
	.
	case SDL_OTHERSYSTEMEVENT:
	.
	.
	.

/* now the default should be like this */
	default:
		if (event.type == my_event_id_1) {
		} else if (event.type == my_event_id_2) {
		} else if (event.type == my_event_id_N) {
		} else {
			/* really unknown event */
		}


      .bill




More information about the SDL mailing list