Suggestion for SDL_UserEvent

I have got the following problem:

I have an Object A running the main thread of an application.
There is a Object B running a seperate thread for some background processing.
(Both objects running in a process :wink: )

Object B wants to inform Object A about it’s background processing status
when Object B’s status changes (hope thats somehow clearly explained).

My idea was that Object B should generate an event (e.q. SDL_UserEvent) and put
it to the event queue. Object A can receive this event and react somehow.

BUT, …
My 'lil Object B wants to exchange data (status param, etc…) with Object A. So
i need at least a pointer that i can pass.

My suggestion whould be to extend the current event structs and add a special
event which can pass parameters.

e.q. :

/* Event enumerations /
enum { SDL_NOEVENT, /
Unused (do not remove) /
SDL_ACTIVEEVENT, /
Application loses/gains visibility /
SDL_KEYDOWN, /
Keys pressed /
SDL_KEYUP, /
Keys released /
SDL_MOUSEMOTION, /
Mouse moved /
SDL_MOUSEBUTTONDOWN, /
Mouse button pressed /
SDL_MOUSEBUTTONUP, /
Mouse button released /
SDL_JOYMOTION, /
Joystick axis motion /
SDL_JOYBUTTONDOWN, /
Joystick button pressed /
SDL_JOYBUTTONUP, /
Joystick button released /
SDL_QUIT, /
User-requested quit /
SDL_SYSWMEVENT, /
System specific event */

   SDL_APPEVENT,		<<< MAYBE THE NEW ONE

   /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
   SDL_USEREVENT = 24,
   /* This last event is only for bounding internal arrays
  It is the number of bits in the event mask datatype -- Uint32
    */
   SDL_NUMEVENTS = 32

};

/* Predefined event masks */
#define SDL_EVENTMASK(X) (1<<(X))
enum {
SDL_ACTIVEEVENTMASK = SDL_EVENTMASK(SDL_ACTIVEEVENT),
SDL_KEYDOWNMASK = SDL_EVENTMASK(SDL_KEYDOWN),
SDL_KEYUPMASK = SDL_EVENTMASK(SDL_KEYUP),
SDL_MOUSEMOTIONMASK = SDL_EVENTMASK(SDL_MOUSEMOTION),
SDL_MOUSEBUTTONDOWNMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONDOWN),
SDL_MOUSEBUTTONUPMASK = SDL_EVENTMASK(SDL_MOUSEBUTTONUP),
SDL_JOYMOTIONMASK = SDL_EVENTMASK(SDL_JOYMOTION),
SDL_JOYBUTTONDOWNMASK = SDL_EVENTMASK(SDL_JOYBUTTONDOWN),
SDL_JOYBUTTONUPMASK = SDL_EVENTMASK(SDL_JOYBUTTONUP),
SDL_QUITMASK = SDL_EVENTMASK(SDL_QUIT),
SDL_SYSWMEVENTMASK = SDL_EVENTMASK(SDL_SYSWMEVENT)

SDL_APPEVENTMASK  = SDL_EVENTMASK(SDL_APPEVENT)			<<<

};

typedef struct {
Uint8 type;
Uint32 id;
void* param;
} SDL_AppEvent;

typedef union {
Uint8 type;
SDL_ActiveEvent active;
SDL_KeyboardEvent key;
SDL_MouseMotionEvent motion;
SDL_MouseButtonEvent button;
SDL_QuitEvent quit;
SDL_SysWMEvent syswm;
SDL_AppEvent app; <<<
} SDL_Event;

maybe it could be renamed to something else :wink:

What do you think of my weird ideas Sam ?

Alex

What do you think of my weird ideas Sam ?

Yeah, actually I meant to add that to the SDL 1.1 API, and completely
forgot about it. Remind me again next week, and I’ll add it.

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec