mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-20 18:42:17 +00:00
- consolidated the 3 atterm implementations.
Each platform had its own copy. Why? # Conflicts: # src/CMakeLists.txt # src/dobjtype.cpp # src/g_mapinfo.cpp # src/g_statusbar/sbarinfo.cpp # src/i_net.cpp # src/menu/menudef.cpp # src/p_setup.cpp # src/posix/cocoa/i_video.mm # src/posix/i_system.h # src/posix/sdl/i_main.cpp # src/r_utility.cpp # src/s_advsound.cpp # src/s_sound.cpp # src/v_video.cpp # src/win32/i_input.cpp # src/win32/i_system.h # Conflicts: # src/CMakeLists.txt # src/doomtype.h # src/i_net.cpp # src/posix/sdl/i_system.cpp # src/win32/i_system.cpp # src/win32/win32video.cpp
This commit is contained in:
parent
d76c7306ca
commit
b473fc936c
34 changed files with 133 additions and 153 deletions
|
@ -1287,6 +1287,7 @@ set (PCH_SOURCES
|
|||
sound/wildmidi/wildmidi_lib.cpp
|
||||
sound/wildmidi/wm_error.cpp
|
||||
events.cpp
|
||||
atterm.cpp
|
||||
GuillotineBinPack.cpp
|
||||
SkylineBinPack.cpp
|
||||
)
|
||||
|
|
97
src/atterm.cpp
Normal file
97
src/atterm.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
** attern.cpp
|
||||
** Termination handling
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 1998-2007 Randy Heit
|
||||
** Copyright 2019 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include "tarray.h"
|
||||
#include "atterm.h"
|
||||
|
||||
static TArray<std::pair<void (*)(void), const char *>> TermFuncs;
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// atterm
|
||||
//
|
||||
// Our own atexit because atexit can be problematic under Linux, though I
|
||||
// forget the circumstances that cause trouble.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void addterm(void (*func)(), const char *name)
|
||||
{
|
||||
// Make sure this function wasn't already registered.
|
||||
|
||||
for (auto &term : TermFuncs)
|
||||
{
|
||||
if (term.first == func)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
TermFuncs.Push(std::make_pair(func, name));
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// call_terms
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void call_terms()
|
||||
{
|
||||
for(int i = TermFuncs.Size()-1; i >= 0; i--)
|
||||
{
|
||||
TermFuncs[i].first();
|
||||
}
|
||||
TermFuncs.Clear();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// popterm
|
||||
//
|
||||
// Removes the most recently register atterm function.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void popterm()
|
||||
{
|
||||
if (TermFuncs.Size() > 0)
|
||||
{
|
||||
TermFuncs.Pop();
|
||||
}
|
||||
}
|
||||
|
6
src/atterm.h
Normal file
6
src/atterm.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
void addterm (void (*func)(void), const char *name);
|
||||
#define atterm(t) addterm (t, #t)
|
||||
void popterm ();
|
||||
void call_terms();
|
|
@ -118,6 +118,7 @@
|
|||
#include "vm.h"
|
||||
#include "types.h"
|
||||
#include "r_data/r_vanillatrans.h"
|
||||
#include "atterm.h"
|
||||
|
||||
EXTERN_CVAR(Bool, hud_althud)
|
||||
void DrawHUD();
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "vm.h"
|
||||
#include "types.h"
|
||||
#include "scriptutil.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include "v_text.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "events.h"
|
||||
#include "atterm.h"
|
||||
|
||||
TArray<cluster_info_t> wadclusterinfos;
|
||||
TArray<level_info_t> wadlevelinfos;
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "cmdlib.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#define ARTIFLASH_OFFSET (statusBar->invBarOffset+6)
|
||||
enum
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
#include "st_start.h"
|
||||
#include "m_misc.h"
|
||||
#include "doomstat.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include "i_net.h"
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
|
||||
#include "gameconfigfile.h"
|
||||
#include "gstrings.h"
|
||||
#include "atterm.h"
|
||||
|
||||
FGameConfigFile *GameConfig;
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "gameconfigfile.h"
|
||||
#include "m_argv.h"
|
||||
#include "i_soundfont.h"
|
||||
#include "atterm.h"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
#include "types.h"
|
||||
#include "i_time.h"
|
||||
#include "scripting/vm/vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include "fragglescript/t_fs.h"
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "m_joy.h"
|
||||
#include "templates.h"
|
||||
#include "v_text.h"
|
||||
#include "atterm.h"
|
||||
|
||||
|
||||
EXTERN_CVAR(Bool, joy_axespolling)
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
#include "i_common.h"
|
||||
#include "s_sound.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <unistd.h>
|
||||
|
@ -67,57 +68,6 @@ EXTERN_CVAR(Bool, fullscreen )
|
|||
namespace
|
||||
{
|
||||
|
||||
// The maximum number of functions that can be registered with atterm.
|
||||
const size_t MAX_TERMS = 64;
|
||||
|
||||
void (*TermFuncs[MAX_TERMS])();
|
||||
const char *TermNames[MAX_TERMS];
|
||||
size_t NumTerms;
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
// Expose this for i_main_except.cpp
|
||||
void call_terms()
|
||||
{
|
||||
while (NumTerms > 0)
|
||||
{
|
||||
TermFuncs[--NumTerms]();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void addterm(void (*func)(), const char *name)
|
||||
{
|
||||
// Make sure this function wasn't already registered.
|
||||
|
||||
for (size_t i = 0; i < NumTerms; ++i)
|
||||
{
|
||||
if (TermFuncs[i] == func)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (NumTerms == MAX_TERMS)
|
||||
{
|
||||
func();
|
||||
I_FatalError("Too many exit functions registered.");
|
||||
}
|
||||
|
||||
TermNames[NumTerms] = name;
|
||||
TermFuncs[NumTerms] = func;
|
||||
|
||||
++NumTerms;
|
||||
}
|
||||
|
||||
void popterm()
|
||||
{
|
||||
if (NumTerms)
|
||||
{
|
||||
--NumTerms;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Mac_I_FatalError(const char* const message)
|
||||
{
|
||||
|
|
|
@ -36,9 +36,9 @@
|
|||
|
||||
#include "doomerrors.h"
|
||||
#include "vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// Import some functions from i_main.mm
|
||||
void call_terms();
|
||||
void Mac_I_FatalError(const char* const message);
|
||||
void OriginalMainTry(int argc, char** argv);
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "v_text.h"
|
||||
#include "x86.h"
|
||||
#include "cmdlib.h"
|
||||
#include "atterm.h"
|
||||
|
||||
|
||||
EXTERN_CVAR(String, language)
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "v_video.h"
|
||||
#include "version.h"
|
||||
#include "videomodes.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include "gl/system/gl_system.h"
|
||||
#include "gl/data/gl_vertexbuffer.h"
|
||||
|
|
|
@ -90,10 +90,6 @@ void I_Tactile (int on, int off, int total);
|
|||
void I_Error (const char *error, ...) GCCPRINTF(1,2);
|
||||
void I_FatalError (const char *error, ...) GCCPRINTF(1,2);
|
||||
|
||||
void addterm (void (*func)(void), const char *name);
|
||||
#define atterm(t) addterm (t, #t)
|
||||
void popterm ();
|
||||
|
||||
void I_DebugPrint (const char *cp);
|
||||
|
||||
// Print a console string
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include "sdlglvideo.h"
|
||||
#include "r_renderer.h"
|
||||
#include "swrenderer/r_swrenderer.h"
|
||||
#include "atterm.h"
|
||||
|
||||
EXTERN_CVAR (Bool, ticker)
|
||||
EXTERN_CVAR (Bool, fullscreen)
|
||||
|
|
|
@ -58,6 +58,7 @@
|
|||
#include "r_utility.h"
|
||||
#include "doomstat.h"
|
||||
#include "vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
@ -91,47 +92,9 @@ FArgs *Args;
|
|||
|
||||
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
||||
|
||||
static void (*TermFuncs[MAX_TERMS]) ();
|
||||
static const char *TermNames[MAX_TERMS];
|
||||
static int NumTerms;
|
||||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
void addterm (void (*func) (), const char *name)
|
||||
{
|
||||
// Make sure this function wasn't already registered.
|
||||
for (int i = 0; i < NumTerms; ++i)
|
||||
{
|
||||
if (TermFuncs[i] == func)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (NumTerms == MAX_TERMS)
|
||||
{
|
||||
func ();
|
||||
I_FatalError (
|
||||
"Too many exit functions registered.\n"
|
||||
"Increase MAX_TERMS in i_main.cpp");
|
||||
}
|
||||
TermNames[NumTerms] = name;
|
||||
TermFuncs[NumTerms++] = func;
|
||||
}
|
||||
|
||||
void popterm ()
|
||||
{
|
||||
if (NumTerms)
|
||||
NumTerms--;
|
||||
}
|
||||
|
||||
void call_terms ()
|
||||
{
|
||||
while (NumTerms > 0)
|
||||
{
|
||||
// printf ("term %d - %s\n", NumTerms, TermNames[NumTerms-1]);
|
||||
TermFuncs[--NumTerms] ();
|
||||
}
|
||||
}
|
||||
|
||||
static void NewFailure ()
|
||||
{
|
||||
|
|
|
@ -56,6 +56,7 @@
|
|||
#include "g_game.h"
|
||||
#include "i_system.h"
|
||||
#include "c_dispatch.h"
|
||||
#include "atterm.h"
|
||||
#include "templates.h"
|
||||
#include "v_palette.h"
|
||||
#include "textures.h"
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "doomdef.h"
|
||||
#include "i_system.h"
|
||||
#include "c_cvars.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@
|
|||
#include "vm.h"
|
||||
#include "i_time.h"
|
||||
#include "actorinlines.h"
|
||||
#include "atterm.h"
|
||||
|
||||
|
||||
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "g_levellocals.h"
|
||||
#include "r_data/sprites.h"
|
||||
#include "vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "vm.h"
|
||||
#include "dobject.h"
|
||||
#include "menu/menu.h"
|
||||
#include "atterm.h"
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@
|
|||
#include "r_state.h"
|
||||
#include "g_levellocals.h"
|
||||
#include "vm.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// MACROS ------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "templates.h"
|
||||
#include "r_utility.h"
|
||||
#include "r_renderer.h"
|
||||
#include "atterm.h"
|
||||
#include <atomic>
|
||||
|
||||
FDynamicColormap NormalLight;
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
#include "vm.h"
|
||||
#include "r_videoscale.h"
|
||||
#include "i_time.h"
|
||||
#include "atterm.h"
|
||||
|
||||
EXTERN_CVAR(Bool, r_blendmethod)
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include "m_argv.h"
|
||||
#include "version.h"
|
||||
#include "swrenderer/r_swrenderer.h"
|
||||
#include "atterm.h"
|
||||
|
||||
EXTERN_CVAR (Bool, ticker)
|
||||
EXTERN_CVAR (Bool, fullscreen)
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
|
||||
#include "i_cd.h"
|
||||
#include "helperthread.h"
|
||||
#include "atterm.h"
|
||||
|
||||
extern HWND Window;
|
||||
extern HINSTANCE g_hInst;
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
#include "v_text.h"
|
||||
#include "version.h"
|
||||
#include "events.h"
|
||||
#include "atterm.h"
|
||||
|
||||
// Prototypes and declarations.
|
||||
#include "rawinput.h"
|
||||
|
|
|
@ -84,6 +84,7 @@
|
|||
#include "s_sound.h"
|
||||
#include "vm.h"
|
||||
#include "gstrings.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include "stats.h"
|
||||
#include "st_start.h"
|
||||
|
@ -165,65 +166,9 @@ DYN_WIN32_SYM(SHGetKnownFolderPath);
|
|||
|
||||
static const WCHAR WinClassName[] = WGAMENAME "MainWindow";
|
||||
static HMODULE hwtsapi32; // handle to wtsapi32.dll
|
||||
static void (*TermFuncs[MAX_TERMS])(void);
|
||||
static int NumTerms;
|
||||
|
||||
// CODE --------------------------------------------------------------------
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// atterm
|
||||
//
|
||||
// Our own atexit because atexit can be problematic under Linux, though I
|
||||
// forget the circumstances that cause trouble.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void atterm (void (*func)(void))
|
||||
{
|
||||
// Make sure this function wasn't already registered.
|
||||
for (int i = 0; i < NumTerms; ++i)
|
||||
{
|
||||
if (TermFuncs[i] == func)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (NumTerms == MAX_TERMS)
|
||||
{
|
||||
func ();
|
||||
I_FatalError ("Too many exit functions registered.\nIncrease MAX_TERMS in i_main.cpp");
|
||||
}
|
||||
TermFuncs[NumTerms++] = func;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// popterm
|
||||
//
|
||||
// Removes the most recently register atterm function.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void popterm ()
|
||||
{
|
||||
if (NumTerms)
|
||||
NumTerms--;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// call_terms
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
static void call_terms (void)
|
||||
{
|
||||
while (NumTerms > 0)
|
||||
{
|
||||
TermFuncs[--NumTerms]();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
static int NewFailure (size_t size)
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
#include "stats.h"
|
||||
#include "textures/bitmap.h"
|
||||
#include "textures/textures.h"
|
||||
#include "atterm.h"
|
||||
|
||||
#include "optwin32.h"
|
||||
|
||||
|
|
|
@ -82,9 +82,6 @@ void I_Tactile (int on, int off, int total);
|
|||
void I_Error (const char *error, ...) GCCPRINTF(1,2);
|
||||
void I_FatalError (const char *error, ...) GCCPRINTF(1,2);
|
||||
|
||||
void atterm (void (*func)(void));
|
||||
void popterm ();
|
||||
|
||||
// Set the mouse cursor. The texture must be 32x32.
|
||||
class FTexture;
|
||||
bool I_SetCursor(FTexture *cursor);
|
||||
|
|
|
@ -60,6 +60,7 @@
|
|||
#include "c_dispatch.h"
|
||||
#include "templates.h"
|
||||
#include "i_system.h"
|
||||
#include "atterm.h"
|
||||
#include "i_video.h"
|
||||
#include "v_video.h"
|
||||
#include "v_pfx.h"
|
||||
|
|
Loading…
Reference in a new issue