src/SDL.c
changeset 7360 b86947ea2749
parent 7346 ff228f955a48
child 7588 f1ca6adffc4b
     1.1 --- a/src/SDL.c	Sat Jul 06 11:56:04 2013 -0700
     1.2 +++ b/src/SDL.c	Sat Jul 06 12:28:57 2013 -0700
     1.3 @@ -27,6 +27,7 @@
     1.4  #include "SDL_revision.h"
     1.5  #include "SDL_fatal.h"
     1.6  #include "SDL_assert_c.h"
     1.7 +#include "events/SDL_events_c.h"
     1.8  #include "haptic/SDL_haptic_c.h"
     1.9  #include "joystick/SDL_joystick_c.h"
    1.10  
    1.11 @@ -111,8 +112,33 @@
    1.12      SDL_InitTicks();
    1.13  #endif
    1.14  
    1.15 +    if ((flags & SDL_INIT_GAMECONTROLLER)) {
    1.16 +        /* game controller implies joystick */
    1.17 +        flags |= SDL_INIT_JOYSTICK;
    1.18 +    }
    1.19 +
    1.20 +    if ((flags & (SDL_INIT_VIDEO|SDL_INIT_JOYSTICK))) {
    1.21 +        /* video or joystick implies events */
    1.22 +        flags |= SDL_INIT_EVENTS;
    1.23 +    }
    1.24 +
    1.25 +    /* Initialize the event subsystem */
    1.26 +    if ((flags & SDL_INIT_EVENTS)) {
    1.27 +#if !SDL_EVENTS_DISABLED
    1.28 +        if (SDL_PrivateShouldInitSubsystem(SDL_INIT_EVENTS)) {
    1.29 +            if (SDL_StartEventLoop() < 0) {
    1.30 +                return (-1);
    1.31 +            }
    1.32 +            SDL_QuitInit();
    1.33 +        }
    1.34 +        SDL_PrivateSubsystemRefCountIncr(SDL_INIT_EVENTS);
    1.35 +#else
    1.36 +        return SDL_SetError("SDL not built with events support");
    1.37 +#endif
    1.38 +    }
    1.39 +
    1.40      /* Initialize the timer subsystem */
    1.41 -    if ((flags & SDL_INIT_TIMER) ){
    1.42 +    if ((flags & SDL_INIT_TIMER)){
    1.43  #if !SDL_TIMERS_DISABLED
    1.44          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_TIMER)) {
    1.45              if (SDL_TimerInit() < 0) {
    1.46 @@ -125,8 +151,8 @@
    1.47  #endif
    1.48      }
    1.49  
    1.50 -    /* Initialize the video/event subsystem */
    1.51 -    if ((flags & SDL_INIT_VIDEO) ){
    1.52 +    /* Initialize the video subsystem */
    1.53 +    if ((flags & SDL_INIT_VIDEO)){
    1.54  #if !SDL_VIDEO_DISABLED
    1.55          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_VIDEO)) {
    1.56              if (SDL_VideoInit(NULL) < 0) {
    1.57 @@ -140,7 +166,7 @@
    1.58      }
    1.59  
    1.60      /* Initialize the audio subsystem */
    1.61 -    if ((flags & SDL_INIT_AUDIO) ){
    1.62 +    if ((flags & SDL_INIT_AUDIO)){
    1.63  #if !SDL_AUDIO_DISABLED
    1.64          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_AUDIO)) {
    1.65              if (SDL_AudioInit(NULL) < 0) {
    1.66 @@ -153,13 +179,8 @@
    1.67  #endif
    1.68      }
    1.69  
    1.70 -    if ((flags & SDL_INIT_GAMECONTROLLER)) {
    1.71 -        /* Game controller implies Joystick. */
    1.72 -        flags |= SDL_INIT_JOYSTICK;
    1.73 -    }
    1.74 -
    1.75      /* Initialize the joystick subsystem */
    1.76 -    if ((flags & SDL_INIT_JOYSTICK) ){
    1.77 +    if ((flags & SDL_INIT_JOYSTICK)){
    1.78  #if !SDL_JOYSTICK_DISABLED
    1.79          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_JOYSTICK)) {
    1.80             if (SDL_JoystickInit() < 0) {
    1.81 @@ -172,7 +193,7 @@
    1.82  #endif
    1.83      }
    1.84  
    1.85 -    if ((flags & SDL_INIT_GAMECONTROLLER) ){
    1.86 +    if ((flags & SDL_INIT_GAMECONTROLLER)){
    1.87  #if !SDL_JOYSTICK_DISABLED
    1.88          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_GAMECONTROLLER)) {
    1.89              if (SDL_GameControllerInit() < 0) {
    1.90 @@ -186,7 +207,7 @@
    1.91      }
    1.92  
    1.93      /* Initialize the haptic subsystem */
    1.94 -    if ((flags & SDL_INIT_HAPTIC) ){
    1.95 +    if ((flags & SDL_INIT_HAPTIC)){
    1.96  #if !SDL_HAPTIC_DISABLED
    1.97          if (SDL_PrivateShouldInitSubsystem(SDL_INIT_HAPTIC)) {
    1.98              if (SDL_HapticInit() < 0) {
    1.99 @@ -237,7 +258,7 @@
   1.100      /* Shut down requested initialized subsystems */
   1.101  #if !SDL_JOYSTICK_DISABLED
   1.102      if ((flags & SDL_INIT_GAMECONTROLLER)) {
   1.103 -        /* Game controller implies Joystick. */
   1.104 +        /* game controller implies joystick */
   1.105          flags |= SDL_INIT_JOYSTICK;
   1.106  
   1.107          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_GAMECONTROLLER)) {
   1.108 @@ -247,6 +268,9 @@
   1.109      }
   1.110  
   1.111      if ((flags & SDL_INIT_JOYSTICK)) {
   1.112 +        /* joystick implies events */
   1.113 +        flags |= SDL_INIT_EVENTS;
   1.114 +
   1.115          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_JOYSTICK)) {
   1.116              SDL_JoystickQuit();
   1.117          }
   1.118 @@ -274,6 +298,9 @@
   1.119  
   1.120  #if !SDL_VIDEO_DISABLED
   1.121      if ((flags & SDL_INIT_VIDEO)) {
   1.122 +        /* video implies events */
   1.123 +        flags |= SDL_INIT_EVENTS;
   1.124 +
   1.125          if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_VIDEO)) {
   1.126              SDL_VideoQuit();
   1.127          }
   1.128 @@ -289,6 +316,16 @@
   1.129          SDL_PrivateSubsystemRefCountDecr(SDL_INIT_TIMER);
   1.130      }
   1.131  #endif
   1.132 +
   1.133 +#if !SDL_EVENTS_DISABLED
   1.134 +    if ((flags & SDL_INIT_EVENTS)) {
   1.135 +        if (SDL_PrivateShouldQuitSubsystem(SDL_INIT_EVENTS)) {
   1.136 +            SDL_QuitQuit();
   1.137 +            SDL_StopEventLoop();
   1.138 +        }
   1.139 +        SDL_PrivateSubsystemRefCountDecr(SDL_INIT_EVENTS);
   1.140 +    }
   1.141 +#endif
   1.142  }
   1.143  
   1.144  Uint32