Backport atexit consolidation
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
|
||||
#if SDL_MAJOR_VERSION == 1
|
||||
|
||||
static void TFB_PreQuit (void);
|
||||
|
||||
void
|
||||
TFB_PreInit (void)
|
||||
{
|
||||
@@ -62,6 +64,12 @@ TFB_PreInit (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
TFB_PreQuit (void)
|
||||
{
|
||||
SDL_Quit ();
|
||||
}
|
||||
|
||||
int
|
||||
TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
||||
{
|
||||
@@ -229,9 +237,7 @@ Create_Screen (SDL_Surface *templat, int w, int h)
|
||||
int
|
||||
SDL1_ReInit_Screen (SDL_Surface **screen, SDL_Surface *templat, int w, int h)
|
||||
{
|
||||
if (*screen) {
|
||||
SDL_FreeSurface (*screen);
|
||||
}
|
||||
UnInit_Screen (screen);
|
||||
*screen = Create_Screen (templat, w, h);
|
||||
|
||||
return *screen == 0 ? -1 : 0;
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#if SDL_MAJOR_VERSION > 1
|
||||
|
||||
static void TFB_PreQuit (void);
|
||||
|
||||
void
|
||||
TFB_PreInit (void)
|
||||
{
|
||||
@@ -62,6 +64,14 @@ TFB_PreInit (void)
|
||||
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
|
||||
@@ -90,7 +100,7 @@ TFB_ReInitGraphics (int driver, int flags, int width, int height)
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
bool
|
||||
TFB_SetGamma (float gamma)
|
||||
{
|
||||
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 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
|
||||
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
|
||||
TFB_InitGraphics (int driver, int flags, int width, int height)
|
||||
{
|
||||
int result;
|
||||
int i, result;
|
||||
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;
|
||||
|
||||
if (driver == TFB_GFXDRIVER_SDL_OPENGL)
|
||||
@@ -373,3 +343,14 @@ TFB_HasColorKey (SDL_Surface *surface)
|
||||
Uint32 key;
|
||||
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