[SDL] FastEvents question (for Bob or anyone who knows)
Charles McGarvey
onefriedrice at brokenzipper.com
Mon May 5 10:34:27 PDT 2008
I'm sure Bob could explain more about the technical specifics, but I'll just mention that you can use FastEvents 'reading' functions from another thread if (like you said) SDL and FastEvents are initialized in that thread. There is no reason why you need to initialize SDL or FastEvents in the main thread. Therefore, the flow goes something like this:
MAIN: Detach a thread.
THREAD1: Call SDL_Init and FE_Init.
THREAD1: Enter event loop, calling FE_PollEvent or FE_WaitEvent.
MAIN: Setup rendering context; enter rendering loop.
The only thing to watch out for is to make sure the main thread does not call SDL functions until the detached thread has initialized SDL, but this is fairly obvious and very simple.
That's it,
chaz
----- Original Message -----
From: Mason Wheeler
To: A list for developers using the SDL library. (includes SDL-announce)
Sent: Monday, May 05, 2008 10:18 AM
Subject: [SDL] FastEvents question (for Bob or anyone who knows)
The notes on FastEvents say that only the thread that initialized SDL should be used to call FE_PollEvent() or FE_WaitEvent(). I'm curious as to why that is, since it seems to me to be completely backwards for a multithreaded game.
The main thread has to be used for rendering. As I understand it, this is an invariant. The main thread MUST be your rendering thread. Problem with doing event handling on the same thread is that it's conceivable for certain commands to use blocking behavior. (My game engine, which I'm trying to port to SDL does this in fact. There are a handful of keyboard commands that call Sleep() as part of their handler.) Doing this on the rendering thread is a bad idea for obvious reasons.
Is there a particular reason why the FastEvents reading functions should only happen on the main thread, and is there a modification that could be made to work around the restriction?
Mason
------------------------------------------------------------------------------
_______________________________________________
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080505/4c661281/attachment.htm>
More information about the SDL
mailing list