Add a define that enables additional checks in SDL functions.
SDL_PARANOIA == 0 disables all additional checks,
SDL_PARANOIA == 1 enables checks for common errors,
SDL_PARANOIA == 2 enables checks for rare errors or errors that occur
only in extreme situations (such as counter/timer roll over, etc),
SDL_PARANOIA == 3 enables checks for errors caused by programming
errors in the client application (such as passing an invalid mouse
id),
SDL_PARANOIA == 4 enables checks for things which should be impossible
(and therefore indicate bugs in SDL itself).
When debugging SDL, use SDL_PARANOIA == 4.
When debugging a user program, use a libSDL built with SDL_PARANOIA == 3.
In situations where stability and portability is more important than
speed, release your program with a libSDL built with SDL_PARANOIA ==
2.
Usually, you should release your program with a libSDL compiled with
SDL_PARANOIA == 1.
If speed is more important than stability and portability, compile
your program with a libSDL built with SDL_PARANOIA == 0.
Add an additional define to enable additional checks and locks for
multithreaded applications.
SDL_MULTITHREADED == 0 disables support for multithreading,
SDL_MULTITHREADED == 1 enables basic support for multithreaded applications,
SDL_MULTITHREADED == 2 enables additional multithreading support.
Certain checks could then be wrapped by both SDL_MULTITHREADED and SDL_PARANOIA.
Certain functions may behave quite differently with SDL_MULTITHREADED
== 2. For example, in a multithreaded application on Windows you
might need to create a separate thread to handle window messages, then
implement SDL_WaitEventTimeout() using a semaphore.
Like this:
int
SDL_WaitEventTimeout(SDL_Event * event, int timeout)
{
return (SDL_SemWaitTimeout(event_sem, timeout) == 0 &&
SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS) == 1);
}
SDL_PeepEvents would then need to implement a lock on the event queue.
SDL_PumpEvents would either not be necessary, or could be implemented
using a condition variable.