RFI Events

Is it possible to create your own events which can be received by the SDL
event queue.
I can only find the predefined events, but how can I pass on signals/data
between two threads.

Assuming a seperate rendering Thread is needed because my mainthread is
needed to do stuff which might take longer then a couple of frames to
finish.
For my current engine this should not be a problem, but in a possible
future with slow hardware (CPU) this could be a problem.

Am I on the wrong track here for thinking I need a high priority render
thread with a lower priority game engine thread, which communicate through
events.
That?s the way I started with BeOS.

And how do I get a graphics rendering thread to run a nearly fixed 30 FPS.
I can?t use a delay because then I run less then 30 FPS because the
rendering itself takes time.
rendering waiting rendering waiting
5mS 30mS 7mS 30ms

So in this case I do about 1 frame/36mS. Which could be even worse on low
CPU machines.
The other option is to request an SDL_Delay of 33 mS
render()
SDL_DELAY(33mS)
get statemutex
do some other state updates.
release statemutex
if (checkmutex IS_Rendering)
GetMutex (IS_Rendering)
render SDL Graphic Fuctions
ReleaseMutes(IsRendering)
end

The problem here is that the manual states I can?t use SDL_Delay() in
multithreaded aps and I may not call any other functions from here
I think that by using mutexes I can forget about the second problem.

What is the SDL solution to my problem.
Assuming I really want my software to run on low grade machines.

Marco Feenstra

DTC

Marco Feenstra/JDR wrote:

Am I on the wrong track here for thinking I need a high priority render
thread with a lower priority game engine thread, which communicate through
events.
That?s the way I started with BeOS.

And how do I get a graphics rendering thread to run a nearly fixed 30 FPS.
I can?t use a delay because then I run less then 30 FPS because the
rendering itself takes time.
rendering waiting rendering waiting
5mS 30mS 7mS 30ms

So in this case I do about 1 frame/36mS. Which could be even worse on low
CPU machines.

I think the traditional way of doing this is doing a SDL_GetTicks() BEFORE
you begin rendering. Then, when finished rendering do another
SDL_GetTicks(). If the difference is less than 33 ms, then SDL_Delay() for
33 minus the difference.

Hope that helped,

-Loren

Assuming a seperate rendering Thread is needed because
my mainthread is needed to do stuff which might take
longer then a couple of frames to finish.
For my current engine this should not be a problem, but
in a possible future with slow hardware (CPU) this could
be a problem.

First, remember this will only work on a SMP machine. With only one
processor,
a multithreaded version will be slower due to the threading overhead. What
you really want to do for best performance on a 1-CPU system is to break the
long-running computation down into little chunks, then process one chunk
each frame as part of your main loop.

If you really want to multithread, then you could just set up a non-blocking
socket between the UI thread and the computation thread. The UI thread
should call read() on the socket once per loop; it can then read whatever
data has been put there by the second thread, and if the socket is empty,
it’ll just go on and render another fame. (You’re already spending 100% of
the CPU, so there’s no need for any sort of ‘waiting’ on events, right?)

Dan