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_AUDIO 0x00000010
#define SDL_INIT_VIDEO 0x00000020
#define SDL_INIT_JOYSTICK 0x00000200
#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
#define SDL_INIT_JOYSTICK 0x00000200 /**< SDL_INIT_JOYSTICK implies SDL_INIT_EVENTS */
#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_EVENTS 0x00004000
#define SDL_INIT_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */
#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 \
)
/*@}*/

View file

@ -27,6 +27,7 @@
#include "SDL_revision.h"
#include "SDL_fatal.h"
#include "SDL_assert_c.h"
#include "events/SDL_events_c.h"
#include "haptic/SDL_haptic_c.h"
#include "joystick/SDL_joystick_c.h"
@ -111,6 +112,31 @@ SDL_InitSubSystem(Uint32 flags)
SDL_InitTicks();
#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 */
if ((flags & SDL_INIT_TIMER)){
#if !SDL_TIMERS_DISABLED
@ -125,7 +151,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}
/* Initialize the video/event subsystem */
/* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
@ -153,11 +179,6 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* Game controller implies Joystick. */
flags |= SDL_INIT_JOYSTICK;
}
/* Initialize the joystick subsystem */
if ((flags & SDL_INIT_JOYSTICK)){
#if !SDL_JOYSTICK_DISABLED
@ -237,7 +258,7 @@ SDL_QuitSubSystem(Uint32 flags)
/* Shut down requested initialized subsystems */
#if !SDL_JOYSTICK_DISABLED
if ((flags & SDL_INIT_GAMECONTROLLER)) {
/* Game controller implies Joystick. */
/* game controller implies joystick */
flags |= SDL_INIT_JOYSTICK;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
@ -247,6 +268,9 @@ SDL_QuitSubSystem(Uint32 flags)
}
if ((flags & SDL_INIT_JOYSTICK)) {
/* joystick implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
SDL_JoystickQuit();
}
@ -274,6 +298,9 @@ SDL_QuitSubSystem(Uint32 flags)
#if !SDL_VIDEO_DISABLED
if ((flags & SDL_INIT_VIDEO)) {
/* video implies events */
flags |= SDL_INIT_EVENTS;
if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
SDL_VideoQuit();
}
@ -289,6 +316,16 @@ SDL_QuitSubSystem(Uint32 flags)
SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
}
#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

View file

@ -48,6 +48,12 @@ SDL_JoystickInit(void)
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();
if (status >= 0) {
status = 0;
@ -458,6 +464,10 @@ SDL_JoystickQuit(void)
/* Quit the joystick setup */
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
/* Start the event loop */
if (SDL_StartEventLoop() < 0 ||
if (SDL_InitSubSystem(SDL_INIT_EVENTS) < 0 ||
SDL_KeyboardInit() < 0 ||
SDL_MouseInit() < 0 ||
SDL_TouchInit() < 0 ||
SDL_QuitInit() < 0) {
SDL_TouchInit() < 0) {
return -1;
}
@ -2233,10 +2232,10 @@ SDL_VideoQuit(void)
}
/* Halt event processing before doing anything else */
SDL_QuitQuit();
SDL_TouchQuit();
SDL_MouseQuit();
SDL_KeyboardQuit();
SDL_StopEventLoop();
SDL_QuitSubSystem(SDL_INIT_EVENTS);
SDL_EnableScreenSaver();