- consolidated the 3 atterm implementations.

Each platform had its own copy. Why?
This commit is contained in:
Christoph Oelckers 2019-06-10 12:01:01 +02:00
parent 9f2fbc1294
commit 2766303cfc
34 changed files with 137 additions and 153 deletions

View File

@ -1298,6 +1298,7 @@ set (PCH_SOURCES
utility/nodebuilder/nodebuild_utility.cpp
utility/sc_man.cpp
utility/stats.cpp
utility/atterm.cpp
utility/cmdlib.cpp
utility/colormatcher.cpp
utility/configfile.cpp

View File

@ -102,6 +102,7 @@
#include "i_system.h"
#include "g_cvars.h"
#include "r_data/r_vanillatrans.h"
#include "atterm.h"
EXTERN_CVAR(Bool, hud_althud)
EXTERN_CVAR(Int, vr_mode)

View File

@ -50,6 +50,7 @@
#include "types.h"
#include "scriptutil.h"
#include "i_system.h"
#include "atterm.h"
// MACROS ------------------------------------------------------------------

View File

@ -302,6 +302,11 @@ inline float DEG2RAD(float deg)
return deg * float(M_PI / 180.0);
}
inline double DEG2RAD(double deg)
{
return deg * (M_PI / 180.0);
}
inline float RAD2DEG(float deg)
{
return deg * float(180. / M_PI);

View File

@ -49,6 +49,7 @@
#include "vm.h"
#include "i_system.h"
#include "utf8.h"
#include "atterm.h"
#define ARTIFLASH_OFFSET (statusBar->invBarOffset+6)
enum

View File

@ -50,6 +50,7 @@
#include "g_levellocals.h"
#include "events.h"
#include "i_system.h"
#include "atterm.h"
static TArray<cluster_info_t> wadclusterinfos;
TArray<level_info_t> wadlevelinfos;

View File

@ -62,6 +62,7 @@
#include "st_start.h"
#include "m_misc.h"
#include "doomerrors.h"
#include "atterm.h"
#include "i_net.h"

View File

@ -66,6 +66,7 @@
#include "gameconfigfile.h"
#include "gstrings.h"
#include "atterm.h"
FGameConfigFile *GameConfig;

View File

@ -50,6 +50,7 @@
#include "gstrings.h"
#include "teaminfo.h"
#include "r_data/sprites.h"
#include "atterm.h"
void ClearSaveGames();

View File

@ -75,6 +75,7 @@
#include "i_system.h"
#include "v_video.h"
#include "fragglescript/t_script.h"
#include "atterm.h"
extern AActor *SpawnMapThing (int index, FMapThing *mthing, int position);

View File

@ -42,6 +42,7 @@
#include "m_joy.h"
#include "templates.h"
#include "v_text.h"
#include "atterm.h"
EXTERN_CVAR(Bool, joy_axespolling)

View File

@ -33,6 +33,7 @@
#include "i_common.h"
#include "s_sound.h"
#include "atterm.h"
#include <sys/sysctl.h>
@ -64,57 +65,6 @@ EXTERN_CVAR(Bool, vid_vsync )
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)
{

View File

@ -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);

View File

@ -48,6 +48,7 @@
#include "v_text.h"
#include "x86.h"
#include "cmdlib.h"
#include "atterm.h"
EXTERN_CVAR(String, language)

View File

@ -54,6 +54,7 @@
#include "v_text.h"
#include "version.h"
#include "doomerrors.h"
#include "atterm.h"
#include "gl/system/gl_framebuffer.h"
#include "vulkan/system/vk_framebuffer.h"

View File

@ -89,10 +89,6 @@ void I_Quit (void);
void I_Tactile (int on, int off, int total);
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

View File

@ -43,6 +43,7 @@
#include "m_argv.h"
#include "doomerrors.h"
#include "swrenderer/r_swrenderer.h"
#include "atterm.h"
IVideo *Video;

View File

@ -56,6 +56,7 @@
#include "doomerrors.h"
#include "i_system.h"
#include "g_game.h"
#include "atterm.h"
// MACROS ------------------------------------------------------------------
@ -89,47 +90,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 ()
{

View File

@ -51,6 +51,7 @@
#include "d_net.h"
#include "g_game.h"
#include "c_dispatch.h"
#include "atterm.h"
#include "gameconfigfile.h"

View File

@ -42,6 +42,7 @@
#include "doomdef.h"
#include "i_system.h"
#include "c_cvars.h"
#include "atterm.h"
// MACROS ------------------------------------------------------------------

View File

@ -64,6 +64,7 @@
#include "actorinlines.h"
#include "g_game.h"
#include "i_system.h"
#include "atterm.h"
// EXTERNAL DATA DECLARATIONS ----------------------------------------------

View File

@ -55,6 +55,7 @@
#include "templates.h"
#include "r_utility.h"
#include "r_renderer.h"
#include "atterm.h"
#include <atomic>
FDynamicColormap NormalLight;

View File

@ -48,6 +48,7 @@
#include "r_data/sprites.h"
#include "vm.h"
#include "i_system.h"
#include "atterm.h"
// MACROS ------------------------------------------------------------------

View File

@ -46,6 +46,7 @@
#include "vm.h"
#include "dobject.h"
#include "menu/menu.h"
#include "atterm.h"

View File

@ -83,6 +83,7 @@
#include "g_levellocals.h"
#include "vm.h"
#include "g_game.h"
#include "atterm.h"
// MACROS ------------------------------------------------------------------

97
src/utility/atterm.cpp Normal file
View 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/utility/atterm.h Normal file
View 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();

View File

@ -69,6 +69,7 @@
#include "version.h"
#include "g_levellocals.h"
#include "am_map.h"
#include "atterm.h"
EXTERN_CVAR(Int, menu_resolution_custom_width)
EXTERN_CVAR(Int, menu_resolution_custom_height)

View File

@ -50,6 +50,7 @@
#include "doomerrors.h"
#include "i_system.h"
#include "swrenderer/r_swrenderer.h"
#include "atterm.h"
EXTERN_CVAR(Int, vid_enablevulkan)

View File

@ -46,6 +46,7 @@
#include "i_cd.h"
#include "helperthread.h"
#include "atterm.h"
extern HWND Window;
extern HINSTANCE g_hInst;

View File

@ -92,6 +92,7 @@
#include "doomerrors.h"
#include "i_system.h"
#include "g_levellocals.h"
#include "atterm.h"
// Prototypes and declarations.
#include "rawinput.h"

View File

@ -74,6 +74,7 @@
#include "vm.h"
#include "i_system.h"
#include "gstrings.h"
#include "atterm.h"
#include "stats.h"
#include "st_start.h"
@ -153,65 +154,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)

View File

@ -84,6 +84,7 @@
#include "doomstat.h"
#include "i_system.h"
#include "textures/bitmap.h"
#include "atterm.h"
#include "optwin32.h"

View File

@ -80,9 +80,6 @@ void I_Quit (void);
void I_Tactile (int on, int off, int total);
void atterm (void (*func)(void));
void popterm ();
// Set the mouse cursor. The texture must be 32x32.
class FTexture;
bool I_SetCursor(FTexture *cursor);