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

Commit

Permalink
move Ticks initialization tracking to separate function and ensure it…
Browse files Browse the repository at this point in the history
…'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) ?
  • Loading branch information
urkle committed May 3, 2013
1 parent d557ddf commit abe6516
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/SDL.c
Expand Up @@ -32,9 +32,9 @@

/* Initialization/Cleanup routines */
#if !SDL_TIMERS_DISABLED
extern void SDL_StartTicks(void);
extern int SDL_TimerInit(void);
extern void SDL_TimerQuit(void);
extern void SDL_InitTicks(void);
#endif
#if SDL_VIDEO_DRIVER_WINDOWS
extern int SDL_HelperWindowCreate(void);
Expand All @@ -43,7 +43,6 @@ extern int SDL_HelperWindowDestroy(void);


/* The initialized subsystems */
static Uint32 ticks_started = 0;
static SDL_bool SDL_bInMainQuit = SDL_FALSE;
static Uint8 SDL_SubsystemRefCount[ 32 ];

Expand Down Expand Up @@ -93,10 +92,7 @@ int
SDL_InitSubSystem(Uint32 flags)
{
#if !SDL_TIMERS_DISABLED
if (!ticks_started) {
SDL_StartTicks();
ticks_started = 1;
}
SDL_InitTicks();
#endif

/* Initialize the timer subsystem */
Expand Down
12 changes: 12 additions & 0 deletions src/timer/SDL_timer.c
Expand Up @@ -26,6 +26,8 @@
#include "SDL_cpuinfo.h"
#include "SDL_thread.h"

extern void SDL_StartTicks(void);

/* #define DEBUG_TIMERS */

typedef struct _SDL_Timer
Expand Down Expand Up @@ -70,6 +72,16 @@ typedef struct {

static SDL_TimerData SDL_timer_data;

static Uint32 ticks_started = 0;

void
SDL_InitTicks(void)
{
if (!ticks_started) {
SDL_StartTicks();
ticks_started = 1;
}
}

/* The idea here is that any thread might add a timer, but a single
* thread manages the active timer queue, sorted by scheduling time.
Expand Down
1 change: 1 addition & 0 deletions src/timer/SDL_timer_c.h
Expand Up @@ -26,6 +26,7 @@
#define ROUND_RESOLUTION(X) \
(((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION)

extern void SDL_InitTicks(void);
extern int SDL_TimerInit(void);
extern void SDL_TimerQuit(void);

Expand Down
5 changes: 5 additions & 0 deletions src/video/SDL_video.c
Expand Up @@ -29,6 +29,7 @@
#include "SDL_pixels_c.h"
#include "SDL_rect_c.h"
#include "../events/SDL_events_c.h"
#include "../timer/SDL_timer_c.h"

#if SDL_VIDEO_OPENGL
#include "SDL_opengl.h"
Expand Down Expand Up @@ -415,6 +416,10 @@ SDL_VideoInit(const char *driver_name)
if (_this != NULL) {
SDL_VideoQuit();
}

#if !SDL_TIMERS_DISABLED
SDL_InitTicks();
#endif

/* Start the event loop */
if (SDL_StartEventLoop() < 0 ||
Expand Down

0 comments on commit abe6516

Please sign in to comment.