Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

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

  • Loading branch information
slouken committed Jul 6, 2013
1 parent c110771 commit 8545818fcedad51e4c53cfc652309f0cba912441
Showing with 70 additions and 23 deletions.
  1. +6 −5 include/SDL.h
  2. +50 −13 src/SDL.c
  3. +10 −0 src/joystick/SDL_joystick.c
  4. +4 −5 src/video/SDL_video.c
@@ -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 \
)
/*@}*/
@@ -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,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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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) {
@@ -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
@@ -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
}


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

0 comments on commit 8545818

Please sign in to comment.