move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init
authorEdward Rudd <urkle@outoforder.cc>
Thu, 02 May 2013 21:40:59 -0400
changeset 7139dd722e7460c5
parent 7138 52ba4fa156c7
child 7140 e1896b95a8a7
move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init

-- why do we even allow initialization w/o calling at least SDL_Init(0) ?
src/SDL.c
src/timer/SDL_timer.c
src/timer/SDL_timer_c.h
src/video/SDL_video.c
     1.1 --- a/src/SDL.c	Thu May 02 21:23:38 2013 -0400
     1.2 +++ b/src/SDL.c	Thu May 02 21:40:59 2013 -0400
     1.3 @@ -32,9 +32,9 @@
     1.4  
     1.5  /* Initialization/Cleanup routines */
     1.6  #if !SDL_TIMERS_DISABLED
     1.7 -extern void SDL_StartTicks(void);
     1.8  extern int SDL_TimerInit(void);
     1.9  extern void SDL_TimerQuit(void);
    1.10 +extern void SDL_InitTicks(void);
    1.11  #endif
    1.12  #if SDL_VIDEO_DRIVER_WINDOWS
    1.13  extern int SDL_HelperWindowCreate(void);
    1.14 @@ -43,7 +43,6 @@
    1.15  
    1.16  
    1.17  /* The initialized subsystems */
    1.18 -static Uint32 ticks_started = 0;
    1.19  static SDL_bool SDL_bInMainQuit = SDL_FALSE;
    1.20  static Uint8 SDL_SubsystemRefCount[ 32 ];
    1.21  
    1.22 @@ -93,10 +92,7 @@
    1.23  SDL_InitSubSystem(Uint32 flags)
    1.24  {
    1.25  #if !SDL_TIMERS_DISABLED
    1.26 -    if (!ticks_started) {
    1.27 -        SDL_StartTicks();
    1.28 -        ticks_started = 1;
    1.29 -    }
    1.30 +    SDL_InitTicks();
    1.31  #endif
    1.32  
    1.33      /* Initialize the timer subsystem */
     2.1 --- a/src/timer/SDL_timer.c	Thu May 02 21:23:38 2013 -0400
     2.2 +++ b/src/timer/SDL_timer.c	Thu May 02 21:40:59 2013 -0400
     2.3 @@ -26,6 +26,8 @@
     2.4  #include "SDL_cpuinfo.h"
     2.5  #include "SDL_thread.h"
     2.6  
     2.7 +extern void SDL_StartTicks(void);
     2.8 +
     2.9  /* #define DEBUG_TIMERS */
    2.10  
    2.11  typedef struct _SDL_Timer
    2.12 @@ -70,6 +72,16 @@
    2.13  
    2.14  static SDL_TimerData SDL_timer_data;
    2.15  
    2.16 +static Uint32 ticks_started = 0;
    2.17 +
    2.18 +void
    2.19 +SDL_InitTicks(void)
    2.20 +{
    2.21 +    if (!ticks_started) {
    2.22 +        SDL_StartTicks();
    2.23 +        ticks_started = 1;
    2.24 +    }
    2.25 +}
    2.26  
    2.27  /* The idea here is that any thread might add a timer, but a single
    2.28   * thread manages the active timer queue, sorted by scheduling time.
     3.1 --- a/src/timer/SDL_timer_c.h	Thu May 02 21:23:38 2013 -0400
     3.2 +++ b/src/timer/SDL_timer_c.h	Thu May 02 21:40:59 2013 -0400
     3.3 @@ -26,6 +26,7 @@
     3.4  #define ROUND_RESOLUTION(X)	\
     3.5  	(((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)
     3.6  
     3.7 +extern void SDL_InitTicks(void);
     3.8  extern int SDL_TimerInit(void);
     3.9  extern void SDL_TimerQuit(void);
    3.10  
     4.1 --- a/src/video/SDL_video.c	Thu May 02 21:23:38 2013 -0400
     4.2 +++ b/src/video/SDL_video.c	Thu May 02 21:40:59 2013 -0400
     4.3 @@ -29,6 +29,7 @@
     4.4  #include "SDL_pixels_c.h"
     4.5  #include "SDL_rect_c.h"
     4.6  #include "../events/SDL_events_c.h"
     4.7 +#include "../timer/SDL_timer_c.h"
     4.8  
     4.9  #if SDL_VIDEO_OPENGL
    4.10  #include "SDL_opengl.h"
    4.11 @@ -415,6 +416,10 @@
    4.12      if (_this != NULL) {
    4.13          SDL_VideoQuit();
    4.14      }
    4.15 +    
    4.16 +#if !SDL_TIMERS_DISABLED
    4.17 +    SDL_InitTicks();
    4.18 +#endif
    4.19  
    4.20      /* Start the event loop */
    4.21      if (SDL_StartEventLoop() < 0 ||