Event communication

The Event documentation specifies that:

The event queue can actually be used as a two way communication
channel. Not only can events be read from the queue, but the user can
also push their own events onto it. event is a pointer to the event
structure you wish to push onto the queue.

To be used for two-way communication, either the communication channel
must be full-duplex (allowing messages between peers in both
directions simultaneously) or multiple communications channels must be
available to create one channel for each direction of communication.

I’m looking to pass messages from thread 1 to thread 2, and, while
thread 2 is awaiting a message from thread 1, it may also desire to
send a message to thread 1.

Is the proper way to do this, to use, for example, USEREVENT+0 for
communication in one direction and USEREVENT+1 for communication in
the other direction, and then use SDL_PeepEvents() instead of
SDL_PollEvent()?

Thanks,

Derrell

To be used for two-way communication, either the communication channel
must be full-duplex (allowing messages between peers in both
directions simultaneously) or multiple communications channels must be
available to create one channel for each direction of communication.

I’m looking to pass messages from thread 1 to thread 2, and, while
thread 2 is awaiting a message from thread 1, it may also desire to
send a message to thread 1.

You probably want to implement your own message passing mechanism.
SDL’s event queue is a one-way FIFO.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

A good method to do this is using the observer pattern. I learned this in
C++, but it could easily be implemented in straight C as well. Think
Client-Server. Basically, you send a function pointer that accepts a
packet/message to the subject(or if in C++, make an abstract class that has
one function that accepts a packet and inherit from it). The subject takes
puts the function pointer in a vector/list/whatever. Units that want to
pass a message now send it to the subject (which is either static or a
singleton). The subject then passes it to all the functions/classes in the
list. If you want to get fancy, you can have the observer attach to only a
specific thread ID or all the threads. For more information, look up
patterns on a search engine.> ----- Original Message -----

From: owner-sdl@lokigames.com [mailto:owner-sdl at lokigames.com]On Behalf
Of Sam Lantinga
Sent: Saturday, March 03, 2001 7:13 PM
To: sdl at lokigames.com
Subject: Re: [SDL] Event communication

To be used for two-way communication, either the communication channel
must be full-duplex (allowing messages between peers in both
directions simultaneously) or multiple communications channels must be
available to create one channel for each direction of communication.

I’m looking to pass messages from thread 1 to thread 2, and, while
thread 2 is awaiting a message from thread 1, it may also desire to
send a message to thread 1.

You probably want to implement your own message passing mechanism.
SDL’s event queue is a one-way FIFO.

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software