diff --git a/src/deh_soc.c b/src/deh_soc.c index 76488462e..c9d0eb602 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -32,6 +32,7 @@ #include "r_picformats.h" #include "r_things.h" // R_Char2Frame #include "r_sky.h" +#include "s_sound.h" #include "fastcmp.h" #include "lua_script.h" // Reluctantly included for LUA_EvalMath #include "d_clisrv.h" @@ -1221,7 +1222,7 @@ void readlevelheader(MYFILE *f, char * name) sizeof(mapheaderinfo[num]->musname[j]), va("Level header %d: music", num)); j++; } while ((tmp = strtok(NULL,",")) != NULL); - + if (tmp != NULL) deh_warning("Level header %d: additional music slots past %d discarded", num, MAXMUSNAMES); mapheaderinfo[num]->musname_size = j; @@ -1245,7 +1246,7 @@ void readlevelheader(MYFILE *f, char * name) sizeof(mapheaderinfo[num]->associatedmus[j]), va("Level header %d: associated music", num)); j++; } while ((tmp = strtok(NULL,",")) != NULL); - + if (tmp != NULL) deh_warning("Level header %d: additional associated music slots past %d discarded", num, MAXMUSNAMES); mapheaderinfo[num]->associatedmus_size = j; @@ -2761,7 +2762,7 @@ static void readcondition(UINT16 set, UINT32 id, char *word2) deh_warning("Invalid cup result %s for condition ID %d", params[2], id+1); return; } - + } } else if ((offset=0) || fastcmp(params[0], "PODIUMEMERALD") diff --git a/src/discord.c b/src/discord.c index df8f3cd85..516172a67 100644 --- a/src/discord.c +++ b/src/discord.c @@ -23,6 +23,7 @@ #include "k_menu.h" // gametype_cons_t #include "r_things.h" // skins #include "mserv.h" // cv_advertise +#include "s_sound.h" #include "z_zone.h" #include "byteptr.h" #include "stun.h" diff --git a/src/k_terrain.c b/src/k_terrain.c index f9114f75c..36edb5261 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -24,6 +24,7 @@ #include "p_local.h" #include "p_mobj.h" #include "r_textures.h" +#include "s_sound.h" #include "w_wad.h" #include "z_zone.h" @@ -740,7 +741,7 @@ static void K_SpawnSplashParticles(mobj_t *mo, t_splash_t *s, fixed_t impact) { mobj_t *dust = NULL; angle_t pushAngle = (particleSpread * i); - + fixed_t xOff = 0; fixed_t yOff = 0; diff --git a/src/menus/play-online-join-ip.c b/src/menus/play-online-join-ip.c index 33d775f60..526665a9b 100644 --- a/src/menus/play-online-join-ip.c +++ b/src/menus/play-online-join-ip.c @@ -7,6 +7,7 @@ #include "../i_video.h" // I_UpdateNoBlit #include "../m_misc.h" // NUMLOGIP #include "../f_finale.h" // g_wipeskiprender +#include "../s_sound.h" menuitem_t PLAY_MP_JoinIP[] = { diff --git a/src/r_skins.c b/src/r_skins.c index 30c4fa487..938f963f5 100644 --- a/src/r_skins.c +++ b/src/r_skins.c @@ -30,6 +30,7 @@ #include "m_cond.h" #include "k_kart.h" #include "m_random.h" +#include "s_sound.h" #if 0 #include "k_kart.h" // K_KartResetPlayerColor #endif @@ -520,7 +521,7 @@ void SetRandomFakePlayerSkin(player_t* player, boolean fast) { S_StartSound(player->mo, sfx_kc33); S_StartSound(player->mo, sfx_cdfm44); - + mobj_t *parent = player->mo; fixed_t baseangle = P_RandomRange(PR_DECORATION, 0, 359); INT32 j; @@ -551,7 +552,7 @@ void SetRandomFakePlayerSkin(player_t* player, boolean fast) box->cusval = 1; else box->cusval = 0; - + if (j > 3) { P_SetMobjState(box, (j == 4) ? S_MAGICIANBOX_TOP : S_MAGICIANBOX_BOTTOM); @@ -1066,7 +1067,7 @@ next_token: Z_Free(unloadedskin); break; - + } } diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index e77b40910..aaf15644e 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -7,7 +7,7 @@ target_sources(SRB2SDL2 PRIVATE rhi_gl3_core_platform.hpp i_threads.c i_net.c - i_system.c + i_system.cpp i_main.cpp i_video.cpp dosstr.c @@ -92,6 +92,9 @@ endif() target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXER -DSOUND=SOUND_MIXER) target_compile_definitions(SRB2SDL2 PRIVATE -DDIRECTFULLSCREEN -DHAVE_SDL) +# NOMUMBLE till WRITE* macros are fixed for C++ or mumble integration is rewritten +target_compile_definitions(SRB2SDL2 PRIVATE -DNOMUMBLE) + #### Installation #### if("${CMAKE_SYSTEM_NAME}" MATCHES Darwin) install(TARGETS SRB2SDL2 diff --git a/src/sdl/i_system.c b/src/sdl/i_system.cpp similarity index 98% rename from src/sdl/i_system.c rename to src/sdl/i_system.cpp index 5bd806cae..c3208d5aa 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.cpp @@ -23,6 +23,8 @@ /// \file /// \brief SRB2 system stuff for SDL +#include + #include #ifdef _WIN32 @@ -168,6 +170,8 @@ static char returnWadPath[256]; #include "../d_net.h" #include "../g_game.h" #include "../filesrch.h" +#include "../s_sound.h" +#include "../core/thread_pool.h" #include "endtxt.h" #include "sdlmain.h" @@ -194,6 +198,8 @@ static char returnWadPath[256]; #include "../byteptr.h" #endif +static std::thread::id g_main_thread_id; + /** \brief SDL info about joysticks */ SDLJoyInfo_t JoyInfo[MAXSPLITSCREENPLAYERS]; @@ -350,7 +356,7 @@ static void I_ShowErrorMessageBox(const char *messagefordevelopers, boolean dump // which should fail gracefully if it can't put a message box up // on the target system SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Dr. Robotnik's Ring Racers "VERSIONSTRING" Error", + "Dr. Robotnik's Ring Racers " VERSIONSTRING " Error", finalmessage, NULL); // Note that SDL_ShowSimpleMessageBox does *not* require SDL to be @@ -423,6 +429,14 @@ static void I_ReportSignal(int num, int coredumped) #ifndef NEWSIGNALHANDLER FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) { + if (g_main_thread_id != std::this_thread::get_id()) + { + // Do not attempt any sort of recovery if this signal triggers off the main thread + signal(num, SIG_DFL); + raise(num); + exit(-2); + } + D_QuitNetGame(); // Fix server freezes CL_AbortDownloadResume(); G_DirtyGameData(); @@ -799,6 +813,8 @@ static inline void I_ShutdownConsole(void){} // static void I_RegisterSignals (void) { + g_main_thread_id = std::this_thread::get_id(); + #ifdef SIGINT signal(SIGINT , quit_handler); #endif @@ -910,7 +926,7 @@ void I_OutputMsg(const char *fmt, ...) return; } - ReadConsoleOutputCharacter(co, oldLines, oldLength, coordNextWrite, &bytesWritten); + ReadConsoleOutputCharacter(co, (LPSTR)oldLines, oldLength, coordNextWrite, &bytesWritten); // Move to where we what to print - which is where we would've been, // had console input not been in the way, @@ -1251,7 +1267,8 @@ const char *I_GetJoyName(INT32 joyindex) tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) { - strncpy(joyname, tempname, 255); + strncpy(joyname, tempname, 254); + joyname[254] = 0; } return joyname; @@ -1267,7 +1284,7 @@ const char *I_GetJoyName(INT32 joyindex) #define DEG2RAD (0.017453292519943295769236907684883l) // TAU/360 or PI/180 #define MUMBLEUNIT (64.0f) // FRACUNITS in a Meter -static struct { +static struct mumble_s { #ifdef WINMUMBLE UINT32 uiVersion; DWORD uiTick; @@ -1300,7 +1317,7 @@ static void I_SetupMumble(void) if (!hMap) return; - mumble = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(*mumble)); + mumble = static_cast(MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(*mumble))); if (!mumble) CloseHandle(hMap); #elif defined (HAVE_SHM) @@ -1587,6 +1604,8 @@ INT32 I_StartupSystem(void) #ifdef HAVE_THREADS I_start_threads(); I_AddExitFunc(I_stop_threads); + I_ThreadPoolInit(); + I_AddExitFunc(I_ThreadPoolShutdown); #endif I_StartupConsole(); #ifdef NEWSIGNALHANDLER @@ -1693,6 +1712,12 @@ void I_Error(const char *error, ...) va_list argptr; char buffer[8192]; + if (std::this_thread::get_id() != g_main_thread_id) + { + // Do not attempt a graceful shutdown. Errors off the main thread are unresolvable. + exit(-2); + } + // recursive error detecting if (shutdowning) { @@ -1728,7 +1753,7 @@ void I_Error(const char *error, ...) // on the target system if (!M_CheckParm("-dedicated")) SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, - "Dr. Robotnik's Ring Racers "VERSIONSTRING" Recursive Error", + "Dr. Robotnik's Ring Racers " VERSIONSTRING " Recursive Error", buffer, NULL); W_Shutdown(); @@ -2074,7 +2099,7 @@ const char *I_ClipboardPaste(void) */ static boolean isWadPathOk(const char *path) { - char *wad3path = malloc(256); + char *wad3path = static_cast(malloc(256)); if (!wad3path) return false;