Backport atexit consolidation
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#if SDL_MAJOR_VERSION == 1
|
#if SDL_MAJOR_VERSION == 1
|
||||||
|
|
||||||
|
static void TFB_PreQuit (void);
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_PreInit (void)
|
TFB_PreInit (void)
|
||||||
{
|
{
|
||||||
@@ -62,6 +64,12 @@ TFB_PreInit (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
TFB_PreQuit (void)
|
||||||
|
{
|
||||||
|
SDL_Quit ();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
||||||
{
|
{
|
||||||
@@ -229,9 +237,7 @@ Create_Screen (SDL_Surface *templat, int w, int h)
|
|||||||
int
|
int
|
||||||
SDL1_ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h)
|
SDL1_ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h)
|
||||||
{
|
{
|
||||||
if (*screen) {
|
UnInit_Screen (screen);
|
||||||
SDL_FreeSurface (*screen);
|
|
||||||
}
|
|
||||||
*screen = Create_Screen (templat, w, h);
|
*screen = Create_Screen (templat, w, h);
|
||||||
|
|
||||||
return *screen == 0 ? -1 : 0;
|
return *screen == 0 ? -1 : 0;
|
||||||
|
|||||||
@@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
#if SDL_MAJOR_VERSION > 1
|
#if SDL_MAJOR_VERSION > 1
|
||||||
|
|
||||||
|
static void TFB_PreQuit (void);
|
||||||
|
|
||||||
void
|
void
|
||||||
TFB_PreInit (void)
|
TFB_PreInit (void)
|
||||||
{
|
{
|
||||||
@@ -62,6 +64,14 @@ TFB_PreInit (void)
|
|||||||
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
|
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
atexit (TFB_PreQuit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
TFB_PreQuit (void)
|
||||||
|
{
|
||||||
|
SDL_Quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@@ -90,7 +100,7 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
bool
|
||||||
TFB_SetGamma (float gamma)
|
TFB_SetGamma (float gamma)
|
||||||
{
|
{
|
||||||
log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine.");
|
log_add (log_Warning, "Custom gamma correction is not available in the SDL2 engine.");
|
||||||
|
|||||||
@@ -50,42 +50,6 @@ TFB_GRAPHICS_BACKEND *graphics_backend = NULL;
|
|||||||
volatile int QuitPosted = 0;
|
volatile int QuitPosted = 0;
|
||||||
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
|
volatile int GameActive = 1; // Track the SDL_ACTIVEEVENT state SDL_APPACTIVE
|
||||||
|
|
||||||
static void TFB_PreQuit (void);
|
|
||||||
|
|
||||||
void
|
|
||||||
TFB_PreInit (void)
|
|
||||||
{
|
|
||||||
log_add (log_Info, "Initializing base SDL functionality.");
|
|
||||||
log_add (log_Info, "Using SDL version %d.%d.%d (compiled with "
|
|
||||||
"%d.%d.%d)", SDL_Linked_Version ()->major,
|
|
||||||
SDL_Linked_Version ()->minor, SDL_Linked_Version ()->patch,
|
|
||||||
SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL);
|
|
||||||
#if 0
|
|
||||||
if (SDL_Linked_Version ()->major != SDL_MAJOR_VERSION ||
|
|
||||||
SDL_Linked_Version ()->minor != SDL_MINOR_VERSION ||
|
|
||||||
SDL_Linked_Version ()->patch != SDL_PATCHLEVEL) {
|
|
||||||
log_add (log_Warning, "The used SDL library is not the same version "
|
|
||||||
"as the one used to compile The Ur-Quan Masters with! "
|
|
||||||
"If you experience any crashes, this would be an excellent "
|
|
||||||
"suspect.");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((SDL_Init (SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1))
|
|
||||||
{
|
|
||||||
log_add (log_Fatal, "Could not initialize SDL: %s.", SDL_GetError ());
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
atexit (TFB_PreQuit);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
TFB_PreQuit (void)
|
|
||||||
{
|
|
||||||
SDL_Quit ();
|
|
||||||
}
|
|
||||||
|
|
||||||
int
|
int
|
||||||
TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
||||||
{
|
{
|
||||||
@@ -137,9 +101,15 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
|||||||
int
|
int
|
||||||
TFB_InitGraphics (int driver, int flags, int width, int height)
|
TFB_InitGraphics (int driver, int flags, int width, int height)
|
||||||
{
|
{
|
||||||
int result;
|
int i, result;
|
||||||
char caption[200];
|
char caption[200];
|
||||||
|
|
||||||
|
/* Null out screen pointers for the first time */
|
||||||
|
for (i = 0; i < TFB_GFX_NUMSCREENS; i++)
|
||||||
|
{
|
||||||
|
SDL_Screens[i] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
GfxFlags = flags;
|
GfxFlags = flags;
|
||||||
|
|
||||||
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
|
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
|
||||||
@@ -373,3 +343,14 @@ TFB_HasColorKey (SDL_Surface *surface)
|
|||||||
Uint32 key;
|
Uint32 key;
|
||||||
return TFB_GetColorKey (surface, &key) == 0;
|
return TFB_GetColorKey (surface, &key) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
UnInit_Screen (SDL_Surface **screen)
|
||||||
|
{
|
||||||
|
if (*screen == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_FreeSurface (*screen);
|
||||||
|
*screen = NULL;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user