Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Make it possible to use SDL events separately from the video subsystem.
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jul 6, 2013
1 parent c110771 commit 8545818
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 23 deletions.
11 changes: 6 additions & 5 deletions include/SDL.h
Expand Up @@ -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_NOPARACHUTE 0x00100000 /**< Don't catch fatal signals */
#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 \
)
/*@}*/
Expand Down
63 changes: 50 additions & 13 deletions src/SDL.c
Expand Up @@ -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"

Expand Down Expand Up @@ -111,8 +112,33 @@ 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 ((flags & SDL_INIT_TIMER)){
#if !SDL_TIMERS_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
if (SDL_TimerInit() < 0) {
Expand All @@ -125,8 +151,8 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}

/* Initialize the video/event subsystem */
if ((flags & SDL_INIT_VIDEO) ){
/* Initialize the video subsystem */
if ((flags & SDL_INIT_VIDEO)){
#if !SDL_VIDEO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
if (SDL_VideoInit(NULL) < 0) {
Expand All @@ -140,7 +166,7 @@ SDL_InitSubSystem(Uint32 flags)
}

/* Initialize the audio subsystem */
if ((flags & SDL_INIT_AUDIO) ){
if ((flags & SDL_INIT_AUDIO)){
#if !SDL_AUDIO_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
if (SDL_AudioInit(NULL) < 0) {
Expand All @@ -153,13 +179,8 @@ 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 ((flags & SDL_INIT_JOYSTICK)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
if (SDL_JoystickInit() < 0) {
Expand All @@ -172,7 +193,7 @@ SDL_InitSubSystem(Uint32 flags)
#endif
}

if ((flags & SDL_INIT_GAMECONTROLLER) ){
if ((flags & SDL_INIT_GAMECONTROLLER)){
#if !SDL_JOYSTICK_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
if (SDL_GameControllerInit() < 0) {
Expand All @@ -186,7 +207,7 @@ SDL_InitSubSystem(Uint32 flags)
}

/* Initialize the haptic subsystem */
if ((flags & SDL_INIT_HAPTIC) ){
if ((flags & SDL_INIT_HAPTIC)){
#if !SDL_HAPTIC_DISABLED
if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
if (SDL_HapticInit() < 0) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/joystick/SDL_joystick.c
Expand Up @@ -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;
Expand Down Expand Up @@ -458,6 +464,10 @@ SDL_JoystickQuit(void)

/* Quit the joystick setup */
SDL_SYS_JoystickQuit();

#if !SDL_EVENTS_DISABLED
SDL_QuitSubSystem(SDL_INIT_EVENTS);
#endif
}


Expand Down
9 changes: 4 additions & 5 deletions src/video/SDL_video.c
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 8545818

Please sign in to comment.