Make it possible to use SDL events separately from the video subsystem.

This commit is contained in:
Sam Lantinga 2013-07-06 12:28:57 -07:00
parent 4b0d90ff15
commit 156a8638f0
4 changed files with 70 additions and 23 deletions

View file

@ -106,13 +106,14 @@ extern "C" {
/*@{*/ /*@{*/
#define SDL_INIT_TIMER 0x00000001 #define SDL_INIT_TIMER 0x00000001
#define SDL_INIT_AUDIO 0x00000010 #define SDL_INIT_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020 #define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200 #define SDL_INIT_JOYSTICK 0x00000200 /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#define SDL_INIT_HAPTIC 0x00001000 #define SDL_INIT_HAPTIC 0x00001000
#define SDL_INIT_GAMECONTROLLER 0x00002000 /**< turn on game controller also implicitly does JOYSTICK */ #define SDL_INIT_GAMECONTROLLER 0x00002000 /**< SDL_INIT_GAMECONTROLLE implies SDL_INIT_JOYSTICK */
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */ #define SDL_INIT_EVENTS 0x00004000
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */
#define SDL_INIT_EVERYTHING ( \ #define SDL_INIT_EVERYTHING ( \
SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | \ SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_EVENTS | \
SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \ SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER \
) )
/*@}*/ /*@}*/

View file

@ -27,6 +27,7 @@
#include "SDL_revision.h" #include "SDL_revision.h"
#include "SDL_fatal.h" #include "SDL_fatal.h"
#include "SDL_assert_c.h" #include "SDL_assert_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h" #include "haptic/SDL_haptic_c.h"
#include "joystick/SDL_joystick_c.h" #include "joystick/SDL_joystick_c.h"
@ -111,8 +112,33 @@ SDL_InitSubSystem(Uint32 flags)
SDL_InitTicks(); SDL_InitTicks();
#endif #endif
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
}
if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
/* video or joystick implies events */
flags |= SDL_INIT_EVENTS;
}
/* Initialize the event subsystem */
if ((flags & SDL_INIT_EVENTS)) {
#if !SDL_EVENTS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
if (SDL_StartEventLoop() < 0) {
return (-1);
}
SDL_QuitInit();
}
SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
#else
return SDL_SetError("SDL not built with events support");
#endif
}
/* Initialize the timer subsystem */ /* Initialize the timer subsystem */
if ((flags & SDL_INIT_TIMER) ){ if ((flags & SDL_INIT_TIMER)){
#if !SDL_TIMERS_DISABLED #if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) { if (SDL_TimerInit() < 0) {
@ -125,8 +151,8 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
/* Initialize the video/event subsystem */ /* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO) ){ if ((flags & SDL_INIT_VIDEO)){
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) { if (SDL_VideoInit(NULL) < 0) {
@ -140,7 +166,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the audio subsystem */ /* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO) ){ if ((flags & SDL_INIT_AUDIO)){
#if !SDL_AUDIO_DISABLED #if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) { if (SDL_AudioInit(NULL) < 0) {
@ -153,13 +179,8 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* Game controller implies Joystick. */
flags |= SDL_INIT_JOYSTICK;
}
/* Initialize the joystick subsystem */ /* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK) ){ if ((flags & SDL_INIT_JOYSTICK)){
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) { if (SDL_JoystickInit() < 0) {
@ -172,7 +193,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif #endif
} }
if ((flags & SDL_INIT_GAMECONTROLLER) ){ if ((flags & SDL_INIT_GAMECONTROLLER)){
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) { if (SDL_GameControllerInit() < 0) {
@ -186,7 +207,7 @@ SDL_InitSubSystem(Uint32 flags)
} }
/* Initialize the haptic subsystem */ /* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC) ){ if ((flags & SDL_INIT_HAPTIC)){
#if !SDL_HAPTIC_DISABLED #if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) { if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) { if (SDL_HapticInit() < 0) {
@ -237,7 +258,7 @@ SDL_QuitSubSystem(Uint32 flags)
/* Shut down requested initialized subsystems */ /* Shut down requested initialized subsystems */
#if !SDL_JOYSTICK_DISABLED #if !SDL_JOYSTICK_DISABLED
if ((flags & SDL_INIT_GAMECONTROLLER)) { if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* Game controller implies Joystick. */ /* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK; flags |= SDL_INIT_JOYSTICK;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) { if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
@ -247,6 +268,9 @@ SDL_QuitSubSystem(Uint32 flags)
} }
if ((flags & SDL_INIT_JOYSTICK)) { if ((flags & SDL_INIT_JOYSTICK)) {
/* joystick implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) { if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit(); SDL_JoystickQuit();
} }
@ -274,6 +298,9 @@ SDL_QuitSubSystem(Uint32 flags)
#if !SDL_VIDEO_DISABLED #if !SDL_VIDEO_DISABLED
if ((flags & SDL_INIT_VIDEO)) { if ((flags & SDL_INIT_VIDEO)) {
/* video implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) { if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
SDL_VideoQuit(); SDL_VideoQuit();
} }
@ -289,6 +316,16 @@ SDL_QuitSubSystem(Uint32 flags)
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER); SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
} }
#endif #endif
#if !SDL_EVENTS_DISABLED
if ((flags & SDL_INIT_EVENTS)) {
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
SDL_QuitQuit();
SDL_StopEventLoop();
}
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
}
#endif
} }
Uint32 Uint32

View file

@ -48,6 +48,12 @@ SDL_JoystickInit(void)
SDL_joystick_allows_background_events = SDL_TRUE; SDL_joystick_allows_background_events = SDL_TRUE;
} }
#if !SDL_EVENTS_DISABLED
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0) {
return -1;
}
#endif /* !SDL_EVENTS_DISABLED */
status = SDL_SYS_JoystickInit(); status = SDL_SYS_JoystickInit();
if (status >= 0) { if (status >= 0) {
status = 0; status = 0;
@ -458,6 +464,10 @@ SDL_JoystickQuit(void)
/* Quit the joystick setup */ /* Quit the joystick setup */
SDL_SYS_JoystickQuit(); SDL_SYS_JoystickQuit();
#if !SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
} }

View file

@ -422,11 +422,10 @@ SDL_VideoInit(const char *driver_name)
#endif #endif
/* Start the event loop */ /* Start the event loop */
if (SDL_StartEventLoop() < 0 || if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
SDL_KeyboardInit() < 0 || SDL_KeyboardInit() < 0 ||
SDL_MouseInit() < 0 || SDL_MouseInit() < 0 ||
SDL_TouchInit() < 0 || SDL_TouchInit() < 0) {
SDL_QuitInit() < 0) {
return -1; return -1;
} }
@ -2233,10 +2232,10 @@ SDL_VideoQuit(void)
} }
/* Halt event processing before doing anything else */ /* Halt event processing before doing anything else */
SDL_QuitQuit(); SDL_TouchQuit();
SDL_MouseQuit(); SDL_MouseQuit();
SDL_KeyboardQuit(); SDL_KeyboardQuit();
SDL_StopEventLoop(); SDL_QuitSubSystem(SDL_INIT_EVENTS);
SDL_EnableScreenSaver(); SDL_EnableScreenSaver();