From 501c5360170ad52f37f54fabefe5124aad8c5ddb Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Mon, 29 Mar 2021 18:23:53 +0200 Subject: [PATCH] :art: Clean up appfat --- Source/appfat.cpp | 16 ++++++++++------ Source/appfat.h | 16 +++------------- Source/dthread.cpp | 6 +++--- Source/multi.cpp | 4 ++-- Source/nthread.cpp | 6 +++--- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Source/appfat.cpp b/Source/appfat.cpp index 3778a730..03d96212 100644 --- a/Source/appfat.cpp +++ b/Source/appfat.cpp @@ -7,10 +7,12 @@ #include "../3rdParty/Storm/Source/storm.h" #include -DEVILUTION_BEGIN_NAMESPACE +namespace dvl { + +namespace { /** Set to true when a fatal error is encountered and the application should shut down. */ -BOOL terminating; +bool terminating = false; /** Thread id of the last callee to FreeDlg(). */ SDL_threadID cleanup_thread_id; @@ -19,7 +21,7 @@ SDL_threadID cleanup_thread_id; * @param pszFmt Error message format * @param va Additional parameters for message format */ -static void MsgBox(const char *pszFmt, va_list va) +void MsgBox(const char *pszFmt, va_list va) { char text[256]; @@ -31,12 +33,12 @@ static void MsgBox(const char *pszFmt, va_list va) /** * @brief Cleans up after a fatal application error. */ -static void FreeDlg() +void FreeDlg() { if (terminating && cleanup_thread_id != SDL_GetThreadID(NULL)) SDL_Delay(20000); - terminating = TRUE; + terminating = true; cleanup_thread_id = SDL_GetThreadID(NULL); if (gbIsMultiplayer) { @@ -47,6 +49,8 @@ static void FreeDlg() SNetDestroy(); } +} + /** * @brief Terminates the game and displays an error message box. * @param pszFmt Optional error message. @@ -169,4 +173,4 @@ void DirErrorDlg(const char *error) app_fatal(NULL); } -DEVILUTION_END_NAMESPACE +} diff --git a/Source/appfat.h b/Source/appfat.h index 53f283fa..9ebbafa2 100644 --- a/Source/appfat.h +++ b/Source/appfat.h @@ -3,16 +3,12 @@ * * Interface of error dialogs. */ -#ifndef __APPFAT_H__ -#define __APPFAT_H__ +#pragma once -DEVILUTION_BEGIN_NAMESPACE +#include -#ifdef __cplusplus -extern "C" { -#endif +namespace dvl { -#define TraceLastError SDL_GetError [[noreturn]] void app_fatal(const char *pszFmt, ...); void DrawDlg(const char *pszFmt, ...); #ifdef _DEBUG @@ -23,10 +19,4 @@ void DrawDlg(const char *pszFmt, ...); [[noreturn]] void InsertCDDlg(); [[noreturn]] void DirErrorDlg(const char *error); -#ifdef __cplusplus } -#endif - -DEVILUTION_END_NAMESPACE - -#endif /* __APPFAT_H__ */ diff --git a/Source/dthread.cpp b/Source/dthread.cpp index a0cf61af..d0ba30f4 100644 --- a/Source/dthread.cpp +++ b/Source/dthread.cpp @@ -25,7 +25,7 @@ static unsigned int dthread_handler(void *data) while (dthread_running) { if (!sgpInfoHead && WaitForEvent(sghWorkToDoEvent) == -1) { - error_buf = TraceLastError(); + error_buf = SDL_GetError(); app_fatal("dthread4:\n%s", error_buf); } @@ -103,7 +103,7 @@ void dthread_start() sghWorkToDoEvent = StartEvent(); if (sghWorkToDoEvent == NULL) { - error_buf = TraceLastError(); + error_buf = SDL_GetError(); app_fatal("dthread:1\n%s", error_buf); } @@ -111,7 +111,7 @@ void dthread_start() sghThread = CreateThread(dthread_handler, &glpDThreadId); if (sghThread == NULL) { - error_buf = TraceLastError(); + error_buf = SDL_GetError(); app_fatal("dthread2:\n%s", error_buf); } } diff --git a/Source/multi.cpp b/Source/multi.cpp index 15e70bd5..2fe7a57e 100644 --- a/Source/multi.cpp +++ b/Source/multi.cpp @@ -706,7 +706,7 @@ static void multi_event_handler(BOOL add) for (i = 0; i < 3; i++) { if (!fn(event_types[i], multi_handle_events) && add) { - app_fatal("SNetRegisterEventHandler:\n%s", TraceLastError()); + app_fatal("SNetRegisterEventHandler:\n%s", SDL_GetError()); } } } @@ -831,7 +831,7 @@ BOOL multi_init_single(_SNETPROGRAMDATA *client_info, _SNETPLAYERDATA *user_info unused = 0; if (!SNetCreateGame("local", "local", "local", 0, (char *)&sgGameInitInfo, sizeof(sgGameInitInfo), 1, "local", "local", &unused)) { - app_fatal("SNetCreateGame1:\n%s", TraceLastError()); + app_fatal("SNetCreateGame1:\n%s", SDL_GetError()); } myplr = 0; diff --git a/Source/nthread.cpp b/Source/nthread.cpp index ddba5917..76fc0003 100644 --- a/Source/nthread.cpp +++ b/Source/nthread.cpp @@ -40,7 +40,7 @@ void nthread_terminate_game(const char *pszFcn) } else if (sErr == STORM_ERROR_NOT_IN_GAME) { gbGameDestroyed = TRUE; } else { - app_fatal("%s:\n%s", pszFcn, TraceLastError()); + app_fatal("%s:\n%s", pszFcn, SDL_GetError()); } } @@ -160,7 +160,7 @@ void nthread_start(BOOL set_turn_upper_bit) turn_upper_bit = 0; caps.size = 36; if (!SNetGetProviderCaps(&caps)) { - err = TraceLastError(); + err = SDL_GetError(); app_fatal("SNetGetProviderCaps:\n%s", err); } gdwTurnsInTransit = caps.defaultturnsintransit; @@ -193,7 +193,7 @@ void nthread_start(BOOL set_turn_upper_bit) nthread_should_run = TRUE; sghThread = CreateThread(nthread_handler, &glpNThreadId); if (sghThread == NULL) { - err2 = TraceLastError(); + err2 = SDL_GetError(); app_fatal("nthread2:\n%s", err2); } }