From 0cc4b8d6db42e403b2692eb5e8f97ff0686c2320 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Tue, 6 Feb 2018 14:50:08 -0500 Subject: [PATCH 001/194] Smoother MD2 interpolation --- src/hardware/hw_md2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f59c1d4f..d1315979 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -1347,7 +1347,7 @@ void HWR_DrawMD2(gr_vissprite_t *spr) frame = (spr->mobj->frame & FF_FRAMEMASK) % md2->model->header.numFrames; buff = md2->model->glCommandBuffer; curr = &md2->model->frames[frame]; - if (cv_grmd2.value == 1) + if (cv_grmd2.value == 1 && tics <= durs) { // frames are handled differently for states with FF_ANIMATE, so get the next frame differently for the interpolation if (spr->mobj->frame & FF_ANIMATE) From 490f5beb89b90f77a98d49c39de700200859b170 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Tue, 13 Feb 2018 17:53:18 +0100 Subject: [PATCH 002/194] Do not prevent all net commands for the current tic from being executed because of an unkown net command ID --- src/d_clisrv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d48f223c..87b154f8 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -401,8 +401,7 @@ static void ExtraDataTicker(void) DEBFILE(va("player %d kicked [gametic=%u] reason as follows:\n", i, gametic)); } CONS_Alert(CONS_WARNING, M_GetText("Got unknown net command [%s]=%d (max %d)\n"), sizeu1(curpos - bufferstart), *curpos, bufferstart[0]); - D_FreeTextcmd(gametic); - return; + break; } } } From bd2334dd93985799cb6f77909f2a145ab1474ab5 Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Wed, 14 Feb 2018 21:00:55 +0100 Subject: [PATCH 003/194] Fix SV_StopServer not calling D_Clearticcmd correctly --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 87b154f8..e42bceef 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3292,7 +3292,7 @@ void SV_StopServer(void) localtextcmd[0] = 0; localtextcmd2[0] = 0; - for (i = 0; i < BACKUPTICS; i++) + for (i = firstticstosend; i < firstticstosend + BACKUPTICS; i++) D_Clearticcmd(i); consoleplayer = 0; From 2139d4771f1fd6a0a870e73d76df9d44ef64b397 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Wed, 11 Apr 2018 14:40:05 -0400 Subject: [PATCH 004/194] Default sound volume is too loud --- src/android/i_cdmus.c | 2 +- src/djgppdos/i_cdmus.c | 2 +- src/s_sound.c | 2 +- src/sdl12/i_cdmus.c | 2 +- src/win32/win_cd.c | 2 +- src/win32ce/win_cd.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/android/i_cdmus.c b/src/android/i_cdmus.c index c5aac8f1..426bc5dc 100644 --- a/src/android/i_cdmus.c +++ b/src/android/i_cdmus.c @@ -8,7 +8,7 @@ UINT8 cdaudio_started = 0; -consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cd_volume = {"cd_volume","18",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/djgppdos/i_cdmus.c b/src/djgppdos/i_cdmus.c index f707add5..2a629ca1 100644 --- a/src/djgppdos/i_cdmus.c +++ b/src/djgppdos/i_cdmus.c @@ -50,7 +50,7 @@ static boolean wasPlaying; static int cdVolume=0; // current cd volume (0-31) // 0-31 like Music & Sfx, though CD hardware volume is 0-255. -consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cd_volume = {"cd_volume","18",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // allow Update for next/loop track // some crap cd drivers take up to diff --git a/src/s_sound.c b/src/s_sound.c index 47a95556..76ee4c64 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -78,7 +78,7 @@ consvar_t stereoreverse = {"stereoreverse", "Off", CV_SAVE, CV_OnOff, NULL, 0, N static consvar_t precachesound = {"precachesound", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // actual general (maximum) sound & music volume, saved into the config -consvar_t cv_soundvolume = {"soundvolume", "31", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_soundvolume = {"soundvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_digmusicvolume = {"digmusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_midimusicvolume = {"midimusicvolume", "18", CV_SAVE, soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // number of channels available diff --git a/src/sdl12/i_cdmus.c b/src/sdl12/i_cdmus.c index 1eeac370..b3490592 100644 --- a/src/sdl12/i_cdmus.c +++ b/src/sdl12/i_cdmus.c @@ -60,7 +60,7 @@ void SDL_SYS_CDQuit(void) UINT8 cdaudio_started = 0; // for system startup/shutdown -consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cd_volume = {"cd_volume","18",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; #ifndef NOSDLCD diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index 4ac1506e..f6c43074 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -161,7 +161,7 @@ static BOOL wasPlaying; //static INT cdVolume = 0; // current cd volume (0-31) // 0-31 like Music & Sfx, though CD hardware volume is 0-255. -consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cd_volume = {"cd_volume","18",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // allow Update for next/loop track // some crap cd drivers take up to diff --git a/src/win32ce/win_cd.c b/src/win32ce/win_cd.c index 2b1a8be9..940f59ff 100644 --- a/src/win32ce/win_cd.c +++ b/src/win32ce/win_cd.c @@ -159,7 +159,7 @@ static boolean wasPlaying; //static int cdVolume = 0; // current cd volume (0-31) // 0-31 like Music & Sfx, though CD hardware volume is 0-255. -consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cd_volume = {"cd_volume","18",CV_SAVE,soundvolume_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // allow Update for next/loop track // some crap cd drivers take up to From e66e0bb20e7b2f211c5ed5956b2539abcca1f99a Mon Sep 17 00:00:00 2001 From: GoldenTails <39245725+GoldenTails@users.noreply.github.com> Date: Sun, 13 May 2018 14:19:36 -0500 Subject: [PATCH 005/194] Fixed MD2 models not loading correctly on Linux --- src/hardware/hw_md2.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f59c1d4f..5d156e1d 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -288,7 +288,8 @@ static md2_model_t *md2_readModel(const char *filename) if (model == NULL) return 0; - file = fopen(filename, "rb"); + //Filename checking fixed ~Monster Iestyn and Golden + file = fopen(va("%s"PATHSEP"%s", srb2home, filename), "rb"); if (!file) { free(model); @@ -477,7 +478,8 @@ static GrTextureFormat_t PNG_Load(const char *filename, int *w, int *h, GLPatch_ #endif #endif png_FILE_p png_FILE; - char *pngfilename = va("md2/%s", filename); + //Filename checking fixed ~Monster Iestyn and Golden + char *pngfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2home, filename); FIL_ForceExtension(pngfilename, ".png"); png_FILE = fopen(pngfilename, "rb"); @@ -605,7 +607,8 @@ static GrTextureFormat_t PCX_Load(const char *filename, int *w, int *h, size_t pw, ph, size, ptr = 0; INT32 ch, rep; FILE *file; - char *pcxfilename = va("md2/%s", filename); + //Filename checking fixed ~Monster Iestyn and Golden + char *pcxfilename = va("%s"PATHSEP"md2"PATHSEP"%s", srb2home, filename); FIL_ForceExtension(pcxfilename, ".pcx"); file = fopen(pcxfilename, "rb"); @@ -795,7 +798,8 @@ void HWR_InitMD2(void) } // read the md2.dat file - f = fopen("md2.dat", "rt"); + //Filename checking fixed ~Monster Iestyn and Golden + f = fopen(va("%s"PATHSEP"%s", srb2home, "md2.dat"), "rt"); if (!f) { @@ -861,7 +865,8 @@ void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup CONS_Printf("AddPlayerMD2()...\n"); // read the md2.dat file - f = fopen("md2.dat", "rt"); + //Filename checking fixed ~Monster Iestyn and Golden + f = fopen(va("%s"PATHSEP"%s", srb2home, "md2.dat"), "rt"); if (!f) { @@ -906,7 +911,8 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu return; // Read the md2.dat file - f = fopen("md2.dat", "rt"); + //Filename checking fixed ~Monster Iestyn and Golden + f = fopen(va("%s"PATHSEP"%s", srb2home, "md2.dat"), "rt"); if (!f) { From 5f0a45124c8209fb10800ec76261e40a92572006 Mon Sep 17 00:00:00 2001 From: GoldenTails <39245725+GoldenTails@users.noreply.github.com> Date: Sun, 13 May 2018 14:32:33 -0500 Subject: [PATCH 006/194] Update hw_md2.c --- src/hardware/hw_md2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 5d156e1d..3dc43470 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -26,6 +26,7 @@ #include #include +#include "../d_main.h" #include "../doomdef.h" #include "../doomstat.h" From 7783ddd13443854955a977d70a7fe087edad6d64 Mon Sep 17 00:00:00 2001 From: GoldenTails <39245725+GoldenTails@users.noreply.github.com> Date: Sun, 13 May 2018 14:34:08 -0500 Subject: [PATCH 007/194] Update hw_md2.c --- src/hardware/hw_md2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 3dc43470..be547e5a 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -26,7 +26,6 @@ #include #include -#include "../d_main.h" #include "../doomdef.h" #include "../doomstat.h" @@ -34,6 +33,7 @@ #include "hw_drv.h" #include "hw_light.h" #include "hw_md2.h" +#include "../d_main.h" #include "../r_bsp.h" #include "../r_main.h" #include "../m_misc.h" From 7f084868b9a84baf9929e153513c9d5e224c9a4e Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 13 May 2018 15:35:38 -0400 Subject: [PATCH 008/194] More helpful error message --- src/hardware/hw_md2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index f59c1d4f..99018e1e 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -799,7 +799,7 @@ void HWR_InitMD2(void) if (!f) { - CONS_Printf("%s", M_GetText("Error while loading md2.dat\n")); + CONS_Printf("%s %s\n", M_GetText("Error while loading md2.dat:"), strerror(errno)); nomd2s = true; return; } From b4d479ad9a121bcb4095e7610baaed63c27f6ebe Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 13 May 2018 16:04:34 -0400 Subject: [PATCH 009/194] Include errno if not already included. --- src/hardware/hw_md2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 99018e1e..d6052445 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -67,6 +67,10 @@ #endif #endif +#ifndef errno +#include "errno.h" +#endif + #define NUMVERTEXNORMALS 162 float avertexnormals[NUMVERTEXNORMALS][3] = { {-0.525731f, 0.000000f, 0.850651f}, From 0b6d6c3363d4b1aeece18a415caec54e7b0aca86 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 24 May 2018 16:24:09 -0400 Subject: [PATCH 010/194] GME low volume fix --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 71832459..8938cb74 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -458,7 +458,7 @@ static void mix_gme(void *udata, Uint8 *stream, int len) // apply volume to stream for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * music_volume / 31; + *p = ((INT32)*p) * music_volume*2/31; } #endif From 0248fcecd40c67fa6adffe0b6d0ff2a93ea46ceb Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Tue, 29 May 2018 20:31:28 -0400 Subject: [PATCH 011/194] Some small change Really this is just to prevent the music end up being disorted at max volume --- src/sdl/mixer_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 8938cb74..fd8e64de 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -458,7 +458,8 @@ static void mix_gme(void *udata, Uint8 *stream, int len) // apply volume to stream for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * music_volume*2/31; + *p = ((INT32)*p) * music_volume*2 / 42; + CONS_Printf("%hs", p); } #endif From e394f7992deb81a195709126bec7e9cc68d14114 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Tue, 29 May 2018 22:12:36 -0400 Subject: [PATCH 012/194] Removed CONS_Printf line. That wasn't meant to be commited. --- src/sdl/mixer_sound.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index fd8e64de..49742272 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -459,7 +459,6 @@ static void mix_gme(void *udata, Uint8 *stream, int len) // apply volume to stream for (i = 0, p = (short *)stream; i < len/2; i++, p++) *p = ((INT32)*p) * music_volume*2 / 42; - CONS_Printf("%hs", p); } #endif From 77362c45cc0d6b1371f7145daaef6a1c6dd66a82 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 3 Jun 2018 18:15:20 -0400 Subject: [PATCH 013/194] Fix pausing on gme --- src/sdl/mixer_sound.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 71832459..18670649 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -475,12 +475,24 @@ void I_ShutdownMusic(void) void I_PauseSong(INT32 handle) { (void)handle; +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(NULL, NULL); + } +#endif Mix_PauseMusic(); } void I_ResumeSong(INT32 handle) { (void)handle; +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(mix_gme, gme); + } +#endif Mix_ResumeMusic(); } From 91081a3e534ad6885bac1fae3013444f9fb2c67e Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Mon, 4 Jun 2018 22:14:01 +0200 Subject: [PATCH 014/194] Disable admin password by default --- src/d_main.c | 9 --------- src/d_netcmd.c | 9 +++++++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index fbec5f7d..df339875 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1051,15 +1051,6 @@ void D_SRB2Main(void) if (M_CheckParm("-password") && M_IsNextParm()) D_SetPassword(M_GetNextParm()); - else - { - size_t z; - char junkpw[25]; - for (z = 0; z < 24; z++) - junkpw[z] = (char)(rand() & 64)+32; - junkpw[24] = '\0'; - D_SetPassword(junkpw); - } // add any files specified on the command line with -file wadfile // to the wad list diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 673d64fd..876a3852 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2656,10 +2656,12 @@ static void D_MD5PasswordPass(const UINT8 *buffer, size_t len, const char *salt, #define BASESALT "basepasswordstorage" static UINT8 adminpassmd5[16]; +static boolean adminpasswordset = false; void D_SetPassword(const char *pw) { D_MD5PasswordPass((const UINT8 *)pw, strlen(pw), BASESALT, &adminpassmd5); + adminpasswordset = true; } // Remote Administration @@ -2728,6 +2730,9 @@ static void Got_Login(UINT8 **cp, INT32 playernum) READMEM(*cp, sentmd5, 16); + if (!adminpasswordset) + CONS_Printf(M_GetText("Password from %s failed (no password set).\n"), player_names[playernum]); + if (client) return; @@ -3951,7 +3956,7 @@ static void Command_RestartAudio_f(void) I_ShutdownSound(); I_StartupSound(); I_InitMusic(); - + // These must be called or no sound and music until manually set. I_SetSfxVolume(cv_soundvolume.value); @@ -3959,7 +3964,7 @@ static void Command_RestartAudio_f(void) I_SetMIDIMusicVolume(cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); - + } /** Quits a game and returns to the title screen. From c389c0b3dc5fb285f5492474f1c93b62c6336b7a Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Mon, 4 Jun 2018 22:30:27 +0200 Subject: [PATCH 015/194] xd --- src/d_netcmd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 876a3852..727d5eff 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2731,7 +2731,10 @@ static void Got_Login(UINT8 **cp, INT32 playernum) READMEM(*cp, sentmd5, 16); if (!adminpasswordset) + { CONS_Printf(M_GetText("Password from %s failed (no password set).\n"), player_names[playernum]); + return; + } if (client) return; From aed30519d4413e14c26f114e67f29e73d4c35ec5 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 23 Jun 2018 18:47:32 +0100 Subject: [PATCH 016/194] Fix HWR_ProjectSprite to check properly whether the displayed player's mobj or its subsector exists, to avoid a crash when checking for fake planes. (also use viewplayer since its available to use, silly hardware code) Also tweaked a weird splitscreen check in HWR_DrawSpriteShadow; still investigating whether stplyr is ever not player 2 when it's player 2's view, but this looks better for now --- src/hardware/hw_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a5fe6b67..5d9c2993 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3941,7 +3941,7 @@ static void HWR_DrawSpriteShadow(gr_vissprite_t *spr, GLPatch_t *gpatch, float t angle_t shadowdir; // Set direction - if (splitscreen && stplyr != &players[displayplayer]) + if (splitscreen && stplyr == &players[secondarydisplayplayer]) shadowdir = localangle2 + FixedAngle(cv_cam2_rotate.value); else shadowdir = localangle + FixedAngle(cv_cam_rotate.value); @@ -5302,7 +5302,10 @@ static void HWR_ProjectSprite(mobj_t *thing) } heightsec = thing->subsector->sector->heightsec; - phs = players[displayplayer].mo->subsector->sector->heightsec; + if (viewplayer->mo && viewplayer->mo->subsector) + phs = viewplayer->mo->subsector->sector->heightsec; + else + phs = -1; if (heightsec != -1 && phs != -1) // only clip things which are in special sectors { From d8a86a8d744f13f6206b1aefa25ce1bb2047323a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 26 Jun 2018 21:41:05 +0100 Subject: [PATCH 017/194] Fix OpenGL completely missing the ability to alter FOF wall pegging by lower unpegged flag. Stupid OpenGL. Sorry in advance Lat'! --- src/hardware/hw_main.c | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a5fe6b67..1caf84fe 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2182,27 +2182,34 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) } else if (drawtextured) { -#ifdef ESLOPE // P.S. this is better-organized than the old version - fixed_t offs = sides[(newline ? newline : rover->master)->sidenum[0]].rowoffset; - grTex = HWR_GetTexture(texnum); - - wallVerts[3].t = (*rover->topheight - h + offs) * grTex->scaleY; - wallVerts[2].t = (*rover->topheight - hS + offs) * grTex->scaleY; - wallVerts[0].t = (*rover->topheight - l + offs) * grTex->scaleY; - wallVerts[1].t = (*rover->topheight - lS + offs) * grTex->scaleY; -#else - grTex = HWR_GetTexture(texnum); + fixed_t texturevpeg; + // Wow, how was this missing from OpenGL for so long? + // ...Oh well, anyway, Lower Unpegged now changes pegging of FOFs like in software + // -- Monster Iestyn 26/06/18 if (newline) { - wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + sides[newline->sidenum[0]].rowoffset) * grTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (h - l + (*rover->topheight - h + sides[newline->sidenum[0]].rowoffset)) * grTex->scaleY; + texturevpeg = sides[newline->sidenum[0]].rowoffset; + if (newline->flags & ML_DONTPEGBOTTOM) + texturevpeg -= *rover->topheight - *rover->bottomheight; } else { - wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset) * grTex->scaleY; - wallVerts[0].t = wallVerts[1].t = (h - l + (*rover->topheight - h + sides[rover->master->sidenum[0]].rowoffset)) * grTex->scaleY; + texturevpeg = sides[rover->master->sidenum[0]].rowoffset; + if (gr_linedef->flags & ML_DONTPEGBOTTOM) + texturevpeg -= *rover->topheight - *rover->bottomheight; } + + grTex = HWR_GetTexture(texnum); + +#ifdef ESLOPE + wallVerts[3].t = (*rover->topheight - h + texturevpeg) * grTex->scaleY; + wallVerts[2].t = (*rover->topheight - hS + texturevpeg) * grTex->scaleY; + wallVerts[0].t = (*rover->topheight - l + texturevpeg) * grTex->scaleY; + wallVerts[1].t = (*rover->topheight - lS + texturevpeg) * grTex->scaleY; +#else + wallVerts[3].t = wallVerts[2].t = (*rover->topheight - h + texturevpeg) * grTex->scaleY; + wallVerts[0].t = wallVerts[1].t = (*rover->topheight - l + texturevpeg) * grTex->scaleY; #endif wallVerts[0].s = wallVerts[3].s = cliplow * grTex->scaleX; From 82d953bbc219d02edd0cba6bde6ac44a591c96bf Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 4 Jul 2018 20:15:36 +0100 Subject: [PATCH 018/194] Fixed the Lua crash exploit. --- src/lua_consolelib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 566e7374..3239b7c5 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -77,7 +77,9 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum) deny: //must be hacked/buggy client - lua_settop(gL, 0); // clear stack + if (gL) // check if Lua is actually turned on first, you dummmy -- Monster Iestyn 04/07/18 + lua_settop(gL, 0); // clear stack + CONS_Alert(CONS_WARNING, M_GetText("Illegal lua command received from %s\n"), player_names[playernum]); if (server) { From 7da6aca4505e0f5227cb3e802b11d200bef4aec0 Mon Sep 17 00:00:00 2001 From: Alam Arias Date: Sat, 7 Jul 2018 20:33:19 +0000 Subject: [PATCH 019/194] Update m_misc.c --- src/m_misc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/m_misc.c b/src/m_misc.c index 041899a3..69542dc9 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -56,7 +56,9 @@ typedef off_t off64_t; #endif #endif -#if defined (_WIN32) +#if defined(__MINGW32__) &&(__GNUC__ > 7) || (__GNUC__ == 6 && __GNUC_MINOR__ >= 3) +#define PRIdS "u" +#elif defined (_WIN32) #define PRIdS "Iu" #elif defined (_PSP) || defined (_arch_dreamcast) || defined (DJGPP) || defined (_WII) || defined (_NDS) || defined (_PS3) #define PRIdS "u" From a79b9a912709c0bf23e9ae99302cc6cbc23c7ce5 Mon Sep 17 00:00:00 2001 From: Alam Arias Date: Sat, 7 Jul 2018 20:41:11 +0000 Subject: [PATCH 020/194] Update m_misc.c --- src/m_misc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_misc.c b/src/m_misc.c index 69542dc9..5c4e7f2f 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -56,7 +56,7 @@ typedef off_t off64_t; #endif #endif -#if defined(__MINGW32__) &&(__GNUC__ > 7) || (__GNUC__ == 6 && __GNUC_MINOR__ >= 3) +#if defined(__MINGW32__) && ((__GNUC__ > 7) || (__GNUC__ == 6 && __GNUC_MINOR__ >= 3)) #define PRIdS "u" #elif defined (_WIN32) #define PRIdS "Iu" From 0a931a1364a0f151eba1ff8f644dfda4558ae700 Mon Sep 17 00:00:00 2001 From: colette Date: Sat, 7 Jul 2018 20:20:46 -0400 Subject: [PATCH 021/194] Update f_finale.c --- src/f_finale.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/f_finale.c b/src/f_finale.c index 958bef0f..a8b27bb8 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -977,7 +977,6 @@ static const char *credits[] = { "\1Programming", "Alam \"GBC\" Arias", "Logan \"GBA\" Arias", - "Colette \"fickle\" Bordelon", "Callum Dickinson", "Scott \"Graue\" Feeney", "Nathan \"Jazz\" Giroux", From 6b1fa399dc6b85c962ab7d260406d9fe03d608c9 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 14 Jul 2018 18:15:59 +0100 Subject: [PATCH 022/194] Use plain malloc instead of Z_Malloc to allocate sound buffers in mixer_sound.c's I_GetSfx. This should prevent I_FreeSfx making a mess of things later, hopefully. --- src/sdl/mixer_sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 71832459..0447b521 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -176,7 +176,7 @@ static Mix_Chunk *ds2chunk(void *stream) return NULL; // would and/or did wrap, can't store. break; } - sound = Z_Malloc(newsamples<<2, PU_SOUND, NULL); // samples * frequency shift * bytes per sample * channels + sound = malloc(newsamples<<2); // samples * frequency shift * bytes per sample * channels s = (SINT8 *)stream; d = (INT16 *)sound; @@ -304,7 +304,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, NULL); + mem = malloc(len); gme_play(emu, len >> 1, mem); gme_delete(emu); @@ -376,7 +376,7 @@ void *I_GetSfx(sfxinfo_t *sfx) gme_track_info(emu, &info, 0); len = (info->play_length * 441 / 10) << 2; - mem = Z_Malloc(len, PU_SOUND, NULL); + mem = malloc(len); gme_play(emu, len >> 1, mem); gme_delete(emu); From 1ee7eda0ad1971b5a826138368356d25468574f8 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Fri, 20 Jul 2018 17:35:18 -0400 Subject: [PATCH 023/194] Fixup PROFILEMODE --- src/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 57bd0644..dd250b0b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,3 +1,4 @@ + # GNU Make makefile for SRB2 ############################################################################# # Copyright (C) 1998-2000 by DooM Legacy Team. @@ -421,7 +422,8 @@ endif ifdef PROFILEMODE # build with profiling information - CFLAGS:=-pg $(CFLAGS) + CFLAGS+=-pg + LDFLAGS+=-pg endif ifdef ZDEBUG From c02ee9a50283088eb490b401999937ad99ff84be Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sat, 28 Jul 2018 01:58:25 -0400 Subject: [PATCH 024/194] Re-did this fix. --- src/sdl/mixer_sound.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 18670649..7ab1523c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -66,6 +66,7 @@ static boolean midimode; static Mix_Music *music; static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; +static boolean songpaused; #ifdef HAVE_LIBGME static Music_Emu *gme; @@ -102,6 +103,7 @@ void I_StartupSound(void) } sound_started = true; + songpaused = false; Mix_AllocateChannels(256); } @@ -450,7 +452,7 @@ static void mix_gme(void *udata, Uint8 *stream, int len) (void)udata; // no gme? no music. - if (!gme || gme_track_ended(gme)) + if (!gme || gme_track_ended(gme) || songpaused) return; // play gme into stream @@ -475,25 +477,15 @@ void I_ShutdownMusic(void) void I_PauseSong(INT32 handle) { (void)handle; -#ifdef HAVE_LIBGME - if (gme) - { - Mix_HookMusic(NULL, NULL); - } -#endif Mix_PauseMusic(); + songpaused = true; } void I_ResumeSong(INT32 handle) { (void)handle; -#ifdef HAVE_LIBGME - if (gme) - { - Mix_HookMusic(mix_gme, gme); - } -#endif Mix_ResumeMusic(); + songpaused = false; } // From 8d622ff6f8d428fd848c473566240402b748a487 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 5 Aug 2018 20:17:30 +0100 Subject: [PATCH 025/194] Quick fix for LJ's password fix: don't check if password is set until we've confirmed that the receiving player is the server! --- src/d_netcmd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 727d5eff..bf26ca61 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2730,15 +2730,15 @@ static void Got_Login(UINT8 **cp, INT32 playernum) READMEM(*cp, sentmd5, 16); + if (client) + return; + if (!adminpasswordset) { CONS_Printf(M_GetText("Password from %s failed (no password set).\n"), player_names[playernum]); return; } - if (client) - return; - // Do the final pass to compare with the sent md5 D_MD5PasswordPass(adminpassmd5, 16, va("PNUM%02d", playernum), &finalmd5); From ecc9ebe8c1f88da4b67a546fc2f4eab8089d6573 Mon Sep 17 00:00:00 2001 From: toaster Date: Tue, 7 Aug 2018 19:12:10 +0100 Subject: [PATCH 026/194] Change the order of operations when applying transparency and colormap such that colormap isn't applied to the screen pixel twice (or, in the case of R_DrawTranslatedTranslucentColumn_8, thrice). Please note I haven't touched the ASM equivalent, given as it's not actually used. --- src/r_draw8.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index 39585f58..9240cc3f 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -297,7 +297,7 @@ void R_DrawTranslucentColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = colormap[*(transmap + (source[frac>>FRACBITS]<<8) + (*dest))]; + *dest = *(transmap + (colormap[source[frac>>FRACBITS]]<<8) + (*dest)); dest += vid.width; if ((frac += fracstep) >= heightmask) frac -= heightmask; @@ -308,15 +308,15 @@ void R_DrawTranslucentColumn_8(void) { while ((count -= 2) >= 0) // texture height is a power of 2 { - *dest = colormap[*(transmap + ((source[(frac>>FRACBITS)&heightmask]<<8)) + (*dest))]; + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); dest += vid.width; frac += fracstep; - *dest = colormap[*(transmap + ((source[(frac>>FRACBITS)&heightmask]<<8)) + (*dest))]; + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); dest += vid.width; frac += fracstep; } if (count & 1) - *dest = colormap[*(transmap + ((source[(frac>>FRACBITS)&heightmask]<<8)) + (*dest))]; + *dest = *(transmap + (colormap[source[(frac>>FRACBITS)&heightmask]]<<8) + (*dest)); } } } @@ -367,8 +367,7 @@ void R_DrawTranslatedTranslucentColumn_8(void) // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = dc_colormap[*(dc_transmap - + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest))]; + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest)); dest += vid.width; if ((frac += fracstep) >= heightmask) @@ -380,17 +379,15 @@ void R_DrawTranslatedTranslucentColumn_8(void) { while ((count -= 2) >= 0) // texture height is a power of 2 { - *dest = dc_colormap[*(dc_transmap - + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest))]; + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); dest += vid.width; frac += fracstep; - *dest = dc_colormap[*(dc_transmap - + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest))]; + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); dest += vid.width; frac += fracstep; } if (count & 1) - *dest = dc_colormap[*(dc_transmap + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]] <<8) + (*dest))]; + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[(frac>>FRACBITS)&heightmask]]]<<8) + (*dest)); } } } @@ -1220,35 +1217,35 @@ void R_DrawTranslucentSpan_8 (void) // SoM: Why didn't I see this earlier? the spot variable is a waste now because we don't // have the uber complicated math to calculate it now, so that was a memory write we didn't // need! - dest[0] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[0])]; + dest[0] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[0]); xposition += xstep; yposition += ystep; - dest[1] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[1])]; + dest[1] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[1]); xposition += xstep; yposition += ystep; - dest[2] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[2])]; + dest[2] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[2]); xposition += xstep; yposition += ystep; - dest[3] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[3])]; + dest[3] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[3]); xposition += xstep; yposition += ystep; - dest[4] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[4])]; + dest[4] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[4]); xposition += xstep; yposition += ystep; - dest[5] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[5])]; + dest[5] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[5]); xposition += xstep; yposition += ystep; - dest[6] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[6])]; + dest[6] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[6]); xposition += xstep; yposition += ystep; - dest[7] = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + dest[7])]; + dest[7] = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + dest[7]); xposition += xstep; yposition += ystep; @@ -1257,7 +1254,7 @@ void R_DrawTranslucentSpan_8 (void) } while (count--) { - *dest = colormap[*(ds_transmap + (source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)] << 8) + *dest)]; + *dest = *(ds_transmap + (colormap[source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]] << 8) + *dest); dest++; xposition += xstep; yposition += ystep; From 5daeaf529fc26fac71e36fb821bbd9eea3c99bd7 Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 9 Aug 2018 16:56:43 +0100 Subject: [PATCH 027/194] Apply the double-colormap ordering fix to R_DrawTiltedTranslucentSpan_8 as well. --- src/r_draw8.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index 9240cc3f..d4aaf5cf 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -735,8 +735,7 @@ void R_DrawTiltedTranslucentSpan_8(void) v = (INT64)(vz*z) + viewy; colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - - *dest = colormap[*(ds_transmap + (source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)] << 8) + dest[0])]; + *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); dest++; iz += ds_sz.x; uz += ds_su.x; @@ -773,7 +772,7 @@ void R_DrawTiltedTranslucentSpan_8(void) for (i = SPANSIZE-1; i >= 0; i--) { colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[*(ds_transmap + (source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)] << 8) + dest[0])]; + *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); dest++; u += stepu; v += stepv; @@ -789,7 +788,7 @@ void R_DrawTiltedTranslucentSpan_8(void) u = (INT64)(startu); v = (INT64)(startv); colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[*(ds_transmap + (source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)] << 8) + dest[0])]; + *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); } else { @@ -810,7 +809,7 @@ void R_DrawTiltedTranslucentSpan_8(void) for (; width != 0; width--) { colormap = planezlight[tiltlighting[ds_x1++]] + (ds_colormap - colormaps); - *dest = colormap[*(ds_transmap + (source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)] << 8) + dest[0])]; + *dest = *(ds_transmap + (colormap[source[((v >> nflatyshift) & nflatmask) | (u >> nflatxshift)]] << 8) + *dest); dest++; u += stepu; v += stepv; From 145c050e14e55f1053d8a33b92e1b7792398944d Mon Sep 17 00:00:00 2001 From: toaster Date: Thu, 9 Aug 2018 17:08:20 +0100 Subject: [PATCH 028/194] ...and R_DrawTranslucentSplat_8, even though it isn't used! --- src/r_draw8.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index d4aaf5cf..800f28b6 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -1120,49 +1120,49 @@ void R_DrawTranslucentSplat_8 (void) // need! val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[0] = colormap[*(ds_transmap + (val << 8) + dest[0])]; + dest[0] = *(ds_transmap + (colormap[val] << 8) + dest[0]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[1] = colormap[*(ds_transmap + (val << 8) + dest[1])]; + dest[1] = *(ds_transmap + (colormap[val] << 8) + dest[1]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[2] = colormap[*(ds_transmap + (val << 8) + dest[2])]; + dest[2] = *(ds_transmap + (colormap[val] << 8) + dest[2]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[3] = colormap[*(ds_transmap + (val << 8) + dest[3])]; + dest[3] = *(ds_transmap + (colormap[val] << 8) + dest[3]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[4] = colormap[*(ds_transmap + (val << 8) + dest[4])]; + dest[4] = *(ds_transmap + (colormap[val] << 8) + dest[4]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[5] = colormap[*(ds_transmap + (val << 8) + dest[5])]; + dest[5] = *(ds_transmap + (colormap[val] << 8) + dest[5]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[6] = colormap[*(ds_transmap + (val << 8) + dest[6])]; + dest[6] = *(ds_transmap + (colormap[val] << 8) + dest[6]); xposition += xstep; yposition += ystep; val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - dest[7] = colormap[*(ds_transmap + (val << 8) + dest[7])]; + dest[7] = *(ds_transmap + (colormap[val] << 8) + dest[7]); xposition += xstep; yposition += ystep; @@ -1173,7 +1173,7 @@ void R_DrawTranslucentSplat_8 (void) { val = source[((yposition >> nflatyshift) & nflatmask) | (xposition >> nflatxshift)]; if (val != TRANSPARENTPIXEL) - *dest = colormap[*(ds_transmap + (val << 8) + *dest)]; + *dest = *(ds_transmap + (colormap[val] << 8) + *dest); dest++; xposition += xstep; From 3479310546def653edd77a7270e0efdd8dfd7a67 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Fri, 10 Aug 2018 17:08:39 -0400 Subject: [PATCH 029/194] SDL: update IMG_xpm.c --- src/sdl/IMG_xpm.c | 1412 +++++++++++++++++++++++++++++++----------- src/sdl/SDL_icon.xpm | 2 +- src/sdl/i_video.c | 4 + 3 files changed, 1057 insertions(+), 361 deletions(-) diff --git a/src/sdl/IMG_xpm.c b/src/sdl/IMG_xpm.c index e08736d6..8adfd343 100644 --- a/src/sdl/IMG_xpm.c +++ b/src/sdl/IMG_xpm.c @@ -1,27 +1,24 @@ /* - SDL_image: An example image loading library for use with SDL - Copyright (C) 1999-2004 Sam Lantinga + SDL_image: An example image loading library for use with SDL + Copyright (C) 1997-2018 Sam Lantinga - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Sam Lantinga - slouken@libsdl.org + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. */ -/* $Id: IMG_xpm.c,v 1.10 2004/01/04 22:04:38 slouken Exp $ */ - /* * XPM (X PixMap) image loader: * @@ -45,98 +42,110 @@ * requires about 13K in binary form. */ -#include -#include -#include -#include - -//#include "SDL_image.h" - +#if 0 +#include "SDL_image.h" +#else +extern SDLCALL int SDLCALL IMG_isXPM(SDL_RWops *src); +extern SDLCALL SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src); +extern SDLCALL SDL_Surface * SDLCALL IMG_ReadXPMFromArray(const char **xpm); +#define IMG_SetError SDL_SetError +#define IMG_GetError SDL_GetError +#endif #ifdef LOAD_XPM /* See if an image is contained in a data source */ -#if 0 int IMG_isXPM(SDL_RWops *src) { - char magic[9]; + Sint64 start; + int is_XPM; + char magic[9]; - return (SDL_RWread(src, magic, sizeof (magic), 1) - && memcmp(magic, "/* XPM */", 9) == 0); + if ( !src ) + return 0; + start = SDL_RWtell(src); + is_XPM = 0; + if ( SDL_RWread(src, magic, sizeof(magic), 1) ) { + if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) { + is_XPM = 1; + } + } + SDL_RWseek(src, start, RW_SEEK_SET); + return(is_XPM); } -#endif /* Hash table to look up colors from pixel strings */ #define STARTING_HASH_SIZE 256 struct hash_entry { - char *key; - Uint32 color; - struct hash_entry *next; + const char *key; + Uint32 color; + struct hash_entry *next; }; struct color_hash { - struct hash_entry **table; - struct hash_entry *entries; /* array of all entries */ - struct hash_entry *next_free; - size_t size; - int maxnum; + struct hash_entry **table; + struct hash_entry *entries; /* array of all entries */ + struct hash_entry *next_free; + int size; + int maxnum; }; -static int hash_key(const char *key, int cpp, size_t size) +static int hash_key(const char *key, int cpp, int size) { - int hash; + int hash; - hash = 0; - while ( cpp-- > 0 ) { - hash = hash * 33 + *key++; - } - return (int)(hash & (size - 1)); + hash = 0; + while ( cpp-- > 0 ) { + hash = hash * 33 + *key++; + } + return hash & (size - 1); } static struct color_hash *create_colorhash(int maxnum) { - size_t bytes; - int s; - struct color_hash *hash; + int bytes, s; + struct color_hash *hash; - /* we know how many entries we need, so we can allocate - everything here */ - hash = malloc(sizeof *hash); - if (!hash) - return NULL; + /* we know how many entries we need, so we can allocate + everything here */ + hash = (struct color_hash *)SDL_malloc(sizeof *hash); + if (!hash) + return NULL; - /* use power-of-2 sized hash table for decoding speed */ - for (s = STARTING_HASH_SIZE; s < maxnum; s <<= 1) - ; - hash->size = s; - hash->maxnum = maxnum; - bytes = hash->size * sizeof (struct hash_entry **); - hash->entries = NULL; /* in case malloc fails */ - hash->table = malloc(bytes); - if (!hash->table) - return NULL; - memset(hash->table, 0, bytes); - hash->entries = malloc(maxnum * sizeof (struct hash_entry)); - if (!hash->entries) - { - free(hash->table); - return NULL; - } - hash->next_free = hash->entries; - return hash; + /* use power-of-2 sized hash table for decoding speed */ + for (s = STARTING_HASH_SIZE; s < maxnum; s <<= 1) + ; + hash->size = s; + hash->maxnum = maxnum; + bytes = hash->size * sizeof(struct hash_entry **); + hash->entries = NULL; /* in case malloc fails */ + hash->table = (struct hash_entry **)SDL_malloc(bytes); + if (!hash->table) { + SDL_free(hash); + return NULL; + } + SDL_memset(hash->table, 0, bytes); + hash->entries = (struct hash_entry *)SDL_malloc(maxnum * sizeof(struct hash_entry)); + if (!hash->entries) { + SDL_free(hash->table); + SDL_free(hash); + return NULL; + } + hash->next_free = hash->entries; + return hash; } static int add_colorhash(struct color_hash *hash, char *key, int cpp, Uint32 color) { - const int indexkey = hash_key(key, cpp, hash->size); - struct hash_entry *e = hash->next_free++; - e->color = color; - e->key = key; - e->next = hash->table[indexkey]; - hash->table[indexkey] = e; - return 1; + int index = hash_key(key, cpp, hash->size); + struct hash_entry *e = hash->next_free++; + e->color = color; + e->key = key; + e->next = hash->table[index]; + hash->table[index] = e; + return 1; } /* fast lookup that works if cpp == 1 */ @@ -144,88 +153,756 @@ static int add_colorhash(struct color_hash *hash, static Uint32 get_colorhash(struct color_hash *hash, const char *key, int cpp) { - struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)]; - while (entry) { - if (memcmp(key, entry->key, cpp) == 0) - return entry->color; - entry = entry->next; - } - return 0; /* garbage in - garbage out */ + struct hash_entry *entry = hash->table[hash_key(key, cpp, hash->size)]; + while (entry) { + if (SDL_memcmp(key, entry->key, cpp) == 0) + return entry->color; + entry = entry->next; + } + return 0; /* garbage in - garbage out */ } static void free_colorhash(struct color_hash *hash) { - if (hash && hash->table) { - free(hash->table); - free(hash->entries); - free(hash); - } + if (hash) { + if (hash->table) + SDL_free(hash->table); + if (hash->entries) + SDL_free(hash->entries); + SDL_free(hash); + } } -/* portable case-insensitive string comparison */ -static int string_equal(const char *a, const char *b, size_t n) -{ - while (*a && *b && n) { - if (toupper((unsigned char)*a) != toupper((unsigned char)*b)) - return 0; - a++; - b++; - n--; - } - return *a == *b; -} - -#undef ARRAYSIZE -#define ARRAYSIZE(a) (int)(sizeof (a) / sizeof ((a)[0])) - /* * convert colour spec to RGB (in 0xrrggbb format). * return 1 if successful. */ -static int color_to_rgb(const char *spec, size_t speclen, Uint32 *rgb) +static int color_to_rgb(const char *spec, int speclen, Uint32 *rgb) { - /* poor man's rgb.txt */ - static struct { const char *name; Uint32 rgb; } known[] = { - {"none", 0xffffffff}, - {"black", 0x00000000}, - {"white", 0x00ffffff}, - {"red", 0x00ff0000}, - {"green", 0x0000ff00}, - {"blue", 0x000000ff} - }; + /* poor man's rgb.txt */ + static struct { const char *name; Uint32 rgb; } known[] = { + { "none", 0xFFFFFFFF }, + { "black", 0x000000 }, + { "white", 0xFFFFFF }, + { "red", 0xFF0000 }, + { "green", 0x00FF00 }, + { "blue", 0x0000FF }, +/* This table increases the size of the library by 40K, so it's disabled by default */ +#ifdef EXTENDED_XPM_COLORS + { "aliceblue", 0xf0f8ff }, + { "antiquewhite", 0xfaebd7 }, + { "antiquewhite1", 0xffefdb }, + { "antiquewhite2", 0xeedfcc }, + { "antiquewhite3", 0xcdc0b0 }, + { "antiquewhite4", 0x8b8378 }, + { "aqua", 0x00ffff }, + { "aquamarine", 0x7fffd4 }, + { "aquamarine1", 0x7fffd4 }, + { "aquamarine2", 0x76eec6 }, + { "aquamarine3", 0x66cdaa }, + { "aquamarine4", 0x458b74 }, + { "azure", 0xf0ffff }, + { "azure1", 0xf0ffff }, + { "azure2", 0xe0eeee }, + { "azure3", 0xc1cdcd }, + { "azure4", 0x838b8b }, + { "beige", 0xf5f5dc }, + { "bisque", 0xffe4c4 }, + { "bisque1", 0xffe4c4 }, + { "bisque2", 0xeed5b7 }, + { "bisque3", 0xcdb79e }, + { "bisque4", 0x8b7d6b }, + { "black", 0x000000 }, + { "blanchedalmond", 0xffebcd }, + { "blue", 0x0000ff }, + { "blue1", 0x0000ff }, + { "blue2", 0x0000ee }, + { "blue3", 0x0000cd }, + { "blue4", 0x00008B }, + { "blueviolet", 0x8a2be2 }, + { "brown", 0xA52A2A }, + { "brown1", 0xFF4040 }, + { "brown2", 0xEE3B3B }, + { "brown3", 0xCD3333 }, + { "brown4", 0x8B2323 }, + { "burlywood", 0xDEB887 }, + { "burlywood1", 0xFFD39B }, + { "burlywood2", 0xEEC591 }, + { "burlywood3", 0xCDAA7D }, + { "burlywood4", 0x8B7355 }, + { "cadetblue", 0x5F9EA0 }, + { "cadetblue", 0x5f9ea0 }, + { "cadetblue1", 0x98f5ff }, + { "cadetblue2", 0x8ee5ee }, + { "cadetblue3", 0x7ac5cd }, + { "cadetblue4", 0x53868b }, + { "chartreuse", 0x7FFF00 }, + { "chartreuse1", 0x7FFF00 }, + { "chartreuse2", 0x76EE00 }, + { "chartreuse3", 0x66CD00 }, + { "chartreuse4", 0x458B00 }, + { "chocolate", 0xD2691E }, + { "chocolate1", 0xFF7F24 }, + { "chocolate2", 0xEE7621 }, + { "chocolate3", 0xCD661D }, + { "chocolate4", 0x8B4513 }, + { "coral", 0xFF7F50 }, + { "coral1", 0xFF7256 }, + { "coral2", 0xEE6A50 }, + { "coral3", 0xCD5B45 }, + { "coral4", 0x8B3E2F }, + { "cornflowerblue", 0x6495ed }, + { "cornsilk", 0xFFF8DC }, + { "cornsilk1", 0xFFF8DC }, + { "cornsilk2", 0xEEE8CD }, + { "cornsilk3", 0xCDC8B1 }, + { "cornsilk4", 0x8B8878 }, + { "crimson", 0xDC143C }, + { "cyan", 0x00FFFF }, + { "cyan1", 0x00FFFF }, + { "cyan2", 0x00EEEE }, + { "cyan3", 0x00CDCD }, + { "cyan4", 0x008B8B }, + { "darkblue", 0x00008b }, + { "darkcyan", 0x008b8b }, + { "darkgoldenrod", 0xb8860b }, + { "darkgoldenrod1", 0xffb90f }, + { "darkgoldenrod2", 0xeead0e }, + { "darkgoldenrod3", 0xcd950c }, + { "darkgoldenrod4", 0x8b6508 }, + { "darkgray", 0xa9a9a9 }, + { "darkgreen", 0x006400 }, + { "darkgrey", 0xa9a9a9 }, + { "darkkhaki", 0xbdb76b }, + { "darkmagenta", 0x8b008b }, + { "darkolivegreen", 0x556b2f }, + { "darkolivegreen1", 0xcaff70 }, + { "darkolivegreen2", 0xbcee68 }, + { "darkolivegreen3", 0xa2cd5a }, + { "darkolivegreen4", 0x6e8b3d }, + { "darkorange", 0xff8c00 }, + { "darkorange1", 0xff7f00 }, + { "darkorange2", 0xee7600 }, + { "darkorange3", 0xcd6600 }, + { "darkorange4", 0x8b4500 }, + { "darkorchid", 0x9932cc }, + { "darkorchid1", 0xbf3eff }, + { "darkorchid2", 0xb23aee }, + { "darkorchid3", 0x9a32cd }, + { "darkorchid4", 0x68228b }, + { "darkred", 0x8b0000 }, + { "darksalmon", 0xe9967a }, + { "darkseagreen", 0x8fbc8f }, + { "darkseagreen1", 0xc1ffc1 }, + { "darkseagreen2", 0xb4eeb4 }, + { "darkseagreen3", 0x9bcd9b }, + { "darkseagreen4", 0x698b69 }, + { "darkslateblue", 0x483d8b }, + { "darkslategray", 0x2f4f4f }, + { "darkslategray1", 0x97ffff }, + { "darkslategray2", 0x8deeee }, + { "darkslategray3", 0x79cdcd }, + { "darkslategray4", 0x528b8b }, + { "darkslategrey", 0x2f4f4f }, + { "darkturquoise", 0x00ced1 }, + { "darkviolet", 0x9400D3 }, + { "darkviolet", 0x9400d3 }, + { "deeppink", 0xff1493 }, + { "deeppink1", 0xff1493 }, + { "deeppink2", 0xee1289 }, + { "deeppink3", 0xcd1076 }, + { "deeppink4", 0x8b0a50 }, + { "deepskyblue", 0x00bfff }, + { "deepskyblue1", 0x00bfff }, + { "deepskyblue2", 0x00b2ee }, + { "deepskyblue3", 0x009acd }, + { "deepskyblue4", 0x00688b }, + { "dimgray", 0x696969 }, + { "dimgrey", 0x696969 }, + { "dodgerblue", 0x1e90ff }, + { "dodgerblue1", 0x1e90ff }, + { "dodgerblue2", 0x1c86ee }, + { "dodgerblue3", 0x1874cd }, + { "dodgerblue4", 0x104e8b }, + { "firebrick", 0xB22222 }, + { "firebrick1", 0xFF3030 }, + { "firebrick2", 0xEE2C2C }, + { "firebrick3", 0xCD2626 }, + { "firebrick4", 0x8B1A1A }, + { "floralwhite", 0xfffaf0 }, + { "forestgreen", 0x228b22 }, + { "fractal", 0x808080 }, + { "fuchsia", 0xFF00FF }, + { "gainsboro", 0xDCDCDC }, + { "ghostwhite", 0xf8f8ff }, + { "gold", 0xFFD700 }, + { "gold1", 0xFFD700 }, + { "gold2", 0xEEC900 }, + { "gold3", 0xCDAD00 }, + { "gold4", 0x8B7500 }, + { "goldenrod", 0xDAA520 }, + { "goldenrod1", 0xFFC125 }, + { "goldenrod2", 0xEEB422 }, + { "goldenrod3", 0xCD9B1D }, + { "goldenrod4", 0x8B6914 }, + { "gray", 0x7E7E7E }, + { "gray", 0xBEBEBE }, + { "gray0", 0x000000 }, + { "gray1", 0x030303 }, + { "gray10", 0x1A1A1A }, + { "gray100", 0xFFFFFF }, + { "gray11", 0x1C1C1C }, + { "gray12", 0x1F1F1F }, + { "gray13", 0x212121 }, + { "gray14", 0x242424 }, + { "gray15", 0x262626 }, + { "gray16", 0x292929 }, + { "gray17", 0x2B2B2B }, + { "gray18", 0x2E2E2E }, + { "gray19", 0x303030 }, + { "gray2", 0x050505 }, + { "gray20", 0x333333 }, + { "gray21", 0x363636 }, + { "gray22", 0x383838 }, + { "gray23", 0x3B3B3B }, + { "gray24", 0x3D3D3D }, + { "gray25", 0x404040 }, + { "gray26", 0x424242 }, + { "gray27", 0x454545 }, + { "gray28", 0x474747 }, + { "gray29", 0x4A4A4A }, + { "gray3", 0x080808 }, + { "gray30", 0x4D4D4D }, + { "gray31", 0x4F4F4F }, + { "gray32", 0x525252 }, + { "gray33", 0x545454 }, + { "gray34", 0x575757 }, + { "gray35", 0x595959 }, + { "gray36", 0x5C5C5C }, + { "gray37", 0x5E5E5E }, + { "gray38", 0x616161 }, + { "gray39", 0x636363 }, + { "gray4", 0x0A0A0A }, + { "gray40", 0x666666 }, + { "gray41", 0x696969 }, + { "gray42", 0x6B6B6B }, + { "gray43", 0x6E6E6E }, + { "gray44", 0x707070 }, + { "gray45", 0x737373 }, + { "gray46", 0x757575 }, + { "gray47", 0x787878 }, + { "gray48", 0x7A7A7A }, + { "gray49", 0x7D7D7D }, + { "gray5", 0x0D0D0D }, + { "gray50", 0x7F7F7F }, + { "gray51", 0x828282 }, + { "gray52", 0x858585 }, + { "gray53", 0x878787 }, + { "gray54", 0x8A8A8A }, + { "gray55", 0x8C8C8C }, + { "gray56", 0x8F8F8F }, + { "gray57", 0x919191 }, + { "gray58", 0x949494 }, + { "gray59", 0x969696 }, + { "gray6", 0x0F0F0F }, + { "gray60", 0x999999 }, + { "gray61", 0x9C9C9C }, + { "gray62", 0x9E9E9E }, + { "gray63", 0xA1A1A1 }, + { "gray64", 0xA3A3A3 }, + { "gray65", 0xA6A6A6 }, + { "gray66", 0xA8A8A8 }, + { "gray67", 0xABABAB }, + { "gray68", 0xADADAD }, + { "gray69", 0xB0B0B0 }, + { "gray7", 0x121212 }, + { "gray70", 0xB3B3B3 }, + { "gray71", 0xB5B5B5 }, + { "gray72", 0xB8B8B8 }, + { "gray73", 0xBABABA }, + { "gray74", 0xBDBDBD }, + { "gray75", 0xBFBFBF }, + { "gray76", 0xC2C2C2 }, + { "gray77", 0xC4C4C4 }, + { "gray78", 0xC7C7C7 }, + { "gray79", 0xC9C9C9 }, + { "gray8", 0x141414 }, + { "gray80", 0xCCCCCC }, + { "gray81", 0xCFCFCF }, + { "gray82", 0xD1D1D1 }, + { "gray83", 0xD4D4D4 }, + { "gray84", 0xD6D6D6 }, + { "gray85", 0xD9D9D9 }, + { "gray86", 0xDBDBDB }, + { "gray87", 0xDEDEDE }, + { "gray88", 0xE0E0E0 }, + { "gray89", 0xE3E3E3 }, + { "gray9", 0x171717 }, + { "gray90", 0xE5E5E5 }, + { "gray91", 0xE8E8E8 }, + { "gray92", 0xEBEBEB }, + { "gray93", 0xEDEDED }, + { "gray94", 0xF0F0F0 }, + { "gray95", 0xF2F2F2 }, + { "gray96", 0xF5F5F5 }, + { "gray97", 0xF7F7F7 }, + { "gray98", 0xFAFAFA }, + { "gray99", 0xFCFCFC }, + { "green", 0x008000 }, + { "green", 0x00FF00 }, + { "green1", 0x00FF00 }, + { "green2", 0x00EE00 }, + { "green3", 0x00CD00 }, + { "green4", 0x008B00 }, + { "greenyellow", 0xadff2f }, + { "grey", 0xBEBEBE }, + { "grey0", 0x000000 }, + { "grey1", 0x030303 }, + { "grey10", 0x1A1A1A }, + { "grey100", 0xFFFFFF }, + { "grey11", 0x1C1C1C }, + { "grey12", 0x1F1F1F }, + { "grey13", 0x212121 }, + { "grey14", 0x242424 }, + { "grey15", 0x262626 }, + { "grey16", 0x292929 }, + { "grey17", 0x2B2B2B }, + { "grey18", 0x2E2E2E }, + { "grey19", 0x303030 }, + { "grey2", 0x050505 }, + { "grey20", 0x333333 }, + { "grey21", 0x363636 }, + { "grey22", 0x383838 }, + { "grey23", 0x3B3B3B }, + { "grey24", 0x3D3D3D }, + { "grey25", 0x404040 }, + { "grey26", 0x424242 }, + { "grey27", 0x454545 }, + { "grey28", 0x474747 }, + { "grey29", 0x4A4A4A }, + { "grey3", 0x080808 }, + { "grey30", 0x4D4D4D }, + { "grey31", 0x4F4F4F }, + { "grey32", 0x525252 }, + { "grey33", 0x545454 }, + { "grey34", 0x575757 }, + { "grey35", 0x595959 }, + { "grey36", 0x5C5C5C }, + { "grey37", 0x5E5E5E }, + { "grey38", 0x616161 }, + { "grey39", 0x636363 }, + { "grey4", 0x0A0A0A }, + { "grey40", 0x666666 }, + { "grey41", 0x696969 }, + { "grey42", 0x6B6B6B }, + { "grey43", 0x6E6E6E }, + { "grey44", 0x707070 }, + { "grey45", 0x737373 }, + { "grey46", 0x757575 }, + { "grey47", 0x787878 }, + { "grey48", 0x7A7A7A }, + { "grey49", 0x7D7D7D }, + { "grey5", 0x0D0D0D }, + { "grey50", 0x7F7F7F }, + { "grey51", 0x828282 }, + { "grey52", 0x858585 }, + { "grey53", 0x878787 }, + { "grey54", 0x8A8A8A }, + { "grey55", 0x8C8C8C }, + { "grey56", 0x8F8F8F }, + { "grey57", 0x919191 }, + { "grey58", 0x949494 }, + { "grey59", 0x969696 }, + { "grey6", 0x0F0F0F }, + { "grey60", 0x999999 }, + { "grey61", 0x9C9C9C }, + { "grey62", 0x9E9E9E }, + { "grey63", 0xA1A1A1 }, + { "grey64", 0xA3A3A3 }, + { "grey65", 0xA6A6A6 }, + { "grey66", 0xA8A8A8 }, + { "grey67", 0xABABAB }, + { "grey68", 0xADADAD }, + { "grey69", 0xB0B0B0 }, + { "grey7", 0x121212 }, + { "grey70", 0xB3B3B3 }, + { "grey71", 0xB5B5B5 }, + { "grey72", 0xB8B8B8 }, + { "grey73", 0xBABABA }, + { "grey74", 0xBDBDBD }, + { "grey75", 0xBFBFBF }, + { "grey76", 0xC2C2C2 }, + { "grey77", 0xC4C4C4 }, + { "grey78", 0xC7C7C7 }, + { "grey79", 0xC9C9C9 }, + { "grey8", 0x141414 }, + { "grey80", 0xCCCCCC }, + { "grey81", 0xCFCFCF }, + { "grey82", 0xD1D1D1 }, + { "grey83", 0xD4D4D4 }, + { "grey84", 0xD6D6D6 }, + { "grey85", 0xD9D9D9 }, + { "grey86", 0xDBDBDB }, + { "grey87", 0xDEDEDE }, + { "grey88", 0xE0E0E0 }, + { "grey89", 0xE3E3E3 }, + { "grey9", 0x171717 }, + { "grey90", 0xE5E5E5 }, + { "grey91", 0xE8E8E8 }, + { "grey92", 0xEBEBEB }, + { "grey93", 0xEDEDED }, + { "grey94", 0xF0F0F0 }, + { "grey95", 0xF2F2F2 }, + { "grey96", 0xF5F5F5 }, + { "grey97", 0xF7F7F7 }, + { "grey98", 0xFAFAFA }, + { "grey99", 0xFCFCFC }, + { "honeydew", 0xF0FFF0 }, + { "honeydew1", 0xF0FFF0 }, + { "honeydew2", 0xE0EEE0 }, + { "honeydew3", 0xC1CDC1 }, + { "honeydew4", 0x838B83 }, + { "hotpink", 0xff69b4 }, + { "hotpink1", 0xff6eb4 }, + { "hotpink2", 0xee6aa7 }, + { "hotpink3", 0xcd6090 }, + { "hotpink4", 0x8b3a62 }, + { "indianred", 0xcd5c5c }, + { "indianred1", 0xff6a6a }, + { "indianred2", 0xee6363 }, + { "indianred3", 0xcd5555 }, + { "indianred4", 0x8b3a3a }, + { "indigo", 0x4B0082 }, + { "ivory", 0xFFFFF0 }, + { "ivory1", 0xFFFFF0 }, + { "ivory2", 0xEEEEE0 }, + { "ivory3", 0xCDCDC1 }, + { "ivory4", 0x8B8B83 }, + { "khaki", 0xF0E68C }, + { "khaki1", 0xFFF68F }, + { "khaki2", 0xEEE685 }, + { "khaki3", 0xCDC673 }, + { "khaki4", 0x8B864E }, + { "lavender", 0xE6E6FA }, + { "lavenderblush", 0xfff0f5 }, + { "lavenderblush1", 0xfff0f5 }, + { "lavenderblush2", 0xeee0e5 }, + { "lavenderblush3", 0xcdc1c5 }, + { "lavenderblush4", 0x8b8386 }, + { "lawngreen", 0x7cfc00 }, + { "lemonchiffon", 0xfffacd }, + { "lemonchiffon1", 0xfffacd }, + { "lemonchiffon2", 0xeee9bf }, + { "lemonchiffon3", 0xcdc9a5 }, + { "lemonchiffon4", 0x8b8970 }, + { "lightblue", 0xadd8e6 }, + { "lightblue1", 0xbfefff }, + { "lightblue2", 0xb2dfee }, + { "lightblue3", 0x9ac0cd }, + { "lightblue4", 0x68838b }, + { "lightcoral", 0xf08080 }, + { "lightcyan", 0xe0ffff }, + { "lightcyan1", 0xe0ffff }, + { "lightcyan2", 0xd1eeee }, + { "lightcyan3", 0xb4cdcd }, + { "lightcyan4", 0x7a8b8b }, + { "lightgoldenrod", 0xeedd82 }, + { "lightgoldenrod1", 0xffec8b }, + { "lightgoldenrod2", 0xeedc82 }, + { "lightgoldenrod3", 0xcdbe70 }, + { "lightgoldenrod4", 0x8b814c }, + { "lightgoldenrodyellow", 0xfafad2 }, + { "lightgray", 0xd3d3d3 }, + { "lightgreen", 0x90ee90 }, + { "lightgrey", 0xd3d3d3 }, + { "lightpink", 0xffb6c1 }, + { "lightpink1", 0xffaeb9 }, + { "lightpink2", 0xeea2ad }, + { "lightpink3", 0xcd8c95 }, + { "lightpink4", 0x8b5f65 }, + { "lightsalmon", 0xffa07a }, + { "lightsalmon1", 0xffa07a }, + { "lightsalmon2", 0xee9572 }, + { "lightsalmon3", 0xcd8162 }, + { "lightsalmon4", 0x8b5742 }, + { "lightseagreen", 0x20b2aa }, + { "lightskyblue", 0x87cefa }, + { "lightskyblue1", 0xb0e2ff }, + { "lightskyblue2", 0xa4d3ee }, + { "lightskyblue3", 0x8db6cd }, + { "lightskyblue4", 0x607b8b }, + { "lightslateblue", 0x8470ff }, + { "lightslategray", 0x778899 }, + { "lightslategrey", 0x778899 }, + { "lightsteelblue", 0xb0c4de }, + { "lightsteelblue1", 0xcae1ff }, + { "lightsteelblue2", 0xbcd2ee }, + { "lightsteelblue3", 0xa2b5cd }, + { "lightsteelblue4", 0x6e7b8b }, + { "lightyellow", 0xffffe0 }, + { "lightyellow1", 0xffffe0 }, + { "lightyellow2", 0xeeeed1 }, + { "lightyellow3", 0xcdcdb4 }, + { "lightyellow4", 0x8b8b7a }, + { "lime", 0x00FF00 }, + { "limegreen", 0x32cd32 }, + { "linen", 0xFAF0E6 }, + { "magenta", 0xFF00FF }, + { "magenta1", 0xFF00FF }, + { "magenta2", 0xEE00EE }, + { "magenta3", 0xCD00CD }, + { "magenta4", 0x8B008B }, + { "maroon", 0x800000 }, + { "maroon", 0xB03060 }, + { "maroon1", 0xFF34B3 }, + { "maroon2", 0xEE30A7 }, + { "maroon3", 0xCD2990 }, + { "maroon4", 0x8B1C62 }, + { "mediumaquamarine", 0x66cdaa }, + { "mediumblue", 0x0000cd }, + { "mediumforestgreen", 0x32814b }, + { "mediumgoldenrod", 0xd1c166 }, + { "mediumorchid", 0xba55d3 }, + { "mediumorchid1", 0xe066ff }, + { "mediumorchid2", 0xd15fee }, + { "mediumorchid3", 0xb452cd }, + { "mediumorchid4", 0x7a378b }, + { "mediumpurple", 0x9370db }, + { "mediumpurple1", 0xab82ff }, + { "mediumpurple2", 0x9f79ee }, + { "mediumpurple3", 0x8968cd }, + { "mediumpurple4", 0x5d478b }, + { "mediumseagreen", 0x3cb371 }, + { "mediumslateblue", 0x7b68ee }, + { "mediumspringgreen", 0x00fa9a }, + { "mediumturquoise", 0x48d1cc }, + { "mediumvioletred", 0xc71585 }, + { "midnightblue", 0x191970 }, + { "mintcream", 0xf5fffa }, + { "mistyrose", 0xffe4e1 }, + { "mistyrose1", 0xffe4e1 }, + { "mistyrose2", 0xeed5d2 }, + { "mistyrose3", 0xcdb7b5 }, + { "mistyrose4", 0x8b7d7b }, + { "moccasin", 0xFFE4B5 }, + { "navajowhite", 0xffdead }, + { "navajowhite1", 0xffdead }, + { "navajowhite2", 0xeecfa1 }, + { "navajowhite3", 0xcdb38b }, + { "navajowhite4", 0x8b795e }, + { "navy", 0x000080 }, + { "navyblue", 0x000080 }, + { "none", 0x0000FF }, + { "oldlace", 0xfdf5e6 }, + { "olive", 0x808000 }, + { "olivedrab", 0x6b8e23 }, + { "olivedrab1", 0xc0ff3e }, + { "olivedrab2", 0xb3ee3a }, + { "olivedrab3", 0x9acd32 }, + { "olivedrab4", 0x698b22 }, + { "opaque", 0x000000 }, + { "orange", 0xFFA500 }, + { "orange1", 0xFFA500 }, + { "orange2", 0xEE9A00 }, + { "orange3", 0xCD8500 }, + { "orange4", 0x8B5A00 }, + { "orangered", 0xff4500 }, + { "orangered1", 0xff4500 }, + { "orangered2", 0xee4000 }, + { "orangered3", 0xcd3700 }, + { "orangered4", 0x8b2500 }, + { "orchid", 0xDA70D6 }, + { "orchid1", 0xFF83FA }, + { "orchid2", 0xEE7AE9 }, + { "orchid3", 0xCD69C9 }, + { "orchid4", 0x8B4789 }, + { "palegoldenrod", 0xeee8aa }, + { "palegreen", 0x98fb98 }, + { "palegreen1", 0x9aff9a }, + { "palegreen2", 0x90ee90 }, + { "palegreen3", 0x7ccd7c }, + { "palegreen4", 0x548b54 }, + { "paleturquoise", 0xafeeee }, + { "paleturquoise1", 0xbbffff }, + { "paleturquoise2", 0xaeeeee }, + { "paleturquoise3", 0x96cdcd }, + { "paleturquoise4", 0x668b8b }, + { "palevioletred", 0xdb7093 }, + { "palevioletred1", 0xff82ab }, + { "palevioletred2", 0xee799f }, + { "palevioletred3", 0xcd6889 }, + { "palevioletred4", 0x8b475d }, + { "papayawhip", 0xffefd5 }, + { "peachpuff", 0xffdab9 }, + { "peachpuff1", 0xffdab9 }, + { "peachpuff2", 0xeecbad }, + { "peachpuff3", 0xcdaf95 }, + { "peachpuff4", 0x8b7765 }, + { "peru", 0xCD853F }, + { "pink", 0xFFC0CB }, + { "pink1", 0xFFB5C5 }, + { "pink2", 0xEEA9B8 }, + { "pink3", 0xCD919E }, + { "pink4", 0x8B636C }, + { "plum", 0xDDA0DD }, + { "plum1", 0xFFBBFF }, + { "plum2", 0xEEAEEE }, + { "plum3", 0xCD96CD }, + { "plum4", 0x8B668B }, + { "powderblue", 0xb0e0e6 }, + { "purple", 0x800080 }, + { "purple", 0xA020F0 }, + { "purple1", 0x9B30FF }, + { "purple2", 0x912CEE }, + { "purple3", 0x7D26CD }, + { "purple4", 0x551A8B }, + { "red", 0xFF0000 }, + { "red1", 0xFF0000 }, + { "red2", 0xEE0000 }, + { "red3", 0xCD0000 }, + { "red4", 0x8B0000 }, + { "rosybrown", 0xbc8f8f }, + { "rosybrown1", 0xffc1c1 }, + { "rosybrown2", 0xeeb4b4 }, + { "rosybrown3", 0xcd9b9b }, + { "rosybrown4", 0x8b6969 }, + { "royalblue", 0x4169e1 }, + { "royalblue1", 0x4876ff }, + { "royalblue2", 0x436eee }, + { "royalblue3", 0x3a5fcd }, + { "royalblue4", 0x27408b }, + { "saddlebrown", 0x8b4513 }, + { "salmon", 0xFA8072 }, + { "salmon1", 0xFF8C69 }, + { "salmon2", 0xEE8262 }, + { "salmon3", 0xCD7054 }, + { "salmon4", 0x8B4C39 }, + { "sandybrown", 0xf4a460 }, + { "seagreen", 0x2e8b57 }, + { "seagreen1", 0x54ff9f }, + { "seagreen2", 0x4eee94 }, + { "seagreen3", 0x43cd80 }, + { "seagreen4", 0x2e8b57 }, + { "seashell", 0xFFF5EE }, + { "seashell1", 0xFFF5EE }, + { "seashell2", 0xEEE5DE }, + { "seashell3", 0xCDC5BF }, + { "seashell4", 0x8B8682 }, + { "sienna", 0xA0522D }, + { "sienna1", 0xFF8247 }, + { "sienna2", 0xEE7942 }, + { "sienna3", 0xCD6839 }, + { "sienna4", 0x8B4726 }, + { "silver", 0xC0C0C0 }, + { "skyblue", 0x87ceeb }, + { "skyblue1", 0x87ceff }, + { "skyblue2", 0x7ec0ee }, + { "skyblue3", 0x6ca6cd }, + { "skyblue4", 0x4a708b }, + { "slateblue", 0x6a5acd }, + { "slateblue1", 0x836fff }, + { "slateblue2", 0x7a67ee }, + { "slateblue3", 0x6959cd }, + { "slateblue4", 0x473c8b }, + { "slategray", 0x708090 }, + { "slategray1", 0xc6e2ff }, + { "slategray2", 0xb9d3ee }, + { "slategray3", 0x9fb6cd }, + { "slategray4", 0x6c7b8b }, + { "slategrey", 0x708090 }, + { "snow", 0xFFFAFA }, + { "snow1", 0xFFFAFA }, + { "snow2", 0xEEE9E9 }, + { "snow3", 0xCDC9C9 }, + { "snow4", 0x8B8989 }, + { "springgreen", 0x00ff7f }, + { "springgreen1", 0x00ff7f }, + { "springgreen2", 0x00ee76 }, + { "springgreen3", 0x00cd66 }, + { "springgreen4", 0x008b45 }, + { "steelblue", 0x4682b4 }, + { "steelblue1", 0x63b8ff }, + { "steelblue2", 0x5cacee }, + { "steelblue3", 0x4f94cd }, + { "steelblue4", 0x36648b }, + { "tan", 0xD2B48C }, + { "tan1", 0xFFA54F }, + { "tan2", 0xEE9A49 }, + { "tan3", 0xCD853F }, + { "tan4", 0x8B5A2B }, + { "teal", 0x008080 }, + { "thistle", 0xD8BFD8 }, + { "thistle1", 0xFFE1FF }, + { "thistle2", 0xEED2EE }, + { "thistle3", 0xCDB5CD }, + { "thistle4", 0x8B7B8B }, + { "tomato", 0xFF6347 }, + { "tomato1", 0xFF6347 }, + { "tomato2", 0xEE5C42 }, + { "tomato3", 0xCD4F39 }, + { "tomato4", 0x8B3626 }, + { "transparent", 0x0000FF }, + { "turquoise", 0x40E0D0 }, + { "turquoise1", 0x00F5FF }, + { "turquoise2", 0x00E5EE }, + { "turquoise3", 0x00C5CD }, + { "turquoise4", 0x00868B }, + { "violet", 0xEE82EE }, + { "violetred", 0xd02090 }, + { "violetred1", 0xff3e96 }, + { "violetred2", 0xee3a8c }, + { "violetred3", 0xcd3278 }, + { "violetred4", 0x8b2252 }, + { "wheat", 0xF5DEB3 }, + { "wheat1", 0xFFE7BA }, + { "wheat2", 0xEED8AE }, + { "wheat3", 0xCDBA96 }, + { "wheat4", 0x8B7E66 }, + { "white", 0xFFFFFF }, + { "whitesmoke", 0xf5f5f5 }, + { "yellow", 0xFFFF00 }, + { "yellow1", 0xFFFF00 }, + { "yellow2", 0xEEEE00 }, + { "yellow3", 0xCDCD00 }, + { "yellow4", 0x8B8B00 }, + { "yellowgreen", 0x9acd32 }, +#endif /* EXTENDED_XPM_COLORS */ + {"none", 0xFFFFFF} + }; - if (spec[0] == '#') { - char buf[7]; - switch (speclen) { - case 4: - buf[0] = buf[1] = spec[1]; - buf[2] = buf[3] = spec[2]; - buf[4] = buf[5] = spec[3]; - break; - case 7: - memcpy(buf, spec + 1, 6); - break; - case 13: - buf[0] = spec[1]; - buf[1] = spec[2]; - buf[2] = spec[5]; - buf[3] = spec[6]; - buf[4] = spec[9]; - buf[5] = spec[10]; - break; - } - buf[6] = '\0'; - *rgb = (Uint32)strtol(buf, NULL, 16); - return 1; - } else { - int i; - for (i = 0; i < ARRAYSIZE(known); i++) - if (string_equal(known[i].name, spec, speclen)) { - *rgb = known[i].rgb; - return 1; - } - return 0; + if (spec[0] == '#') { + char buf[7]; + switch(speclen) { + case 4: + buf[0] = buf[1] = spec[1]; + buf[2] = buf[3] = spec[2]; + buf[4] = buf[5] = spec[3]; + break; + case 7: + SDL_memcpy(buf, spec + 1, 6); + break; + case 13: + buf[0] = spec[1]; + buf[1] = spec[2]; + buf[2] = spec[5]; + buf[3] = spec[6]; + buf[4] = spec[9]; + buf[5] = spec[10]; + break; } + buf[6] = '\0'; + *rgb = (Uint32)SDL_strtol(buf, NULL, 16); + return 1; + } else { + size_t i; + for (i = 0; i < SDL_arraysize(known); i++) { + if (SDL_strncasecmp(known[i].name, spec, speclen) == 0) { + *rgb = known[i].rgb; + return 1; + } + } + return 0; + } } #ifndef MAX @@ -243,263 +920,278 @@ static const char *error; */ static const char *get_next_line(const char ***lines, SDL_RWops *src, int len) { - char *linebufnew; - if (lines) { - return *(*lines)++; - } else { - char c; - int n; - do { - if (SDL_RWread(src, &c, 1, 1) <= 0) { - error = "Premature end of data"; - return NULL; - } - } while (c != '"'); - if (len) { - len += 4; /* "\",\n\0" */ - if (len > buflen){ - buflen = len; - linebufnew = realloc(linebuf, buflen); - if(!linebufnew) { - free(linebuf); - error = "Out of memory"; - return NULL; - } - linebuf = linebufnew; - } - if (SDL_RWread(src, linebuf, len - 1, 1) <= 0) { - error = "Premature end of data"; - return NULL; - } - n = len - 2; - } else { - n = 0; - do { - if (n >= buflen - 1) { - if (buflen == 0) - buflen = 16; - buflen *= 2; - linebufnew = realloc(linebuf, buflen); - if(!linebufnew) { - free(linebuf); - error = "Out of memory"; - return NULL; - } - linebuf = linebufnew; - } - if (SDL_RWread(src, linebuf + n, 1, 1) <= 0) { - error = "Premature end of data"; - return NULL; - } - } while (linebuf[n++] != '"'); - n--; + char *linebufnew; + + if (lines) { + return *(*lines)++; + } else { + char c; + int n; + do { + if (SDL_RWread(src, &c, 1, 1) <= 0) { + error = "Premature end of data"; + return NULL; + } + } while (c != '"'); + if (len) { + len += 4; /* "\",\n\0" */ + if (len > buflen){ + buflen = len; + linebufnew = (char *)SDL_realloc(linebuf, buflen); + if (!linebufnew) { + SDL_free(linebuf); + error = "Out of memory"; + return NULL; } - linebuf[n] = '\0'; - return linebuf; + linebuf = linebufnew; + } + if (SDL_RWread(src, linebuf, len - 1, 1) <= 0) { + error = "Premature end of data"; + return NULL; + } + n = len - 2; + } else { + n = 0; + do { + if (n >= buflen - 1) { + if (buflen == 0) + buflen = 16; + buflen *= 2; + linebufnew = (char *)SDL_realloc(linebuf, buflen); + if (!linebufnew) { + SDL_free(linebuf); + error = "Out of memory"; + return NULL; + } + linebuf = linebufnew; + } + if (SDL_RWread(src, linebuf + n, 1, 1) <= 0) { + error = "Premature end of data"; + return NULL; + } + } while (linebuf[n++] != '"'); + n--; } + linebuf[n] = '\0'; + return linebuf; + } } -#define SKIPSPACE(p) \ -do { \ - while (isspace((unsigned char)*(p))) \ - ++(p); \ +#define SKIPSPACE(p) \ +do { \ + while (SDL_isspace((unsigned char)*(p))) \ + ++(p); \ } while (0) -#define SKIPNONSPACE(p) \ -do { \ - while (!isspace((unsigned char)*(p)) && *p) \ - ++(p); \ +#define SKIPNONSPACE(p) \ +do { \ + while (!SDL_isspace((unsigned char)*(p)) && *p) \ + ++(p); \ } while (0) /* read XPM from either array or RWops */ static SDL_Surface *load_xpm(const char **xpm, SDL_RWops *src) { - SDL_Surface *image = NULL; - int indexc; - int x, y; - int w, h, ncolors, cpp; - int indexed; - Uint8 *dst; - struct color_hash *colors = NULL; - SDL_Color *im_colors = NULL; - char *keystrings = NULL, *nextkey; - const char *line; - const char ***xpmlines = NULL; - int pixels_len; + Sint64 start = 0; + SDL_Surface *image = NULL; + int index; + int x, y; + int w, h, ncolors, cpp; + int indexed; + Uint8 *dst; + struct color_hash *colors = NULL; + SDL_Color *im_colors = NULL; + char *keystrings = NULL, *nextkey; + const char *line; + const char ***xpmlines = NULL; + int pixels_len; - error = NULL; - linebuf = NULL; - buflen = 0; + error = NULL; + linebuf = NULL; + buflen = 0; - if (xpm) - xpmlines = &xpm; + if (src) + start = SDL_RWtell(src); + if (xpm) + xpmlines = &xpm; + + line = get_next_line(xpmlines, src, 0); + if (!line) + goto done; + /* + * The header string of an XPMv3 image has the format + * + * [ ] + * + * where the hotspot coords are intended for mouse cursors. + * Right now we don't use the hotspots but it should be handled + * one day. + */ + if (SDL_sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4 + || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) { + error = "Invalid format description"; + goto done; + } + + keystrings = (char *)SDL_malloc(ncolors * cpp); + if (!keystrings) { + error = "Out of memory"; + goto done; + } + nextkey = keystrings; + + /* Create the new surface */ + if (ncolors <= 256) { + indexed = 1; + image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, + 0, 0, 0, 0); + im_colors = image->format->palette->colors; + image->format->palette->ncolors = ncolors; + } else { + indexed = 0; + image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, + 0xff0000, 0x00ff00, 0x0000ff, 0); + } + if (!image) { + /* Hmm, some SDL error (out of memory?) */ + goto done; + } + + /* Read the colors */ + colors = create_colorhash(ncolors); + if (!colors) { + error = "Out of memory"; + goto done; + } + for (index = 0; index < ncolors; ++index ) { + const char *p; line = get_next_line(xpmlines, src, 0); if (!line) - goto done; - /* - * The header string of an XPMv3 image has the format - * - * [ ] - * - * where the hotspot coords are intended for mouse cursors. - * Right now we don't use the hotspots but it should be handled - * one day. - */ - if (sscanf(line, "%d %d %d %d", &w, &h, &ncolors, &cpp) != 4 - || w <= 0 || h <= 0 || ncolors <= 0 || cpp <= 0) { - error = "Invalid format description"; - goto done; - } + goto done; - keystrings = malloc(ncolors * cpp); - if (!keystrings) { - error = "Out of memory"; - goto done; - } - nextkey = keystrings; + p = line + cpp + 1; - /* Create the new surface */ - if (ncolors <= 256) { - indexed = 1; - image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, - 0, 0, 0, 0); - im_colors = image->format->palette->colors; - image->format->palette->ncolors = ncolors; + /* parse a colour definition */ + for (;;) { + char nametype; + const char *colname; + Uint32 rgb, pixel; + + SKIPSPACE(p); + if (!*p) { + error = "colour parse error"; + goto done; + } + nametype = *p; + SKIPNONSPACE(p); + SKIPSPACE(p); + colname = p; + SKIPNONSPACE(p); + if (nametype == 's') + continue; /* skip symbolic colour names */ + + if (!color_to_rgb(colname, (int)(p - colname), &rgb)) + continue; + + SDL_memcpy(nextkey, line, cpp); + if (indexed) { + SDL_Color *c = im_colors + index; + c->r = (Uint8)(rgb >> 16); + c->g = (Uint8)(rgb >> 8); + c->b = (Uint8)(rgb); + pixel = index; + } else + pixel = rgb; + add_colorhash(colors, nextkey, cpp, pixel); + nextkey += cpp; + if (rgb == 0xffffffff) + SDL_SetColorKey(image, SDL_TRUE, pixel); + break; + } + } + + /* Read the pixels */ + pixels_len = w * cpp; + dst = (Uint8 *)image->pixels; + for (y = 0; y < h; y++) { + line = get_next_line(xpmlines, src, pixels_len); + if (!line) + goto done; + + if (indexed) { + /* optimization for some common cases */ + if (cpp == 1) + for (x = 0; x < w; x++) + dst[x] = (Uint8)QUICK_COLORHASH(colors, + line + x); + else + for (x = 0; x < w; x++) + dst[x] = (Uint8)get_colorhash(colors, + line + x * cpp, + cpp); } else { - indexed = 0; - image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, - 0xff0000, 0x00ff00, 0x0000ff, 0); - } - if (!image) { - /* Hmm, some SDL error (out of memory?) */ - goto done; - } - - /* Read the colors */ - colors = create_colorhash(ncolors); - if (!colors) { - error = "Out of memory"; - goto done; - } - for (indexc = 0; indexc < ncolors; ++indexc ) { - const char *p; - line = get_next_line(xpmlines, src, 0); - if (!line) - goto done; - - p = line + cpp + 1; - - /* parse a colour definition */ - for (;;) { - char nametype; - const char *colname; - Uint32 rgb, pixel; - - SKIPSPACE(p); - if (!*p) { - error = "colour parse error"; - goto done; - } - nametype = *p; - SKIPNONSPACE(p); - SKIPSPACE(p); - colname = p; - SKIPNONSPACE(p); - if (nametype == 's') - continue; /* skip symbolic colour names */ - - if (!color_to_rgb(colname, p - colname, &rgb)) - continue; - - memcpy(nextkey, line, cpp); - if (indexed) { - SDL_Color *c = im_colors + indexc; - c->r = (Uint8)(rgb >> 16); - c->g = (Uint8)(rgb >> 8); - c->b = (Uint8)(rgb); - pixel = indexc; - } else - pixel = rgb; - add_colorhash(colors, nextkey, cpp, pixel); - nextkey += cpp; - if (rgb == 0xffffffff) - SDL_SetColorKey(image, SDL_SRCCOLORKEY, pixel); - break; - } - } - - /* Read the pixels */ - pixels_len = w * cpp; - dst = image->pixels; - for (y = 0; y < h; y++) { - line = get_next_line(xpmlines, src, pixels_len); - if (indexed) { - /* optimization for some common cases */ - if (cpp == 1) - for (x = 0; x < w; x++) - dst[x] = (Uint8)QUICK_COLORHASH(colors, - line + x); - else - for (x = 0; x < w; x++) - dst[x] = (Uint8)get_colorhash(colors, - line + x * cpp, - cpp); - } else { - for (x = 0; x < w; x++) - ((Uint32*)dst)[x] = get_colorhash(colors, - line + x * cpp, - cpp); - } - dst += image->pitch; + for (x = 0; x < w; x++) + ((Uint32*)dst)[x] = get_colorhash(colors, + line + x * cpp, + cpp); } + dst += image->pitch; + } done: - if (error) { - SDL_FreeSurface(image); - image = NULL; - SDL_SetError(error); + if (error) { + if ( src ) + SDL_RWseek(src, start, RW_SEEK_SET); + if ( image ) { + SDL_FreeSurface(image); + image = NULL; } - free(keystrings); - free_colorhash(colors); - free(linebuf); - return(image); + IMG_SetError("%s", error); + } + if (keystrings) + SDL_free(keystrings); + free_colorhash(colors); + if (linebuf) + SDL_free(linebuf); + return(image); } /* Load a XPM type image from an RWops datasource */ -#if 0 SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) { - if ( !src ) { - /* The error message has been set in SDL_RWFromFile */ - return NULL; - } - return load_xpm(NULL, src); + if ( !src ) { + /* The error message has been set in SDL_RWFromFile */ + return NULL; + } + return load_xpm(NULL, src); } -#endif -static inline SDL_Surface *IMG_ReadXPMFromArray(const char **xpm) +SDL_Surface *IMG_ReadXPMFromArray(const char **xpm) { - return load_xpm(xpm, NULL); + if (!xpm) { + IMG_SetError("array is NULL"); + return NULL; + } + return load_xpm(xpm, NULL); } #else /* not LOAD_XPM */ /* See if an image is contained in a data source */ -#if 0 int IMG_isXPM(SDL_RWops *src) { - return(0); + return(0); } + /* Load a XPM type image from an SDL datasource */ SDL_Surface *IMG_LoadXPM_RW(SDL_RWops *src) { - return(NULL); + return(NULL); } -#endif -static inline SDL_Surface *IMG_ReadXPMFromArray(const char **xpm) +SDL_Surface *IMG_ReadXPMFromArray(char **xpm) { return NULL; } diff --git a/src/sdl/SDL_icon.xpm b/src/sdl/SDL_icon.xpm index cf72960d..ba252276 100644 --- a/src/sdl/SDL_icon.xpm +++ b/src/sdl/SDL_icon.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * C:\Repo\srb2\src\sdl\SDL_icon_xpm[] = { +static const char * SDL_icon_xpm[] = { "32 32 390 2", " c None", ". c #4F4F70", diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 4eab0ae3..ce84e86a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -39,6 +39,10 @@ #ifdef HAVE_IMAGE #include "SDL_image.h" +#elif 1 +#define LOAD_XPM //I want XPM! +#include "IMG_xpm.c" //Alam: I don't want to add SDL_Image.dll/so +#define HAVE_IMAGE //I have SDL_Image, sortof #endif #ifdef HAVE_IMAGE From 0575d2f1f98b35f53f6bebb45a85b708a1d170e2 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Fri, 10 Aug 2018 17:16:10 -0400 Subject: [PATCH 030/194] TravisCI: remove gcc-5 test, gcc-5 package is gone --- .travis.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4648ae56..c2f7f1f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -71,20 +71,6 @@ matrix: - gcc-4.9 compiler: gcc-4.9 #gcc-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - libsdl2-mixer-dev - - libpng-dev - - libgl1-mesa-dev - - libgme-dev - - p7zip-full - - gcc-5 - compiler: gcc-5 - #gcc-5 (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204 - os: linux addons: apt: From d9c7334dea997feaf13a5bb32c7d2878f6fa4f77 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Fri, 10 Aug 2018 19:02:03 -0400 Subject: [PATCH 031/194] Fix white being treated as transparent. --- src/sdl/SDL_icon.xpm | 624 ++++++++++++++----------------------------- 1 file changed, 206 insertions(+), 418 deletions(-) diff --git a/src/sdl/SDL_icon.xpm b/src/sdl/SDL_icon.xpm index ba252276..30259d55 100644 --- a/src/sdl/SDL_icon.xpm +++ b/src/sdl/SDL_icon.xpm @@ -1,425 +1,213 @@ /* XPM */ -static const char * SDL_icon_xpm[] = { -"32 32 390 2", -" c None", -". c #4F4F70", -"+ c #4D4D87", -"@ c #4D4D84", -"# c #4E4E6C", -"$ c #6C6C95", -"% c #5E5EB2", -"& c #6B6BE7", -"* c #7373F9", -"= c #7C7CFF", -"- c #6F70E7", -"; c #494BB2", -"> c #4F4FA3", -", c #6464D4", -"' c #7979F5", -") c #5F5FCA", -"! c #5D5D93", -"~ c #3A3A9F", -"{ c #6060AC", -"] c #777793", -"^ c #5C5CB3", -"/ c #7373EA", -"( c #7A7AFF", -"_ c #7575FF", -": c #7979FF", -"< c #6264DD", -"[ c #47478C", -"} c #564567", -"| c #4647D0", -"1 c #5C5CAE", -"2 c #5E5EFF", -"3 c #2929FF", -"4 c #1D1DFF", -"5 c #1919D1", -"6 c #4F4F90", -"7 c #1E1ECE", -"8 c #5858FF", -"9 c #6767A8", -"0 c #4949A0", -"a c #7070FB", -"b c #7D7DFF", -"c c #7777FF", -"d c #7373FF", -"e c #7272FF", -"f c #7878FF", -"g c #6465D8", -"h c #363886", -"i c #9F7655", -"j c #C89B5C", -"k c #1D1CB7", -"l c #3031B1", -"m c #1919F4", -"n c #1111FF", -"o c #1818FF", -"p c #1B1BFF", -"q c #1C1CFF", -"r c #2626B3", -"s c #1E1EC8", -"t c #1A1AE8", -"u c #24249F", -"v c #2F2FD2", -"w c #7676FF", -"x c #6869E2", -"y c #414290", -"z c #8C6751", -"A c #FCBA68", -"B c #E9BD7D", -"C c #201EB8", -"D c #090AB8", -"E c #1616EB", -"F c #1818FD", -"G c #1414EE", -"H c #1010E1", -"I c #0E0EE2", -"J c #0E0EF4", -"K c #0606B2", -"L c #7A7A89", -"M c #0C0C9A", -"N c #0A0AA7", -"O c #2424E4", -"P c #6669E6", -"Q c #4F4A8F", -"R c #BF853B", -"S c #FFD98D", -"T c #CDAB76", -"U c #1717C4", -"V c #0F10BA", -"W c #0909B6", -"X c #0505C3", -"Y c #0000B6", -"Z c #0000BE", -"` c #0000AD", -" . c #1D1D83", -".. c #63638E", -"+. c #090975", -"@. c #1414F3", -"#. c #5B5BFF", -"$. c #7B7BFF", -"%. c #7070FF", -"&. c #6E6EFF", -"*. c #7172F6", -"=. c #625DAF", -"-. c #BA9E6C", -";. c #887167", -">. c #090DF2", -",. c #1313BE", -"'. c #000085", -"). c #0000AC", -"!. c #0202AA", -"~. c #242488", -"{. c #1414C7", -"]. c #1717FF", -"^. c #5959FF", -"/. c #7F7FFF", -"(. c #7474FF", -"_. c #7171FF", -":. c #8686FF", -"<. c #7574FF", -"[. c #797CFF", -"}. c #5756B8", -"|. c #1C19A4", -"1. c #1617FF", -"2. c #1212BD", -"3. c #040485", -"4. c #0707A4", -"5. c #1B1B71", -"6. c #373797", -"7. c #1616FF", -"8. c #5050FF", -"9. c #8080FF", -"0. c #AAAAFF", -"a. c #AEAEF6", -"b. c #8A8AEF", -"c. c #6969FB", -"d. c #2728FF", -"e. c #1314FF", -"f. c #1919FF", -"g. c #1313E8", -"h. c #1F1FF4", -"i. c #5454FF", -"j. c #6D6DF0", -"k. c #6868B5", -"l. c #0B0BB8", -"m. c #1212C5", -"n. c #1616FC", -"o. c #1515FF", -"p. c #1212FF", -"q. c #2323FF", -"r. c #3636FF", -"s. c #4040FF", -"t. c #4343F9", -"u. c #5D5DB8", -"v. c #7F7F92", -"w. c #878793", -"x. c #4B4B94", -"y. c #0B0CE2", -"z. c #1313FF", -"A. c #4C4CFF", -"B. c #8282FF", -"C. c #7171ED", -"D. c #636394", -"E. c #575785", -"F. c #A9A99C", -"G. c #1414BC", -"H. c #1414FF", -"I. c #0707FD", -"J. c #2525AA", -"K. c #A8A8A4", -"L. c #EBEBE2", -"M. c #F9F9F2", -"N. c #E1E1CC", -"O. c #4D4D9F", -"P. c #0B0BF7", -"Q. c #2121FF", -"R. c #3232FF", -"S. c #5555FF", -"T. c #6161B4", -"U. c #B5B5B2", -"V. c #FFFFF8", -"W. c #4F4F9A", -"X. c #0B0BF5", -"Y. c #1616C5", -"Z. c #A8A8A1", -"`. c #FFFFFC", -" + c #FFFFFF", -".+ c #C0C0C4", -"++ c #1212D4", -"@+ c #4444FF", -"#+ c #6464FF", -"$+ c #8383FF", -"%+ c #6767C3", -"&+ c #E4E4E4", -"*+ c #9494AE", -"=+ c #0808DF", -"-+ c #0D0DF2", -";+ c #61619A", -">+ c #F1F1E0", -",+ c #E8E8DD", -"'+ c #2424BB", -")+ c #1010FF", -"!+ c #3434FF", -"~+ c #6161FF", -"{+ c #6969D2", -"]+ c #EFEFF0", -"^+ c #C2C2BA", -"/+ c #1010B6", -"(+ c #0909AC", -"_+ c #A4A49A", -":+ c #EAEADE", -"<+ c #2525B8", -"[+ c #2F2FFF", -"}+ c #3C3CB5", -"|+ c #EEEEEE", -"1+ c #BBBBAD", -"2+ c #0B0B56", -"3+ c #0B0BFC", -"4+ c #1212EF", -"5+ c #0C0C3E", -"6+ c #919187", -"7+ c #DEDED6", -"8+ c #1F1FC0", -"9+ c #1A1AFF", -"0+ c #1717FA", -"a+ c #1515F8", -"b+ c #1111FC", -"c+ c #494992", -"d+ c #999998", -"e+ c #3E3E3B", -"f+ c #3C3C99", -"g+ c #535397", -"h+ c #5A5A4D", -"i+ c #6F6F70", -"j+ c #BFBFC9", -"k+ c #1111D6", -"l+ c #1515F1", -"m+ c #0F0FE2", -"n+ c #0D0DD9", -"o+ c #0909CD", -"p+ c #0808C7", -"q+ c #0505C7", -"r+ c #0303CB", -"s+ c #0101C0", -"t+ c #0202AF", -"u+ c #0606AC", -"v+ c #121283", -"w+ c #BBBBBB", -"x+ c #BEBEBE", -"y+ c #2F2F2E", -"z+ c #C7C8BB", -"A+ c #D8DAD1", -"B+ c #272828", -"C+ c #929292", -"D+ c #8688C7", -"E+ c #0506F6", -"F+ c #1616F5", -"G+ c #0B0BD3", -"H+ c #0202B6", -"I+ c #0000AF", -"J+ c #0000B4", -"K+ c #0000BD", -"L+ c #0000BB", -"M+ c #00009E", -"N+ c #2C2C7E", -"O+ c #6A6A8B", -"P+ c #959595", -"Q+ c #F0F0F1", -"R+ c #E1E1E1", -"S+ c #8C8E90", -"T+ c #BEBEBF", -"U+ c #C9C7C5", -"V+ c #939699", -"W+ c #E7EAED", -"X+ c #CBCBC7", -"Y+ c #413B9B", -"Z+ c #0607DD", -"`+ c #0C0CE2", -" @ c #0303B9", -".@ c #0000A8", -"+@ c #181888", -"@@ c #6A6A6A", -"#@ c #626263", -"$@ c #4B4B4C", -"%@ c #3E3B36", -"&@ c #9B805C", -"*@ c #D9B07D", -"=@ c #C9AE89", -"-@ c #B9AF9E", -";@ c #C7C5C4", -">@ c #CBCCCF", -",@ c #C7C6C6", -"'@ c #AEA59A", -")@ c #B69974", -"!@ c #D8B87F", -"~@ c #9B8272", -"{@ c #0E0B9B", -"]@ c #0000B7", -"^@ c #0000B8", -"/@ c #000082", -"(@ c #00007A", -"_@ c #636379", -":@ c #62533E", -"<@ c #B59B6C", -"[@ c #DEB07B", -"}@ c #FECC90", -"|@ c #FFCE92", -"1@ c #FEC98C", -"2@ c #F1BD82", -"3@ c #D1A979", -"4@ c #BC9E73", -"5@ c #CCA777", -"6@ c #EAB980", -"7@ c #FFCD90", -"8@ c #FFD595", -"9@ c #FDD782", -"0@ c #413678", -"a@ c #0000AE", -"b@ c #000077", -"c@ c #010193", -"d@ c #0C0CE4", -"e@ c #38389E", -"f@ c #EEC585", -"g@ c #FFDA9D", -"h@ c #FFC992", -"i@ c #FFC88F", -"j@ c #FFC990", -"k@ c #FFCE93", -"l@ c #FFD094", -"m@ c #FFCC92", -"n@ c #C9A174", -"o@ c #EDBD88", -"p@ c #FAD287", -"q@ c #3A2F7F", -"r@ c #0000BA", -"s@ c #0000B0", -"t@ c #0101B2", -"u@ c #1111ED", -"v@ c #1919C1", -"w@ c #95887C", -"x@ c #DCAC6E", -"y@ c #FFD393", -"z@ c #FFCD94", -"A@ c #FFCA93", -"B@ c #FFC991", -"C@ c #FFC78E", -"D@ c #FFCB91", -"E@ c #E0B581", -"F@ c #BB9A6F", -"G@ c #FFDC97", -"H@ c #C1A173", -"I@ c #0E0B9A", -"J@ c #0000B5", -"K@ c #0101B6", -"L@ c #1010E0", -"M@ c #1616EC", -"N@ c #A68156", -"O@ c #E7AC6B", -"P@ c #FFC582", -"Q@ c #FFCF8F", -"R@ c #FFD195", -"S@ c #FFD296", -"T@ c #FFD396", -"U@ c #FFD193", -"V@ c #FFD28F", -"W@ c #D2A96B", -"X@ c #2F2482", -"Y@ c #0000C1", -"Z@ c #0000C0", -"`@ c #0000BF", -" # c #0101BF", -".# c #1212F0", -"+# c #767698", -"@# c #9C866E", -"## c #A9865D", -"$# c #C0915D", -"%# c #C89760", -"&# c #C29360", -"*# c #AD8A61", -"=# c #9D8971", -"-# c #7F7A7A", -";# c #70708F", -"># c #6F6F91", -",# c #575788", -"'# c #464687", -")# c #2F2F87", -"!# c #15158F", -"~# c #0101A8", -"{# c #1313FB", -"]# c #57579F", -"^# c #343487", -"/# c #434388", +static const char *SDL_icon_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 175 2 ", +" c None", +". c #2E2E2E", +"X c #3C3C3C", +"o c #493939", +"O c #4E473F", +"+ c #161658", +"@ c #131369", +"# c #06067B", +"$ c #111173", +"% c #16167F", +"& c #252567", +"* c #372B7C", +"= c #3D3679", +"- c #41414A", +"; c #575655", +": c #6A5841", +"> c #5B4B72", +", c #616160", +"< c #7B7B7B", +"1 c #906E49", +"2 c #89685D", +"3 c #A67B4A", +"4 c #AA7F50", +"5 c #9B7560", +"6 c #856C78", +"7 c #997B7D", +"8 c #B48552", +"9 c #BA8A55", +"0 c #A48665", +"q c #B98F67", +"w c #B9946A", +"e c #B7937A", +"r c #C8955C", +"t c #CA9966", +"y c #DAA469", +"u c #C9A37B", +"i c #D7AB7B", +"p c #DFB07D", +"a c #EBAE6A", +"s c #E5B27A", +"d c #F1B779", +"f c #0A0A83", +"g c #05058B", +"h c #060687", +"j c #101089", +"k c #131382", +"l c #040494", +"z c #02029D", +"x c #0C0B9C", +"c c #120F9E", +"v c #19199B", +"b c #382D84", +"n c #39398D", +"m c #222296", +"M c #0101A6", +"N c #0A0AA2", +"B c #0202AC", +"V c #1919A2", +"C c #1616AD", +"Z c #0000B5", +"A c #0202BC", +"S c #0C0CB6", +"D c #1313B3", +"F c #1011BD", +"G c #1B1BBE", +"H c #2B2BAC", +"J c #3737A1", +"K c #2A26BE", +"L c #2A29B4", +"P c #3B3BB8", +"I c #48478B", +"U c #57578A", +"Y c #4A499A", +"T c #524F95", +"R c #565399", +"E c #4C4CA8", +"W c #524DA7", +"Q c #5353A4", +"! c #5555A9", +"~ c #5555B4", +"^ c #5656B7", +"/ c #6464A6", +"( c #6F67B5", +") c #0404C3", +"_ c #0707CA", +"` c #1414CB", +"' c #1A1AC6", +"] c #0A0AD3", +"[ c #0D0DDC", +"{ c #1A1AD4", +"} c #1010DF", +"| c #1E1EDE", +" . c #1817DE", +".. c #221FCA", +"X. c #2B2BCC", +"o. c #2727C9", +"O. c #3434C3", +"+. c #3434D4", +"@. c #0F0FE2", +"#. c #1313E5", +"$. c #1515ED", +"%. c #1B1BEA", +"&. c #1C1CE4", +"*. c #1515F4", +"=. c #1818F3", +"-. c #1717FD", +";. c #1818FF", +":. c #2B2BE9", +">. c #2424FF", +",. c #2A2AFF", +"<. c #2222F1", +"1. c #3737FF", +"2. c #5D5DC3", +"3. c #5F5FC9", +"4. c #5655C2", +"5. c #4747D1", +"6. c #5B5BD4", +"7. c #6565C8", +"8. c #6363DA", +"9. c #4545FF", +"0. c #4D4DFC", +"q. c #5454FF", +"w. c #5959FF", +"e. c #6969E5", +"r. c #6B6CEA", +"t. c #6666E7", +"y. c #6B6BFE", +"u. c #6767F8", +"i. c #7070F6", +"p. c #7373FF", +"a. c #7C7CFF", +"s. c #91918F", +"d. c #8F9090", +"f. c #979797", +"g. c #9C9C9C", +"h. c #8585A1", +"j. c #9C9CA7", +"k. c #9292B6", +"l. c #A4A4A4", +"z. c #BDB2A4", +"x. c #A4A4B1", +"c. c #BFBFBD", +"v. c #BABAB7", +"b. c #C8AA87", +"n. c #DAAE82", +"m. c #DBB081", +"M. c #EBBA85", +"N. c #F3BF84", +"B. c #F2BE88", +"V. c #C2B3A3", +"C. c #FBC386", +"Z. c #FCC68C", +"A. c #FFC88F", +"S. c #F4C387", +"D. c #FFC990", +"F. c #C3C1BF", +"G. c #8F8FCB", +"H. c #BDBDC2", +"J. c #BDBDD1", +"K. c #8888F9", +"L. c #A4A4FB", +"P. c #CDCDCC", +"I. c #CECAC6", +"U. c #D3CFCA", +"Y. c #D3D0CC", +"T. c #C0C0D5", +"R. c #D6D5D4", +"E. c #D7D7DD", +"W. c #E1E1DF", +"Q. c #DEDEE1", +"!. c #E4E4E4", +"~. c #E8E8E8", +"^. c #F0F0EE", +"/. c #F5F5F2", +"(. c #FFFFFF", +/* pixels */ " ", " ", " ", -" . + @ # ", -" $ % & * = - ; > , ' ) ! ", -" ~ { ] ^ / = ( _ : < [ } | 1 2 3 4 5 6 ", -" 7 8 9 0 a b c d e f g h i j k l m n o p q r ", -" s t u v _ f d d d w x y z A B C D E F G H I J K L ", -" M N O _ c e d d d _ P Q R S T U V W X Y Z ` ... ", -" +.@.#.$.d d d d %.&._ *.=.-.;.>.,.'.).!.~. ", -" {.].^./.(.d d _.$.:._ <.[.}.|.1.2.3.4.5. ", -" 6.7.7.4 8.e : w 9.0.a.b.c.2 d.e.f.g.h.i.j.k. ", -" l.m.n.o.p.q.r.s.t.u.v.w.x.y.z.o o z.A.B./.b C.D. ", -" E.F.G.].o H.z.I.J.K.L.M.N.O.P.o o o Q.R.S._.b B.T. ", -" U.V.W.X.f.f.7.Y.Z.`. + + +.+++].o o o.n z.q.@+#+$+%+ ", -" &+ +*+=+].o -+;+>+ + + + +,+'+H.o o o o o H.)+o !+~+{+ ", -" ]+ +^+/+H.o.(+_+ + + + + +:+<+z.o o o o o o o 7.n H.[+}+ ", -" |+ +1+2+3+4+5+6+ + + + + +7+8+H.o o f.9+f.9+f.F 0+a+b+o.c+ ", -" &+ +d+e+f+g+h+i+ + + + + +j+k+].f.9+l+m+n+o+p+q+r+s+t+u+v+ ", -" w+ +x+y+z+A+B+C+ + + + + +D+E+9+F+G+H+I+J+K+L+M+N+O+ ", -" P+Q+R+S+T+U+V+W+ + + + +X+Y+Z+`+ @I+J+Z .@+@E. ", -" @@#@$@%@&@*@=@-@;@>@,@'@)@!@~@{@]@^@I+/@(@_@ ", -" :@<@[@}@|@1@2@3@4@5@6@7@8@9@0@L+a@b@c@d@e@ ", -" f@g@h@i@i@j@k@l@|@m@n@o@p@q@r@s@t@u@p v@ ", -" w@x@y@z@A@B@i@C@D@E@F@G@H@I@L+J@K@L@p M@ ", -" N@O@P@Q@R@S@T@U@V@W@X@Y@Z@Y@`@ #.#p +# ", -" @###$#%#&#*#=#-#;#>#,#'#)#!#~#{#]# ", -" ^#/# ", +" I Q T = ", +" Q 7.e.r.i.8.E E 3.r.6.J ", +" H ~ n 4.r.p.p.p.p.8.R > 5.^ w.,.-.{ v ", +" { 9.^ & P t.p.p.p.p.p.8.I 5 q K L <.;.;.;.-.' ", +" { %.H +.y.p.p.p.p.p.e.Y 2 a n.K F $.*.$.@.} ] N ", +" x D :.y.p.p.p.p.p.p.r.R 8 C.u ..F A ) A Z M h $ ", +" f =.q.p.p.p.p.p.p.p.p.i.( e 6 $.` l B M g ", +" ` ;.q.p.p.p.p.p.a.K.a.p.p.4.L -.` l N % ", +" V =.-.>.q.y.p.p.p.L.L.K.i.w.,.-.;.$.<.q.u.2. ", +" D { =.-.;.>.1.1.9.( h.h.Q &.-.-.-.;.9.p.p.p.r.! ", +" U j.o.-.;.-.;.-.P x.Q.^.R.~ *.-.;.;.>.1.q.y.p.i.2. ", +" H./.! *.;.;.;.o.x./.(.(.(.J.| -.-.;.-.-.;.,.9.u.p.7. ", +" !.(.k.#.;.-.=./ !.(.(.(.(.Q.X.-.;.;.;.;.-.-.;.;.1.w.6. ", +" ~.(.H.G ;.-.D j.(.(.(.(.(.!.O.-.-.;.;.;.-.;.-.;.-.;.,.O. ", +" ~.(.v.@ *.$.+ d.(.(.(.(.(.E.o.-.-.;.;.-.;.;.;.*.=.=.*.$.v ", +" ~.(.l.- Y T ; < (.(.(.(.(.J.&.-.;.;.$.@.[ ] _ ) ) Z B B f ", +" P.(.F.X c.I.X f.(.(.(.(.(.G.=.-.=.] A Z Z Z Z z f $ ", +" l.!.R.s.F.I.g.W.(.(.(.(.R.E .[ A Z Z Z B g $ ", +" . , ; - 0 M.b.V.U.R.Y.z.u n.7 c Z Z B g # + ", +" : w p Z.D.A.S.p u i M.A.A.S.* Z B h z ] C ", +" s D.D.A.A.A.A.A.A.A.i B.B.b A Z Z @.-.` ", +" 1 y C.D.A.A.A.A.A.M.u Z.e c A Z Z [ ;.&. ", +" 8 y d C.A.A.A.C.B.t * B Z Z Z A #.=.m ", +" 3 9 r t r 9 8 o @ $ # f j l B #.V ", +" j k ", " ", " ", " ", -" "}; +" " +}; From b5cc11f7d89afd79779c1fab1b767cdde5f98757 Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sat, 11 Aug 2018 21:44:07 -0400 Subject: [PATCH 032/194] TravisCI: gcc-4.9 is also gone --- .travis.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2f7f1f7..a2a0648c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,20 +57,6 @@ matrix: - gcc-4.8 compiler: gcc-4.8 #gcc-4.8 (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - libsdl2-mixer-dev - - libpng-dev - - libgl1-mesa-dev - - libgme-dev - - p7zip-full - - gcc-4.9 - compiler: gcc-4.9 - #gcc-4.9 (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 - os: linux addons: apt: From 7d3e4f729f6056a6ebb1935a0baae88c294595ee Mon Sep 17 00:00:00 2001 From: Alam Ed Arias Date: Sat, 11 Aug 2018 21:58:57 -0400 Subject: [PATCH 033/194] TravisCI: also remove gcc-6 --- .travis.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index a2a0648c..a9f4ddfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,21 +57,6 @@ matrix: - gcc-4.8 compiler: gcc-4.8 #gcc-4.8 (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5 - - os: linux - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - libsdl2-mixer-dev - - libpng-dev - - libgl1-mesa-dev - - libgme-dev - - p7zip-full - - gcc-6 - compiler: gcc-6 - env: WFLAGS="-Wno-tautological-compare" - #gcc-6 (Ubuntu 6.1.1-3ubuntu11~14.04.1) 6.1.1 20160511 - os: linux addons: apt: From 973b3c3f5eca07cde2a5924524f26bd152fc5d77 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 25 Aug 2018 16:46:45 +0100 Subject: [PATCH 034/194] Continuing my recent streak of making random lighting/colormap-related fixes to long-standing bugs: * Fix that thing where ALL transparent FOF planes were continuously fullbright unless encased in a fog which disables sprite fullbrightness, which was long-hated by many people in the community! * For backwards compatibility, setting flag 1 in that fog field (which is probably the most common "in-the-wild" usage of this feature) will continue to make objects un-fullbright. * For situations where you desperately want the behaviour to be enabled, you can apply fog flag 2. * Change the fadestart and fadeend range in which colormaps are generated. * The problem HERE was that the darkest light level reached by generated colormaps was actually slightly brighter than the darkest level reached by normal colormaps. * The typo I fixed does have SOME basis in fact - standard colormap lumps are 34 (33 in 0-indexing) long rather than 32 (31), but whoever wrote this didn't realise that the code for generating them didn't do it DooM style, just bright-to-dark with no extras on the end... --- src/r_data.c | 22 +++++++++++----------- src/r_plane.c | 4 ++-- src/r_things.c | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index d19882dd..e1d4b893 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1087,7 +1087,7 @@ INT32 R_ColormapNumForName(char *name) extra_colormaps[num_extra_colormaps].fadecolor = 0x0; extra_colormaps[num_extra_colormaps].maskamt = 0x0; extra_colormaps[num_extra_colormaps].fadestart = 0; - extra_colormaps[num_extra_colormaps].fadeend = 33; + extra_colormaps[num_extra_colormaps].fadeend = 31; extra_colormaps[num_extra_colormaps].fog = 0; num_extra_colormaps++; @@ -1115,7 +1115,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) size_t mapnum = num_extra_colormaps; size_t i; UINT32 cr, cg, cb, maskcolor, fadecolor; - UINT32 fadestart = 0, fadeend = 33, fadedist = 33; + UINT32 fadestart = 0, fadeend = 31, fadedist = 31; #define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0) if (p1[0] == '#') @@ -1156,12 +1156,12 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) // Get parameters like fadestart, fadeend, and the fogflag fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10); fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10); - if (fadestart > 32) + if (fadestart > 30) fadestart = 0; - if (fadeend > 33 || fadeend < 1) - fadeend = 33; + if (fadeend > 31 || fadeend < 1) + fadeend = 31; fadedist = fadeend - fadestart; - fog = NUMFROMCHAR(p2[1]) ? 1 : 0; + fog = NUMFROMCHAR(p2[1]); } #undef getnum @@ -1262,7 +1262,7 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) size_t i; char *colormap_p; UINT32 cr, cg, cb, maskcolor, fadecolor; - UINT32 fadestart = 0, fadeend = 33, fadedist = 33; + UINT32 fadestart = 0, fadeend = 31, fadedist = 31; #define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0) if (p1[0] == '#') @@ -1303,12 +1303,12 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) // Get parameters like fadestart, fadeend, and the fogflag fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10); fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10); - if (fadestart > 32) + if (fadestart > 30) fadestart = 0; - if (fadeend > 33 || fadeend < 1) - fadeend = 33; + if (fadeend > 31 || fadeend < 1) + fadeend = 31; fadedist = fadeend - fadestart; - fog = NUMFROMCHAR(p2[1]) ? 1 : 0; + fog = NUMFROMCHAR(p2[1]); } #undef getnum diff --git a/src/r_plane.c b/src/r_plane.c index b7b9eaff..734493eb 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -768,7 +768,7 @@ void R_DrawSinglePlane(visplane_t *pl) else // Opaque, but allow transparent flat pixels spanfunc = splatfunc; - if (pl->extra_colormap && pl->extra_colormap->fog) + if (!pl->extra_colormap || !(pl->extra_colormap->fog & 2)) light = (pl->lightlevel >> LIGHTSEGSHIFT); else light = LIGHTLEVELS-1; @@ -822,7 +822,7 @@ void R_DrawSinglePlane(visplane_t *pl) else // Opaque, but allow transparent flat pixels spanfunc = splatfunc; - if (pl->extra_colormap && pl->extra_colormap->fog) + if (!pl->extra_colormap || !(pl->extra_colormap->fog & 2)) light = (pl->lightlevel >> LIGHTSEGSHIFT); else light = LIGHTLEVELS-1; diff --git a/src/r_things.c b/src/r_things.c index 331febab..0b176416 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1023,7 +1023,7 @@ static void R_SplitSprite(vissprite_t *sprite, mobj_t *thing) else */ if (!((thing->frame & (FF_FULLBRIGHT|FF_TRANSMASK) || thing->flags2 & MF2_SHADOW) - && (!newsprite->extra_colormap || !newsprite->extra_colormap->fog))) + && (!newsprite->extra_colormap || !(newsprite->extra_colormap->fog & 1)))) { lindex = FixedMul(sprite->xscale, FixedDiv(640, vid.width))>>(LIGHTSCALESHIFT); @@ -1324,7 +1324,7 @@ static void R_ProjectSprite(mobj_t *thing) vis->transmap = transtables + (thing->frame & FF_TRANSMASK) - 0x10000; if (((thing->frame & FF_FULLBRIGHT) || (thing->flags2 & MF2_SHADOW)) - && (!vis->extra_colormap || !vis->extra_colormap->fog)) + && (!vis->extra_colormap || !(vis->extra_colormap->fog & 1))) { // full bright: goggles vis->colormap = colormaps; From 91eb248e469f6c9e8180ab0c1cc70310343c7fca Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 25 Aug 2018 17:11:49 +0100 Subject: [PATCH 035/194] Fix up them there ghosts! * Stop orphaning their memory. They ARE PU_LEVEL, so they'll disappear eventually, but, like... it's not good memory management practice to just *orphan* them when you're literally never going to do anything with them ever again. Y'know? * Make ghosts spawn properly on slopes. --- src/g_game.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index bcae69fd..4f1c49b4 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4362,6 +4362,7 @@ void G_GhostTicker(void) p->next = g->next; else ghosts = g->next; + Z_Free(g); continue; } p = g; @@ -5314,29 +5315,28 @@ void G_AddGhost(char *defdemoname) mthing = playerstarts[0]; I_Assert(mthing); { // A bit more complex than P_SpawnPlayer because ghosts aren't solid and won't just push themselves out of the ceiling. - fixed_t x,y,z; - sector_t *sector; - x = mthing->x << FRACBITS; - y = mthing->y << FRACBITS; - sector = R_PointInSubsector(x, y)->sector; + fixed_t z,f,c; + gh->mo = P_SpawnMobj(mthing->x << FRACBITS, mthing->y << FRACBITS, 0, MT_GHOST); + gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT); + f = gh->mo->floorz; + c = gh->mo->ceilingz - mobjinfo[MT_PLAYER].height; if (!!(mthing->options & MTF_AMBUSH) ^ !!(mthing->options & MTF_OBJECTFLIP)) { - z = sector->ceilingheight - mobjinfo[MT_PLAYER].height; + z = c; if (mthing->options >> ZSHIFT) z -= ((mthing->options >> ZSHIFT) << FRACBITS); - if (z < sector->floorheight) - z = sector->floorheight; + if (z < f) + z = f; } else { - z = sector->floorheight; + z = f; if (mthing->options >> ZSHIFT) z += ((mthing->options >> ZSHIFT) << FRACBITS); - if (z > sector->ceilingheight - mobjinfo[MT_PLAYER].height) - z = sector->ceilingheight - mobjinfo[MT_PLAYER].height; + if (z > c) + z = c; } - gh->mo = P_SpawnMobj(x, y, z, MT_GHOST); - gh->mo->angle = FixedAngle(mthing->angle*FRACUNIT); + gh->mo->z = z; } gh->mo->state = states+S_PLAY_STND; gh->mo->sprite = gh->mo->state->sprite; @@ -5534,8 +5534,14 @@ boolean G_CheckDemoStatus(void) { boolean saved; - if(ghosts) // ... ... ... - ghosts = NULL; // :) + while (ghosts) + { + demoghost *next = ghosts->next; + Z_Free(ghosts); + ghosts = next; + } + ghosts = NULL; + // DO NOT end metal sonic demos here From 80ac2366ba31250788c62bd47fb49946f966b296 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 25 Aug 2018 19:52:17 +0100 Subject: [PATCH 036/194] Clean up a bunch of v_video.c functions that previously exhibited unfortunate side effects when run in non-green resolutions. * V_DrawFixedPatch and ilk: * Change the offset of V_FLIP so it's not one screen-pixel off where its non-flipped sprite would have started being drawn from. * Write to x and y as well as desttop so that anti-screen-overflow checks later in the function behave properly with non-green resolutions. * V_DrawFill: * Reduce number of operations performed upon `c`. * V_DrawString and ilk: * Offset the left and right boundary checks in non-green resolutions such that you can actually draw stuff to the left of basevid screen x coordinate 0. --- src/v_video.c | 142 +++++++++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 58 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 161c03d0..7541402a 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -418,7 +418,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t if (scrn & V_FLIP) { flip = true; - x -= FixedMul((SHORT(patch->width) - SHORT(patch->leftoffset))<width) - SHORT(patch->leftoffset))<leftoffset)<>= FRACBITS; y >>= FRACBITS; - desttop += (y*vid.width) + x; // Center it if necessary if (!(scrn & V_SCALEPATCHMASK)) { - if (vid.width != BASEVIDWIDTH * dupx) - { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, - // so center this imaginary screen - if (scrn & V_SNAPTORIGHT) - desttop += (vid.width - (BASEVIDWIDTH * dupx)); - else if (!(scrn & V_SNAPTOLEFT)) - desttop += (vid.width - (BASEVIDWIDTH * dupx)) / 2; - } - if (vid.height != BASEVIDHEIGHT * dupy) - { - // same thing here - if ((scrn & (V_SPLITSCREEN|V_SNAPTOBOTTOM)) == (V_SPLITSCREEN|V_SNAPTOBOTTOM)) - desttop += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)) * vid.width; - else if (scrn & V_SNAPTOBOTTOM) - desttop += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width; - else if (!(scrn & V_SNAPTOTOP)) - desttop += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width / 2; - } // if it's meant to cover the whole screen, black out the rest if (x == 0 && SHORT(patch->width) == BASEVIDWIDTH && y == 0 && SHORT(patch->height) == BASEVIDHEIGHT) { @@ -477,6 +457,27 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t source = (const UINT8 *)(column) + 3; V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } + if (vid.width != BASEVIDWIDTH * dupx) + { + // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // so center this imaginary screen + if (scrn & V_SNAPTORIGHT) + x += (vid.width - (BASEVIDWIDTH * dupx)); + else if (!(scrn & V_SNAPTOLEFT)) + x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + } + if (vid.height != BASEVIDHEIGHT * dupy) + { + // same thing here + if ((scrn & (V_SPLITSCREEN|V_SNAPTOBOTTOM)) == (V_SPLITSCREEN|V_SNAPTOBOTTOM)) + y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)) * vid.width; + else if (scrn & V_SNAPTOBOTTOM) + y += (vid.height - (BASEVIDHEIGHT * dupy)); + else if (!(scrn & V_SNAPTOTOP)) + y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + } + + desttop += (y*vid.width) + x; } } @@ -583,28 +584,10 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ y = FixedMul(y,dupy<>= FRACBITS; y >>= FRACBITS; - desttop += (y*vid.width) + x; // Center it if necessary if (!(scrn & V_SCALEPATCHMASK)) { - if (vid.width != BASEVIDWIDTH * dupx) - { - // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, - // so center this imaginary screen - if (scrn & V_SNAPTORIGHT) - desttop += (vid.width - (BASEVIDWIDTH * dupx)); - else if (!(scrn & V_SNAPTOLEFT)) - desttop += (vid.width - (BASEVIDWIDTH * dupx)) / 2; - } - if (vid.height != BASEVIDHEIGHT * dupy) - { - // same thing here - if (scrn & V_SNAPTOBOTTOM) - desttop += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width; - else if (!(scrn & V_SNAPTOTOP)) - desttop += (vid.height - (BASEVIDHEIGHT * dupy)) * vid.width / 2; - } // if it's meant to cover the whole screen, black out the rest if (x == 0 && SHORT(patch->width) == BASEVIDWIDTH && y == 0 && SHORT(patch->height) == BASEVIDHEIGHT) { @@ -612,7 +595,26 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ source = (const UINT8 *)(column) + 3; V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, (column->topdelta == 0xff ? 31 : source[0])); } + if (vid.width != BASEVIDWIDTH * dupx) + { + // dupx adjustments pretend that screen width is BASEVIDWIDTH * dupx, + // so center this imaginary screen + if (scrn & V_SNAPTORIGHT) + x += (vid.width - (BASEVIDWIDTH * dupx)); + else if (!(scrn & V_SNAPTOLEFT)) + x += (vid.width - (BASEVIDWIDTH * dupx)) / 2; + } + if (vid.height != BASEVIDHEIGHT * dupy) + { + // same thing here + if (scrn & V_SNAPTOBOTTOM) + y += (vid.height - (BASEVIDHEIGHT * dupy)); + else if (!(scrn & V_SNAPTOTOP)) + y += (vid.height - (BASEVIDHEIGHT * dupy)) / 2; + } } + + desttop += (y*vid.width) + x; } for (col = sx<>FRACBITS) < SHORT(patch->width) && (col>>FRACBITS) < w; col += colfrac, ++x, desttop++) @@ -776,7 +778,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) if (x == 0 && y == 0 && w == BASEVIDWIDTH && h == BASEVIDHEIGHT) { // Clear the entire screen, from dest to deststop. Yes, this really works. - memset(screens[0], (UINT8)(c&255), vid.width * vid.height * vid.bpp); + memset(screens[0], (c&255), vid.width * vid.height * vid.bpp); return; } @@ -831,7 +833,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) c &= 255; for (;(--h >= 0) && dest < deststop; dest += vid.width) - memset(dest, (UINT8)(c&255), w * vid.bpp); + memset(dest, c, w * vid.bpp); } // @@ -1129,7 +1131,7 @@ char *V_WordWrap(INT32 x, INT32 w, INT32 option, const char *string) // void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth = BASEVIDWIDTH, center = 0; + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -1145,7 +1147,12 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) scrwidth = vid.width; } else + { dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } charflags = (option & V_CHARCOLORMASK); @@ -1206,9 +1213,9 @@ void V_DrawString(INT32 x, INT32 y, INT32 option, const char *string) else w = SHORT(hu_font[c]->width) * dupx; - if (cx + w > scrwidth) + if (cx > scrwidth) break; - if (cx < 0) //left boundary check + if (cx+left + w < 0) //left boundary check { cx += w; continue; @@ -1239,7 +1246,7 @@ void V_DrawRightAlignedString(INT32 x, INT32 y, INT32 option, const char *string // void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth = BASEVIDWIDTH, center = 0; + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, center = 0, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -1255,7 +1262,12 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) scrwidth = vid.width; } else + { dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } charflags = (option & V_CHARCOLORMASK); @@ -1314,9 +1326,9 @@ void V_DrawSmallString(INT32 x, INT32 y, INT32 option, const char *string) } else w = SHORT(hu_font[c]->width) * dupx / 2; - if (cx + w > scrwidth) + if (cx > scrwidth) break; - if (cx < 0) //left boundary check + if (cx+left + w < 0) //left boundary check { cx += w; continue; @@ -1341,7 +1353,7 @@ void V_DrawRightAlignedSmallString(INT32 x, INT32 y, INT32 option, const char *s // void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth = BASEVIDWIDTH; + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; const char *ch = string; INT32 charflags = 0; const UINT8 *colormap = NULL; @@ -1357,7 +1369,12 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) scrwidth = vid.width; } else + { dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } charflags = (option & V_CHARCOLORMASK); @@ -1414,9 +1431,9 @@ void V_DrawThinString(INT32 x, INT32 y, INT32 option, const char *string) else w = (SHORT(tny_font[c]->width) * dupx); - if (cx + w > scrwidth) + if (cx > scrwidth) break; - if (cx < 0) //left boundary check + if (cx+left + w < 0) //left boundary check { cx += w; continue; @@ -1439,7 +1456,7 @@ void V_DrawRightAlignedThinString(INT32 x, INT32 y, INT32 option, const char *st void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) { fixed_t cx = x, cy = y; - INT32 w, c, dupx, dupy, scrwidth = BASEVIDWIDTH, center = 0; + INT32 w, c, dupx, dupy, scrwidth, center = 0, left = 0; const char *ch = string; INT32 spacewidth = 4, charwidth = 0; @@ -1453,7 +1470,12 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) scrwidth = vid.width; } else + { dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } switch (option & V_SPACINGMASK) { @@ -1507,9 +1529,9 @@ void V_DrawStringAtFixed(fixed_t x, fixed_t y, INT32 option, const char *string) else w = SHORT(hu_font[c]->width) * dupx; - if ((cx>>FRACBITS) + w > scrwidth) + if ((cx>>FRACBITS) > scrwidth) break; - if (cx < 0) //left boundary check + if ((cx>>FRACBITS)+left + w < 0) //left boundary check { cx += w<width) * dupx; - if ((cx>>FRACBITS) + w > scrwidth) + if ((cx>>FRACBITS) > scrwidth) break; V_DrawSciencePatch(cx, cy, option, cred_font[c], FRACUNIT); @@ -1645,7 +1667,7 @@ INT32 V_CreditStringWidth(const char *string) // void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) { - INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth = BASEVIDWIDTH; + INT32 w, c, cx = x, cy = y, dupx, dupy, scrwidth, left = 0; const char *ch = string; if (option & V_NOSCALESTART) @@ -1655,7 +1677,12 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) scrwidth = vid.width; } else + { dupx = dupy = 1; + scrwidth = vid.width/vid.dupx; + left = (scrwidth - BASEVIDWIDTH)/2; + scrwidth -= left; + } for (;;) { @@ -1677,11 +1704,10 @@ void V_DrawLevelTitle(INT32 x, INT32 y, INT32 option, const char *string) } w = SHORT(lt_font[c]->width) * dupx; - if (cx + w > scrwidth) + if (cx > scrwidth) break; + if (cx+left + w < 0) //left boundary check - //left boundary check - if (cx < 0) { cx += w; continue; From 85474e33dd499e868caf513797bf27a10da7b5a0 Mon Sep 17 00:00:00 2001 From: toaster Date: Sat, 25 Aug 2018 21:17:34 +0100 Subject: [PATCH 037/194] Introduce a temporary measure to enable the old stuff, minus one of the most obviously terrible bugbears of yesteryear. Let it be known that any downstream poirt will almost certainly toggle this ASAP. --- src/r_plane.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/r_plane.c b/src/r_plane.c index 734493eb..2c4a1329 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -37,6 +37,9 @@ // Quincunx antialiasing of flats! //#define QUINCUNX +// good night sweet prince +#define SHITPLANESPARENCY + //SoM: 3/23/2000: Use Boom visplane hashing. #define MAXVISPLANES 512 @@ -768,7 +771,11 @@ void R_DrawSinglePlane(visplane_t *pl) else // Opaque, but allow transparent flat pixels spanfunc = splatfunc; +#ifdef SHITPLANESPARENCY + if (spanfunc == splatfunc || (pl->extra_colormap && pl->extra_colormap->fog)) +#else if (!pl->extra_colormap || !(pl->extra_colormap->fog & 2)) +#endif light = (pl->lightlevel >> LIGHTSEGSHIFT); else light = LIGHTLEVELS-1; @@ -822,7 +829,11 @@ void R_DrawSinglePlane(visplane_t *pl) else // Opaque, but allow transparent flat pixels spanfunc = splatfunc; +#ifdef SHITPLANESPARENCY + if (spanfunc == splatfunc || (pl->extra_colormap && pl->extra_colormap->fog)) +#else if (!pl->extra_colormap || !(pl->extra_colormap->fog & 2)) +#endif light = (pl->lightlevel >> LIGHTSEGSHIFT); else light = LIGHTLEVELS-1; From 710550bb9dc3332e20dc3849161d6c1296b68d0e Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 26 Aug 2018 12:38:53 +0100 Subject: [PATCH 038/194] Missed one! --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 7541402a..aa2852c0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -470,7 +470,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t { // same thing here if ((scrn & (V_SPLITSCREEN|V_SNAPTOBOTTOM)) == (V_SPLITSCREEN|V_SNAPTOBOTTOM)) - y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)) * vid.width; + y += (vid.height/2 - (BASEVIDHEIGHT/2 * dupy)); else if (scrn & V_SNAPTOBOTTOM) y += (vid.height - (BASEVIDHEIGHT * dupy)); else if (!(scrn & V_SNAPTOTOP)) From 322da62b3c1eb9bbab46adc344100b13b8fa602b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 31 Aug 2018 17:14:44 +0100 Subject: [PATCH 039/194] Fix HOM removal not working properly for non-green resolutions --- src/r_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index e50e8001..f2a0c889 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1235,9 +1235,9 @@ void R_RenderPlayerView(player_t *player) if (cv_homremoval.value && player == &players[displayplayer]) // if this is display player 1 { if (cv_homremoval.value == 1) - V_DrawFill(0, 0, vid.width, vid.height, 31); // No HOM effect! + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 31); // No HOM effect! else //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. - V_DrawFill(0, 0, vid.width, vid.height, 128+(timeinmap&15)); + V_DrawFill(0, 0, BASEVIDWIDTH, BASEVIDHEIGHT, 128+(timeinmap&15)); } // load previous saved value of skyVisible for the player From c0bf79ad8e8230bb315035f6be7d93d137d3d176 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 9 Sep 2018 22:48:09 +0100 Subject: [PATCH 040/194] R_CreateColormap2 and R_MakeColormaps have been made obsolete, it's just R_CreateColormap now, like it used to be! With that, I moved R_CreateColormap2's exclusive software colormap malloc code to R_CreateColormap, and merged the two software-only blocks of code into one. I also disabled any unneeded variables and fixed a preprocessor-related goofup --- src/p_setup.c | 2 +- src/r_data.c | 88 +++++++++++++++++++++++++++++++++++++++------------ src/r_data.h | 4 +-- 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index d8c913e0..58170e26 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2673,7 +2673,7 @@ boolean P_SetupLevel(boolean skipprecip) P_CreateBlockMap(); // Graue 02-29-2004 P_LoadSideDefs2(lastloadedmaplumpnum + ML_SIDEDEFS); - R_MakeColormaps(); + //R_MakeColormaps(); P_LoadLineDefs2(); P_LoadSubsectors(lastloadedmaplumpnum + ML_SSECTORS); P_LoadNodes(lastloadedmaplumpnum + ML_NODES); diff --git a/src/r_data.c b/src/r_data.c index e1d4b893..2551a294 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1038,8 +1038,8 @@ void R_ReInitColormaps(UINT16 num) static lumpnum_t foundcolormaps[MAXCOLORMAPS]; -static char colormapFixingArray[MAXCOLORMAPS][3][9]; -static size_t carrayindex; +//static char colormapFixingArray[MAXCOLORMAPS][3][9]; +//static size_t carrayindex; // // R_ClearColormaps @@ -1052,7 +1052,7 @@ void R_ClearColormaps(void) num_extra_colormaps = 0; - carrayindex = 0; + //carrayindex = 0; for (i = 0; i < MAXCOLORMAPS; i++) foundcolormaps[i] = LUMPERROR; @@ -1110,7 +1110,7 @@ static int RoundUp(double number); INT32 R_CreateColormap(char *p1, char *p2, char *p3) { double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; - double r, g, b, cbrightness, maskamt = 0, othermask = 0; + double maskamt = 0, othermask = 0; int mask, fog = 0; size_t mapnum = num_extra_colormaps; size_t i; @@ -1163,7 +1163,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) fadedist = fadeend - fadestart; fog = NUMFROMCHAR(p2[1]); } -#undef getnum +#undef NUMFROMCHAR if (p3[0] == '#') { @@ -1194,14 +1194,35 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) if (num_extra_colormaps == MAXCOLORMAPS) I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - strncpy(colormapFixingArray[num_extra_colormaps][0], p1, 8); - strncpy(colormapFixingArray[num_extra_colormaps][1], p2, 8); - strncpy(colormapFixingArray[num_extra_colormaps][2], p3, 8); + //strncpy(colormapFixingArray[num_extra_colormaps][0], p1, 8); + //strncpy(colormapFixingArray[num_extra_colormaps][1], p2, 8); + //strncpy(colormapFixingArray[num_extra_colormaps][2], p3, 8); num_extra_colormaps++; + foundcolormaps[mapnum] = LUMPERROR; + + // aligned on 8 bit for asm code + extra_colormaps[mapnum].colormap = NULL; + extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; + extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; + extra_colormaps[mapnum].maskamt = maskamt; + extra_colormaps[mapnum].fadestart = (UINT16)fadestart; + extra_colormaps[mapnum].fadeend = (UINT16)fadeend; + extra_colormaps[mapnum].fog = fog; + + // This code creates the colormap array used by software renderer if (rendermode == render_soft) { + double r, g, b, cbrightness; + int p; + char *colormap_p; + + // Initialise the map and delta arrays + // map[i] stores an RGB color (as double) for index i, + // which is then converted to SRB2's palette later + // deltas[i] stores a corresponding fade delta between the RGB color and the final fade color; + // map[i]'s values are decremented by after each use for (i = 0; i < 256; i++) { r = pLocalPalette[i].s.red; @@ -1224,22 +1245,48 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) map[i][2] = 255.0l; deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist; } + + // Now allocate memory for the actual colormap array itself! + colormap_p = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8); + extra_colormaps[mapnum].colormap = (UINT8 *)colormap_p; + + // Calculate the palette index for each palette index, for each light level + // (as well as the two unused colormap lines we inherited from Doom) + for (p = 0; p < 34; p++) + { + for (i = 0; i < 256; i++) + { + *colormap_p = NearestColor((UINT8)RoundUp(map[i][0]), + (UINT8)RoundUp(map[i][1]), + (UINT8)RoundUp(map[i][2])); + colormap_p++; + + if ((UINT32)p < fadestart) + continue; +#define ABS2(x) ((x) < 0 ? -(x) : (x)) + if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0])) + map[i][0] -= deltas[i][0]; + else + map[i][0] = cdestr; + + if (ABS2(map[i][1] - cdestg) > ABS2(deltas[i][1])) + map[i][1] -= deltas[i][1]; + else + map[i][1] = cdestg; + + if (ABS2(map[i][2] - cdestb) > ABS2(deltas[i][1])) + map[i][2] -= deltas[i][2]; + else + map[i][2] = cdestb; +#undef ABS2 + } + } } - foundcolormaps[mapnum] = LUMPERROR; - - // aligned on 8 bit for asm code - extra_colormaps[mapnum].colormap = NULL; - extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; - extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; - extra_colormaps[mapnum].maskamt = maskamt; - extra_colormaps[mapnum].fadestart = (UINT16)fadestart; - extra_colormaps[mapnum].fadeend = (UINT16)fadeend; - extra_colormaps[mapnum].fog = fog; - return (INT32)mapnum; } +/* void R_MakeColormaps(void) { size_t i; @@ -1310,7 +1357,7 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) fadedist = fadeend - fadestart; fog = NUMFROMCHAR(p2[1]); } -#undef getnum +#undef NUMFROMCHAR if (p3[0] == '#') { @@ -1419,6 +1466,7 @@ void R_CreateColormap2(char *p1, char *p2, char *p3) return; } +*/ // Thanks to quake2 source! // utils3/qdata/images.c diff --git a/src/r_data.h b/src/r_data.h index 1e9e0eb5..c1f2a73d 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -93,8 +93,8 @@ void R_ReInitColormaps(UINT16 num); void R_ClearColormaps(void); INT32 R_ColormapNumForName(char *name); INT32 R_CreateColormap(char *p1, char *p2, char *p3); -void R_CreateColormap2(char *p1, char *p2, char *p3); -void R_MakeColormaps(void); +//void R_CreateColormap2(char *p1, char *p2, char *p3); +//void R_MakeColormaps(void); const char *R_ColormapNameForNum(INT32 num); extern INT32 numtextures; From 40ff43682971987413b56721d03b5bd8a2daba9a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 10 Sep 2018 15:49:21 +0100 Subject: [PATCH 041/194] Remove commented out stuff, now I've confirmed everything works fine without them --- src/p_setup.c | 1 - src/r_data.c | 191 -------------------------------------------------- src/r_data.h | 2 - 3 files changed, 194 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 58170e26..17a6797f 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2673,7 +2673,6 @@ boolean P_SetupLevel(boolean skipprecip) P_CreateBlockMap(); // Graue 02-29-2004 P_LoadSideDefs2(lastloadedmaplumpnum + ML_SIDEDEFS); - //R_MakeColormaps(); P_LoadLineDefs2(); P_LoadSubsectors(lastloadedmaplumpnum + ML_SSECTORS); P_LoadNodes(lastloadedmaplumpnum + ML_NODES); diff --git a/src/r_data.c b/src/r_data.c index 2551a294..f2c9b146 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1038,9 +1038,6 @@ void R_ReInitColormaps(UINT16 num) static lumpnum_t foundcolormaps[MAXCOLORMAPS]; -//static char colormapFixingArray[MAXCOLORMAPS][3][9]; -//static size_t carrayindex; - // // R_ClearColormaps // @@ -1052,8 +1049,6 @@ void R_ClearColormaps(void) num_extra_colormaps = 0; - //carrayindex = 0; - for (i = 0; i < MAXCOLORMAPS; i++) foundcolormaps[i] = LUMPERROR; @@ -1194,10 +1189,6 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) if (num_extra_colormaps == MAXCOLORMAPS) I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - //strncpy(colormapFixingArray[num_extra_colormaps][0], p1, 8); - //strncpy(colormapFixingArray[num_extra_colormaps][1], p2, 8); - //strncpy(colormapFixingArray[num_extra_colormaps][2], p3, 8); - num_extra_colormaps++; foundcolormaps[mapnum] = LUMPERROR; @@ -1286,188 +1277,6 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) return (INT32)mapnum; } -/* -void R_MakeColormaps(void) -{ - size_t i; - - carrayindex = num_extra_colormaps; - num_extra_colormaps = 0; - - for (i = 0; i < carrayindex; i++) - R_CreateColormap2(colormapFixingArray[i][0], colormapFixingArray[i][1], - colormapFixingArray[i][2]); -} - -void R_CreateColormap2(char *p1, char *p2, char *p3) -{ - double cmaskr, cmaskg, cmaskb, cdestr, cdestg, cdestb; - double r, g, b, cbrightness; - double maskamt = 0, othermask = 0; - int mask, p, fog = 0; - size_t mapnum = num_extra_colormaps; - size_t i; - char *colormap_p; - UINT32 cr, cg, cb, maskcolor, fadecolor; - UINT32 fadestart = 0, fadeend = 31, fadedist = 31; - -#define HEX2INT(x) (UINT32)(x >= '0' && x <= '9' ? x - '0' : x >= 'a' && x <= 'f' ? x - 'a' + 10 : x >= 'A' && x <= 'F' ? x - 'A' + 10 : 0) - if (p1[0] == '#') - { - cr = ((HEX2INT(p1[1]) * 16) + HEX2INT(p1[2])); - cmaskr = cr; - cg = ((HEX2INT(p1[3]) * 16) + HEX2INT(p1[4])); - cmaskg = cg; - cb = ((HEX2INT(p1[5]) * 16) + HEX2INT(p1[6])); - cmaskb = cb; - // Create a rough approximation of the color (a 16 bit color) - maskcolor = ((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11); - if (p1[7] >= 'a' && p1[7] <= 'z') - mask = (p1[7] - 'a'); - else if (p1[7] >= 'A' && p1[7] <= 'Z') - mask = (p1[7] - 'A'); - else - mask = 24; - - maskamt = (double)(mask/24.0l); - - othermask = 1 - maskamt; - maskamt /= 0xff; - cmaskr *= maskamt; - cmaskg *= maskamt; - cmaskb *= maskamt; - } - else - { - cmaskr = cmaskg = cmaskb = 0xff; - maskamt = 0; - maskcolor = ((0xff) >> 3) + (((0xff) >> 2) << 5) + (((0xff) >> 3) << 11); - } - -#define NUMFROMCHAR(c) (c >= '0' && c <= '9' ? c - '0' : 0) - if (p2[0] == '#') - { - // Get parameters like fadestart, fadeend, and the fogflag - fadestart = NUMFROMCHAR(p2[3]) + (NUMFROMCHAR(p2[2]) * 10); - fadeend = NUMFROMCHAR(p2[5]) + (NUMFROMCHAR(p2[4]) * 10); - if (fadestart > 30) - fadestart = 0; - if (fadeend > 31 || fadeend < 1) - fadeend = 31; - fadedist = fadeend - fadestart; - fog = NUMFROMCHAR(p2[1]); - } -#undef NUMFROMCHAR - - if (p3[0] == '#') - { - cdestr = cr = ((HEX2INT(p3[1]) * 16) + HEX2INT(p3[2])); - cdestg = cg = ((HEX2INT(p3[3]) * 16) + HEX2INT(p3[4])); - cdestb = cb = ((HEX2INT(p3[5]) * 16) + HEX2INT(p3[6])); - fadecolor = (((cb) >> 3) + (((cg) >> 2) << 5) + (((cr) >> 3) << 11)); - } - else - cdestr = cdestg = cdestb = fadecolor = 0; -#undef HEX2INT - - for (i = 0; i < num_extra_colormaps; i++) - { - if (foundcolormaps[i] != LUMPERROR) - continue; - if (maskcolor == extra_colormaps[i].maskcolor - && fadecolor == extra_colormaps[i].fadecolor - && (float)maskamt == (float)extra_colormaps[i].maskamt - && fadestart == extra_colormaps[i].fadestart - && fadeend == extra_colormaps[i].fadeend - && fog == extra_colormaps[i].fog) - { - return; - } - } - - if (num_extra_colormaps == MAXCOLORMAPS) - I_Error("R_CreateColormap: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); - - num_extra_colormaps++; - - if (rendermode == render_soft) - { - for (i = 0; i < 256; i++) - { - r = pLocalPalette[i].s.red; - g = pLocalPalette[i].s.green; - b = pLocalPalette[i].s.blue; - cbrightness = sqrt((r*r) + (g*g) + (b*b)); - - map[i][0] = (cbrightness * cmaskr) + (r * othermask); - if (map[i][0] > 255.0l) - map[i][0] = 255.0l; - deltas[i][0] = (map[i][0] - cdestr) / (double)fadedist; - - map[i][1] = (cbrightness * cmaskg) + (g * othermask); - if (map[i][1] > 255.0l) - map[i][1] = 255.0l; - deltas[i][1] = (map[i][1] - cdestg) / (double)fadedist; - - map[i][2] = (cbrightness * cmaskb) + (b * othermask); - if (map[i][2] > 255.0l) - map[i][2] = 255.0l; - deltas[i][2] = (map[i][2] - cdestb) / (double)fadedist; - } - } - - foundcolormaps[mapnum] = LUMPERROR; - - // aligned on 8 bit for asm code - extra_colormaps[mapnum].colormap = NULL; - extra_colormaps[mapnum].maskcolor = (UINT16)maskcolor; - extra_colormaps[mapnum].fadecolor = (UINT16)fadecolor; - extra_colormaps[mapnum].maskamt = maskamt; - extra_colormaps[mapnum].fadestart = (UINT16)fadestart; - extra_colormaps[mapnum].fadeend = (UINT16)fadeend; - extra_colormaps[mapnum].fog = fog; - -#define ABS2(x) ((x) < 0 ? -(x) : (x)) - if (rendermode == render_soft) - { - colormap_p = Z_MallocAlign((256 * 34) + 10, PU_LEVEL, NULL, 8); - extra_colormaps[mapnum].colormap = (UINT8 *)colormap_p; - - for (p = 0; p < 34; p++) - { - for (i = 0; i < 256; i++) - { - *colormap_p = NearestColor((UINT8)RoundUp(map[i][0]), - (UINT8)RoundUp(map[i][1]), - (UINT8)RoundUp(map[i][2])); - colormap_p++; - - if ((UINT32)p < fadestart) - continue; - - if (ABS2(map[i][0] - cdestr) > ABS2(deltas[i][0])) - map[i][0] -= deltas[i][0]; - else - map[i][0] = cdestr; - - if (ABS2(map[i][1] - cdestg) > ABS2(deltas[i][1])) - map[i][1] -= deltas[i][1]; - else - map[i][1] = cdestg; - - if (ABS2(map[i][2] - cdestb) > ABS2(deltas[i][1])) - map[i][2] -= deltas[i][2]; - else - map[i][2] = cdestb; - } - } - } -#undef ABS2 - - return; -} -*/ - // Thanks to quake2 source! // utils3/qdata/images.c static UINT8 NearestColor(UINT8 r, UINT8 g, UINT8 b) diff --git a/src/r_data.h b/src/r_data.h index c1f2a73d..a656e5db 100644 --- a/src/r_data.h +++ b/src/r_data.h @@ -93,8 +93,6 @@ void R_ReInitColormaps(UINT16 num); void R_ClearColormaps(void); INT32 R_ColormapNumForName(char *name); INT32 R_CreateColormap(char *p1, char *p2, char *p3); -//void R_CreateColormap2(char *p1, char *p2, char *p3); -//void R_MakeColormaps(void); const char *R_ColormapNameForNum(INT32 num); extern INT32 numtextures; From d26ba2ee5451bb53bf15384b1ad7af12ecd665ff Mon Sep 17 00:00:00 2001 From: PrisimaTheFox Date: Sun, 9 Sep 2018 23:16:28 -0500 Subject: [PATCH 042/194] Update m_anigif.c More accurate GIF delay. --- src/m_anigif.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 2540665a..5c7cfbd6 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -492,7 +492,9 @@ static void GIF_framewrite(void) // screen regions are handled in GIF_lzw { - UINT16 delay = 3; // todo + int d1 = (int)((100.0/NEWTICRATE)*gif_frames); + int d2 = (int)((100.0/NEWTICRATE)*(gif_frames-1)); + UINT16 delay = d1-d2; INT32 startline; WRITEMEM(p, gifframe_gchead, 4); From 4ada0b0a9e42f5b3b71cf509bc66f7881104b4aa Mon Sep 17 00:00:00 2001 From: PrisimaTheFox Date: Sun, 9 Sep 2018 23:33:51 -0500 Subject: [PATCH 043/194] Update m_anigif.c Remember gif_frames starts at 0 --- src/m_anigif.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index 5c7cfbd6..d46d889b 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -492,8 +492,8 @@ static void GIF_framewrite(void) // screen regions are handled in GIF_lzw { - int d1 = (int)((100.0/NEWTICRATE)*gif_frames); - int d2 = (int)((100.0/NEWTICRATE)*(gif_frames-1)); + int d1 = (int)((100.0/NEWTICRATE)*gif_frames+1); + int d2 = (int)((100.0/NEWTICRATE)*(gif_frames)); UINT16 delay = d1-d2; INT32 startline; From b59aa2710433ca89744f4f9a91eb1e0dba727c6f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 09:37:02 -0400 Subject: [PATCH 044/194] Loose ends other targets (cherry picked from commit 9a5fc5f66a31baf713c6f32f7a696b933da6907b) --- src/android/i_sound.c | 22 ++++----- src/djgppdos/i_sound.c | 28 +---------- src/dummy/i_sound.c | 15 ++---- src/sdl/sdl_sound.c | 6 +-- src/win32/win_main.c | 4 +- src/win32/win_snd.c | 106 +++++++++++++++++++++-------------------- 6 files changed, 74 insertions(+), 107 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index ecf96f2f..1011dbb6 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -64,12 +64,12 @@ void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; } @@ -80,23 +80,19 @@ void I_ResumeSong(INT32 handle) UINT8 midimusic_started = 0; -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -void I_SetMIDIMusicVolume(INT32 volume) -{ - (void)volume; -} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, INT32 looping) +void I_SetMIDIMusicVolume(INT32 volume) +{ + (void)volume; +} + +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 88fc807f..105e8d67 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -408,31 +408,7 @@ void I_ShutdownMIDIMusic(void) music_started=false; } -void I_InitDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_ShutdownDigMusic(void) -{ -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - -void I_InitMusic(void) -{ - if (!nodigimusic) - I_InitDigMusic(); - if (!nomidimusic) - I_InitMIDIMusic(); -} - -void I_ShutdownMusic(void) -{ - I_ShutdownMIDIMusic(); - I_ShutdownDigMusic(); -} - -boolean I_PlaySong(INT32 handle, INT32 looping) +boolean I_PlaySong(boolean looping) { handle = 0; if (nomidimusic) @@ -495,7 +471,7 @@ void I_UnRegisterSong(INT32 handle) //destroy_midi(currsong); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { int e = len; //Alam: For error if (nomidimusic) diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 51dbb610..2f6f0001 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -70,7 +70,7 @@ void I_PauseSong(INT32 handle) (void)handle; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; } @@ -79,23 +79,14 @@ void I_ResumeSong(INT32 handle) // MIDI I/O // -void I_InitMIDIMusic(void){} - -void I_ShutdownMIDIMusic(void){} - -void I_SetMIDIMusicVolume(UINT8 volume) -{ - (void)volume; -} - -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { (void)data; (void)len; return -1; } -boolean I_PlaySong(INT32 handle, boolean looping) +boolean I_PlaySong(boolean looping) { (void)handle; (void)looping; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 6c70c163..c714f675 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1605,7 +1605,7 @@ static void I_PauseGME(void) #endif } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { (void)handle; I_PauseGME(); @@ -1625,7 +1625,7 @@ static void I_ResumeGME(void) #endif } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { (void)handle; I_ResumeGME(); @@ -1669,7 +1669,7 @@ void I_UnRegisterSong(INT32 handle) #endif } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_LoadSong(char *data, size_t len) { #ifdef HAVE_MIXER if (nomidimusic || !musicStarted) diff --git a/src/win32/win_main.c b/src/win32/win_main.c index 6c774f55..bfe620a4 100644 --- a/src/win32/win_main.c +++ b/src/win32/win_main.c @@ -110,9 +110,9 @@ static LRESULT CALLBACK MainWndproc(HWND hWnd, UINT message, WPARAM wParam, LPAR // pause music when alt-tab if (appActive && !paused) - I_ResumeSong(0); + I_ResumeSong(); else if (!paused) - I_PauseSong(0); + I_PauseSong(); { HANDLE ci = GetStdHandle(STD_INPUT_HANDLE); DWORD mode; diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index f168f1fe..18c88d26 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -456,14 +456,14 @@ void I_ShutdownMusic(void) I_ShutdownMIDIMusic(); } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) @@ -644,60 +644,64 @@ boolean I_StartDigSong(const char *musicname, boolean looping) current_track = 0; // Try to find a loop point in streaming music formats (ogg, mp3) - if (looping) - { - FMOD_RESULT e; - FMOD_TAG tag; - unsigned int loopstart, loopend; + FMOD_RESULT e; + FMOD_TAG tag; + unsigned int loopstart, loopend; - // A proper LOOPPOINT is its own tag, stupid. - e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) + // A proper LOOPPOINT is its own tag, stupid. + e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + FMR(e); + loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); + if (loopstart > 0) + FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); + return true; + } + + // todo + // if(music type == MIDI) + // { + // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + // return true; + // } + + // Use LOOPMS for time in miliseconds. + e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + FMR(e); + loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM)); + if (loopstart > 0) + FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM)); + return true; + } + + // Try to fetch it from the COMMENT tag, like A.J. Freda + e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag); + if (e != FMOD_ERR_TAGNOTFOUND) + { + char *loopText; + // Handle any errors that arose, first + FMR(e); + // Figure out where the number starts + loopText = strstr((char *)tag.data,"LOOPPOINT="); + if (loopText != NULL) { - FMR(e); - loopstart = atoi((char *)tag.data); // assumed to be a string data tag. + // Skip the "LOOPPOINT=" part. + loopText += 10; + // Convert it to our looppoint + // FMOD seems to ensure the tag is properly NULL-terminated. + // atoi will stop when it reaches anything that's not a number. + loopstart = atoi(loopText); + // Now do the rest like above FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); if (loopstart > 0) FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); - return true; - } - - // Use LOOPMS for time in miliseconds. - e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) - { - FMR(e); - loopstart = atoi((char *)tag.data); // assumed to be a string data tag. - FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_MS, &loopend, FMOD_TIMEUNIT_PCM)); - if (loopstart > 0) - FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_MS, loopend, FMOD_TIMEUNIT_PCM)); - return true; - } - - // Try to fetch it from the COMMENT tag, like A.J. Freda - e = FMOD_Sound_GetTag(music_stream, "COMMENT", 0, &tag); - if (e != FMOD_ERR_TAGNOTFOUND) - { - char *loopText; - // Handle any errors that arose, first - FMR(e); - // Figure out where the number starts - loopText = strstr((char *)tag.data,"LOOPPOINT="); - if (loopText != NULL) - { - // Skip the "LOOPPOINT=" part. - loopText += 10; - // Convert it to our looppoint - // FMOD seems to ensure the tag is properly NULL-terminated. - // atoi will stop when it reaches anything that's not a number. - loopstart = atoi(loopText); - // Now do the rest like above - FMR(FMOD_Sound_GetLoopPoints(music_stream, NULL, FMOD_TIMEUNIT_PCM, &loopend, FMOD_TIMEUNIT_PCM)); - if (loopstart > 0) - FMR(FMOD_Sound_SetLoopPoints(music_stream, loopstart, FMOD_TIMEUNIT_PCM, loopend, FMOD_TIMEUNIT_PCM)); - } - return true; } + return true; } // No special loop point, but we're playing so it's all good. @@ -825,7 +829,7 @@ void I_SetMIDIMusicVolume(UINT8 volume) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } -INT32 I_RegisterSong(void *data, size_t len) +boolean I_PlaySong(boolean looping) { FMOD_CREATESOUNDEXINFO fmt; memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); From 06b73679414f3c52755ee407833b0d965f0ab761 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:18:38 -0400 Subject: [PATCH 045/194] Added I_GetMusicType and removed midimode variable * Revised S_PlayMusic arguments * Now music plays again! (cherry picked from commit 55f3803e4b9f8104c90cc6c769d54121e5bac0b8) --- src/i_sound.h | 18 +++++++++++++++ src/s_sound.c | 16 +++++++------ src/sdl/mixer_sound.c | 54 +++++++++++++++++++++++++++++++++---------- 3 files changed, 69 insertions(+), 19 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 084479ee..0fe62d5e 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -18,6 +18,21 @@ #include "sounds.h" #include "command.h" +// copied from SDL mixer, plus GME +typedef enum { + MU_NONE, + MU_CMD, + MU_WAV, + MU_MOD, + MU_MID, + MU_OGG, + MU_MP3, + MU_MP3_MAD_UNUSED, // use MU_MP3 instead + MU_FLAC, + MU_MODPLUG_UNUSED, // use MU_MOD instead + MU_GME +} musictype_t; + /** \brief Sound subsystem runing and waiting */ extern UINT8 sound_started; @@ -108,6 +123,9 @@ void I_SetSfxVolume(UINT8 volume); // // MUSIC I/O // + +musictype_t I_GetMusicType(void); + /** \brief Init the music systems */ void I_InitMusic(void); diff --git a/src/s_sound.c b/src/s_sound.c index 76ee4c64..279f0dc6 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1227,7 +1227,7 @@ static boolean S_MIDIMusic(const char *mname, boolean looping) return true; } -static boolean S_DigMusic(const char *mname, boolean looping) +static boolean S_PlayMusic(boolean looping) { if (nodigimusic || digital_disabled) return false; // try midi @@ -1235,11 +1235,6 @@ static boolean S_DigMusic(const char *mname, boolean looping) if (!I_StartDigSong(mname, looping)) return false; - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = LUMPERROR; - music_data = NULL; - music_handle = 0; return true; } @@ -1262,11 +1257,18 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (strncmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music - if (!S_DigMusic(mmusic, looping) && !S_MIDIMusic(mmusic, looping)) + + if (!S_LoadMusic(mmusic)) { CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; } + + if (!S_PlayMusic(looping)) + { + CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); + return; + } } I_SetSongTrack(mflags & MUSIC_TRACKMASK); } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 5211efe0..0888d5d3 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -62,7 +62,6 @@ UINT8 sound_started = false; -static boolean midimode; static Mix_Music *music; static UINT8 music_volume, midi_volume, sfx_volume; static float loop_point; @@ -87,7 +86,6 @@ void I_StartupSound(void) return; } - midimode = false; music = NULL; music_volume = midi_volume = sfx_volume = 0; @@ -436,6 +434,25 @@ void I_SetSfxVolume(UINT8 volume) // Music // +musictype_t I_GetMusicType(void) +{ +#ifdef HAVE_LIBGME + if (gme) + return MU_GME; + else +#endif + if (!music) + return MU_NONE; + else if (Mix_GetMusicType(music) == MUS_MID) + return MU_MID; + else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED) + return MU_MOD; + else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) + return MU_MP3; + else + return (musictype_t)Mix_GetMusicType(music); +} + // Music hooks static void music_loop(void) { @@ -470,8 +487,19 @@ FUNCMATH void I_InitMusic(void) void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(NULL, NULL); + gme_delete(gme); + gme = NULL; + } +#endif + if (!music) + return; + Mix_HookMusicFinished(NULL); + Mix_FreeMusic(music); + music = NULL; } void I_PauseSong(INT32 handle) @@ -492,7 +520,15 @@ void I_ResumeSong(INT32 handle) // Digital Music // -void I_InitDigMusic(void) +void I_SetDigMusicVolume(UINT8 volume) +{ + music_volume = volume; + if (I_GetMusicType() == MU_MID || !music) + return; + Mix_VolumeMusic((UINT32)volume*128/31); +} + +boolean I_SetSongSpeed(float speed) { #ifdef HAVE_LIBGME gme = NULL; @@ -691,8 +727,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) void I_StopDigSong(void) { - if (midimode) - return; #ifdef HAVE_LIBGME if (gme) { @@ -791,7 +825,7 @@ void I_SetMIDIMusicVolume(UINT8 volume) midi_volume = 31; //midi_volume = volume; - if (!midimode || !music) + if (I_GetMusicType() != MU_MID || !music) return; Mix_VolumeMusic((UINT32)midi_volume*128/31); } @@ -834,10 +868,6 @@ void I_StopSong(INT32 handle) void I_UnRegisterSong(INT32 handle) { - if (!midimode || !music) - return; - - (void)handle; Mix_FreeMusic(music); music = NULL; } From 46b53e8baeede0df6c75d93697301a027aeb8a70 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 10:19:04 -0400 Subject: [PATCH 046/194] Added I_GetMusicType and removed midimode variable: other targets (cherry picked from commit 14b393ab16736bb44dab6fd4a90b7bdd8ff782e0) --- src/android/i_sound.c | 24 ++---- src/djgppdos/i_sound.c | 33 ++++----- src/dummy/i_sound.c | 31 ++++---- src/sdl/sdl_sound.c | 98 +++++++++++-------------- src/win32/win_snd.c | 162 +++++++++++++++++++---------------------- 5 files changed, 155 insertions(+), 193 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 1011dbb6..c3fc038e 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -60,6 +60,11 @@ void I_SetSfxVolume(INT32 volume) // UINT8 music_started = 0; +musictype_t I_GetMusicType(void) +{ + return MU_NONE; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} @@ -99,12 +104,12 @@ boolean I_PlaySong(boolean looping) return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -115,19 +120,6 @@ void I_UnRegisterSong(INT32 handle) UINT8 digmusic_started = 0; -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(INT32 volume) { (void)volume; @@ -137,4 +129,4 @@ boolean I_SetSongSpeed(float speed) { (void)speed; return false; -} +} \ No newline at end of file diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 105e8d67..4c8ceb20 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -322,6 +322,13 @@ static int islooping=0; static int musicdies=-1; UINT8 music_started=0; +musictype_t I_GetMusicType(void) +{ + if (currsong) + return MU_MID; + else + return MU_NONE; +} /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to @@ -389,7 +396,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) return midi; } -void I_InitMIDIMusic(void) +void I_InitMusic(void) { if (nomidimusic) return; @@ -398,12 +405,12 @@ void I_InitMIDIMusic(void) music_started = true; } -void I_ShutdownMIDIMusic(void) +void I_ShutdownMusic(void) { if ( !music_started ) return; - I_StopSong(1); + I_StopSong(); music_started=false; } @@ -439,7 +446,7 @@ void I_ResumeSong (INT32 handle) midi_resume(); } -void I_StopSong(INT32 handle) +void I_StopSong(void) { handle = 0; if (nomidimusic) @@ -462,7 +469,7 @@ int I_QrySongPlaying(int handle) } #endif -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { handle = 0; if (nomidimusic) @@ -496,20 +503,6 @@ boolean I_LoadSong(char *data, size_t len) return 1; } -/// \todo Add OGG/MP3 support for dos -boolean I_StartDigSong(const char *musicname, INT32 looping) -{ - musicname = NULL; - looping = 0; - //CONS_Printf("I_StartDigSong: Not yet supported under DOS.\n"); - return false; -} - -void I_StopDigSong(void) -{ -// CONS_Printf("I_StopDigSong: Not yet supported under DOS.\n"); -} - void I_SetDigMusicVolume(INT32 volume) { volume = 0; @@ -524,4 +517,4 @@ boolean I_SetSongSpeed(float speed) { (void)speed; return false; -} +} \ No newline at end of file diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 2f6f0001..60cf51f7 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -61,11 +61,21 @@ void I_SetSfxVolume(UINT8 volume) // MUSIC I/O // +musictype_t I_GetMusicType(void) +{ + return MU_NONE; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_PauseSong(INT32 handle) +void I_SetMIDIMusicVolume(UINT8 volume) +{ + (void)volume; +} + +void I_PauseSong(void) { (void)handle; } @@ -93,12 +103,12 @@ boolean I_PlaySong(boolean looping) return false; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { (void)handle; } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { (void)handle; } @@ -107,19 +117,6 @@ void I_UnRegisterSong(INT32 handle) // DIGMUSIC I/O // -void I_InitDigMusic(void){} - -void I_ShutdownDigMusic(void){} - -boolean I_StartDigSong(const char *musicname, boolean looping) -{ - (void)musicname; - (void)looping; - return false; -} - -void I_StopDigSong(void){} - void I_SetDigMusicVolume(UINT8 volume) { (void)volume; @@ -135,4 +132,4 @@ boolean I_SetSongTrack(int track) { (void)track; return false; -} +} \ No newline at end of file diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index c714f675..b729d4d8 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,10 +1313,27 @@ void I_StartupSound(void) // MUSIC API. // -void I_ShutdownMIDIMusic(void) +musictype_t I_GetMusicType(void) { - nomidimusic = false; - if (nodigimusic) I_ShutdownMusic(); +#ifdef HAVE_MIXER +#ifdef HAVE_LIBGME + if (gme) + return MU_GME; + else +#endif + if (!music) + return MU_NONE; + else if (Mix_GetMusicType(music) == MUS_MID) + return MU_MID; + else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED) + return MU_MOD; + else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) + return MU_MP3; + else + return (musictype_t)Mix_GetMusicType(music); +#else + return MU_NONE +#endif } #ifdef HAVE_LIBGME @@ -1330,12 +1347,6 @@ static void I_ShutdownGMEMusic(void) } #endif -void I_ShutdownDigMusic(void) -{ - nodigimusic = false; - if (nomidimusic) I_ShutdownMusic(); -} - #ifdef HAVE_MIXER static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) { @@ -1436,8 +1447,8 @@ void I_ShutdownMusic(void) CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - I_UnRegisterSong(0); - I_StopDigSong(); + I_UnloadSong(); + I_StopSong(); Mix_CloseAudio(); #ifdef MIX_INIT Mix_Quit(); @@ -1450,16 +1461,6 @@ void I_ShutdownMusic(void) #endif } -void I_InitMIDIMusic(void) -{ - if (nodigimusic) I_InitMusic(); -} - -void I_InitDigMusic(void) -{ - if (nomidimusic) I_InitMusic(); -} - void I_InitMusic(void) { #ifdef HAVE_MIXER @@ -1639,17 +1640,29 @@ void I_ResumeSong(void) #endif } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - (void)handle; + I_StopGME(); #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (nodigimusic) return; - Mix_FadeOutMusic(MIDIfade); + +#ifdef MIXER_POS + if (canlooping) + Mix_HookMusicFinished(NULL); #endif + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[1]) + Mix_FreeMusic(music[1]); + music[1] = NULL; + LoadSong(NULL, 0, 1); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { #ifdef HAVE_MIXER @@ -1714,7 +1727,7 @@ static void I_CleanupGME(void *userdata) static boolean I_StartGMESong(const char *musicname, boolean looping) { #ifdef HAVE_LIBGME - XBOXSTATIC char filename[9]; + char filename[9]; void *data; lumpnum_t lumpnum; size_t lumplength; @@ -1769,7 +1782,7 @@ static boolean I_StartGMESong(const char *musicname, boolean looping) boolean I_StartDigSong(const char *musicname, boolean looping) { #ifdef HAVE_MIXER - XBOXSTATIC char filename[9]; + char filename[9]; void *data; lumpnum_t lumpnum; size_t lumplength; @@ -1786,7 +1799,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) lumpnum = W_CheckNumForName(filename); - I_StopDigSong(); + I_StopSong(); if (lumpnum == LUMPERROR) { @@ -1811,7 +1824,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) { size_t scan; const char *dataum = data; - XBOXSTATIC char looplength[64]; + char looplength[64]; UINT32 loopstart = 0; UINT8 newcount = 0; @@ -1938,29 +1951,6 @@ static void I_StopGME(void) #endif } -void I_StopDigSong(void) -{ - I_StopGME(); -#ifdef HAVE_MIXER - if (nodigimusic) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -#endif -} - void I_SetDigMusicVolume(UINT8 volume) { I_SetMIDIMusicVolume(volume); @@ -1995,4 +1985,4 @@ static void SDLCALL I_FinishMusic(void) if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); } #endif -#endif //HAVE_SDL +#endif //HAVE_SDL \ No newline at end of file diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 18c88d26..295d6868 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -22,12 +22,10 @@ #define HAVE_ZLIB #ifndef _MSC_VER -#ifndef _WII #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE #endif #endif -#endif #ifndef _LFS64_LARGEFILE #define _LFS64_LARGEFILE @@ -44,7 +42,6 @@ static FMOD_SYSTEM *fsys; static FMOD_SOUND *music_stream; static FMOD_CHANNEL *music_channel; -static boolean midimode; static UINT8 music_volume, midi_volume, sfx_volume; static INT32 current_track; @@ -446,14 +443,48 @@ void I_SetSfxVolume(UINT8 volume) // MUSIC // +musictype_t I_GetMusicType(void) +{ +#ifdef HAVE_LIBGME + if (gme) + return MU_GME; +#endif + + if (!music_stream) + return MU_NONE; + + FMOD_SOUND_TYPE type; + if (FMOD_Sound_GetFormat(music_stream, &type, NULL, NULL, NULL) == FMOD_OK) + { + switch(type) + { + case FMOD_SOUND_TYPE_WAV: + return MU_WAV; + case FMOD_SOUND_TYPE_MOD: + return MU_MOD; + case FMOD_SOUND_TYPE_MID: + return MU_MID; + case FMOD_SOUND_TYPE_OGGVORBIS: + return MU_OGG; + case FMOD_SOUND_TYPE_MP3: + return MU_MP3; + case FMOD_SOUND_TYPE_FLAC: + return MU_FLAC; + default: + return MU_NONE; + } + } + else + return MU_NONE; +} + void I_InitMusic(void) { } void I_ShutdownMusic(void) { - I_ShutdownDigMusic(); - I_ShutdownMIDIMusic(); + I_StopSong(); } void I_PauseSong(void) @@ -470,17 +501,7 @@ void I_ResumeSong(void) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); } -void I_InitDigMusic(void) -{ -} - -void I_ShutdownDigMusic(void) -{ - if (!midimode) - I_StopDigSong(); -} - -boolean I_StartDigSong(const char *musicname, boolean looping) +boolean I_LoadSong(char *data, size_t len) { char *data; size_t len; @@ -492,10 +513,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) lumpnum = W_CheckNumForName(va("D_%s",musicname)); if (lumpnum == LUMPERROR) return false; - midimode = true; } - else - midimode = false; data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); len = W_LumpLength(lumpnum); @@ -605,8 +623,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) { gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(data); // We don't need this anymore. - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; @@ -616,32 +632,21 @@ boolean I_StartDigSong(const char *musicname, boolean looping) fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif fmt.length = len; + + FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); + if (e != FMOD_OK) { - FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); - if (e != FMOD_OK) - { - if (e == FMOD_ERR_FORMAT) - CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); - else - FMR(e); - return false; - } + if (e == FMOD_ERR_FORMAT) + CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); + else + FMR(e); + return false; } - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (midimode) - FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - else - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - current_track = 0; // Try to find a loop point in streaming music formats (ogg, mp3) FMOD_RESULT e; @@ -704,28 +709,15 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } - // No special loop point, but we're playing so it's all good. + // No special loop point return true; } -void I_StopDigSong(void) -{ - if (music_stream) - FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; -} - void I_SetDigMusicVolume(UINT8 volume) { // volume is 0 to 31. music_volume = volume; - if (!midimode && music_stream) + if (I_GetMusicType() != MU_MID && music_stream) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } @@ -811,57 +803,55 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_InitMIDIMusic(void) -{ -} - -void I_ShutdownMIDIMusic(void) -{ - if (midimode) - I_StopSong(0); -} - void I_SetMIDIMusicVolume(UINT8 volume) { // volume is 0 to 31. midi_volume = volume; - if (midimode && music_stream) + if (I_GetMusicType() != MU_MID && music_stream) FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); } boolean I_PlaySong(boolean looping) { - FMOD_CREATESOUNDEXINFO fmt; - memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); - fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); - fmt.length = len; - FMR(FMOD_System_CreateStream(fsys, (char *)data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream)); - return 1337; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - if (1337 == handle) +#ifdef HAVE_LIBGME + if (gme) { - midimode = true; - if (looping) - FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); + gme_start_track(gme, 0); + current_track = 0; FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - FMR_MUSIC(FMOD_Channel_SetPriority(music_channel, 0)); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + return true; } +#endif + + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + if (I_GetMusicType() != MU_MID) + FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); + else + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + current_track = 0; + return true; } -void I_StopSong(INT32 handle) +void I_StopSong(void) { - I_UnRegisterSong(handle); +#ifdef HAVE_LIBGME + if (gme) + gme_delete(gme); + gme = NULL; +#endif + current_track = -1; + + I_UnloadSong(); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { UNREFERENCED_PARAMETER(handle); if (music_stream) FMR(FMOD_Sound_Release(music_stream)); music_stream = NULL; -} +} \ No newline at end of file From a7ed7b2c90e5dcc2b342adca4227a33a1432d38d Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:51:23 -0400 Subject: [PATCH 047/194] Consolidate I_SetDigMusicVolume and I_SetMIDIMusicVolume into one method * In s_sound, they are merged to one method as well, but there are still two separate digvolume and seqvolume variables * Simplified Dig/MidiMusicDisabled in s_sound * Method reordering (cherry picked from commit 701cc5a7dd1dfead87a42ec7558c9fa6a1deb193) --- src/d_netcmd.c | 4 +- src/i_sound.h | 47 ++----- src/s_sound.c | 161 +++++++++++++++-------- src/s_sound.h | 28 +++- src/sdl/mixer_sound.c | 298 +++++++++++++++--------------------------- 5 files changed, 242 insertions(+), 296 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index bf26ca61..ab3201c5 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3963,11 +3963,9 @@ static void Command_RestartAudio_f(void) // These must be called or no sound and music until manually set. I_SetSfxVolume(cv_soundvolume.value); - I_SetDigMusicVolume(cv_digmusicvolume.value); - I_SetMIDIMusicVolume(cv_midimusicvolume.value); + S_SetMusicVolume(cv_digmusicvolume.value, cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); - } /** Quits a game and returns to the title screen. diff --git a/src/i_sound.h b/src/i_sound.h index 0fe62d5e..1d4d6ff7 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -140,7 +140,7 @@ void I_ShutdownMusic(void); \return void */ -void I_PauseSong(INT32 handle); +void I_PauseSong(void); /** \brief RESUME game handling @@ -148,20 +148,12 @@ void I_PauseSong(INT32 handle); \return void */ -void I_ResumeSong(INT32 handle); +void I_ResumeSong(void); // // MIDI I/O // -/** \brief Startup the MIDI music system -*/ -void I_InitMIDIMusic(void); - -/** \brief Shutdown the MIDI music system -*/ -void I_ShutdownMIDIMusic(void); - /** \brief The I_SetMIDIMusicVolume function \param volume volume to set at @@ -179,7 +171,7 @@ void I_SetMIDIMusicVolume(UINT8 volume); \todo Remove this */ -INT32 I_RegisterSong(void *data, size_t len); +boolean I_LoadSong(char *data, size_t len); /** \brief Called by anything that wishes to start music @@ -190,7 +182,7 @@ INT32 I_RegisterSong(void *data, size_t len); \todo pass music name, not handle */ -boolean I_PlaySong(INT32 handle, boolean looping); +boolean I_PlaySong(boolean looping); /** \brief Stops a song over 3 seconds @@ -199,46 +191,25 @@ boolean I_PlaySong(INT32 handle, boolean looping); /todo drop handle */ -void I_StopSong(INT32 handle); +void I_StopSong(void); -/** \brief See ::I_RegisterSong, then think backwards +/** \brief See ::I_LoadSong, then think backwards \param handle song handle - \sa I_RegisterSong + \sa I_LoadSong \todo remove midi handle */ -void I_UnRegisterSong(INT32 handle); +void I_UnloadSong(void); // // DIGMUSIC I/O // -/** \brief Startup the music system -*/ -void I_InitDigMusic(void); - -/** \brief Shutdown the music system -*/ -void I_ShutdownDigMusic(void); - boolean I_SetSongSpeed(float speed); boolean I_SetSongTrack(INT32 track); -/** \brief The I_StartDigSong function - - \param musicname music lump name - \param looping if true, loop the song - - \return if true, song playing -*/ -boolean I_StartDigSong(const char *musicname, boolean looping); - -/** \brief stop non-MIDI song -*/ -void I_StopDigSong(void); - /** \brief The I_SetDigMusicVolume function \param volume volume to set at @@ -297,4 +268,4 @@ void I_PlayCD(UINT8 track, UINT8 looping); */ boolean I_SetVolumeCD(INT32 volume); -#endif +#endif \ No newline at end of file diff --git a/src/s_sound.c b/src/s_sound.c index 279f0dc6..a1c53acd 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1180,28 +1180,71 @@ const char *compat_special_music_slots[16] = #define music_playing (music_name[0]) // String is empty if no music is playing static char music_name[7]; // up to 6-character name -static lumpnum_t music_lumpnum; // lump number of music (used??) -static void *music_data; // music raw data -static INT32 music_handle; // once registered, the handle for the music +static boolean mus_paused = 0; // whether songs are mus_paused -static boolean mus_paused = 0; // whether songs are mus_paused +/// ------------------------ +/// Music Status +/// ------------------------ -static boolean S_MIDIMusic(const char *mname, boolean looping) +boolean S_DigMusicDisabled() +{ + return (nodigimusic || digital_disabled); +} + +boolean S_MIDIMusicDisabled() +{ + return (nomidimusic || music_disabled); +} + +boolean S_MusicDisabled() +{ + return ( + (nodigimusic && nomidimusic) || + (music_disabled && digital_disabled) || + (nodigimusic && music_disabled) || + (nomidimusic && digital_disabled) + ); +} + +/// ------------------------ +/// Music Properties +/// ------------------------ + +boolean S_SpeedMusic(float speed) +{ + return I_SetSongSpeed(speed); +} + +/// ------------------------ +/// Music Routines +/// ------------------------ + +static boolean S_LoadMusic(const char *mname) { lumpnum_t mlumpnum; void *mdata; - INT32 mhandle; - if (nomidimusic || music_disabled) - return false; // didn't search. - - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + if (S_MusicDisabled()) return false; - mlumpnum = W_GetNumForName(va("d_%s", mname)); + + if (S_DigMusicDisabled()) + { + if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + return false; + mlumpnum = W_GetNumForName(va("d_%s", mname)); + } + else + { + if (W_CheckNumForName(va("o_%s", mname)) != LUMPERROR) + mlumpnum = W_GetNumForName(va("o_%s", mname)); + else if (W_CheckNumForName(va("d_%s", mname)) != LUMPERROR) + mlumpnum = W_GetNumForName(va("d_%s", mname)); + else + return false; + } // load & register it mdata = W_CacheLumpNum(mlumpnum, PU_MUSIC); - mhandle = I_RegisterSong(mdata, W_LumpLength(mlumpnum)); #ifdef MUSSERV if (msg_id != -1) @@ -1215,16 +1258,20 @@ static boolean S_MIDIMusic(const char *mname, boolean looping) } #endif - // play it - if (!I_PlaySong(mhandle, looping)) + if (I_LoadSong(mdata, W_LumpLength(mlumpnum))) + { + strncpy(music_name, mname, 7); + music_name[6] = 0; + return true; + } + else return false; +} - strncpy(music_name, mname, 7); - music_name[6] = 0; - music_lumpnum = mlumpnum; - music_data = mdata; - music_handle = mhandle; - return true; +static void S_UnloadMusic(void) +{ + I_UnloadSong(); + music_name[0] = 0; } static boolean S_PlayMusic(boolean looping) @@ -1232,9 +1279,13 @@ static boolean S_PlayMusic(boolean looping) if (nodigimusic || digital_disabled) return false; // try midi - if (!I_StartDigSong(mname, looping)) + if (!I_PlaySong(looping)) + { + S_UnloadMusic(); return false; + } + S_InitMusicVolume(); // switch between digi and sequence volume return true; } @@ -1244,7 +1295,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_ClearSfx(); #endif - if ((nomidimusic || music_disabled) && (nodigimusic || digital_disabled)) + if (S_MusicDisabled()) return; // No Music (empty string) @@ -1273,60 +1324,55 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) I_SetSongTrack(mflags & MUSIC_TRACKMASK); } -boolean S_SpeedMusic(float speed) -{ - return I_SetSongSpeed(speed); -} - void S_StopMusic(void) { if (!music_playing) return; if (mus_paused) - I_ResumeSong(music_handle); - - if (!nodigimusic) - I_StopDigSong(); + I_ResumeSong(); S_SpeedMusic(1.0f); - I_StopSong(music_handle); - I_UnRegisterSong(music_handle); + I_StopSong(); + I_UnloadSong(); #ifndef HAVE_SDL //SDL uses RWOPS Z_ChangeTag(music_data, PU_CACHE); #endif - music_data = NULL; music_name[0] = 0; } -void S_SetDigMusicVolume(INT32 volume) +void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) { - if (volume < 0 || volume > 31) - CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); + if (digvolume < 0) + digvolume = cv_digmusicvolume.value; + if (seqvolume < 0) + seqvolume = cv_midimusicvolume.value; - CV_SetValue(&cv_digmusicvolume, volume&31); + if (digvolume < 0 || digvolume > 31) + CONS_Alert(CONS_WARNING, "digmusicvolume should be between 0-31\n"); + CV_SetValue(&cv_digmusicvolume, digvolume&31); actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var -#ifdef DJGPPDOS - I_SetDigMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. -#endif - I_SetDigMusicVolume(volume&31); -} - -void S_SetMIDIMusicVolume(INT32 volume) -{ - if (volume < 0 || volume > 31) - CONS_Alert(CONS_WARNING, "musicvolume should be between 0-31\n"); - - CV_SetValue(&cv_midimusicvolume, volume&0x1f); + if (digvolume < 0 || digvolume > 31) + CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n"); + CV_SetValue(&cv_midimusicvolume, seqvolume&31); actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var #ifdef DJGPPDOS - I_SetMIDIMusicVolume(31); // Trick for buggy dos drivers. Win32 doesn't need this. + digvolume = seqvolume = 31; #endif - I_SetMIDIMusicVolume(volume&0x1f); + + switch(I_GetMusicType()) + { + case MU_MID: + case MU_MOD: + case MU_GME: + I_SetMusicVolume(seqvolume&31); + default: + I_SetMusicVolume(digvolume&31); + } } /// ------------------------ @@ -1346,8 +1392,7 @@ void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) return; S_SetSfxVolume(sfxVolume); - S_SetDigMusicVolume(digMusicVolume); - S_SetMIDIMusicVolume(midiMusicVolume); + S_SetMusicVolume(digMusicVolume, midiMusicVolume); SetChannelsNum(); @@ -1403,11 +1448,11 @@ void S_Start(void) void S_PauseAudio(void) { if (!nodigimusic) - I_PauseSong(0); + I_PauseSong(); if (music_playing && !mus_paused) { - I_PauseSong(music_handle); + I_PauseSong(); mus_paused = true; } @@ -1422,11 +1467,11 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { if (!nodigimusic) - I_ResumeSong(0); + I_ResumeSong(); else if (music_playing && mus_paused) { - I_ResumeSong(music_handle); + I_ResumeSong(); mus_paused = false; } diff --git a/src/s_sound.h b/src/s_sound.h index 39ec769a..bce3ab8b 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -97,6 +97,25 @@ void S_StartSoundAtVolume(const void *origin, sfxenum_t sound_id, INT32 volume); // Stop sound for thing at void S_StopSound(void *origin); +// +// Music Status +// + +boolean S_DigMusicDisabled(); +boolean S_MIDIMusicDisabled(); +boolean S_MusicDisabled(); + +// +// Music Properties +// + +// Set Speed of Music +boolean S_SpeedMusic(float speed); + +// +// Music Routines +// + // Start music track, arbitrary, given its name, and set whether looping // note: music flags 12 bits for tracknum (gme, other formats with more than one track) // 13-15 aren't used yet @@ -104,9 +123,6 @@ void S_StopSound(void *origin); #define S_ChangeMusicInternal(a,b) S_ChangeMusic(a,0,b) void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping); -// Set Speed of Music -boolean S_SpeedMusic(float speed); - // Stops the music. void S_StopMusic(void); @@ -121,9 +137,11 @@ void S_UpdateSounds(void); FUNCMATH fixed_t S_CalculateSoundDistance(fixed_t px1, fixed_t py1, fixed_t pz1, fixed_t px2, fixed_t py2, fixed_t pz2); -void S_SetDigMusicVolume(INT32 volume); -void S_SetMIDIMusicVolume(INT32 volume); void S_SetSfxVolume(INT32 volume); +void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume); +#define S_SetDigMusicVolume(a) S_SetMusicVolume(a,-1) +#define S_SetMIDIMusicVolume(a) S_SetMusicVolume(-1,a) +#define S_InitMusicVolume() S_SetMusicVolume(-1,-1) INT32 S_OriginPlaying(void *origin); INT32 S_IdPlaying(sfxenum_t id); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 0888d5d3..457f74f9 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -483,6 +483,10 @@ static void mix_gme(void *udata, Uint8 *stream, int len) FUNCMATH void I_InitMusic(void) { +#ifdef HAVE_LIBGME + gme = NULL; + current_track = -1; +#endif } void I_ShutdownMusic(void) @@ -502,16 +506,14 @@ void I_ShutdownMusic(void) music = NULL; } -void I_PauseSong(INT32 handle) +void I_PauseSong(void) { - (void)handle; Mix_PauseMusic(); songpaused = true; } -void I_ResumeSong(INT32 handle) +void I_ResumeSong(void) { - (void)handle; Mix_ResumeMusic(); songpaused = false; } @@ -520,59 +522,66 @@ void I_ResumeSong(INT32 handle) // Digital Music // -void I_SetDigMusicVolume(UINT8 volume) -{ - music_volume = volume; - if (I_GetMusicType() == MU_MID || !music) - return; - Mix_VolumeMusic((UINT32)volume*128/31); -} - boolean I_SetSongSpeed(float speed) { -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif -} - -void I_ShutdownDigMusic(void) -{ - if (midimode) - return; + if (speed > 250.0f) + speed = 250.0f; //limit speed up to 250x #ifdef HAVE_LIBGME if (gme) { - Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; + SDL_LockAudio(); + gme_set_tempo(gme, speed); + SDL_UnlockAudio(); + return true; } +#else + (void)speed; #endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; + return false; } -boolean I_StartDigSong(const char *musicname, boolean looping) +boolean I_SetSongTrack(int track) { - char *data; - size_t len; - lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); +#ifdef HAVE_LIBGME + if (current_track == track) + return false; + // If the specified track is within the number of tracks playing, then change it + if (gme) + { + SDL_LockAudio(); + if (track >= 0 + && track < gme_track_count(gme)) + { + gme_err_t gme_e = gme_start_track(gme, track); + if (gme_e != NULL) + { + CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); + return false; + } + current_track = track; + SDL_UnlockAudio(); + return true; + } + SDL_UnlockAudio(); + return false; + } +#endif + (void)track; + return false; +} + +// +// MIDI Music +// + +boolean I_LoadSong(char *data, size_t len) +{ I_Assert(!music); #ifdef HAVE_LIBGME I_Assert(!gme); #endif - if (lumpnum == LUMPERROR) - return false; - midimode = false; - - data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); - len = W_LumpLength(lumpnum); - #ifdef HAVE_LIBGME if ((UINT8)data[0] == 0x1F && (UINT8)data[1] == 0x8B) @@ -663,8 +672,6 @@ boolean I_StartDigSong(const char *musicname, boolean looping) else if (!gme_open_data(data, len, &gme, 44100)) { gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme, &eq); Mix_HookMusic(mix_gme, gme); return true; @@ -675,48 +682,62 @@ boolean I_StartDigSong(const char *musicname, boolean looping) if (!music) { CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); - return true; + return false; } // Find the OGG loop point. loop_point = 0.0f; - if (looping) + + const char *key1 = "LOOP"; + const char *key2 = "POINT="; + const char *key3 = "MS="; + const size_t key1len = strlen(key1); + const size_t key2len = strlen(key2); + const size_t key3len = strlen(key3); + char *p = data; + while ((UINT32)(p - data) < len) { - const char *key1 = "LOOP"; - const char *key2 = "POINT="; - const char *key3 = "MS="; - const size_t key1len = strlen(key1); - const size_t key2len = strlen(key2); - const size_t key3len = strlen(key3); - char *p = data; - while ((UINT32)(p - data) < len) + if (strncmp(p++, key1, key1len)) + continue; + p += key1len-1; // skip OOP (the L was skipped in strncmp) + if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=? { - if (strncmp(p++, key1, key1len)) - continue; - p += key1len-1; // skip OOP (the L was skipped in strncmp) - if (!strncmp(p, key2, key2len)) // is it LOOPPOINT=? - { - p += key2len; // skip POINT= - loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count. - // because SDL_Mixer is USELESS and can't even tell us - // something simple like the frequency of the streaming music, - // we are unfortunately forced to assume that ALL MUSIC is 44100hz. - // This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly. - } - else if (!strncmp(p, key3, key3len)) // is it LOOPMS=? - { - p += key3len; // skip MS= - loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds. - // Everything that uses LOOPMS will work perfectly with SDL_Mixer. - } - // Neither?! Continue searching. + p += key2len; // skip POINT= + loop_point = (float)((44.1L+atoi(p)) / 44100.0L); // LOOPPOINT works by sample count. + // because SDL_Mixer is USELESS and can't even tell us + // something simple like the frequency of the streaming music, + // we are unfortunately forced to assume that ALL MUSIC is 44100hz. + // This means a lot of tracks that are only 22050hz for a reasonable downloadable file size will loop VERY badly. } + else if (!strncmp(p, key3, key3len)) // is it LOOPMS=? + { + p += key3len; // skip MS= + loop_point = (float)(atoi(p) / 1000.0L); // LOOPMS works by real time, as miliseconds. + // Everything that uses LOOPMS will work perfectly with SDL_Mixer. + } + // Neither?! Continue searching. } + return true; +} + +boolean I_PlaySong(boolean looping) +{ + if (!music) + return false; +#ifdef HAVE_GME + if (gme) + { + gme_start_track(gme, 0); + current_track = 0; + return true; + } +#endif + if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) { CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError()); - return true; + return false; } Mix_VolumeMusic((UINT32)music_volume*128/31); @@ -725,7 +746,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; } -void I_StopDigSong(void) +void I_StopSong(void) { #ifdef HAVE_LIBGME if (gme) @@ -744,132 +765,25 @@ void I_StopDigSong(void) music = NULL; } -void I_SetDigMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { - music_volume = volume; - if (midimode || !music) - return; - Mix_VolumeMusic((UINT32)volume*128/31); -} - -boolean I_SetSongSpeed(float speed) -{ - if (speed > 250.0f) - speed = 250.0f; //limit speed up to 250x -#ifdef HAVE_LIBGME - if (gme) - { - SDL_LockAudio(); - gme_set_tempo(gme, speed); - SDL_UnlockAudio(); - return true; - } -#else - (void)speed; -#endif - return false; -} - -boolean I_SetSongTrack(int track) -{ -#ifdef HAVE_LIBGME - if (current_track == track) - return false; - - // If the specified track is within the number of tracks playing, then change it - if (gme) - { - SDL_LockAudio(); - if (track >= 0 - && track < gme_track_count(gme)) - { - gme_err_t gme_e = gme_start_track(gme, track); - if (gme_e != NULL) - { - CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); - return false; - } - current_track = track; - SDL_UnlockAudio(); - return true; - } - SDL_UnlockAudio(); - return false; - } -#endif - (void)track; - return false; -} - -// -// MIDI Music -// - -FUNCMATH void I_InitMIDIMusic(void) -{ -} - -void I_ShutdownMIDIMusic(void) -{ - if (!midimode || !music) - return; - Mix_FreeMusic(music); - music = NULL; -} - -void I_SetMIDIMusicVolume(UINT8 volume) -{ - // HACK: Until we stop using native MIDI, - // disable volume changes - (void)volume; - midi_volume = 31; - //midi_volume = volume; - - if (I_GetMusicType() != MU_MID || !music) - return; - Mix_VolumeMusic((UINT32)midi_volume*128/31); -} - -INT32 I_RegisterSong(void *data, size_t len) -{ - music = Mix_LoadMUS_RW(SDL_RWFromMem(data, len), SDL_FALSE); if (!music) - { - CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); - return -1; - } - return 1337; -} - -boolean I_PlaySong(INT32 handle, boolean looping) -{ - (void)handle; - - midimode = true; - - if (Mix_PlayMusic(music, looping ? -1 : 0) == -1) - { - CONS_Alert(CONS_ERROR, "Mix_PlayMusic: %s\n", Mix_GetError()); - return false; - } - - Mix_VolumeMusic((UINT32)midi_volume*128/31); - return true; -} - -void I_StopSong(INT32 handle) -{ - if (!midimode || !music) return; - (void)handle; - Mix_HaltMusic(); + if (I_GetMusicType() == MU_MID) + // HACK: Until we stop using native MIDI, + // disable volume changes + music_volume = 31; + else + music_volume = volume; + + Mix_VolumeMusic((UINT32)music_volume*128/31); } -void I_UnRegisterSong(INT32 handle) +void I_UnloadSong(void) { Mix_FreeMusic(music); music = NULL; } -#endif +#endif \ No newline at end of file From e58a8f4fe18609531a5eb06e1d1b302b6cf6c197 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 11:54:58 -0400 Subject: [PATCH 048/194] Consolidate I_SetDigMusicVolume and I_SetMIDIMusicVolume other targets (cherry picked from commit 9fb9386f84b3739fe765a78bcb9683eb7e98bc36) --- src/android/i_sound.c | 7 +------ src/djgppdos/i_sound.c | 12 +----------- src/dummy/i_sound.c | 7 +------ src/sdl/sdl_sound.c | 7 +------ src/win32/win_snd.c | 22 ++++++++++------------ 5 files changed, 14 insertions(+), 41 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index c3fc038e..80b90d2f 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -92,7 +92,7 @@ boolean I_LoadSong(char *data, size_t len) return -1; } -void I_SetMIDIMusicVolume(INT32 volume) +void I_SetMusicVolume(INT32 volume) { (void)volume; } @@ -120,11 +120,6 @@ void I_UnloadSong(void) UINT8 digmusic_started = 0; -void I_SetDigMusicVolume(INT32 volume) -{ - (void)volume; -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 4c8ceb20..e66bf8e2 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,7 +140,7 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } -void I_SetMIDIMusicVolume(INT32 volume) +void I_SetMusicVolume(INT32 volume) { if (nomidimusic) return; @@ -503,16 +503,6 @@ boolean I_LoadSong(char *data, size_t len) return 1; } -void I_SetDigMusicVolume(INT32 volume) -{ - volume = 0; - if (nodigimusic) - return; - - // Now set volume on output device. -// CONS_Printf("Digital music not yet supported under DOS.\n"); -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 60cf51f7..f82bf00d 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -70,7 +70,7 @@ void I_InitMusic(void){} void I_ShutdownMusic(void){} -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { (void)volume; } @@ -117,11 +117,6 @@ void I_UnloadSong(void) // DIGMUSIC I/O // -void I_SetDigMusicVolume(UINT8 volume) -{ - (void)volume; -} - boolean I_SetSongSpeed(float speed) { (void)speed; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index b729d4d8..5f92cde1 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1702,7 +1702,7 @@ boolean I_LoadSong(char *data, size_t len) return false; } -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER if ((nomidimusic && nodigimusic) || !musicStarted) @@ -1951,11 +1951,6 @@ static void I_StopGME(void) #endif } -void I_SetDigMusicVolume(UINT8 volume) -{ - I_SetMIDIMusicVolume(volume); -} - boolean I_SetSongSpeed(float speed) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 295d6868..bfa43d08 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -713,14 +713,6 @@ boolean I_LoadSong(char *data, size_t len) return true; } -void I_SetDigMusicVolume(UINT8 volume) -{ - // volume is 0 to 31. - music_volume = volume; - if (I_GetMusicType() != MU_MID && music_stream) - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); -} - boolean I_SetSongSpeed(float speed) { FMOD_RESULT e; @@ -803,12 +795,18 @@ boolean I_SetSongTrack(INT32 track) // Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. // -void I_SetMIDIMusicVolume(UINT8 volume) +void I_SetMusicVolume(UINT8 volume) { + if (!music_stream) + return; + // volume is 0 to 31. - midi_volume = volume; - if (I_GetMusicType() != MU_MID && music_stream) - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, volume / 31.0)); + if (I_GetMusicType() == MU_MID) + music_volume = 31; // windows bug hack + else + music_volume = volume; + + FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); } boolean I_PlaySong(boolean looping) From 011a043dbaaa5706be45f3e900a3d2f031239217 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:30:47 -0400 Subject: [PATCH 049/194] Refactoring, music statues * S_Init -> S_InitSfxChannels because it did mostly SFX anyway * S_MusicPlaying, S_MusicPaused, S_MusicName, S_MusicExists new status methods * I_MusicPlaying, I_MusicPaused (cherry picked from commit f5f0b5e76c2fd405c8cc895dde653c5ed2652622) --- src/d_main.c | 4 +- src/i_sound.h | 2 + src/m_menu.c | 6 +- src/s_sound.c | 182 +++++++++++++++++++++--------------------- src/s_sound.h | 17 ++-- src/sdl/mixer_sound.c | 10 +++ 6 files changed, 121 insertions(+), 100 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index df339875..f2da8586 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1217,7 +1217,7 @@ void D_SRB2Main(void) } else { - CONS_Printf("S_Init(): Setting up sound.\n"); + CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n"); } if (M_CheckParm("-nosound")) nosound = true; @@ -1232,7 +1232,7 @@ void D_SRB2Main(void) } I_StartupSound(); I_InitMusic(); - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); CONS_Printf("ST_Init(): Init status bar.\n"); ST_Init(); diff --git a/src/i_sound.h b/src/i_sound.h index 1d4d6ff7..901e6c28 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -125,6 +125,8 @@ void I_SetSfxVolume(UINT8 volume); // musictype_t I_GetMusicType(void); +boolean I_MusicPlaying(void); +boolean I_MusicPaused(void); /** \brief Init the music systems */ diff --git a/src/m_menu.c b/src/m_menu.c index 79ac6800..82242c0c 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6955,7 +6955,7 @@ static void M_ToggleSFX(void) nosound = false; I_StartupSound(); if (nosound) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } else @@ -6981,7 +6981,7 @@ static void M_ToggleDigital(void) nodigimusic = false; I_InitDigMusic(); if (nodigimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_StopMusic(); S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); @@ -7009,7 +7009,7 @@ static void M_ToggleMIDI(void) nomidimusic = false; I_InitMIDIMusic(); if (nomidimusic) return; - S_Init(cv_soundvolume.value, cv_digmusicvolume.value, cv_midimusicvolume.value); + S_InitSfxChannels(cv_soundvolume.value); S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); } diff --git a/src/s_sound.c b/src/s_sound.c index a1c53acd..e035c419 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1151,6 +1151,43 @@ void S_StartSoundName(void *mo, const char *soundname) S_StartSound(mo, soundnum); } +// +// Initializes sound stuff, including volume +// Sets channels, SFX volume, +// allocates channel buffer, sets S_sfx lookup. +// +void S_InitSfxChannels(INT32 sfxVolume) +{ + INT32 i; + + if (dedicated) + return; + + S_SetSfxVolume(sfxVolume); + + SetChannelsNum(); + + // Note that sounds have not been cached (yet). + for (i = 1; i < NUMSFX; i++) + { + S_sfx[i].usefulness = -1; // for I_GetSfx() + S_sfx[i].lumpnum = LUMPERROR; + } + + // precache sounds if requested by cmdline, or precachesound var true + if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) + { + // Initialize external data (all sounds) at start, keep static. + CONS_Printf(M_GetText("Loading sounds... ")); + + for (i = 1; i < NUMSFX; i++) + if (S_sfx[i].name) + S_sfx[i].data = I_GetSfx(&S_sfx[i]); + + CONS_Printf(M_GetText(" pre-cached all sound data\n")); + } +} + /// ------------------------ /// Music /// ------------------------ @@ -1177,10 +1214,7 @@ const char *compat_special_music_slots[16] = }; #endif -#define music_playing (music_name[0]) // String is empty if no music is playing - static char music_name[7]; // up to 6-character name -static boolean mus_paused = 0; // whether songs are mus_paused /// ------------------------ /// Music Status @@ -1206,6 +1240,29 @@ boolean S_MusicDisabled() ); } +boolean S_MusicPlaying(void) +{ + return I_MusicPlaying(); +} + +boolean S_MusicPaused(void) +{ + return I_MusicPaused(); +} + +const char *S_MusicName(void) +{ + return music_name; +} + +boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) +{ + return ( + (checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false) + || (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false) + ); +} + /// ------------------------ /// Music Properties /// ------------------------ @@ -1229,15 +1286,15 @@ static boolean S_LoadMusic(const char *mname) if (S_DigMusicDisabled()) { - if (W_CheckNumForName(va("d_%s", mname)) == LUMPERROR) + if (!S_MIDIExists(mname)) return false; mlumpnum = W_GetNumForName(va("d_%s", mname)); } else { - if (W_CheckNumForName(va("o_%s", mname)) != LUMPERROR) + if (S_DigExists(mname)) mlumpnum = W_GetNumForName(va("o_%s", mname)); - else if (W_CheckNumForName(va("d_%s", mname)) != LUMPERROR) + else if (S_MIDIExists(mname)) mlumpnum = W_GetNumForName(va("d_%s", mname)); else return false; @@ -1326,10 +1383,10 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) void S_StopMusic(void) { - if (!music_playing) + if (!I_MusicPlaying()) return; - if (mus_paused) + if (I_MusicPaused()) I_ResumeSong(); S_SpeedMusic(1.0f); @@ -1343,6 +1400,31 @@ void S_StopMusic(void) music_name[0] = 0; } +// +// Stop and resume music, during game PAUSE. +// +void S_PauseAudio(void) +{ + if (I_MusicPlaying() && !I_MusicPaused()) + I_PauseSong(); + + // pause cd music +#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) + I_PauseCD(); +#else + I_StopCD(); +#endif +} + +void S_ResumeAudio(void) +{ + if (I_MusicPlaying() && I_MusicPaused()) + I_ResumeSong(); + + // resume cd music + I_ResumeCD(); +} + void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) { if (digvolume < 0) @@ -1355,7 +1437,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) CV_SetValue(&cv_digmusicvolume, digvolume&31); actualdigmusicvolume = cv_digmusicvolume.value; //check for change of var - if (digvolume < 0 || digvolume > 31) + if (seqvolume < 0 || seqvolume > 31) CONS_Alert(CONS_WARNING, "midimusicvolume should be between 0-31\n"); CV_SetValue(&cv_midimusicvolume, seqvolume&31); actualmidimusicvolume = cv_midimusicvolume.value; //check for change of var @@ -1375,52 +1457,11 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) } } + /// ------------------------ /// Init & Others /// ------------------------ -// -// Initializes sound stuff, including volume -// Sets channels, SFX and music volume, -// allocates channel buffer, sets S_sfx lookup. -// -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume) -{ - INT32 i; - - if (dedicated) - return; - - S_SetSfxVolume(sfxVolume); - S_SetMusicVolume(digMusicVolume, midiMusicVolume); - - SetChannelsNum(); - - // no sounds are playing, and they are not mus_paused - mus_paused = 0; - - // Note that sounds have not been cached (yet). - for (i = 1; i < NUMSFX; i++) - { - S_sfx[i].usefulness = -1; // for I_GetSfx() - S_sfx[i].lumpnum = LUMPERROR; - } - - // precache sounds if requested by cmdline, or precachesound var true - if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) - { - // Initialize external data (all sounds) at start, keep static. - CONS_Printf(M_GetText("Loading sounds... ")); - - for (i = 1; i < NUMSFX; i++) - if (S_sfx[i].name) - S_sfx[i].data = I_GetSfx(&S_sfx[i]); - - CONS_Printf(M_GetText(" pre-cached all sound data\n")); - } -} - - // // Per level startup code. // Kills playing sounds at start of level, @@ -1435,46 +1476,7 @@ void S_Start(void) mapmusflags = (mapheaderinfo[gamemap-1]->mustrack & MUSIC_TRACKMASK); } - mus_paused = 0; - if (cv_resetmusic.value) S_StopMusic(); S_ChangeMusic(mapmusname, mapmusflags, true); } - -// -// Stop and resume music, during game PAUSE. -// -void S_PauseAudio(void) -{ - if (!nodigimusic) - I_PauseSong(); - - if (music_playing && !mus_paused) - { - I_PauseSong(); - mus_paused = true; - } - - // pause cd music -#if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) || defined (HAVE_SDL) - I_PauseCD(); -#else - I_StopCD(); -#endif -} - -void S_ResumeAudio(void) -{ - if (!nodigimusic) - I_ResumeSong(); - else - if (music_playing && mus_paused) - { - I_ResumeSong(); - mus_paused = false; - } - - // resume cd music - I_ResumeCD(); -} diff --git a/src/s_sound.h b/src/s_sound.h index bce3ab8b..9a3f2805 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -69,9 +69,9 @@ void S_RegisterSoundStuff(void); // // Initializes sound stuff, including volume -// Sets channels, SFX and music volume, allocates channel buffer, sets S_sfx lookup. +// Sets channels, SFX, allocates channel buffer, sets S_sfx lookup. // -void S_Init(INT32 sfxVolume, INT32 digMusicVolume, INT32 midiMusicVolume); +void S_InitSfxChannels(INT32 sfxVolume); // // Per level startup code. @@ -101,9 +101,16 @@ void S_StopSound(void *origin); // Music Status // -boolean S_DigMusicDisabled(); -boolean S_MIDIMusicDisabled(); -boolean S_MusicDisabled(); +boolean S_DigMusicDisabled(void); +boolean S_MIDIMusicDisabled(void); +boolean S_MusicDisabled(void); +boolean S_MusicPlaying(void); +boolean S_MusicPaused(void); +const char *S_MusicName(void); +boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); +#define S_DigExists(a) S_MusicExists(a, false, true) +#define S_MIDIExists(a) S_MusicExists(a, true, false) + // // Music Properties diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 457f74f9..1384f1da 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -453,6 +453,16 @@ musictype_t I_GetMusicType(void) return (musictype_t)Mix_GetMusicType(music); } +boolean I_MusicPlaying(void) +{ + return (boolean)music; +} + +boolean I_MusicPaused(void) +{ + return songpaused; +} + // Music hooks static void music_loop(void) { From 44557d9c9d6b6ea3df722987bf778f847193db90 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:31:01 -0400 Subject: [PATCH 050/194] I_MusicPlaying, I_MusicPaused other targets (cherry picked from commit d5ec38815968e267aceb59a48a6cb6d3292c0b69) --- src/android/i_sound.c | 10 ++++++++++ src/djgppdos/i_sound.c | 17 +++++++++++++++-- src/dummy/i_sound.c | 10 ++++++++++ src/sdl/sdl_sound.c | 10 ++++++++++ src/win32/win_snd.c | 13 +++++++++++++ 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 80b90d2f..1cbc53fa 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -65,6 +65,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index e66bf8e2..6e351b52 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -321,6 +321,7 @@ static MIDI* currsong; //im assuming only 1 song will be played at once static int islooping=0; static int musicdies=-1; UINT8 music_started=0; +boolean songpaused=false; musictype_t I_GetMusicType(void) { @@ -330,6 +331,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying() +{ + return (boolean)currsong; +} + +boolean I_MusicPaused() +{ + return songpaused; +} + /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to * a MIDI structure, * or NULL on error. @@ -403,6 +414,7 @@ void I_InitMusic(void) I_AddExitFunc(I_ShutdownMusic); music_started = true; + songpaused = false; } void I_ShutdownMusic(void) @@ -433,8 +445,8 @@ void I_PauseSong (INT32 handle) handle = 0; if (nomidimusic) return; - midi_pause(); + songpaused = true; } void I_ResumeSong (INT32 handle) @@ -442,8 +454,8 @@ void I_ResumeSong (INT32 handle) handle = 0; if (nomidimusic) return; - midi_resume(); + songpaused = false; } void I_StopSong(void) @@ -455,6 +467,7 @@ void I_StopSong(void) islooping = 0; musicdies = 0; stop_midi(); + songpaused = false; } // Is the song playing? diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index f82bf00d..ca90a7da 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -66,6 +66,16 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + void I_InitMusic(void){} void I_ShutdownMusic(void){} diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 5f92cde1..d8d3e0a9 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1336,6 +1336,16 @@ musictype_t I_GetMusicType(void) #endif } +boolean I_MusicPlaying(void) +{ + return music_started; +} + +boolean I_MusicPaused(void) +{ + return Mix_PausedMusic(); +} + #ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index bfa43d08..c6a74d99 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -478,6 +478,19 @@ musictype_t I_GetMusicType(void) return MU_NONE; } +boolean I_MusicPlaying(void) +{ + return (boolean)music_stream; +} + +boolean I_MusicPaused(void) +{ + boolean fmpaused = false; + if (music_stream) + FMOD_Channel_GetPaused(music_channel, &fmpaused); + return fmpaused; +} + void I_InitMusic(void) { } From a414ccf24ae6b59b1945cb0b9177bfaebbfb334e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:42:15 -0400 Subject: [PATCH 051/194] nodigimusic nomusic nosound -> digital_disabled midi_disabled sound_disabled (cherry picked from commit 07738fb0bcf640a4349337373f451fe68e024b2a) --- src/d_main.c | 26 ++++++++++----------- src/doomstat.h | 5 +--- src/m_menu.c | 62 ++++++++++++++++++++------------------------------ src/p_mobj.c | 2 +- src/s_sound.c | 27 +++++++++------------- 5 files changed, 51 insertions(+), 71 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index f2da8586..ed1b4468 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -122,17 +122,17 @@ postimg_t postimgtype2 = postimg_none; INT32 postimgparam2; #ifdef _XBOX -boolean nomidimusic = true, nosound = true; -boolean nodigimusic = true; +boolean midi_disabled = true, sound_disabled = true; +boolean digital_disabled = true; #else -boolean nomidimusic = false, nosound = false; -boolean nodigimusic = false; // No fmod-based music +boolean midi_disabled = false, sound_disabled = false; +boolean digital_disabled = false; // No fmod-based music #endif // These variables are only true if -// the respective sound system is initialized -// and active, but no sounds/music should play. -boolean music_disabled = false; +// whether the respective sound system is disabled +// or they're init'ed, but the player just toggled them +boolean midi_disabled = false; boolean sound_disabled = false; boolean digital_disabled = false; @@ -1212,23 +1212,23 @@ void D_SRB2Main(void) // setting up sound if (dedicated) { - nosound = true; - nomidimusic = nodigimusic = true; + sound_disabled = true; + midi_disabled = digital_disabled = true; } else { CONS_Printf("S_InitSfxChannels(): Setting up sound channels.\n"); } if (M_CheckParm("-nosound")) - nosound = true; + sound_disabled = true; if (M_CheckParm("-nomusic")) // combines -nomidimusic and -nodigmusic - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; else { if (M_CheckParm("-nomidimusic")) - nomidimusic = true; ; // WARNING: DOS version initmusic in I_StartupSound + midi_disabled = true; ; // WARNING: DOS version initmusic in I_StartupSound if (M_CheckParm("-nodigmusic")) - nodigimusic = true; // WARNING: DOS version initmusic in I_StartupSound + digital_disabled = true; // WARNING: DOS version initmusic in I_StartupSound } I_StartupSound(); I_InitMusic(); diff --git a/src/doomstat.h b/src/doomstat.h index 8072a155..27bd3fa1 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -85,10 +85,7 @@ extern boolean fromlevelselect; // Internal parameters for sound rendering. // ======================================== -extern boolean nomidimusic; // defined in d_main.c -extern boolean nosound; -extern boolean nodigimusic; -extern boolean music_disabled; +extern boolean midi_disabled; extern boolean sound_disabled; extern boolean digital_disabled; diff --git a/src/m_menu.c b/src/m_menu.c index 82242c0c..7a5e78a7 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6950,11 +6950,11 @@ static void M_ChangeControl(INT32 choice) // Toggles sound systems in-game. static void M_ToggleSFX(void) { - if (nosound) + if (sound_disabled) { - nosound = false; + sound_disabled = false; I_StartupSound(); - if (nosound) return; + if (sound_disabled) return; S_InitSfxChannels(cv_soundvolume.value); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } @@ -6976,56 +6976,44 @@ static void M_ToggleSFX(void) static void M_ToggleDigital(void) { - if (nodigimusic) + if (digital_disabled) { - nodigimusic = false; - I_InitDigMusic(); - if (nodigimusic) return; - S_InitSfxChannels(cv_soundvolume.value); + digital_disabled = false; + I_InitMusic(); + if (digital_disabled) return; S_StopMusic(); - S_ChangeMusicInternal("lclear", false); + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); } else { - if (digital_disabled) - { - digital_disabled = false; - M_StartMessage(M_GetText("Digital Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - digital_disabled = true; - S_StopMusic(); - M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); - } + digital_disabled = true; + S_StopMusic(); + M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } static void M_ToggleMIDI(void) { - if (nomidimusic) + if (midi_disabled) { - nomidimusic = false; - I_InitMIDIMusic(); - if (nomidimusic) return; - S_InitSfxChannels(cv_soundvolume.value); - S_ChangeMusicInternal("lclear", false); + midi_disabled = false; + I_InitMusic(); + if (midi_disabled) return; + if (Playing()) + P_RestoreMusic(&players[consoleplayer]); + else + S_ChangeMusicInternal("lclear", false); M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); } else { - if (music_disabled) - { - music_disabled = false; - M_StartMessage(M_GetText("MIDI Music Enabled\n"), NULL, MM_NOTHING); - } - else - { - music_disabled = true; - S_StopMusic(); - M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); - } + midi_disabled = true; + S_StopMusic(); + M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/p_mobj.c b/src/p_mobj.c index 5f85474c..a55e5de2 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -8228,7 +8228,7 @@ void P_PrecipitationEffects(void) if (!playeringame[displayplayer] || !players[displayplayer].mo) return; - if (nosound || sound_disabled) + if (sound_disabled) return; // Sound off? D'aw, no fun. if (players[displayplayer].mo->subsector->sector->ceilingpic == skyflatnum) diff --git a/src/s_sound.c b/src/s_sound.c index e035c419..d1993bc8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -226,7 +226,7 @@ void S_RegisterSoundStuff(void) { if (dedicated) { - nosound = true; + sound_disabled = true; return; } @@ -400,7 +400,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) mobj_t *listenmobj = players[displayplayer].mo; mobj_t *listenmobj2 = NULL; - if (sound_disabled || !sound_started || nosound) + if (sound_disabled || !sound_started) return; // Don't want a sound? Okay then... @@ -716,7 +716,7 @@ void S_UpdateSounds(void) return; } - if (dedicated || nosound) + if (dedicated || sound_disabled) return; if (players[displayplayer].awayviewtics) @@ -1175,7 +1175,7 @@ void S_InitSfxChannels(INT32 sfxVolume) } // precache sounds if requested by cmdline, or precachesound var true - if (!nosound && (M_CheckParm("-precachesound") || precachesound.value)) + if (!sound_disabled && (M_CheckParm("-precachesound") || precachesound.value)) { // Initialize external data (all sounds) at start, keep static. CONS_Printf(M_GetText("Loading sounds... ")); @@ -1220,24 +1220,19 @@ static char music_name[7]; // up to 6-character name /// Music Status /// ------------------------ -boolean S_DigMusicDisabled() +boolean S_DigMusicDisabled(void) { - return (nodigimusic || digital_disabled); + return digital_disabled; } -boolean S_MIDIMusicDisabled() +boolean S_MIDIMusicDisabled(void) { - return (nomidimusic || music_disabled); + return midi_disabled; } -boolean S_MusicDisabled() +boolean S_MusicDisabled(void) { - return ( - (nodigimusic && nomidimusic) || - (music_disabled && digital_disabled) || - (nodigimusic && music_disabled) || - (nomidimusic && digital_disabled) - ); + return (midi_disabled && digital_disabled); } boolean S_MusicPlaying(void) @@ -1333,7 +1328,7 @@ static void S_UnloadMusic(void) static boolean S_PlayMusic(boolean looping) { - if (nodigimusic || digital_disabled) + if (S_DigMusicDisabled()) return false; // try midi if (!I_PlaySong(looping)) From 17cf310b84ebeaa096b2172f55bb9a2fb5494e08 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:43:38 -0400 Subject: [PATCH 052/194] nodigimusic nomusic nosound refactor other targets (cherry picked from commit 86f151db654beb14e8d6893cdff2adaa965e8e4b) --- src/djgppdos/i_sound.c | 38 +++++++++++++++++----------------- src/hardware/hw3sound.c | 2 +- src/sdl/sdl_sound.c | 46 ++++++++++++++++++++--------------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 6e351b52..d998016a 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -134,7 +134,7 @@ FUNCINLINE static ATTRINLINE int Volset(int vol) void I_SetSfxVolume(INT32 volume) { - if (nosound) + if (sound_disabled) return; set_volume (Volset(volume),-1); @@ -142,7 +142,7 @@ void I_SetSfxVolume(INT32 volume) void I_SetMusicVolume(INT32 volume) { - if (nomidimusic) + if (midi_disabled) return; // Now set volume on output device. @@ -169,7 +169,7 @@ INT32 I_StartSound ( sfxenum_t id, { int voice; - if (nosound) + if (sound_disabled) return 0; // UNUSED @@ -190,7 +190,7 @@ void I_StopSound (INT32 handle) // an setting the channel to zero. int voice=handle & (VIRTUAL_VOICES-1); - if (nosound) + if (sound_disabled) return; if (voice_check(voice)==S_sfx[handle>>VOICESSHIFT].data) @@ -199,7 +199,7 @@ void I_StopSound (INT32 handle) INT32 I_SoundIsPlaying(INT32 handle) { - if (nosound) + if (sound_disabled) return FALSE; if (voice_check(handle & (VIRTUAL_VOICES-1))==S_sfx[handle>>VOICESSHIFT].data) @@ -229,7 +229,7 @@ void I_UpdateSoundParams( INT32 handle, int voice=handle & (VIRTUAL_VOICES-1); int numsfx=handle>>VOICESSHIFT; - if (nosound) + if (sound_disabled) return; if (voice_check(voice)==S_sfx[numsfx].data) @@ -270,17 +270,17 @@ void I_StartupSound(void) char err[255]; #endif - if (nosound) + if (sound_disabled) sfxcard=DIGI_NONE; else sfxcard=DIGI_AUTODETECT; - if (nomidimusic) + if (midi_disabled) midicard=MIDI_NONE; else midicard=MIDI_AUTODETECT; //DetectMusicCard(); - nodigimusic=true; //Alam: No OGG/MP3/IT/MOD support + digital_disabled=true; //Alam: No OGG/MP3/IT/MOD support // Secure and configure sound device first. CONS_Printf("I_StartupSound: "); @@ -293,8 +293,8 @@ void I_StartupSound(void) { sprintf (err,"Sound init error : %s\n",allegro_error); CONS_Error (err); - nosound=true; - nomidimusic=true; + sound_disabled=true; + midi_disabled=true; } else { @@ -409,7 +409,7 @@ static MIDI *load_midi_mem(char *mempointer,int *e) void I_InitMusic(void) { - if (nomidimusic) + if (midi_disabled) return; I_AddExitFunc(I_ShutdownMusic); @@ -430,7 +430,7 @@ void I_ShutdownMusic(void) boolean I_PlaySong(boolean looping) { handle = 0; - if (nomidimusic) + if (midi_disabled) return false; islooping = looping; @@ -443,7 +443,7 @@ boolean I_PlaySong(boolean looping) void I_PauseSong (INT32 handle) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; midi_pause(); songpaused = true; @@ -452,7 +452,7 @@ void I_PauseSong (INT32 handle) void I_ResumeSong (INT32 handle) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; midi_resume(); songpaused = false; @@ -461,7 +461,7 @@ void I_ResumeSong (INT32 handle) void I_StopSong(void) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; islooping = 0; @@ -474,7 +474,7 @@ void I_StopSong(void) #if 0 int I_QrySongPlaying(int handle) { - if (nomidimusic) + if (midi_disabled) return 0; //return islooping || musicdies > gametic; @@ -485,7 +485,7 @@ int I_QrySongPlaying(int handle) void I_UnloadSong(void) { handle = 0; - if (nomidimusic) + if (midi_disabled) return; //destroy_midi(currsong); @@ -494,7 +494,7 @@ void I_UnloadSong(void) boolean I_LoadSong(char *data, size_t len) { int e = len; //Alam: For error - if (nomidimusic) + if (midi_disabled) return 0; if (memcmp(data,"MThd",4)==0) // support mid file in WAD !!! diff --git a/src/hardware/hw3sound.c b/src/hardware/hw3sound.c index c6843092..f7c6e1da 100644 --- a/src/hardware/hw3sound.c +++ b/src/hardware/hw3sound.c @@ -361,7 +361,7 @@ INT32 HW3S_I_StartSound(const void *origin_p, source3D_data_t *source_parm, chan if (splitscreen) listenmobj2 = players[secondarydisplayplayer].mo; - if (nosound) + if (sound_disabled) return -1; sfx = &S_sfx[sfx_id]; diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index d8d3e0a9..cf54d7d0 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -194,8 +194,8 @@ static srb2audio_t localdata; static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio callback { if (Snd_Mutex) SDL_LockMutex(Snd_Mutex); - else if (nosound) return; - else if (nomidimusic && nodigimusic + else if (sound_disabled) return; + else if (midi_disabled && digital_disabled #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE #endif @@ -208,8 +208,8 @@ static void Snd_LockAudio(void) //Alam: Lock audio data and uninstall audio call static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio callback { if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); - else if (nosound) return; - else if (nomidimusic && nodigimusic + else if (sound_disabled) return; + else if (midi_disabled && digital_disabled #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE #endif @@ -493,7 +493,7 @@ static inline void I_SetChannels(void) INT32 *steptablemid = steptable + 128; - if (nosound) + if (sound_disabled) return; // This table provides step widths for pitch parameters. @@ -609,7 +609,7 @@ INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priori (void)priority; (void)pitch; - if (nosound) + if (sound_disabled) return 0; if (S_sfx[id].data == NULL) return -1; @@ -1136,7 +1136,7 @@ static INT32 Init3DSDriver(const char *soName) void I_ShutdownSound(void) { - if (nosound || !sound_started) + if (sound_disabled || !sound_started) return; CONS_Printf("I_ShutdownSound: "); @@ -1150,7 +1150,7 @@ void I_ShutdownSound(void) } #endif - if (nomidimusic && nodigimusic) + if (midi_disabled && digital_disabled) SDL_CloseAudio(); CONS_Printf("%s", M_GetText("shut down\n")); sound_started = false; @@ -1170,7 +1170,7 @@ void I_StartupSound(void) const char *sdrv_name = NULL; #endif #ifndef HAVE_MIXER - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; #endif memset(channels, 0, sizeof (channels)); //Alam: Clean it @@ -1213,7 +1213,7 @@ void I_StartupSound(void) audio.samples /= 2; } - if (nosound) + if (sound_disabled) return; #ifdef HW3SOUND @@ -1261,7 +1261,7 @@ void I_StartupSound(void) { snddev_t snddev; - //nosound = true; + //sound_disabled = true; //I_AddExitFunc(I_ShutdownSound); snddev.bps = 16; snddev.sample_rate = audio.freq; @@ -1288,7 +1288,7 @@ void I_StartupSound(void) if (!musicStarted && SDL_OpenAudio(&audio, &audio) < 0) { CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - nosound = true; + sound_disabled = true; return; } else @@ -1452,7 +1452,7 @@ static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) void I_ShutdownMusic(void) { #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); @@ -1543,7 +1543,7 @@ void I_InitMusic(void) if (Mix_OpenAudio(audio.freq, audio.format, audio.channels, audio.samples) < 0) //open_music(&audio) { CONS_Printf(M_GetText(" Unable to open music: %s\n"), Mix_GetError()); - nomidimusic = nodigimusic = true; + midi_disabled = digital_disabled = true; if (sound_started #ifdef HW3SOUND && hws_mode == HWS_DEFAULT_MODE @@ -1553,7 +1553,7 @@ void I_InitMusic(void) if (SDL_OpenAudio(&audio, NULL) < 0) //retry { CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - nosound = true; + sound_disabled = true; sound_started = false; } else @@ -1588,7 +1588,7 @@ boolean I_PlaySong(INT32 handle, boolean looping) { (void)handle; #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted || !music[handle]) + if (midi_disabled || !musicStarted || !music[handle]) return false; #ifdef MIXER_POS @@ -1621,7 +1621,7 @@ void I_PauseSong(void) (void)handle; I_PauseGME(); #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; Mix_PauseMusic(); @@ -1641,7 +1641,7 @@ void I_ResumeSong(void) (void)handle; I_ResumeGME(); #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; Mix_VolumeMusic(musicvol); @@ -1654,7 +1654,7 @@ void I_StopSong(void) { I_StopGME(); #ifdef HAVE_MIXER - if (nodigimusic) + if (digital_disabled) return; #ifdef MIXER_POS @@ -1676,7 +1676,7 @@ void I_UnloadSong(void) { #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (midi_disabled || !musicStarted) return; Mix_HaltMusic(); @@ -1695,7 +1695,7 @@ void I_UnloadSong(void) boolean I_LoadSong(char *data, size_t len) { #ifdef HAVE_MIXER - if (nomidimusic || !musicStarted) + if (midi_disabled || !musicStarted) return false; if (!LoadSong(data, len, 0)) @@ -1715,7 +1715,7 @@ boolean I_LoadSong(char *data, size_t len) void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER - if ((nomidimusic && nodigimusic) || !musicStarted) + if ((midi_disabled && digital_disabled) || !musicStarted) return; if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); @@ -1802,7 +1802,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) return true; #ifdef HAVE_MIXER - if (nodigimusic) + if (digital_disabled) return false; snprintf(filename, sizeof filename, "o_%s", musicname); From 7e7899ae831e2203e0cf28b09b8178e66037c554 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 12:51:45 -0400 Subject: [PATCH 053/194] Toggle Digi/MIDI music in menu accurately; add S_MusicType (cherry picked from commit 4aa100aa575cc7fc14a743085222c806ba2c714a) --- src/m_menu.c | 6 ++++-- src/s_sound.c | 36 +++++++++++++++++++++--------------- src/s_sound.h | 2 ++ 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 7a5e78a7..2c82bf84 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6991,7 +6991,8 @@ static void M_ToggleDigital(void) else { digital_disabled = true; - S_StopMusic(); + if (S_MusicType() != MU_MID) + S_StopMusic(); M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -7012,7 +7013,8 @@ static void M_ToggleMIDI(void) else { midi_disabled = true; - S_StopMusic(); + if (S_MusicType() == MU_MID) + S_StopMusic(); M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/s_sound.c b/src/s_sound.c index d1993bc8..54ffffc4 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1245,6 +1245,11 @@ boolean S_MusicPaused(void) return I_MusicPaused(); } +musictype_t S_MusicType(void) +{ + return I_GetMusicType(); +} + const char *S_MusicName(void) { return music_name; @@ -1279,20 +1284,24 @@ static boolean S_LoadMusic(const char *mname) if (S_MusicDisabled()) return false; - if (S_DigMusicDisabled()) - { - if (!S_MIDIExists(mname)) - return false; + if (!S_DigMusicDisabled() && S_DigExists(mname)) + mlumpnum = W_GetNumForName(va("o_%s", mname)); + else if (!S_MIDIMusicDisabled() && S_MIDIExists(mname)) mlumpnum = W_GetNumForName(va("d_%s", mname)); + else if (S_DigMusicDisabled() && S_DigExists(mname)) + { + CONS_Alert(CONS_NOTICE, "Digital music is disabled!\n"); + return false; + } + else if (S_MIDIMusicDisabled() && S_MIDIExists(mname)) + { + CONS_Alert(CONS_NOTICE, "MIDI music is disabled!\n"); + return false; } else { - if (S_DigExists(mname)) - mlumpnum = W_GetNumForName(va("o_%s", mname)); - else if (S_MIDIExists(mname)) - mlumpnum = W_GetNumForName(va("d_%s", mname)); - else - return false; + CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mname); + return false; } // load & register it @@ -1328,8 +1337,8 @@ static void S_UnloadMusic(void) static boolean S_PlayMusic(boolean looping) { - if (S_DigMusicDisabled()) - return false; // try midi + if (S_MusicDisabled()) + return false; if (!I_PlaySong(looping)) { @@ -1362,10 +1371,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_StopMusic(); // shutdown old music if (!S_LoadMusic(mmusic)) - { - CONS_Alert(CONS_ERROR, M_GetText("Music lump %.6s not found!\n"), mmusic); return; - } if (!S_PlayMusic(looping)) { diff --git a/src/s_sound.h b/src/s_sound.h index 9a3f2805..a0ac6c15 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -14,6 +14,7 @@ #ifndef __S_SOUND__ #define __S_SOUND__ +#include "i_sound.h" // musictype_t #include "sounds.h" #include "m_fixed.h" #include "command.h" @@ -106,6 +107,7 @@ boolean S_MIDIMusicDisabled(void); boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); +musictype_t S_MusicType(void); const char *S_MusicName(void); boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); #define S_DigExists(a) S_MusicExists(a, false, true) From 8c78d86c3641675e6c5803afab052cf91055af03 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 16:46:40 -0400 Subject: [PATCH 054/194] Play the opposite type music (Digital/MIDI) when toggling between them in menu * S_MusicInfo method to retrieve name, flags, and looping (cherry picked from commit f6ec93198f0dcfa1d053cca88172c3e3c7ba310c) --- src/m_menu.c | 38 ++++++++++++++++++++++++++++++++++++-- src/s_sound.c | 19 +++++++++++++++++-- src/s_sound.h | 2 +- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2c82bf84..6a6875aa 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6992,7 +6992,24 @@ static void M_ToggleDigital(void) { digital_disabled = true; if (S_MusicType() != MU_MID) - S_StopMusic(); + { + if (midi_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_MIDIExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } M_StartMessage(M_GetText("Digital Music Disabled\n"), NULL, MM_NOTHING); } } @@ -7014,7 +7031,24 @@ static void M_ToggleMIDI(void) { midi_disabled = true; if (S_MusicType() == MU_MID) - S_StopMusic(); + { + if (digital_disabled) + S_StopMusic(); + else + { + char mmusic[7]; + UINT16 mflags; + boolean looping; + + if (S_MusicInfo(mmusic, &mflags, &looping) && S_DigExists(mmusic)) + { + S_StopMusic(); + S_ChangeMusic(mmusic, mflags, looping); + } + else + S_StopMusic(); + } + } M_StartMessage(M_GetText("MIDI Music Disabled\n"), NULL, MM_NOTHING); } } diff --git a/src/s_sound.c b/src/s_sound.c index 54ffffc4..32d9c7b0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1215,6 +1215,8 @@ const char *compat_special_music_slots[16] = #endif static char music_name[7]; // up to 6-character name +static UINT16 music_flags; +static boolean music_looping; /// ------------------------ /// Music Status @@ -1250,9 +1252,17 @@ musictype_t S_MusicType(void) return I_GetMusicType(); } -const char *S_MusicName(void) +boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) { - return music_name; + if (!I_MusicPlaying()) + return false; + + strncpy(mname, music_name, 7); + mname[6] = 0; + *mflags = music_flags; + *looping = music_looping; + + return (boolean)mname[0]; } boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) @@ -1333,6 +1343,8 @@ static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; + music_flags = 0; + music_looping = false; } static boolean S_PlayMusic(boolean looping) @@ -1373,6 +1385,9 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) if (!S_LoadMusic(mmusic)) return; + music_flags = mflags; + music_looping = looping; + if (!S_PlayMusic(looping)) { CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); diff --git a/src/s_sound.h b/src/s_sound.h index a0ac6c15..a2d51a59 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -108,7 +108,7 @@ boolean S_MusicDisabled(void); boolean S_MusicPlaying(void); boolean S_MusicPaused(void); musictype_t S_MusicType(void); -const char *S_MusicName(void); +boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping); boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi); #define S_DigExists(a) S_MusicExists(a, false, true) #define S_MIDIExists(a) S_MusicExists(a, true, false) From 5bac836d4c805e37c1bf7d9d75cfa23c0933538f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:37 -0400 Subject: [PATCH 055/194] Minor refactoring and reordering * I_GetMusicType() -> I_MusicType() * Wrap MIDI volume hack in #ifdef _WIN32 (cherry picked from commit a7d51bf81030c228937a8e759f8f43b85817fce6) --- src/i_sound.h | 89 ++++++++-------- src/s_sound.c | 8 +- src/sdl/mixer_sound.c | 238 +++++++++++++++++++++++------------------- 3 files changed, 174 insertions(+), 161 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 901e6c28..15126d69 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -66,9 +66,9 @@ void I_StartupSound(void); */ void I_ShutdownSound(void); -// -// SFX I/O -// +/// ------------------------ +/// SFX I/O +/// ------------------------ /** \brief Starts a sound in a particular sound channel. \param id sfxid @@ -120,13 +120,9 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep, UINT8 pitch); */ void I_SetSfxVolume(UINT8 volume); -// -// MUSIC I/O -// - -musictype_t I_GetMusicType(void); -boolean I_MusicPlaying(void); -boolean I_MusicPaused(void); +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ /** \brief Init the music systems */ @@ -136,33 +132,23 @@ void I_InitMusic(void); */ void I_ShutdownMusic(void); -/** \brief PAUSE game handling. +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ - \param handle song handle +musictype_t I_MusicType(void); +boolean I_MusicPlaying(void); +boolean I_MusicPaused(void); - \return void -*/ -void I_PauseSong(void); +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -/** \brief RESUME game handling +boolean I_SetSongSpeed(float speed); - \param handle song handle - - \return void -*/ -void I_ResumeSong(void); - -// -// MIDI I/O -// - -/** \brief The I_SetMIDIMusicVolume function - - \param volume volume to set at - - \return void -*/ -void I_SetMIDIMusicVolume(UINT8 volume); +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ /** \brief Registers a song handle to song data. @@ -175,6 +161,15 @@ void I_SetMIDIMusicVolume(UINT8 volume); */ boolean I_LoadSong(char *data, size_t len); +/** \brief See ::I_LoadSong, then think backwards + + \param handle song handle + + \sa I_LoadSong + \todo remove midi handle +*/ +void I_UnloadSong(void); + /** \brief Called by anything that wishes to start music \param handle Song handle @@ -195,35 +190,35 @@ boolean I_PlaySong(boolean looping); */ void I_StopSong(void); -/** \brief See ::I_LoadSong, then think backwards +/** \brief PAUSE game handling. \param handle song handle - \sa I_LoadSong - \todo remove midi handle + \return void */ -void I_UnloadSong(void); +void I_PauseSong(void); -// -// DIGMUSIC I/O -// +/** \brief RESUME game handling -boolean I_SetSongSpeed(float speed); + \param handle song handle -boolean I_SetSongTrack(INT32 track); + \return void +*/ +void I_ResumeSong(void); -/** \brief The I_SetDigMusicVolume function +/** \brief The I_SetMusicVolume function \param volume volume to set at \return void */ -void I_SetDigMusicVolume(UINT8 volume); +void I_SetMusicVolume(UINT8 volume); -// -// CD MUSIC I/O -// +boolean I_SetSongTrack(INT32 track); +/// ------------------------ +// CD MUSIC I/O +/// ------------------------ /** \brief cd music interface */ diff --git a/src/s_sound.c b/src/s_sound.c index 32d9c7b0..bd6022df 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1249,7 +1249,7 @@ boolean S_MusicPaused(void) musictype_t S_MusicType(void) { - return I_GetMusicType(); + return I_MusicType(); } boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) @@ -1274,7 +1274,7 @@ boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi) } /// ------------------------ -/// Music Properties +/// Music Effects /// ------------------------ boolean S_SpeedMusic(float speed) @@ -1283,7 +1283,7 @@ boolean S_SpeedMusic(float speed) } /// ------------------------ -/// Music Routines +/// Music Playback /// ------------------------ static boolean S_LoadMusic(const char *mname) @@ -1462,7 +1462,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) digvolume = seqvolume = 31; #endif - switch(I_GetMusicType()) + switch(I_MusicType()) { case MU_MID: case MU_MOD: diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 1384f1da..9c46625f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -72,6 +72,10 @@ static Music_Emu *gme; static INT32 current_track; #endif +/// ------------------------ +/// Audio System +/// ------------------------ + void I_StartupSound(void) { I_Assert(!sound_started); @@ -128,6 +132,10 @@ FUNCMATH void I_UpdateSound(void) { } +/// ------------------------ +/// SFX +/// ------------------------ + // this is as fast as I can possibly make it. // sorry. more asm needed. static Mix_Chunk *ds2chunk(void *stream) @@ -430,11 +438,72 @@ void I_SetSfxVolume(UINT8 volume) sfx_volume = volume; } -// -// Music -// +/// ------------------------ +/// Music Hooks +/// ------------------------ -musictype_t I_GetMusicType(void) +static void music_loop(void) +{ + Mix_PlayMusic(music, 0); + Mix_SetMusicPosition(loop_point); +} + +#ifdef HAVE_LIBGME +static void mix_gme(void *udata, Uint8 *stream, int len) +{ + int i; + short *p; + + (void)udata; + + // no gme? no music. + if (!gme || gme_track_ended(gme) || songpaused) + return; + + // play gme into stream + gme_play(gme, len/2, (short *)stream); + + // apply volume to stream + for (i = 0, p = (short *)stream; i < len/2; i++, p++) + *p = ((INT32)*p) * music_volume*2 / 42; +} +#endif + + +/// ------------------------ +/// Music System +/// ------------------------ + +FUNCMATH void I_InitMusic(void) +{ +#ifdef HAVE_LIBGME + gme = NULL; + current_track = -1; +#endif +} + +void I_ShutdownMusic(void) +{ +#ifdef HAVE_LIBGME + if (gme) + { + Mix_HookMusic(NULL, NULL); + gme_delete(gme); + gme = NULL; + } +#endif + if (!music) + return; + Mix_HookMusicFinished(NULL); + Mix_FreeMusic(music); + music = NULL; +} + +/// ------------------------ +/// Music Properties +/// ------------------------ + +musictype_t I_MusicType(void) { #ifdef HAVE_LIBGME if (gme) @@ -463,74 +532,9 @@ boolean I_MusicPaused(void) return songpaused; } -// Music hooks -static void music_loop(void) -{ - Mix_PlayMusic(music, 0); - Mix_SetMusicPosition(loop_point); -} - -#ifdef HAVE_LIBGME -static void mix_gme(void *udata, Uint8 *stream, int len) -{ - int i; - short *p; - - (void)udata; - - // no gme? no music. - if (!gme || gme_track_ended(gme) || songpaused) - return; - - // play gme into stream - gme_play(gme, len/2, (short *)stream); - - // apply volume to stream - for (i = 0, p = (short *)stream; i < len/2; i++, p++) - *p = ((INT32)*p) * music_volume*2 / 42; -} -#endif - -FUNCMATH void I_InitMusic(void) -{ -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif -} - -void I_ShutdownMusic(void) -{ -#ifdef HAVE_LIBGME - if (gme) - { - Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; - } -#endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; -} - -void I_PauseSong(void) -{ - Mix_PauseMusic(); - songpaused = true; -} - -void I_ResumeSong(void) -{ - Mix_ResumeMusic(); - songpaused = false; -} - -// -// Digital Music -// +/// ------------------------ +/// Music Effects +/// ------------------------ boolean I_SetSongSpeed(float speed) { @@ -550,40 +554,9 @@ boolean I_SetSongSpeed(float speed) return false; } -boolean I_SetSongTrack(int track) -{ -#ifdef HAVE_LIBGME - if (current_track == track) - return false; - - // If the specified track is within the number of tracks playing, then change it - if (gme) - { - SDL_LockAudio(); - if (track >= 0 - && track < gme_track_count(gme)) - { - gme_err_t gme_e = gme_start_track(gme, track); - if (gme_e != NULL) - { - CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); - return false; - } - current_track = track; - SDL_UnlockAudio(); - return true; - } - SDL_UnlockAudio(); - return false; - } -#endif - (void)track; - return false; -} - -// -// MIDI Music -// +/// ------------------------ +/// Music Playback +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -731,6 +704,12 @@ boolean I_LoadSong(char *data, size_t len) return true; } +void I_UnloadSong(void) +{ + Mix_FreeMusic(music); + music = NULL; +} + boolean I_PlaySong(boolean looping) { if (!music) @@ -775,25 +754,64 @@ void I_StopSong(void) music = NULL; } +void I_PauseSong(void) +{ + Mix_PauseMusic(); + songpaused = true; +} + +void I_ResumeSong(void) +{ + Mix_ResumeMusic(); + songpaused = false; +} + void I_SetMusicVolume(UINT8 volume) { if (!music) return; - if (I_GetMusicType() == MU_MID) +#ifdef _WIN32 + if (I_MusicType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes music_volume = 31; else +#endif music_volume = volume; Mix_VolumeMusic((UINT32)music_volume*128/31); } -void I_UnloadSong(void) +boolean I_SetSongTrack(int track) { - Mix_FreeMusic(music); - music = NULL; +#ifdef HAVE_LIBGME + if (current_track == track) + return false; + + // If the specified track is within the number of tracks playing, then change it + if (gme) + { + SDL_LockAudio(); + if (track >= 0 + && track < gme_track_count(gme)) + { + gme_err_t gme_e = gme_start_track(gme, track); + if (gme_e != NULL) + { + CONS_Alert(CONS_ERROR, "GME error: %s\n", gme_e); + return false; + } + current_track = track; + SDL_UnlockAudio(); + return true; + } + SDL_UnlockAudio(); + return false; + } +#endif + (void)track; + return false; } #endif \ No newline at end of file From d535c14fc6b8d5fb25af05075c6804aaae68270c Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 17:05:47 -0400 Subject: [PATCH 056/194] Refactoring and reordering other targets (cherry picked from commit cf065e106f68fb8af3b0568eba188c8235b1656e) --- src/android/i_sound.c | 66 ++++++------ src/djgppdos/i_sound.c | 198 +++++++++++++++++++--------------- src/dummy/i_sound.c | 64 +++++------ src/sdl/sdl_sound.c | 237 +++++++++++++++++++++++------------------ src/win32/win_snd.c | 218 +++++++++++++++++++------------------ 5 files changed, 428 insertions(+), 355 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index 1cbc53fa..bf54c9ff 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -55,12 +55,22 @@ void I_SetSfxVolume(INT32 volume) (void)volume; } -// -// MUSIC I/O -// -UINT8 music_started = 0; +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +UINT8 music_started = 0; +UINT8 digmusic_started = 0; + +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { return MU_NONE; } @@ -75,23 +85,19 @@ boolean I_MusicPaused(void) return false; } -void I_InitMusic(void){} +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -void I_ShutdownMusic(void){} - -void I_PauseSong(void) +boolean I_SetSongSpeed(float speed) { - (void)handle; + (void)speed; + return false; } -void I_ResumeSong(void) -{ - (void)handle; -} - -// -// MIDI I/O -// +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ UINT8 midimusic_started = 0; @@ -102,9 +108,9 @@ boolean I_LoadSong(char *data, size_t len) return -1; } -void I_SetMusicVolume(INT32 volume) +void I_UnloadSong() { - (void)volume; + } boolean I_PlaySong(boolean looping) @@ -119,19 +125,17 @@ void I_StopSong(void) (void)handle; } -void I_UnloadSong(void) +void I_PauseSong(void) { (void)handle; } -// -// DIGMUSIC I/O -// - -UINT8 digmusic_started = 0; - -boolean I_SetSongSpeed(float speed) +void I_ResumeSong(void) { - (void)speed; - return false; -} \ No newline at end of file + (void)handle; +} + +void I_SetMusicVolume(INT32 volume) +{ + (void)volume; +} diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index d998016a..339b469d 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -140,15 +140,6 @@ void I_SetSfxVolume(INT32 volume) set_volume (Volset(volume),-1); } -void I_SetMusicVolume(INT32 volume) -{ - if (midi_disabled) - return; - - // Now set volume on output device. - set_volume (-1, Volset(volume)); -} - // // Starting a sound means adding it // to the current list of active sounds @@ -323,23 +314,9 @@ static int musicdies=-1; UINT8 music_started=0; boolean songpaused=false; -musictype_t I_GetMusicType(void) -{ - if (currsong) - return MU_MID; - else - return MU_NONE; -} - -boolean I_MusicPlaying() -{ - return (boolean)currsong; -} - -boolean I_MusicPaused() -{ - return songpaused; -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ /* load_midi_mem: * Loads a standard MIDI file from memory, returning a pointer to @@ -427,69 +404,41 @@ void I_ShutdownMusic(void) music_started=false; } -boolean I_PlaySong(boolean looping) -{ - handle = 0; - if (midi_disabled) - return false; +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ - islooping = looping; - musicdies = gametic + NEWTICRATE*30; - if (play_midi(currsong,looping)==0) - return true; +musictype_t I_MusicType(void) +{ + if (currsong) + return MU_MID; + else + return MU_NONE; +} + +boolean I_MusicPlaying() +{ + return (boolean)currsong; +} + +boolean I_MusicPaused() +{ + return songpaused; +} + +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; return false; } -void I_PauseSong (INT32 handle) -{ - handle = 0; - if (midi_disabled) - return; - midi_pause(); - songpaused = true; -} - -void I_ResumeSong (INT32 handle) -{ - handle = 0; - if (midi_disabled) - return; - midi_resume(); - songpaused = false; -} - -void I_StopSong(void) -{ - handle = 0; - if (midi_disabled) - return; - - islooping = 0; - musicdies = 0; - stop_midi(); - songpaused = false; -} - -// Is the song playing? -#if 0 -int I_QrySongPlaying(int handle) -{ - if (midi_disabled) - return 0; - - //return islooping || musicdies > gametic; - return (midi_pos==-1); -} -#endif - -void I_UnloadSong(void) -{ - handle = 0; - if (midi_disabled) - return; - - //destroy_midi(currsong); -} +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -516,8 +465,81 @@ boolean I_LoadSong(char *data, size_t len) return 1; } -boolean I_SetSongSpeed(float speed) +void I_UnloadSong(void) { - (void)speed; + handle = 0; + if (midi_disabled) + return; + + //destroy_midi(currsong); +} + +boolean I_PlaySong(boolean looping) +{ + handle = 0; + if (midi_disabled) + return false; + + islooping = looping; + musicdies = gametic + NEWTICRATE*30; + if (play_midi(currsong,looping)==0) + return true; return false; -} \ No newline at end of file +} + +void I_StopSong(void) +{ + handle = 0; + if (midi_disabled) + return; + + islooping = 0; + musicdies = 0; + stop_midi(); + songpaused = false; +} + +void I_PauseSong (INT32 handle) +{ + handle = 0; + if (midi_disabled) + return; + midi_pause(); + songpaused = true; +} + +void I_ResumeSong (INT32 handle) +{ + handle = 0; + if (midi_disabled) + return; + midi_resume(); + songpaused = false; +} + +void I_SetMusicVolume(INT32 volume) +{ + if (midi_disabled) + return; + + // Now set volume on output device. + set_volume (-1, Volset(volume)); +} + +boolean I_SetSongTrack(INT32 track) +{ + (void)track; + return false; +} + +// Is the song playing? +#if 0 +int I_QrySongPlaying(int handle) +{ + if (midi_disabled) + return 0; + + //return islooping || musicdies > gametic; + return (midi_pos==-1); +} +#endif diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index ca90a7da..fb325c59 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -57,11 +57,19 @@ void I_SetSfxVolume(UINT8 volume) (void)volume; } -// -// MUSIC I/O -// +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +void I_InitMusic(void){} + +void I_ShutdownMusic(void){} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { return MU_NONE; } @@ -76,28 +84,19 @@ boolean I_MusicPaused(void) return false; } -void I_InitMusic(void){} +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ -void I_ShutdownMusic(void){} - -void I_SetMusicVolume(UINT8 volume) +boolean I_SetSongSpeed(float speed) { - (void)volume; + (void)speed; + return false; } -void I_PauseSong(void) -{ - (void)handle; -} - -void I_ResumeSong(void) -{ - (void)handle; -} - -// -// MIDI I/O -// +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -106,6 +105,11 @@ boolean I_LoadSong(char *data, size_t len) return -1; } +void I_UnloadSong(void) +{ + (void)handle; +} + boolean I_PlaySong(boolean looping) { (void)handle; @@ -118,19 +122,19 @@ void I_StopSong(void) (void)handle; } -void I_UnloadSong(void) +void I_PauseSong(void) { (void)handle; } -// -// DIGMUSIC I/O -// - -boolean I_SetSongSpeed(float speed) +void I_ResumeSong(void) { - (void)speed; - return false; + (void)handle; +} + +void I_SetMusicVolume(UINT8 volume) +{ + (void)volume; } boolean I_SetSongTrack(int track) diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index cf54d7d0..6a79220c 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,7 +1313,7 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_GetMusicType(void) +musictype_t I_MusicType(void) { #ifdef HAVE_MIXER #ifdef HAVE_LIBGME @@ -1448,28 +1448,9 @@ static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) } #endif - -void I_ShutdownMusic(void) -{ -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - - I_UnloadSong(); - I_StopSong(); - Mix_CloseAudio(); -#ifdef MIX_INIT - Mix_Quit(); -#endif - CONS_Printf("%s", M_GetText("shut down\n")); - musicStarted = SDL_FALSE; - if (Msc_Mutex) - SDL_DestroyMutex(Msc_Mutex); - Msc_Mutex = NULL; -#endif -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ void I_InitMusic(void) { @@ -1584,11 +1565,106 @@ void I_InitMusic(void) #endif } -boolean I_PlaySong(INT32 handle, boolean looping) +void I_ShutdownMusic(void) { - (void)handle; #ifdef HAVE_MIXER - if (midi_disabled || !musicStarted || !music[handle]) + if ((midi_disabled && digital_disabled) || !musicStarted) + return; + + CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); + + I_UnloadSong(); + I_StopSong(); + Mix_CloseAudio(); +#ifdef MIX_INIT + Mix_Quit(); +#endif + CONS_Printf("%s", M_GetText("shut down\n")); + musicStarted = SDL_FALSE; + if (Msc_Mutex) + SDL_DestroyMutex(Msc_Mutex); + Msc_Mutex = NULL; +#endif +} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) +{ + return MU_NONE; +} + +boolean I_MusicPlaying(void) +{ + return false; +} + +boolean I_MusicPaused(void) +{ + return false; +} + +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) +{ + (void)speed; + return false; +} + +/// ------------------------ +// MUSIC PLAYBACK +// \todo Merge Digital and MIDI +/// ------------------------ + +boolean I_LoadSong(char *data, size_t len) +{ +#ifdef HAVE_MIXER + if (midi_disabled || !musicStarted) + return false; + + if (!LoadSong(data, len, 0)) + return false; + + if (music[0]) + return true; + + CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError()); +#else + (void)len; + (void)data; +#endif + return false; +} + +void I_UnloadSong(void) +{ +#ifdef HAVE_MIXER + + if (midi_disabled || !musicStarted) + return; + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[handle]) + Mix_FreeMusic(music[handle]); + music[handle] = NULL; + LoadSong(NULL, 0, handle); +#else + (void)handle; +#endif +} + +boolean I_PlaySong(boolean looping) +{ +#ifdef HAVE_MIXER + if (!musicStarted || !music[handle]) return false; #ifdef MIXER_POS @@ -1609,6 +1685,28 @@ boolean I_PlaySong(INT32 handle, boolean looping) return false; } +void I_StopSong(void) +{ + I_StopGME(); +#ifdef HAVE_MIXER + if (digital_disabled) + return; + +#ifdef MIXER_POS + if (canlooping) + Mix_HookMusicFinished(NULL); +#endif + + Mix_HaltMusic(); + while (Mix_PlayingMusic()) + ; + + if (music[1]) + Mix_FreeMusic(music[1]); + music[1] = NULL; + LoadSong(NULL, 0, 1); +} + static void I_PauseGME(void) { #ifdef HAVE_LIBGME @@ -1650,68 +1748,6 @@ void I_ResumeSong(void) #endif } -void I_StopSong(void) -{ - I_StopGME(); -#ifdef HAVE_MIXER - if (digital_disabled) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -} - -void I_UnloadSong(void) -{ -#ifdef HAVE_MIXER - - if (midi_disabled || !musicStarted) - return; - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[handle]) - Mix_FreeMusic(music[handle]); - music[handle] = NULL; - LoadSong(NULL, 0, handle); -#else - (void)handle; -#endif -} - -boolean I_LoadSong(char *data, size_t len) -{ -#ifdef HAVE_MIXER - if (midi_disabled || !musicStarted) - return false; - - if (!LoadSong(data, len, 0)) - return false; - - if (music[0]) - return true; - - CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError()); -#else - (void)len; - (void)data; -#endif - return false; -} - void I_SetMusicVolume(UINT8 volume) { #ifdef HAVE_MIXER @@ -1727,6 +1763,18 @@ void I_SetMusicVolume(UINT8 volume) #endif } +boolean I_SetSongTrack(int track) +{ + (void)track; + return false; +} + +/// ------------------------ +// MUSIC LOADING AND CLEANUP +// \todo Split logic between loading and playing, +// then move to Playback section +/// ------------------------ + #ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { @@ -1961,19 +2009,6 @@ static void I_StopGME(void) #endif } -boolean I_SetSongSpeed(float speed) -{ - - (void)speed; - return false; -} - -boolean I_SetSongTrack(int track) -{ - (void)track; - return false; -} - #ifdef MIXER_POS static void SDLCALL I_FinishMusic(void) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index c6a74d99..3dbe6c57 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -439,11 +439,24 @@ void I_SetSfxVolume(UINT8 volume) sfx_volume = volume; } -// -// MUSIC -// +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -musictype_t I_GetMusicType(void) +void I_InitMusic(void) +{ +} + +void I_ShutdownMusic(void) +{ + I_StopSong(); +} + +/// ------------------------ +// MUSIC PROPERTIES +/// ------------------------ + +musictype_t I_MusicType(void) { #ifdef HAVE_LIBGME if (gme) @@ -491,28 +504,46 @@ boolean I_MusicPaused(void) return fmpaused; } -void I_InitMusic(void) +/// ------------------------ +// MUSIC EFFECTS +/// ------------------------ + +boolean I_SetSongSpeed(float speed) { + FMOD_RESULT e; + float frequency; + if (!music_stream) + return false; + if (speed > 250.0f) + speed = 250.0f; //limit speed up to 250x + +#ifdef HAVE_LIBGME + // Try to set GME speed + if (gme) + { + gme_set_tempo(gme, speed); + return true; + } +#endif + + // Try to set Mod/Midi speed + e = FMOD_Sound_SetMusicSpeed(music_stream, speed); + + if (e == FMOD_ERR_FORMAT) + { + // Just change pitch instead for Ogg/etc. + FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL)); + FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency)); + } + else + FMR_MUSIC(e); + + return true; } -void I_ShutdownMusic(void) -{ - I_StopSong(); -} - -void I_PauseSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); -} - -void I_ResumeSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); -} +/// ------------------------ +// MUSIC PLAYBACK +/// ------------------------ boolean I_LoadSong(char *data, size_t len) { @@ -726,39 +757,79 @@ boolean I_LoadSong(char *data, size_t len) return true; } -boolean I_SetSongSpeed(float speed) +void I_UnloadSong(void) { - FMOD_RESULT e; - float frequency; - if (!music_stream) - return false; - if (speed > 250.0f) - speed = 250.0f; //limit speed up to 250x + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR(FMOD_Sound_Release(music_stream)); + music_stream = NULL; +} +boolean I_PlaySong(boolean looping) +{ #ifdef HAVE_LIBGME - // Try to set GME speed if (gme) { - gme_set_tempo(gme, speed); + gme_start_track(gme, 0); + current_track = 0; + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); return true; } #endif - // Try to set Mod/Midi speed - e = FMOD_Sound_SetMusicSpeed(music_stream, speed); - - if (e == FMOD_ERR_FORMAT) - { - // Just change pitch instead for Ogg/etc. - FMR(FMOD_Sound_GetDefaults(music_stream, &frequency, NULL, NULL, NULL)); - FMR_MUSIC(FMOD_Channel_SetFrequency(music_channel, speed*frequency)); - } + FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); + if (I_MusicType() != MU_MID) + FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else - FMR_MUSIC(e); + FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); + FMR(FMOD_Channel_SetPriority(music_channel, 0)); + current_track = 0; return true; } +void I_StopSong(void) +{ +#ifdef HAVE_LIBGME + if (gme) + gme_delete(gme); + gme = NULL; +#endif + current_track = -1; + + I_UnloadSong(); +} + +void I_PauseSong(void) +{ + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); +} + +void I_ResumeSong(void) +{ + UNREFERENCED_PARAMETER(handle); + if (music_stream) + FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); +} + +void I_SetMusicVolume(UINT8 volume) +{ + if (!music_stream) + return; + + // volume is 0 to 31. + if (I_MusicType() == MU_MID) + music_volume = 31; // windows bug hack + else + music_volume = volume; + + FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); +} + boolean I_SetSongTrack(INT32 track) { if (track != current_track) // If the track's already playing, then why bother? @@ -803,66 +874,3 @@ boolean I_SetSongTrack(INT32 track) } return false; } - -// -// Fuck MIDI. ... Okay fine, you can have your silly D_-only mode. -// - -void I_SetMusicVolume(UINT8 volume) -{ - if (!music_stream) - return; - - // volume is 0 to 31. - if (I_GetMusicType() == MU_MID) - music_volume = 31; // windows bug hack - else - music_volume = volume; - - FMR_MUSIC(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); -} - -boolean I_PlaySong(boolean looping) -{ -#ifdef HAVE_LIBGME - if (gme) - { - gme_start_track(gme, 0); - current_track = 0; - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - return true; - } -#endif - - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (I_GetMusicType() != MU_MID) - FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); - else - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); - current_track = 0; - - return true; -} - -void I_StopSong(void) -{ -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; - - I_UnloadSong(); -} - -void I_UnloadSong(void) -{ - UNREFERENCED_PARAMETER(handle); - if (music_stream) - FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; -} \ No newline at end of file From eacf0ba00bc88eeff112b29fbf18f0a8d6ba2b52 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:46 -0400 Subject: [PATCH 057/194] Refactor I_MusicType MusicPlaying and MusicPaused -> I_SongType ... (cherry picked from commit 4b82de9e540d6dc0651bbe8db8e5e15cba39f650) --- src/i_sound.h | 6 +++--- src/s_sound.c | 18 +++++++++--------- src/sdl/mixer_sound.c | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 15126d69..1be970d2 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -136,9 +136,9 @@ void I_ShutdownMusic(void); // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void); -boolean I_MusicPlaying(void); -boolean I_MusicPaused(void); +musictype_t I_SongType(void); +boolean I_SongPlaying(void); +boolean I_SongPaused(void); /// ------------------------ // MUSIC EFFECTS diff --git a/src/s_sound.c b/src/s_sound.c index bd6022df..723401fb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1239,22 +1239,22 @@ boolean S_MusicDisabled(void) boolean S_MusicPlaying(void) { - return I_MusicPlaying(); + return I_SongPlaying(); } boolean S_MusicPaused(void) { - return I_MusicPaused(); + return I_SongPaused(); } musictype_t S_MusicType(void) { - return I_MusicType(); + return I_SongType(); } boolean S_MusicInfo(char *mname, UINT16 *mflags, boolean *looping) { - if (!I_MusicPlaying()) + if (!I_SongPlaying()) return false; strncpy(mname, music_name, 7); @@ -1399,10 +1399,10 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) void S_StopMusic(void) { - if (!I_MusicPlaying()) + if (!I_SongPlaying()) return; - if (I_MusicPaused()) + if (I_SongPaused()) I_ResumeSong(); S_SpeedMusic(1.0f); @@ -1421,7 +1421,7 @@ void S_StopMusic(void) // void S_PauseAudio(void) { - if (I_MusicPlaying() && !I_MusicPaused()) + if (I_SongPlaying() && !I_SongPaused()) I_PauseSong(); // pause cd music @@ -1434,7 +1434,7 @@ void S_PauseAudio(void) void S_ResumeAudio(void) { - if (I_MusicPlaying() && I_MusicPaused()) + if (I_SongPlaying() && I_SongPaused()) I_ResumeSong(); // resume cd music @@ -1462,7 +1462,7 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) digvolume = seqvolume = 31; #endif - switch(I_MusicType()) + switch(I_SongType()) { case MU_MID: case MU_MOD: diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 9c46625f..521bcd03 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -503,7 +503,7 @@ void I_ShutdownMusic(void) /// Music Properties /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_LIBGME if (gme) @@ -522,12 +522,12 @@ musictype_t I_MusicType(void) return (musictype_t)Mix_GetMusicType(music); } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return (boolean)music; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return songpaused; } @@ -772,7 +772,7 @@ void I_SetMusicVolume(UINT8 volume) return; #ifdef _WIN32 - if (I_MusicType() == MU_MID) + if (I_SongType() == MU_MID) // HACK: Until we stop using native MIDI, // disable volume changes music_volume = 31; From 4d61f00b865033a36af0ad246189345a4fa776f8 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 23 Aug 2018 20:14:56 -0400 Subject: [PATCH 058/194] Refactor I_MusicType MusicPlaying and MusicPaused other targets (cherry picked from commit 9e6eebeb8d6b4119d87e9678bb6b0687e3dc5217) --- src/android/i_sound.c | 6 +++--- src/djgppdos/i_sound.c | 6 +++--- src/dummy/i_sound.c | 6 +++--- src/sdl/mixer_sound.c | 4 ++-- src/sdl/sdl_sound.c | 12 ++++++------ src/win32/win_snd.c | 10 +++++----- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index bf54c9ff..1d16e4df 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -70,17 +70,17 @@ void I_ShutdownMusic(void){} // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 339b469d..5403aef1 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -408,7 +408,7 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { if (currsong) return MU_MID; @@ -416,12 +416,12 @@ musictype_t I_MusicType(void) return MU_NONE; } -boolean I_MusicPlaying() +boolean I_SongPlaying() { return (boolean)currsong; } -boolean I_MusicPaused() +boolean I_SongPaused() { return songpaused; } diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index fb325c59..4bace7a4 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -69,17 +69,17 @@ void I_ShutdownMusic(void){} // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 521bcd03..9b84a124 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -63,7 +63,7 @@ UINT8 sound_started = false; static Mix_Music *music; -static UINT8 music_volume, midi_volume, sfx_volume; +static UINT8 music_volume, sfx_volume; static float loop_point; static boolean songpaused; @@ -91,7 +91,7 @@ void I_StartupSound(void) } music = NULL; - music_volume = midi_volume = sfx_volume = 0; + music_volume = sfx_volume = 0; #if SDL_MIXER_VERSION_ATLEAST(1,2,11) Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG); diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 6a79220c..887726eb 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -1313,7 +1313,7 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_MIXER #ifdef HAVE_LIBGME @@ -1336,12 +1336,12 @@ musictype_t I_MusicType(void) #endif } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return music_started; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return Mix_PausedMusic(); } @@ -1591,17 +1591,17 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return false; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { return false; } diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 3dbe6c57..2960ff7d 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -456,7 +456,7 @@ void I_ShutdownMusic(void) // MUSIC PROPERTIES /// ------------------------ -musictype_t I_MusicType(void) +musictype_t I_SongType(void) { #ifdef HAVE_LIBGME if (gme) @@ -491,12 +491,12 @@ musictype_t I_MusicType(void) return MU_NONE; } -boolean I_MusicPlaying(void) +boolean I_SongPlaying(void) { return (boolean)music_stream; } -boolean I_MusicPaused(void) +boolean I_SongPaused(void) { boolean fmpaused = false; if (music_stream) @@ -780,7 +780,7 @@ boolean I_PlaySong(boolean looping) #endif FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - if (I_MusicType() != MU_MID) + if (I_SongType() != MU_MID) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); else FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); @@ -822,7 +822,7 @@ void I_SetMusicVolume(UINT8 volume) return; // volume is 0 to 31. - if (I_MusicType() == MU_MID) + if (I_SongType() == MU_MID) music_volume = 31; // windows bug hack else music_volume = volume; From b0c47e2fb12a234a1fa5c41eab54a5b72e734a43 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:12:14 -0400 Subject: [PATCH 059/194] GME fix: play song in I_PlaySong, not I_LoadSong (cherry picked from commit 5f21bf230d9716b7cc5b52e4bf3591ebe01e9f3a) --- src/sdl/mixer_sound.c | 8 ++++---- src/win32/win_snd.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 9b84a124..ca22724b 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -656,7 +656,6 @@ boolean I_LoadSong(char *data, size_t len) { gme_equalizer_t eq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; gme_set_equalizer(gme, &eq); - Mix_HookMusic(mix_gme, gme); return true; } #endif @@ -712,16 +711,17 @@ void I_UnloadSong(void) boolean I_PlaySong(boolean looping) { - if (!music) - return false; -#ifdef HAVE_GME +#ifdef HAVE_LIBGME if (gme) { gme_start_track(gme, 0); current_track = 0; + Mix_HookMusic(mix_gme, gme); return true; } #endif + else if (!music) + return false; if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) { diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 2960ff7d..2e05c4f7 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -675,7 +675,6 @@ boolean I_LoadSong(char *data, size_t len) fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; - FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); return true; } #endif @@ -772,6 +771,7 @@ boolean I_PlaySong(boolean looping) { gme_start_track(gme, 0); current_track = 0; + FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); From 2fbe206ecb6c978f088f7398e970ecbad8b4b90b Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 13:41:26 -0400 Subject: [PATCH 060/194] A word (cherry picked from commit fb6f8c8a0752c229f5b7369729437c8fecb54d45) --- src/sdl/mixer_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index ca22724b..92706592 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -719,8 +719,9 @@ boolean I_PlaySong(boolean looping) Mix_HookMusic(mix_gme, gme); return true; } + else #endif - else if (!music) + if (!music) return false; if (Mix_PlayMusic(music, looping && loop_point == 0.0f ? -1 : 0) == -1) From 5f22b7d973002eb873551dff56a07a034c564a61 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:01:57 -0400 Subject: [PATCH 061/194] Volume fixes # Conflicts: # src/sdl/mixer_sound.c (cherry picked from commit d39b7011c5b12e5b7abe3e493971e003469a1f3d) --- src/s_sound.c | 6 ++++-- src/sdl/mixer_sound.c | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 723401fb..6b632687 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1465,11 +1465,13 @@ void S_SetMusicVolume(INT32 digvolume, INT32 seqvolume) switch(I_SongType()) { case MU_MID: - case MU_MOD: - case MU_GME: + //case MU_MOD: + //case MU_GME: I_SetMusicVolume(seqvolume&31); + break; default: I_SetMusicVolume(digvolume&31); + break; } } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 92706592..49905efd 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -769,7 +769,7 @@ void I_ResumeSong(void) void I_SetMusicVolume(UINT8 volume) { - if (!music) + if (!I_SongPlaying()) return; #ifdef _WIN32 From d94f7e3cb095b14bad42dc14e39fc40848ed86ee Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:02:46 -0400 Subject: [PATCH 062/194] Stub I_UnloadSong because we already unload in I_StopMusic * Stop-gap for now. Ideally the logic would be in the respective places. # Conflicts: # src/sdl/mixer_sound.c (cherry picked from commit eae5d3333f5001512c82f22f2b1433a955b3a6c3) --- src/sdl/mixer_sound.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 49905efd..676bfc4d 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -705,8 +705,11 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - Mix_FreeMusic(music); - music = NULL; + // \todo unhook looper + //var_cleanup(); + //Mix_FreeMusic(music); + //music = NULL; + I_StopSong(); } boolean I_PlaySong(boolean looping) From 8541963c613cfaaff38feef1e00b00a0d5c9ddbc Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 24 Aug 2018 18:00:18 -0400 Subject: [PATCH 063/194] I_SongPlaying detect GME properly (cherry picked from commit e88d1477616ca66472ecb50d371e37dc79c77c0f) --- src/sdl/mixer_sound.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 676bfc4d..dd00d78f 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -524,7 +524,12 @@ musictype_t I_SongType(void) boolean I_SongPlaying(void) { - return (boolean)music; + return ( +#ifdef HAVE_LIBGME + (I_SongType() == MU_GME && gme) || +#endif + (boolean)music + ); } boolean I_SongPaused(void) From fac7d19637dd29e09622493281744fbfaa045dc0 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 25 Aug 2018 21:42:39 -0400 Subject: [PATCH 064/194] Case-insensitive music_name comparison (cherry picked from commit a7ae059949b320723727aea4468a370bc63c3910) --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 6b632687..53b8a962 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1378,7 +1378,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) return; } - if (strncmp(music_name, mmusic, 6)) + if (strnicmp(music_name, newmusic, 6)) { S_StopMusic(); // shutdown old music From 4b1bc53db13198c4746102cff6a0a90eab2e4d88 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 10:58:41 -0400 Subject: [PATCH 065/194] Compile fixes --- src/d_main.c | 11 ++++------- src/s_sound.c | 2 +- src/sdl/i_video.c | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index ed1b4468..9d2e1bcc 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -121,20 +121,17 @@ INT32 postimgparam; postimg_t postimgtype2 = postimg_none; INT32 postimgparam2; +// These variables are only true if +// whether the respective sound system is disabled +// or they're init'ed, but the player just toggled them #ifdef _XBOX boolean midi_disabled = true, sound_disabled = true; boolean digital_disabled = true; #else -boolean midi_disabled = false, sound_disabled = false; -boolean digital_disabled = false; // No fmod-based music -#endif - -// These variables are only true if -// whether the respective sound system is disabled -// or they're init'ed, but the player just toggled them boolean midi_disabled = false; boolean sound_disabled = false; boolean digital_disabled = false; +#endif boolean advancedemo; #ifdef DEBUGFILE diff --git a/src/s_sound.c b/src/s_sound.c index 53b8a962..969d9fde 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1378,7 +1378,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) return; } - if (strnicmp(music_name, newmusic, 6)) + if (strnicmp(music_name, mmusic, 6)) { S_StopMusic(); // shutdown old music diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index ce84e86a..30ef1b27 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -566,7 +566,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) // Tell game we got focus back, resume music if necessary window_notinfocus = false; if (!paused) - I_ResumeSong(0); //resume it + I_ResumeSong(); //resume it if (!firsttimeonmouse) { @@ -578,7 +578,7 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) { // Tell game we lost focus, pause music window_notinfocus = true; - I_PauseSong(0); + I_PauseSong(); if (!disable_mouse) { From 691de18fbbe502fe15fa30854a09c028897cc312 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 11:10:38 -0400 Subject: [PATCH 066/194] Menu sound toggle fixes (and add starpost sfx to menu) --- src/m_menu.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 6a6875aa..63794c52 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6954,23 +6954,15 @@ static void M_ToggleSFX(void) { sound_disabled = false; I_StartupSound(); - if (sound_disabled) return; S_InitSfxChannels(cv_soundvolume.value); + S_StartSound(NULL, sfx_strpst); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); } else { - if (sound_disabled) - { - sound_disabled = false; - M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); - } - else - { - sound_disabled = true; - S_StopSounds(); - M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING); - } + sound_disabled = true; + S_StopSounds(); + M_StartMessage(M_GetText("SFX Disabled\n"), NULL, MM_NOTHING); } } @@ -6980,7 +6972,6 @@ static void M_ToggleDigital(void) { digital_disabled = false; I_InitMusic(); - if (digital_disabled) return; S_StopMusic(); if (Playing()) P_RestoreMusic(&players[consoleplayer]); @@ -7020,7 +7011,6 @@ static void M_ToggleMIDI(void) { midi_disabled = false; I_InitMusic(); - if (midi_disabled) return; if (Playing()) P_RestoreMusic(&players[consoleplayer]); else From 8e05de17f07e599ebb0e3030cb6d74a0b1f76e02 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 12:29:58 -0400 Subject: [PATCH 067/194] Bring back music_data handle, for srb2dd --- src/s_sound.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/s_sound.c b/src/s_sound.c index 969d9fde..13b8beac 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1215,6 +1215,7 @@ const char *compat_special_music_slots[16] = #endif static char music_name[7]; // up to 6-character name +static void *music_data; static UINT16 music_flags; static boolean music_looping; @@ -1333,6 +1334,7 @@ static boolean S_LoadMusic(const char *mname) { strncpy(music_name, mname, 7); music_name[6] = 0; + music_data = mdata; return true; } else @@ -1343,6 +1345,10 @@ static void S_UnloadMusic(void) { I_UnloadSong(); music_name[0] = 0; +#ifndef HAVE_SDL //SDL uses RWOPS + Z_ChangeTag(music_data, PU_CACHE); +#endif + music_data = NULL; music_flags = 0; music_looping = false; } From e72610a3dc0e7e1d18deb6375daa8bd5ef1e420f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 12:47:33 -0400 Subject: [PATCH 068/194] Separate StopMusic and UnloadMusic --- src/s_sound.c | 12 ++++------- src/sdl/mixer_sound.c | 50 ++++++++++++++++++------------------------- 2 files changed, 25 insertions(+), 37 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 13b8beac..2b8e8e72 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1344,11 +1344,13 @@ static boolean S_LoadMusic(const char *mname) static void S_UnloadMusic(void) { I_UnloadSong(); - music_name[0] = 0; + #ifndef HAVE_SDL //SDL uses RWOPS Z_ChangeTag(music_data, PU_CACHE); #endif music_data = NULL; + + music_name[0] = 0; music_flags = 0; music_looping = false; } @@ -1413,13 +1415,7 @@ void S_StopMusic(void) S_SpeedMusic(1.0f); I_StopSong(); - I_UnloadSong(); - -#ifndef HAVE_SDL //SDL uses RWOPS - Z_ChangeTag(music_data, PU_CACHE); -#endif - - music_name[0] = 0; + S_UnloadMusic(); // for now, stopping also means you unload the song } // diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index dd00d78f..99a379ea 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -484,19 +484,7 @@ FUNCMATH void I_InitMusic(void) void I_ShutdownMusic(void) { -#ifdef HAVE_LIBGME - if (gme) - { - Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; - } -#endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; + I_UnloadSong(); } /// ------------------------ @@ -565,10 +553,8 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t len) { - I_Assert(!music); -#ifdef HAVE_LIBGME - I_Assert(!gme); -#endif + if (music || gme) + I_UnloadSong(); #ifdef HAVE_LIBGME if ((UINT8)data[0] == 0x1F @@ -710,11 +696,20 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - // \todo unhook looper - //var_cleanup(); - //Mix_FreeMusic(music); - //music = NULL; I_StopSong(); + +#ifdef HAVE_LIBGME + if (gme) + { + gme_delete(gme); + gme = NULL; + } +#endif + if (music) + { + Mix_FreeMusic(music); + music = NULL; + } } boolean I_PlaySong(boolean looping) @@ -750,17 +745,14 @@ void I_StopSong(void) if (gme) { Mix_HookMusic(NULL, NULL); - gme_delete(gme); - gme = NULL; current_track = -1; - return; } #endif - if (!music) - return; - Mix_HookMusicFinished(NULL); - Mix_FreeMusic(music); - music = NULL; + if (music) + { + Mix_HookMusicFinished(NULL); + Mix_HaltMusic(); + } } void I_PauseSong(void) From 0999b0f8a8044eae0d8109ba3f0df102bb32c246 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 13:24:15 -0400 Subject: [PATCH 069/194] srb2dd music cleanup fixes --- src/win32/win_cd.c | 2 +- src/win32/win_snd.c | 76 +++++++++++++++++---------------------------- 2 files changed, 29 insertions(+), 49 deletions(-) diff --git a/src/win32/win_cd.c b/src/win32/win_cd.c index f6c43074..2586b844 100644 --- a/src/win32/win_cd.c +++ b/src/win32/win_cd.c @@ -471,7 +471,7 @@ void I_PlayCD(UINT8 nTrack, UINT8 bLooping) //faB: stop MIDI music, MIDI music will restart if volume is upped later cv_digmusicvolume.value = 0; cv_midimusicvolume.value = 0; - I_StopSong (0); + I_StopSong(); //faB: I don't use the notify message, I'm trying to minimize the delay mciPlay.dwCallback = (DWORD)((size_t)hWndMain); diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 2e05c4f7..36a5904a 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -475,11 +475,11 @@ musictype_t I_SongType(void) return MU_WAV; case FMOD_SOUND_TYPE_MOD: return MU_MOD; - case FMOD_SOUND_TYPE_MID: + case FMOD_SOUND_TYPE_MIDI: return MU_MID; case FMOD_SOUND_TYPE_OGGVORBIS: return MU_OGG; - case FMOD_SOUND_TYPE_MP3: + case FMOD_SOUND_TYPE_MPEG: return MU_MP3; case FMOD_SOUND_TYPE_FLAC: return MU_FLAC; @@ -547,20 +547,13 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t len) { - char *data; - size_t len; FMOD_CREATESOUNDEXINFO fmt; - lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); + FMOD_RESULT e; + FMOD_TAG tag; + unsigned int loopstart, loopend; - if (lumpnum == LUMPERROR) - { - lumpnum = W_CheckNumForName(va("D_%s",musicname)); - if (lumpnum == LUMPERROR) - return false; - } - - data = (char *)W_CacheLumpNum(lumpnum, PU_MUSIC); - len = W_LumpLength(lumpnum); + if (gme || music_stream) + I_UnloadSong(); memset(&fmt, 0, sizeof(FMOD_CREATESOUNDEXINFO)); fmt.cbsize = sizeof(FMOD_CREATESOUNDEXINFO); @@ -595,8 +588,6 @@ boolean I_LoadSong(char *data, size_t len) gme_equalizer_t gmeq = {GME_TREBLE, GME_BASS, 0,0,0,0,0,0,0,0}; Z_Free(inflatedData); // GME supposedly makes a copy for itself, so we don't need this lying around Z_Free(data); // We don't need this, either. - gme_start_track(gme, 0); - current_track = 0; gme_set_equalizer(gme,&gmeq); fmt.format = FMOD_SOUND_FORMAT_PCM16; fmt.defaultfrequency = 44100; @@ -605,10 +596,7 @@ boolean I_LoadSong(char *data, size_t len) fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; - FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); - FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); - FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); - FMR(FMOD_Channel_SetPriority(music_channel, 0)); + FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER, &fmt, &music_stream)); return true; } } @@ -675,26 +663,24 @@ boolean I_LoadSong(char *data, size_t len) fmt.decodebuffersize = (44100 * 2) / 35; fmt.pcmreadcallback = GMEReadCallback; fmt.userdata = gme; + FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER, &fmt, &music_stream)); return true; } #endif fmt.length = len; - FMOD_RESULT e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT|(looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream); + e = FMOD_System_CreateStream(fsys, data, FMOD_OPENMEMORY_POINT, &fmt, &music_stream); if (e != FMOD_OK) { if (e == FMOD_ERR_FORMAT) - CONS_Alert(CONS_WARNING, "Failed to play music lump %s due to invalid format.\n", W_CheckNameForNum(lumpnum)); + CONS_Alert(CONS_WARNING, "Failed to play music lump due to invalid format.\n"); else FMR(e); return false; } // Try to find a loop point in streaming music formats (ogg, mp3) - FMOD_RESULT e; - FMOD_TAG tag; - unsigned int loopstart, loopend; // A proper LOOPPOINT is its own tag, stupid. e = FMOD_Sound_GetTag(music_stream, "LOOPPOINT", 0, &tag); @@ -708,13 +694,6 @@ boolean I_LoadSong(char *data, size_t len) return true; } - // todo - // if(music type == MIDI) - // { - // FMR(FMOD_Sound_SetMode(music_stream, FMOD_LOOP_NORMAL)); - // return true; - // } - // Use LOOPMS for time in miliseconds. e = FMOD_Sound_GetTag(music_stream, "LOOPMS", 0, &tag); if (e != FMOD_ERR_TAGNOTFOUND) @@ -758,10 +737,19 @@ boolean I_LoadSong(char *data, size_t len) void I_UnloadSong(void) { - UNREFERENCED_PARAMETER(handle); + I_StopSong(); +#ifdef HAVE_LIBGME + if (gme) + { + gme_delete(gme); + gme = NULL; + } +#endif if (music_stream) + { FMR(FMOD_Sound_Release(music_stream)); - music_stream = NULL; + music_stream = NULL; + } } boolean I_PlaySong(boolean looping) @@ -771,7 +759,6 @@ boolean I_PlaySong(boolean looping) { gme_start_track(gme, 0); current_track = 0; - FMR(FMOD_System_CreateStream(fsys, NULL, FMOD_OPENUSER | (looping ? FMOD_LOOP_NORMAL : 0), &fmt, &music_stream)); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); FMR(FMOD_Channel_SetVolume(music_channel, music_volume / 31.0)); FMR(FMOD_Channel_SetPriority(music_channel, 0)); @@ -779,6 +766,7 @@ boolean I_PlaySong(boolean looping) } #endif + FMR(FMOD_Sound_SetMode(music_stream, (looping ? FMOD_LOOP_NORMAL : FMOD_LOOP_OFF))); FMR(FMOD_System_PlaySound(fsys, FMOD_CHANNEL_FREE, music_stream, false, &music_channel)); if (I_SongType() != MU_MID) FMR(FMOD_Channel_SetVolume(music_channel, midi_volume / 31.0)); @@ -792,33 +780,25 @@ boolean I_PlaySong(boolean looping) void I_StopSong(void) { -#ifdef HAVE_LIBGME - if (gme) - gme_delete(gme); - gme = NULL; -#endif - current_track = -1; - - I_UnloadSong(); + if (music_channel) + FMR_MUSIC(FMOD_Channel_Stop(music_channel)); } void I_PauseSong(void) { - UNREFERENCED_PARAMETER(handle); - if (music_stream) + if (music_channel) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, true)); } void I_ResumeSong(void) { - UNREFERENCED_PARAMETER(handle); - if (music_stream) + if (music_channel) FMR_MUSIC(FMOD_Channel_SetPaused(music_channel, false)); } void I_SetMusicVolume(UINT8 volume) { - if (!music_stream) + if (!music_channel) return; // volume is 0 to 31. From cb4e075137857a391005cfb12c25b294c4e96031 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 13:36:01 -0400 Subject: [PATCH 070/194] I_InitMusic SDL2: Don't unload GME indiscriminately --- src/sdl/mixer_sound.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 99a379ea..f39d375e 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -476,10 +476,6 @@ static void mix_gme(void *udata, Uint8 *stream, int len) FUNCMATH void I_InitMusic(void) { -#ifdef HAVE_LIBGME - gme = NULL; - current_track = -1; -#endif } void I_ShutdownMusic(void) From 76be77b93a2a655cd28983c1709fe058c5878859 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 14:52:24 -0400 Subject: [PATCH 071/194] Rip out SDL Mixer code from sdl_sound.c because superfluous * Mixer code has been in mixer_sound.c; this file is not invoked unless compiling with NOMIXER=1 * Remove everything under #ifdef HAVE_MIXER because this is never triggered * Comment out #ifdef HAVE_LIBGME because we don't support playing music anyway (but theoretically, it could have worked separately from Mixer) * Stub new music calls --- src/sdl/sdl_sound.c | 611 +++----------------------------------------- 1 file changed, 42 insertions(+), 569 deletions(-) diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 887726eb..e29ac080 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -989,7 +989,7 @@ FUNCINLINE static ATTRINLINE void I_UpdateStream16M(Uint8 *stream, int len) if (Snd_Mutex) SDL_UnlockMutex(Snd_Mutex); } -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_UpdateSteamGME(Music_Emu *emu, INT16 *stream, int len, UINT8 looping) { #define GME_BUFFER_LEN 44100*2048 @@ -1049,14 +1049,16 @@ static void SDLCALL I_UpdateStream(void *userdata, Uint8 *stream, int len) else if (audio.channels == 2 && audio.format == AUDIO_S16SYS) { I_UpdateStream16S(stream, len); -#ifdef HAVE_LIBGME - if (userdata) - { - srb2audio_t *sa_userdata = userdata; - if (!sa_userdata->gme_pause) - I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop); - } -#endif + + // Crashes! But no matter; this build doesn't play music anyway... +// #ifdef HAVE_LIBGME +// if (userdata) +// { +// srb2audio_t *sa_userdata = userdata; +// if (!sa_userdata->gme_pause) +// I_UpdateSteamGME(sa_userdata->gme_emu, (INT16 *)stream, len/4, sa_userdata->gme_loop); +// } +// #endif } } @@ -1313,40 +1315,11 @@ void I_StartupSound(void) // MUSIC API. // -musictype_t I_SongType(void) -{ -#ifdef HAVE_MIXER -#ifdef HAVE_LIBGME - if (gme) - return MU_GME; - else -#endif - if (!music) - return MU_NONE; - else if (Mix_GetMusicType(music) == MUS_MID) - return MU_MID; - else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED) - return MU_MOD; - else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) - return MU_MP3; - else - return (musictype_t)Mix_GetMusicType(music); -#else - return MU_NONE -#endif -} +/// ------------------------ +// MUSIC SYSTEM +/// ------------------------ -boolean I_SongPlaying(void) -{ - return music_started; -} - -boolean I_SongPaused(void) -{ - return Mix_PausedMusic(); -} - -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_ShutdownGMEMusic(void) { Snd_LockAudio(); @@ -1357,235 +1330,14 @@ static void I_ShutdownGMEMusic(void) } #endif -#ifdef HAVE_MIXER -static boolean LoadSong(void *data, size_t lumplength, size_t selectpos) -{ - FILE *midfile; - const char *tempname; -#ifdef USE_RWOPS - if (canuseRW) - { - SDL_RWops *SDLRW; - void *olddata = Smidi[selectpos]; //quick shortcut to set - - Z_Free(olddata); //free old memory - Smidi[selectpos] = NULL; - - if (!data) - return olddata != NULL; //was there old data? - - SDLRW = SDL_RWFromConstMem(data, (int)lumplength); //new RWops from Z_zone - if (!SDLRW) //ERROR while making RWops! - { - CONS_Printf(M_GetText("Couldn't load music lump: %s\n"), SDL_GetError()); - Z_Free(data); - return false; - } - - music[selectpos] = Mix_LoadMUS_RW(SDLRW); // new Mix_Chuck from RWops - if (music[selectpos]) - Smidi[selectpos] = data; //all done - else //ERROR while making Mix_Chuck - { - CONS_Printf(M_GetText("Couldn't load music data: %s\n"), Mix_GetError()); - Z_Free(data); - SDL_RWclose(SDLRW); - Smidi[selectpos] = NULL; - } - return true; - } -#endif - tempname = va("%s/%s", MIDI_PATH, fmidi[selectpos]); - - if (!data) - { - if (FIL_FileExists(tempname)) - return unlink(tempname)+1; -#ifdef MIDI_PATH2 - else if (FIL_FileExists(tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos]))) - return unlink(tempname)+1; -#endif - else - return false; - } - - midfile = fopen(tempname, "wb"); - -#ifdef MIDI_PATH2 - if (!midfile) - { - tempname = va("%s/%s", MIDI_PATH2, fmidi[selectpos]); - midfile = fopen(tempname, "wb"); - } -#endif - - if (!midfile) - { - CONS_Printf(M_GetText("Couldn't open file %s to write music in\n"), tempname); - Z_Free(data); - return false; - } - - if (fwrite(data, lumplength, 1, midfile) == 0) - { - CONS_Printf(M_GetText("Couldn't write music into file %s because %s\n"), tempname, strerror(ferror(midfile))); - Z_Free(data); - fclose(midfile); - return false; - } - - fclose(midfile); - - Z_Free(data); - - music[selectpos] = Mix_LoadMUS(tempname); - if (!music[selectpos]) //ERROR while making Mix_Chuck - { - CONS_Printf(M_GetText("Couldn't load music file %s: %s\n"), tempname, Mix_GetError()); - return false; - } - return true; -} -#endif - -/// ------------------------ -// MUSIC SYSTEM -/// ------------------------ - void I_InitMusic(void) { -#ifdef HAVE_MIXER - char ad[100]; - SDL_version MIXcompiled; - const SDL_version *MIXlinked; -#ifdef MIXER_INIT - const int mixstart = MIX_INIT_OGG; - int mixflags; -#endif -#endif -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME I_AddExitFunc(I_ShutdownGMEMusic); #endif - -#ifdef HAVE_MIXER - MIX_VERSION(&MIXcompiled) - MIXlinked = Mix_Linked_Version(); - I_OutputMsg("Compiled for SDL_mixer version: %d.%d.%d\n", - MIXcompiled.major, MIXcompiled.minor, MIXcompiled.patch); -#ifdef MIXER_POS - if (MIXlinked->major == 1 && MIXlinked->minor == 2 && MIXlinked->patch < 7) - canlooping = SDL_FALSE; -#endif -#ifdef USE_RWOPS - if (M_CheckParm("-noRW")) - canuseRW = SDL_FALSE; -#endif - I_OutputMsg("Linked with SDL_mixer version: %d.%d.%d\n", - MIXlinked->major, MIXlinked->minor, MIXlinked->patch); - if (audio.freq < 44100 && !M_CheckParm ("-freq")) //I want atleast 44Khz - { - audio.samples = (Uint16)(audio.samples*(INT32)(44100/audio.freq)); - audio.freq = 44100; //Alam: to keep it around the same XX ms - } - - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - { - I_OutputMsg("Temp Shutdown of SDL Audio System"); - SDL_CloseAudio(); - I_OutputMsg(" Done\n"); - } - - CONS_Printf("%s", M_GetText("I_InitMusic:")); - -#ifdef MIXER_INIT - mixflags = Mix_Init(mixstart); - if ((mixstart & MIX_INIT_FLAC) != (mixflags & MIX_INIT_FLAC)) - { - CONS_Printf("%s", M_GetText(" Unable to load FLAC support\n")); - } - if ((mixstart & MIX_INIT_MOD ) != (mixflags & MIX_INIT_MOD )) - { - CONS_Printf("%s", M_GetText(" Unable to load MOD support\n")); - } - if ((mixstart & MIX_INIT_MP3 ) != (mixflags & MIX_INIT_MP3 )) - { - CONS_Printf("%s", M_GetText(" Unable to load MP3 support\n")); - } - if ((mixstart & MIX_INIT_OGG ) != (mixflags & MIX_INIT_OGG )) - { - CONS_Printf("%s", M_GetText(" Unable to load OGG support\n")); - } -#endif - - if (Mix_OpenAudio(audio.freq, audio.format, audio.channels, audio.samples) < 0) //open_music(&audio) - { - CONS_Printf(M_GetText(" Unable to open music: %s\n"), Mix_GetError()); - midi_disabled = digital_disabled = true; - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - { - if (SDL_OpenAudio(&audio, NULL) < 0) //retry - { - CONS_Printf("%s", M_GetText(" couldn't open audio with desired format\n")); - sound_disabled = true; - sound_started = false; - } - else - { - CONS_Printf(M_GetText(" Starting with audio driver : %s\n"), SDL_AudioDriverName(ad, (int)sizeof ad)); - } - } - return; - } - else - CONS_Printf(M_GetText(" Starting up with audio driver : %s with SDL_Mixer\n"), SDL_AudioDriverName(ad, (int)sizeof ad)); - - samplecount = audio.samples; - CV_SetValue(&cv_samplerate, audio.freq); - if (sound_started -#ifdef HW3SOUND - && hws_mode == HWS_DEFAULT_MODE -#endif - ) - I_OutputMsg(" Reconfigured SDL Audio System"); - else I_OutputMsg(" Configured SDL_Mixer System"); - I_OutputMsg(" with %d samples/slice at %ikhz(%dms buffer)\n", samplecount, audio.freq/1000, (INT32) ((audio.samples * 1000.0f) / audio.freq)); - Mix_SetPostMix(audio.callback, audio.userdata); // after mixing music, add sound effects - Mix_Resume(-1); - CONS_Printf("%s", M_GetText("Music initialized\n")); - musicStarted = SDL_TRUE; - Msc_Mutex = SDL_CreateMutex(); -#endif } -void I_ShutdownMusic(void) -{ -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - CONS_Printf("%s", M_GetText("I_ShutdownMusic: ")); - - I_UnloadSong(); - I_StopSong(); - Mix_CloseAudio(); -#ifdef MIX_INIT - Mix_Quit(); -#endif - CONS_Printf("%s", M_GetText("shut down\n")); - musicStarted = SDL_FALSE; - if (Msc_Mutex) - SDL_DestroyMutex(Msc_Mutex); - Msc_Mutex = NULL; -#endif -} +void I_ShutdownMusic(void) { } /// ------------------------ // MUSIC PROPERTIES @@ -1618,149 +1370,64 @@ boolean I_SetSongSpeed(float speed) /// ------------------------ // MUSIC PLAYBACK -// \todo Merge Digital and MIDI /// ------------------------ +#if 0 //#ifdef HAVE_LIBGME +static void I_StopGME(void) +{ + Snd_LockAudio(); + gme_seek(localdata.gme_emu, 0); + Snd_UnlockAudio(); +} + +static void I_PauseGME(void) +{ + localdata.gme_pause = true; +} + +static void I_ResumeGME(void) +{ + localdata.gme_pause = false; +} +#endif + boolean I_LoadSong(char *data, size_t len) { -#ifdef HAVE_MIXER - if (midi_disabled || !musicStarted) - return false; - - if (!LoadSong(data, len, 0)) - return false; - - if (music[0]) - return true; - - CONS_Printf(M_GetText("Couldn't load MIDI: %s\n"), Mix_GetError()); -#else - (void)len; - (void)data; -#endif return false; } -void I_UnloadSong(void) -{ -#ifdef HAVE_MIXER - - if (midi_disabled || !musicStarted) - return; - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[handle]) - Mix_FreeMusic(music[handle]); - music[handle] = NULL; - LoadSong(NULL, 0, handle); -#else - (void)handle; -#endif -} +void I_UnloadSong(void) { } boolean I_PlaySong(boolean looping) { -#ifdef HAVE_MIXER - if (!musicStarted || !music[handle]) - return false; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - if (Mix_FadeInMusic(music[handle], looping ? -1 : 0, MIDIfade) == -1) - CONS_Printf(M_GetText("Couldn't play song because %s\n"), Mix_GetError()); - else - { - Mix_VolumeMusic(musicvol); - return true; - } -#else (void)looping; -#endif return false; } void I_StopSong(void) { +#if 0 //#ifdef HAVE_LIBGME I_StopGME(); -#ifdef HAVE_MIXER - if (digital_disabled) - return; - -#ifdef MIXER_POS - if (canlooping) - Mix_HookMusicFinished(NULL); -#endif - - Mix_HaltMusic(); - while (Mix_PlayingMusic()) - ; - - if (music[1]) - Mix_FreeMusic(music[1]); - music[1] = NULL; - LoadSong(NULL, 0, 1); -} - -static void I_PauseGME(void) -{ -#ifdef HAVE_LIBGME - localdata.gme_pause = true; #endif } void I_PauseSong(void) { - (void)handle; +#if 0 //#ifdef HAVE_LIBGME I_PauseGME(); -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - Mix_PauseMusic(); - //I_StopSong(handle); -#endif -} - -static void I_ResumeGME(void) -{ -#ifdef HAVE_LIBGME - localdata.gme_pause = false; #endif } void I_ResumeSong(void) { - (void)handle; +#if 0 I_ResumeGME(); -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - Mix_VolumeMusic(musicvol); - Mix_ResumeMusic(); - //I_PlaySong(handle, true); #endif } void I_SetMusicVolume(UINT8 volume) { -#ifdef HAVE_MIXER - if ((midi_disabled && digital_disabled) || !musicStarted) - return; - - if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); - musicvol = volume * 2; - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - Mix_VolumeMusic(musicvol); -#else (void)volume; -#endif } boolean I_SetSongTrack(int track) @@ -1775,16 +1442,14 @@ boolean I_SetSongTrack(int track) // then move to Playback section /// ------------------------ -#ifdef HAVE_LIBGME +#if 0 //#ifdef HAVE_LIBGME static void I_CleanupGME(void *userdata) { Z_Free(userdata); } -#endif static boolean I_StartGMESong(const char *musicname, boolean looping) { -#ifdef HAVE_LIBGME char filename[9]; void *data; lumpnum_t lumpnum; @@ -1830,199 +1495,7 @@ static boolean I_StartGMESong(const char *musicname, boolean looping) Snd_UnlockAudio(); return true; -#else - (void)musicname; - (void)looping; -#endif - return false; -} - -boolean I_StartDigSong(const char *musicname, boolean looping) -{ -#ifdef HAVE_MIXER - char filename[9]; - void *data; - lumpnum_t lumpnum; - size_t lumplength; -#endif - - if(I_StartGMESong(musicname, looping)) - return true; - -#ifdef HAVE_MIXER - if (digital_disabled) - return false; - - snprintf(filename, sizeof filename, "o_%s", musicname); - - lumpnum = W_CheckNumForName(filename); - - I_StopSong(); - - if (lumpnum == LUMPERROR) - { - // Alam_GBC: like in win32/win_snd.c: Graue 02-29-2004: don't worry about missing music, there might still be a MIDI - //I_OutputMsg("Music lump %s not found!\n", filename); - return false; // No music found. Oh well! - } - else - lumplength = W_LumpLength(lumpnum); - - data = W_CacheLumpNum(lumpnum, PU_MUSIC); - - if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); - -#ifdef MIXER_POS - if (canlooping && (loopingDig = looping) == SDL_TRUE && strcmp(data, "OggS") == 0) - looping = false; // Only on looping Ogg files, will we will do our own looping - - // Scan the Ogg Vorbis file for the COMMENT= field for a custom - // loop point - if (!looping && loopingDig) - { - size_t scan; - const char *dataum = data; - char looplength[64]; - UINT32 loopstart = 0; - UINT8 newcount = 0; - - Mix_HookMusicFinished(I_FinishMusic); - - for (scan = 0; scan < lumplength; scan++) - { - if (*dataum++ == 'C'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'M'){ - if (*dataum++ == 'M'){ - if (*dataum++ == 'E'){ - if (*dataum++ == 'N'){ - if (*dataum++ == 'T'){ - if (*dataum++ == '='){ - if (*dataum++ == 'L'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'P'){ - if (*dataum++ == 'P'){ - if (*dataum++ == 'O'){ - if (*dataum++ == 'I'){ - if (*dataum++ == 'N'){ - if (*dataum++ == 'T'){ - if (*dataum++ == '=') - { - - while (*dataum != 1 && newcount != 63) - looplength[newcount++] = *dataum++; - - looplength[newcount] = '\0'; - - loopstart = atoi(looplength); - - } - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - else - dataum--;} - } - - if (loopstart > 0) - { - loopstartDig = (double)((44.1l+loopstart) / 44100.0l); //8 PCM chucks off and PCM to secs -//#ifdef PARANOIA - //I_OutputMsg("I_StartDigSong: setting looping point to %ul PCMs(%f seconds)\n", loopstart, loopstartDig); -//#endif - } - else - { - looping = true; // loopingDig true, but couldn't find start loop point - } - } - else - loopstartDig = 0.0l; -#else - if (looping && strcmp(data, "OggS") == 0) - I_OutputMsg("I_StartDigSong: SRB2 was not compiled with looping music support(no Mix_FadeInMusicPos)\n"); -#endif - - if (!LoadSong(data, lumplength, 1)) - { - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - return false; - } - - // Note: LoadSong() frees the data. Let's make sure - // we don't try to use the data again. - data = NULL; - - if (Mix_FadeInMusic(music[1], looping ? -1 : 0, Digfade) == -1) - { - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - I_OutputMsg("I_StartDigSong: Couldn't play song %s because %s\n", musicname, Mix_GetError()); - return false; - } - Mix_VolumeMusic(musicvol); - - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); - return true; -#else - (void)looping; - (void)musicname; - return false; -#endif -} - -static void I_StopGME(void) -{ -#ifdef HAVE_LIBGME - Snd_LockAudio(); - gme_seek(localdata.gme_emu, 0); - Snd_UnlockAudio(); -#endif -} - -#ifdef MIXER_POS -static void SDLCALL I_FinishMusic(void) -{ - if (!music[1]) - return; - else if (Msc_Mutex) SDL_LockMutex(Msc_Mutex); -// I_OutputMsg("I_FinishMusic: Loopping song to %g seconds\n", loopstartDig); - - if (Mix_FadeInMusicPos(music[1], loopstartDig ? 0 : -1, Digfade, loopstartDig) == 0) - Mix_VolumeMusic(musicvol); - else - I_OutputMsg("I_FinishMusic: Couldn't loop song because %s\n", Mix_GetError()); - - if (Msc_Mutex) SDL_UnlockMutex(Msc_Mutex); } #endif + #endif //HAVE_SDL \ No newline at end of file From b330dc23946ecfae91301ababebbfddc97560c7e Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 16:39:10 -0400 Subject: [PATCH 072/194] Don't call I_StartupSound in SFX toggle * Mixer: make I_StartupSound return early if already set up * Restartaudio: Add StopSFX call --- src/d_netcmd.c | 1 + src/m_menu.c | 1 - src/sdl/mixer_sound.c | 5 ++++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ab3201c5..a58aff3f 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3955,6 +3955,7 @@ static void Command_RestartAudio_f(void) return; S_StopMusic(); + S_StopSounds(); I_ShutdownMusic(); I_ShutdownSound(); I_StartupSound(); diff --git a/src/m_menu.c b/src/m_menu.c index 63794c52..c9adbfb9 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6953,7 +6953,6 @@ static void M_ToggleSFX(void) if (sound_disabled) { sound_disabled = false; - I_StartupSound(); S_InitSfxChannels(cv_soundvolume.value); S_StartSound(NULL, sfx_strpst); M_StartMessage(M_GetText("SFX Enabled\n"), NULL, MM_NOTHING); diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index f39d375e..72217482 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -82,7 +82,10 @@ void I_StartupSound(void) // EE inits audio first so we're following along. if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) - CONS_Printf("SDL Audio already started\n"); + { + CONS_Debug(DBG_DETAILED, "SDL Audio already started\n"); + return; + } else if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { CONS_Alert(CONS_ERROR, "Error initializing SDL Audio: %s\n", SDL_GetError()); From fdbe3e80f6eac3659093a79f8dabfb92df0b1c10 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:07:13 -0400 Subject: [PATCH 073/194] Fix compile errors on buildbots * Check SDL Mixer 2.0.3 for MUS_MODPLUG_UNUSED, MUS_MP3_MAD_UNUSED * Mixed D+C in I_LoadSong --- src/sdl/mixer_sound.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 72217482..d496aa66 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -501,9 +501,17 @@ musictype_t I_SongType(void) return MU_NONE; else if (Mix_GetMusicType(music) == MUS_MID) return MU_MID; - else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED) + else if (Mix_GetMusicType(music) == MUS_MOD +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) + || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED +#endif + ) return MU_MOD; - else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED) + else if (Mix_GetMusicType(music) == MUS_MP3 +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) + || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED +#endif + ) return MU_MP3; else return (musictype_t)Mix_GetMusicType(music); @@ -552,6 +560,14 @@ boolean I_SetSongSpeed(float speed) boolean I_LoadSong(char *data, size_t len) { + const char *key1 = "LOOP"; + const char *key2 = "POINT="; + const char *key3 = "MS="; + const size_t key1len = strlen(key1); + const size_t key2len = strlen(key2); + const size_t key3len = strlen(key3); + char *p = data; + if (music || gme) I_UnloadSong(); @@ -660,13 +676,6 @@ boolean I_LoadSong(char *data, size_t len) // Find the OGG loop point. loop_point = 0.0f; - const char *key1 = "LOOP"; - const char *key2 = "POINT="; - const char *key3 = "MS="; - const size_t key1len = strlen(key1); - const size_t key2len = strlen(key2); - const size_t key3len = strlen(key3); - char *p = data; while ((UINT32)(p - data) < len) { if (strncmp(p++, key1, key1len)) From 17ec5d80220b472fe827e5e87b5c05f083a3cd24 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:27:00 -0400 Subject: [PATCH 074/194] Mixer: Better MODPLUG/MP3_MAD defines (cherry picked from commit 5b724e18b5268b0492b3f8b8980aadd2dd41e235) --- src/sdl/mixer_sound.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index d496aa66..e46da275 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -34,6 +34,12 @@ (SDL_MIXER_COMPILEDVERSION >= SDL_VERSIONNUM(X, Y, Z)) #endif +// thanks alam for making the buildbots happy! +#if SDL_MIXER_VERSION_ATLEAST(2,0,3) +#define MUS_MP3_MAD MUS_MP3_MAD_UNUSED +#define MUS_MODPLUG MUS_MODPLUG_UNUSED +#endif + #ifdef HAVE_LIBGME #include "gme/gme.h" #define GME_TREBLE 5.0 @@ -501,17 +507,9 @@ musictype_t I_SongType(void) return MU_NONE; else if (Mix_GetMusicType(music) == MUS_MID) return MU_MID; - else if (Mix_GetMusicType(music) == MUS_MOD -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) - || Mix_GetMusicType(music) == MUS_MODPLUG_UNUSED -#endif - ) + else if (Mix_GetMusicType(music) == MUS_MOD || Mix_GetMusicType(music) == MUS_MODPLUG) return MU_MOD; - else if (Mix_GetMusicType(music) == MUS_MP3 -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) - || Mix_GetMusicType(music) == MUS_MP3_MAD_UNUSED -#endif - ) + else if (Mix_GetMusicType(music) == MUS_MP3 || Mix_GetMusicType(music) == MUS_MP3_MAD) return MU_MP3; else return (musictype_t)Mix_GetMusicType(music); From 9a5eb024590d5b98afa878a6ebd49eef4fcb28ed Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 14 Sep 2018 17:47:04 -0400 Subject: [PATCH 075/194] Fix Windows buildbot for MP3_MAD/MODPLUG define (the header we use is 2.0.2) --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index e46da275..7d11c32c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -35,7 +35,7 @@ #endif // thanks alam for making the buildbots happy! -#if SDL_MIXER_VERSION_ATLEAST(2,0,3) +#if SDL_MIXER_VERSION_ATLEAST(2,0,2) #define MUS_MP3_MAD MUS_MP3_MAD_UNUSED #define MUS_MODPLUG MUS_MODPLUG_UNUSED #endif From 40a8c9c1ee4fc30e82a8ce3d84d309152a07a5a2 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Sat, 15 Sep 2018 00:34:55 -0400 Subject: [PATCH 076/194] Mixer: HAVE_LIBGME ifdef in I_LoadSong --- src/sdl/mixer_sound.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 7d11c32c..87f8fd67 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -566,7 +566,11 @@ boolean I_LoadSong(char *data, size_t len) const size_t key3len = strlen(key3); char *p = data; - if (music || gme) + if (music +#ifdef HAVE_LIBGME + || gme +#endif + ) I_UnloadSong(); #ifdef HAVE_LIBGME From 1b7b1f3f796eb08385f86e817b4486ec3a25361a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 16 Sep 2018 20:25:07 +0100 Subject: [PATCH 077/194] Fix order of operations messups by adding brackets --- src/m_anigif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_anigif.c b/src/m_anigif.c index d46d889b..e2af7009 100644 --- a/src/m_anigif.c +++ b/src/m_anigif.c @@ -492,7 +492,7 @@ static void GIF_framewrite(void) // screen regions are handled in GIF_lzw { - int d1 = (int)((100.0/NEWTICRATE)*gif_frames+1); + int d1 = (int)((100.0/NEWTICRATE)*(gif_frames+1)); int d2 = (int)((100.0/NEWTICRATE)*(gif_frames)); UINT16 delay = d1-d2; INT32 startline; From 34e403afcb501ae5e456dc292b8a3632a7e5fab9 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Tue, 18 Sep 2018 08:32:34 -0400 Subject: [PATCH 078/194] S_ChangeMusic: More specific load/play fail messages --- src/s_sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 2b8e8e72..ea129a10 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1391,14 +1391,17 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping) S_StopMusic(); // shutdown old music if (!S_LoadMusic(mmusic)) + { + CONS_Alert(CONS_ERROR, "Music %.6s could not be loaded!\n", mmusic); return; + } music_flags = mflags; music_looping = looping; if (!S_PlayMusic(looping)) { - CONS_Alert(CONS_ERROR, "Music cannot be played!\n"); + CONS_Alert(CONS_ERROR, "Music %.6s could not be played!\n", mmusic); return; } } From a53f036149a4ff1d7c9371f9f082fbfe5b65a5b7 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 20 Sep 2018 18:26:59 -0400 Subject: [PATCH 079/194] Use MemAvailable instead --- src/sdl/i_system.c | 49 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e86a39ca..984f6dd2 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -124,6 +124,10 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include "macosx/mac_resources.h" #endif +#ifndef errno +#include +#endif + // Locations for searching the srb2.srb #if defined (__unix__) || defined(__APPLE__) || defined (UNIXCOMMON) #define DEFAULTWADLOCATION1 "/usr/local/share/games/SRB2" @@ -2712,9 +2716,31 @@ const char *I_LocateWad(void) #ifdef __linux__ #define MEMINFO_FILE "/proc/meminfo" #define MEMTOTAL "MemTotal:" +#define MEMAVAILABLE "MemAvailable:" #define MEMFREE "MemFree:" +#define CACHED "Cached:" +#define BUFFERS "Buffers:" +#define SHMEM "Shmem:" #endif +/* Parse the contents of /proc/meminfo (in buf), return value of "name" + * (example: MemTotal) */ +static long get_entry(const char* name, const char* buf) +{ + char* hit = strstr(buf, name); + if (hit == NULL) { + return -1; + } + + errno = 0; + long val = strtol(hit + strlen(name), NULL, 10); + if (errno != 0) { + CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); + return -1; + } + return val; +} + // quick fix for compil UINT32 I_GetFreeMem(UINT32 *total) { @@ -2809,7 +2835,17 @@ UINT32 I_GetFreeMem(UINT32 *total) memTag += sizeof (MEMTOTAL); totalKBytes = atoi(memTag); - if ((memTag = strstr(buf, MEMFREE)) == NULL) + if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) + { + Cached = get_entry(CACHED, buf); + MemFree = get_entry(MEMFREE, buf); + Buffers = get_entry(BUFFERS, buf); + Shmem = get_entry(SHMEM, buf); + MemAvailable = Cached + MemFree + Buffers - Shmem; + guessed = true; + } + + if (MemAvailable == -1 && guessed) { // Error if (total) @@ -2817,8 +2853,15 @@ UINT32 I_GetFreeMem(UINT32 *total) return 0; } - memTag += sizeof (MEMFREE); - freeKBytes = atoi(memTag); + if (guessed) + { + freeKBytes = MemAvailable; + } + else + { + memTag += sizeof (MEMAVAILABLE); + freeKBytes = atoi(memTag); + } if (total) *total = totalKBytes << 10; From 378495cb2b8337c37b6bfefc3f510cf9b6117e61 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 20 Sep 2018 18:33:50 -0400 Subject: [PATCH 080/194] Add some stuff --- src/sdl/i_system.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 984f6dd2..3610a534 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2810,6 +2810,12 @@ UINT32 I_GetFreeMem(UINT32 *total) UINT32 totalKBytes; INT32 n; INT32 meminfo_fd = -1; + long Cached; + long MemFree; + long Buffers; + long Shmem; + long MemAvailable = -1; + boolean guessed = false; // Stupid way to verify if the amount was guessed or not. meminfo_fd = open(MEMINFO_FILE, O_RDONLY); n = read(meminfo_fd, buf, 1023); From be74b4e58b93974bc56a7f96f3f175b541b04230 Mon Sep 17 00:00:00 2001 From: Steel Date: Fri, 21 Sep 2018 07:16:54 -0400 Subject: [PATCH 081/194] Fix up errors with buildbots --- src/sdl/i_system.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 3610a534..e9e1ae92 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1,6 +1,6 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- -// +- // // Copyright (C) 1993-1996 by id Software, Inc. // Portions Copyright (C) 1998-2000 by DooM Legacy Team. // @@ -2095,7 +2095,6 @@ INT32 I_StartupSystem(void) return 0; } - // // I_Quit // @@ -2721,25 +2720,26 @@ const char *I_LocateWad(void) #define CACHED "Cached:" #define BUFFERS "Buffers:" #define SHMEM "Shmem:" -#endif /* Parse the contents of /proc/meminfo (in buf), return value of "name" * (example: MemTotal) */ static long get_entry(const char* name, const char* buf) { + long val; char* hit = strstr(buf, name); if (hit == NULL) { return -1; } errno = 0; - long val = strtol(hit + strlen(name), NULL, 10); + val = strtol(hit + strlen(name), NULL, 10); if (errno != 0) { CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); return -1; } return val; } +#endif // quick fix for compil UINT32 I_GetFreeMem(UINT32 *total) From af58ba9ae3fa661ea406bca3b134ae2ac6b76a2c Mon Sep 17 00:00:00 2001 From: Steel Date: Fri, 21 Sep 2018 07:21:49 -0400 Subject: [PATCH 082/194] Remove this that somehow slipped in. --- src/sdl/i_system.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index e9e1ae92..b7326b06 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1,6 +1,6 @@ // Emacs style mode select -*- C++ -*- //----------------------------------------------------------------------------- -- // +// // Copyright (C) 1993-1996 by id Software, Inc. // Portions Copyright (C) 1998-2000 by DooM Legacy Team. // From 68ec8119096c3744e25115337fd03ea3e124df2a Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Fri, 21 Sep 2018 11:26:08 -0400 Subject: [PATCH 083/194] Rearrange the code. Thanks again MonsterIestyn! --- src/sdl/i_system.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index b7326b06..05d9e092 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -2815,7 +2815,6 @@ UINT32 I_GetFreeMem(UINT32 *total) long Buffers; long Shmem; long MemAvailable = -1; - boolean guessed = false; // Stupid way to verify if the amount was guessed or not. meminfo_fd = open(MEMINFO_FILE, O_RDONLY); n = read(meminfo_fd, buf, 1023); @@ -2848,26 +2847,21 @@ UINT32 I_GetFreeMem(UINT32 *total) Buffers = get_entry(BUFFERS, buf); Shmem = get_entry(SHMEM, buf); MemAvailable = Cached + MemFree + Buffers - Shmem; - guessed = true; - } - if (MemAvailable == -1 && guessed) - { - // Error - if (total) - *total = 0L; - return 0; - } - - if (guessed) - { + if (MemAvailable == -1) + { + // Error + if (total) + *total = 0L; + return 0; + } freeKBytes = MemAvailable; - } - else - { + } + else + { memTag += sizeof (MEMAVAILABLE); freeKBytes = atoi(memTag); - } + } if (total) *total = totalKBytes << 10; From f88708bb75810e5ef089b5cf5246d3a2f9154d02 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Fri, 21 Sep 2018 12:05:52 -0400 Subject: [PATCH 084/194] Fix the weird indentation --- src/sdl/i_system.c | 76 +++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 05d9e092..f92cd4b6 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1683,7 +1683,7 @@ static void I_ShutdownMouse2(void) EscapeCommFunction(mouse2filehandle, CLRRTS); PurgeComm(mouse2filehandle, PURGE_TXABORT | PURGE_RXABORT | - PURGE_TXCLEAR | PURGE_RXCLEAR); + PURGE_TXCLEAR | PURGE_RXCLEAR); CloseHandle(mouse2filehandle); @@ -1876,11 +1876,11 @@ void I_StartupMouse2(void) { // COM file handle mouse2filehandle = CreateFileA(cv_mouse2port.string, GENERIC_READ | GENERIC_WRITE, - 0, // exclusive access - NULL, // no security attrs - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL, - NULL); + 0, // exclusive access + NULL, // no security attrs + OPEN_EXISTING, + FILE_ATTRIBUTE_NORMAL, + NULL); if (mouse2filehandle == INVALID_HANDLE_VALUE) { INT32 e = GetLastError(); @@ -1900,7 +1900,7 @@ void I_StartupMouse2(void) // purge buffers PurgeComm(mouse2filehandle, PURGE_TXABORT | PURGE_RXABORT - | PURGE_TXCLEAR | PURGE_RXCLEAR); + | PURGE_TXCLEAR | PURGE_RXCLEAR); // setup port to 1200 7N1 dcb.DCBlength = sizeof (DCB); @@ -2029,7 +2029,7 @@ static void I_ShutdownTimer(void) tic_t I_GetTime (void) { static Uint32 basetime = 0; - Uint32 ticks = SDL_GetTicks(); + Uint32 ticks = SDL_GetTicks(); if (!basetime) basetime = ticks; @@ -2373,7 +2373,7 @@ void I_GetDiskFreeSpace(INT64 *freespace) { DWORD SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters; GetDiskFreeSpace(NULL, &SectorsPerCluster, &BytesPerSector, - &NumberOfFreeClusters, &TotalNumberOfClusters); + &NumberOfFreeClusters, &TotalNumberOfClusters); *freespace = BytesPerSector*SectorsPerCluster*NumberOfFreeClusters; } #else // Dummy for platform independent; 1GB should be enough @@ -2595,22 +2595,22 @@ static const char *locateWad(void) #ifdef CMAKECONFIG #ifndef NDEBUG - I_OutputMsg(","CMAKE_ASSETS_DIR); - strcpy(returnWadPath, CMAKE_ASSETS_DIR); - if (isWadPathOk(returnWadPath)) - { - return returnWadPath; - } + I_OutputMsg(","CMAKE_ASSETS_DIR); + strcpy(returnWadPath, CMAKE_ASSETS_DIR); + if (isWadPathOk(returnWadPath)) + { + return returnWadPath; + } #endif #endif #ifdef __APPLE__ - OSX_GetResourcesPath(returnWadPath); - I_OutputMsg(",%s", returnWadPath); - if (isWadPathOk(returnWadPath)) - { - return returnWadPath; - } + OSX_GetResourcesPath(returnWadPath); + I_OutputMsg(",%s", returnWadPath); + if (isWadPathOk(returnWadPath)) + { + return returnWadPath; + } #endif // examine default dirs @@ -2725,19 +2725,19 @@ const char *I_LocateWad(void) * (example: MemTotal) */ static long get_entry(const char* name, const char* buf) { - long val; - char* hit = strstr(buf, name); - if (hit == NULL) { - return -1; - } + long val; + char* hit = strstr(buf, name); + if (hit == NULL) { + return -1; + } - errno = 0; - val = strtol(hit + strlen(name), NULL, 10); - if (errno != 0) { - CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); - return -1; - } - return val; + errno = 0; + val = strtol(hit + strlen(name), NULL, 10); + if (errno != 0) { + CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); + return -1; + } + return val; } #endif @@ -2850,18 +2850,18 @@ UINT32 I_GetFreeMem(UINT32 *total) if (MemAvailable == -1) { - // Error + // Error if (total) *total = 0L; return 0; } freeKBytes = MemAvailable; - } - else - { + } + else + { memTag += sizeof (MEMAVAILABLE); freeKBytes = atoi(memTag); - } + } if (total) *total = totalKBytes << 10; From 79f5f4885c70e373cd6d4afc275c2141aa545736 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 4 Oct 2018 19:47:19 -0400 Subject: [PATCH 085/194] Split zlib and libpng --- src/Makefile | 22 +++++++++++++++------- src/sdl/mixer_sound.c | 17 ++++++++--------- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Makefile b/src/Makefile index dd250b0b..7a67c3f0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -66,6 +66,7 @@ # Compile without 3D sound support, add 'NOHS=1' # Compile with GDBstubs, add 'RDB=1' # Compile without PNG, add 'NOPNG=1' +# Compile without zlib, add 'NOZLIB=1' # # Addon for SDL: # To Cross-Compile, add 'SDL_CONFIG=/usr/*/bin/sdl-config' @@ -119,6 +120,7 @@ include Makefile.cfg ifdef DUMMY NOPNG=1 +NOZLIB=1 NONET=1 NOHW=1 NOHS=1 @@ -199,6 +201,7 @@ endif ifdef NDS NOPNG=1 +NOZLIB=1 NONET=1 #NOHW=1 NOHS=1 @@ -325,13 +328,6 @@ LIBS+=$(PNG_LDFLAGS) CFLAGS+=$(PNG_CFLAGS) endif -ZLIB_PKGCONFIG?=zlib -ZLIB_CFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --cflags) -ZLIB_LDFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --libs) - -LIBS+=$(ZLIB_LDFLAGS) -CFLAGS+=$(ZLIB_CFLAGS) - ifdef HAVE_LIBGME OPTS+=-DHAVE_LIBGME @@ -343,6 +339,18 @@ LIBS+=$(LIBGME_LDFLAGS) CFLAGS+=$(LIBGME_CFLAGS) endif +ifndef NOZLIB +OPTS+=-DHAVE_ZLIB +ZLIB_PKGCONFIG?=zlib +ZLIB_CFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --cflags) +ZLIB_LDFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --libs) + +LIBS+=$(ZLIB_LDFLAGS) +CFLAGS+=$(ZLIB_CFLAGS) +else +NOPNG=1 +endif + ifdef STATIC LIBS:=-static $(LIBS) endif diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 5211efe0..362d7f26 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -38,9 +38,6 @@ #include "gme/gme.h" #define GME_TREBLE 5.0 #define GME_BASS 1.0 -#ifdef HAVE_PNG /// TODO: compile with zlib support without libpng - -#define HAVE_ZLIB #ifndef _MSC_VER #ifndef _LARGEFILE64_SOURCE @@ -56,10 +53,13 @@ #define _FILE_OFFSET_BITS 0 #endif -#include "zlib.h" #endif #endif +#ifdef HAVE_ZLIB +#include "zlib.h" +#endif + UINT8 sound_started = false; static boolean midimode; @@ -361,7 +361,7 @@ void *I_GetSfx(sfxinfo_t *sfx) } Z_Free(inflatedData); // GME didn't open jack, but don't let that stop us from freeing this up #else - //CONS_Alert(CONS_ERROR,"Cannot decompress VGZ; no zlib support\n"); + return NULL; // No zlib support #endif } // Try to read it as a GME sound @@ -621,7 +621,8 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } Z_Free(inflatedData); // GME didn't open jack, but don't let that stop us from freeing this up #else - //CONS_Alert(CONS_ERROR,"Cannot decompress VGZ; no zlib support\n"); + CONS_Alert(CONS_ERROR,"Cannot decompress VGZ; no zlib support\n"); + return true; #endif } else if (!gme_open_data(data, len, &gme, 44100)) @@ -840,6 +841,4 @@ void I_UnRegisterSong(INT32 handle) (void)handle; Mix_FreeMusic(music); music = NULL; -} - -#endif +} \ No newline at end of file From 49cb1ffe9fb578f8abb29a3f45355ded6211dc03 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 4 Oct 2018 22:38:59 -0400 Subject: [PATCH 086/194] Restore deleted endif --- src/sdl/mixer_sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 362d7f26..d1083518 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -51,8 +51,6 @@ #ifndef _FILE_OFFSET_BITS #define _FILE_OFFSET_BITS 0 -#endif - #endif #endif @@ -841,4 +839,6 @@ void I_UnRegisterSong(INT32 handle) (void)handle; Mix_FreeMusic(music); music = NULL; -} \ No newline at end of file +} + +#endif \ No newline at end of file From fc5d969642f57f54c12acd137355473f14d84acd Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 4 Oct 2018 22:44:26 -0400 Subject: [PATCH 087/194] Fix DD compiling --- src/win32/win_snd.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index f168f1fe..c030eec5 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -17,9 +17,6 @@ #include "gme/gme.h" #define GME_TREBLE 5.0 #define GME_BASS 1.0 -#ifdef HAVE_PNG /// TODO: compile with zlib support without libpng - -#define HAVE_ZLIB #ifndef _MSC_VER #ifndef _WII From b812a6a4abdf705d65c6f204291ec6645fe5d729 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 4 Oct 2018 22:56:11 -0400 Subject: [PATCH 088/194] Really fix DD compiling this time. --- src/win32/win_snd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index c030eec5..bc04bd6d 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -34,6 +34,7 @@ #define _FILE_OFFSET_BITS 0 #endif +#ifdef HAVE_ZLIB #include "zlib.h" #endif #endif From 1ec601af6b989f7ebdc0fa89f4bc2452977ae209 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 5 Oct 2018 22:42:36 +0100 Subject: [PATCH 089/194] Draw a star for continues if invalid skin numbers are somehow supplied --- src/v_video.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index aa2852c0..802a4d38 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -653,14 +653,10 @@ void V_DrawCroppedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_ // void V_DrawContinueIcon(INT32 x, INT32 y, INT32 flags, INT32 skinnum, UINT8 skincolor) { - if (skins[skinnum].flags & SF_HIRES -#ifdef HWRENDER -// || (rendermode != render_soft && rendermode != render_none) -#endif - ) - V_DrawScaledPatch(x - 10, y - 14, flags, W_CachePatchName("CONTINS", PU_CACHE)); + if (skinnum < 0 || skinnum >= numskins || (skins[skinnum].flags & SF_HIRES)) + V_DrawScaledPatch(x - 10, y - 14, flags, W_CachePatchName("CONTINS", PU_CACHE)); // Draw a star else - { + { // Find front angle of the first waiting frame of the character's actual sprites spriteframe_t *sprframe = &skins[skinnum].spritedef.spriteframes[2 & FF_FRAMEMASK]; patch_t *patch = W_CachePatchNum(sprframe->lumppat[0], PU_CACHE); const UINT8 *colormap = R_GetTranslationColormap(skinnum, skincolor, GTC_CACHE); From 725a65c1f7eff77e5632b6a7d7fdb11c47ee0c3f Mon Sep 17 00:00:00 2001 From: Sryder Date: Sat, 6 Oct 2018 21:44:40 +0100 Subject: [PATCH 090/194] Call SDL_RWclose after an SDL_RWFromMem call to close the RWops. --- src/sdl/mixer_sound.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 5211efe0..e835a55c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -387,7 +387,15 @@ void *I_GetSfx(sfxinfo_t *sfx) #endif // Try to load it as a WAVE or OGG using Mixer. - return Mix_LoadWAV_RW(SDL_RWFromMem(lump, sfx->length), 1); + SDL_RWops *rw = SDL_RWFromMem(lump, sfx->length); + if (rw != NULL) + { + Mix_Chunk *chunk = Mix_LoadWAV_RW(rw, 1); + SDL_RWclose(rw); + return chunk; + } + + return NULL; // haven't been able to get anything } void I_FreeSfx(sfxinfo_t *sfx) @@ -635,7 +643,12 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } #endif - music = Mix_LoadMUS_RW(SDL_RWFromMem(data, len), SDL_FALSE); + SDL_RWops *rw = SDL_RWFromMem(data, len); + if (rw != NULL) + { + music = Mix_LoadMUS_RW(rw, SDL_FALSE); + SDL_RWclose(rw); + } if (!music) { CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); @@ -798,7 +811,12 @@ void I_SetMIDIMusicVolume(UINT8 volume) INT32 I_RegisterSong(void *data, size_t len) { - music = Mix_LoadMUS_RW(SDL_RWFromMem(data, len), SDL_FALSE); + SDL_RWops *rw = SDL_RWFromMem(data, len); + if (rw != NULL) + { + music = Mix_LoadMUS_RW(rw, SDL_FALSE); + SDL_RWclose(rw); + } if (!music) { CONS_Alert(CONS_ERROR, "Mix_LoadMUS_RW: %s\n", Mix_GetError()); From 7b417b573c61eeaeb325366196d78ace780f1b5a Mon Sep 17 00:00:00 2001 From: Sryder Date: Sat, 6 Oct 2018 23:59:39 +0100 Subject: [PATCH 091/194] Mix_QuickLoad_RAW sets a flag in the Mix_Chunk so that Mix_FreeChunk doesn't actually Free the sound. Checks for the flag when freeing, and if it's 0, we free the data manually after Mix_FreeChunk. I went back to Z_Malloc and Z_Free for this because they still work after this. --- src/sdl/mixer_sound.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index e835a55c..15f1595c 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -178,7 +178,7 @@ static Mix_Chunk *ds2chunk(void *stream) return NULL; // would and/or did wrap, can't store. break; } - sound = malloc(newsamples<<2); // samples * frequency shift * bytes per sample * channels + sound = Z_Malloc(newsamples<<2, PU_SOUND, 0); // samples * frequency shift * bytes per sample * channels s = (SINT8 *)stream; d = (INT16 *)sound; @@ -401,7 +401,22 @@ void *I_GetSfx(sfxinfo_t *sfx) void I_FreeSfx(sfxinfo_t *sfx) { if (sfx->data) + { + Mix_Chunk *chunk = (Mix_Chunk*)sfx->data; + UINT8 *abufdata = NULL; + if (chunk->allocated == 0) + { + // We allocated the data in this chunk, so get the abuf from mixer, then let it free the chunk, THEN we free the data + // I believe this should ensure the sound is not playing when we free it + abufdata = chunk->abuf; + } Mix_FreeChunk(sfx->data); + if (abufdata) + { + // I'm going to assume we used Z_Malloc to allocate this data. + Z_Free(abufdata); + } + } sfx->data = NULL; sfx->lumpnum = LUMPERROR; } From d072dd27254596c7c8925b4f6d08c151e57535f2 Mon Sep 17 00:00:00 2001 From: Sryder Date: Sun, 7 Oct 2018 00:22:23 +0100 Subject: [PATCH 092/194] I think that should be NULL, not 0 actually. --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 15f1595c..9fef1646 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -178,7 +178,7 @@ static Mix_Chunk *ds2chunk(void *stream) return NULL; // would and/or did wrap, can't store. break; } - sound = Z_Malloc(newsamples<<2, PU_SOUND, 0); // samples * frequency shift * bytes per sample * channels + sound = Z_Malloc(newsamples<<2, PU_SOUND, NULL); // samples * frequency shift * bytes per sample * channels s = (SINT8 *)stream; d = (INT16 *)sound; From 02597e0bf923c76cb1aed2bd15c285371bdd71ff Mon Sep 17 00:00:00 2001 From: Sryder Date: Sun, 7 Oct 2018 09:26:18 +0100 Subject: [PATCH 093/194] Fix compiler warnings. --- src/sdl/mixer_sound.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 9fef1646..ed15fcda 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -246,6 +246,7 @@ void *I_GetSfx(sfxinfo_t *sfx) { void *lump; Mix_Chunk *chunk; + SDL_RWops *rw; #ifdef HAVE_LIBGME Music_Emu *emu; gme_info_t *info; @@ -387,10 +388,10 @@ void *I_GetSfx(sfxinfo_t *sfx) #endif // Try to load it as a WAVE or OGG using Mixer. - SDL_RWops *rw = SDL_RWFromMem(lump, sfx->length); + rw = SDL_RWFromMem(lump, sfx->length); if (rw != NULL) { - Mix_Chunk *chunk = Mix_LoadWAV_RW(rw, 1); + chunk = Mix_LoadWAV_RW(rw, 1); SDL_RWclose(rw); return chunk; } @@ -547,6 +548,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) char *data; size_t len; lumpnum_t lumpnum = W_CheckNumForName(va("O_%s",musicname)); + SDL_RWops *rw; I_Assert(!music); #ifdef HAVE_LIBGME @@ -658,7 +660,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) } #endif - SDL_RWops *rw = SDL_RWFromMem(data, len); + rw = SDL_RWFromMem(data, len); if (rw != NULL) { music = Mix_LoadMUS_RW(rw, SDL_FALSE); From fb6c3298702e76ee8a167264cc7dc0e86936f862 Mon Sep 17 00:00:00 2001 From: Sryder Date: Sun, 7 Oct 2018 10:37:45 +0100 Subject: [PATCH 094/194] Fix the crashing bug hopefully A value of 1 in freesrc for Mix_LoadWAV_RW and Mix_LoadMus_RW calls SDL_RWclose on the RWops anyway. For Mix_LoadWAV_RW the RWops is freed right after the data is loaded (because it makes a copy of the data in memory) For Mix_LoadMUS_RW the RWops is freed when Mix_FreeMusic is called (because the data is not a copy) So setting 1 on freesrc doesn't actually free the RWops immediately on Mix_LoadMus_RW *unless* it failed to load any music. --- src/sdl/mixer_sound.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index ed15fcda..53a767df 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -392,7 +392,6 @@ void *I_GetSfx(sfxinfo_t *sfx) if (rw != NULL) { chunk = Mix_LoadWAV_RW(rw, 1); - SDL_RWclose(rw); return chunk; } @@ -663,8 +662,7 @@ boolean I_StartDigSong(const char *musicname, boolean looping) rw = SDL_RWFromMem(data, len); if (rw != NULL) { - music = Mix_LoadMUS_RW(rw, SDL_FALSE); - SDL_RWclose(rw); + music = Mix_LoadMUS_RW(rw, 1); } if (!music) { @@ -831,8 +829,7 @@ INT32 I_RegisterSong(void *data, size_t len) SDL_RWops *rw = SDL_RWFromMem(data, len); if (rw != NULL) { - music = Mix_LoadMUS_RW(rw, SDL_FALSE); - SDL_RWclose(rw); + music = Mix_LoadMUS_RW(rw, 1); } if (!music) { From b1e02467bfc009d1b08d83a12181fde87869bae0 Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 7 Oct 2018 15:00:58 +0100 Subject: [PATCH 095/194] Weather is already run client-side. What if we ran it render-side, for major performance gains? This commit will answer all your questions - and more! --- src/hardware/hw_main.c | 22 ++++++++++++++++++---- src/p_mobj.c | 37 ++++++++++++++++++++----------------- src/p_mobj.h | 4 ++++ src/p_saveg.c | 6 ++---- src/p_spec.c | 34 ++++++++++------------------------ src/p_tick.c | 24 ++++++++++++------------ src/r_things.c | 23 +++++++++++++++++++---- 7 files changed, 85 insertions(+), 65 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d7c73415..871a6a49 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5140,8 +5140,10 @@ static void HWR_AddSprites(sector_t *sec) approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); - if (approx_dist <= limit_dist) - HWR_ProjectSprite(thing); + if (approx_dist > limit_dist) + continue; + + HWR_ProjectSprite(thing); } } else @@ -5163,8 +5165,10 @@ static void HWR_AddSprites(sector_t *sec) approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); - if (approx_dist <= limit_dist) - HWR_ProjectPrecipitationSprite(precipthing); + if (approx_dist > limit_dist) + continue; + + HWR_ProjectPrecipitationSprite(precipthing); } } else @@ -5449,6 +5453,16 @@ static void HWR_ProjectPrecipitationSprite(precipmobj_t *thing) x1 = tr_x + x1 * rightcos; x2 = tr_x - x2 * rightcos; + // okay, we can't return now... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } + // // store information in a vissprite // diff --git a/src/p_mobj.c b/src/p_mobj.c index 5f85474c..bb9483d1 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3840,7 +3840,8 @@ void P_RecalcPrecipInSector(sector_t *sector) // void P_NullPrecipThinker(precipmobj_t *mobj) { - (void)mobj; + //(void)mobj; + mobj->precipflags &= ~PCF_THUNK; } void P_SnowThinker(precipmobj_t *mobj) @@ -3860,25 +3861,26 @@ void P_RainThinker(precipmobj_t *mobj) { // cycle through states, // calling action functions at transitions - if (mobj->tics > 0 && --mobj->tics == 0) - { - // you can cycle through multiple states in a tic - if (!P_SetPrecipMobjState(mobj, mobj->state->nextstate)) - return; // freed itself - } + if (mobj->tics <= 0) + return; + + if (--mobj->tics) + return; + + if (!P_SetPrecipMobjState(mobj, mobj->state->nextstate)) + return; + + if (mobj->state != &states[S_RAINRETURN]) + return; + + mobj->z = mobj->ceilingz; + P_SetPrecipMobjState(mobj, S_RAIN1); - if (mobj->state == &states[S_RAINRETURN]) - { - mobj->z = mobj->ceilingz; - P_SetPrecipMobjState(mobj, S_RAIN1); - } return; } // adjust height - mobj->z += mobj->momz; - - if (mobj->z <= mobj->floorz) + if ((mobj->z += mobj->momz) <= mobj->floorz) { // no splashes on sky or bottomless pits if (mobj->precipflags & PCF_PIT) @@ -7926,14 +7928,15 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype static inline precipmobj_t *P_SpawnRainMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) { precipmobj_t *mo = P_SpawnPrecipMobj(x,y,z,type); - mo->thinker.function.acp1 = (actionf_p1)P_RainThinker; + mo->precipflags |= PCF_RAIN; + //mo->thinker.function.acp1 = (actionf_p1)P_RainThinker; return mo; } static inline precipmobj_t *P_SpawnSnowMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) { precipmobj_t *mo = P_SpawnPrecipMobj(x,y,z,type); - mo->thinker.function.acp1 = (actionf_p1)P_SnowThinker; + //mo->thinker.function.acp1 = (actionf_p1)P_SnowThinker; return mo; } diff --git a/src/p_mobj.h b/src/p_mobj.h index 79cffae8..620028d8 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -252,6 +252,10 @@ typedef enum { PCF_FOF = 4, // Above MOVING FOF (this means we need to keep floorz up to date...) PCF_MOVINGFOF = 8, + // Is rain. + PCF_RAIN = 16, + // Ran the thinker this tic. + PCF_THUNK = 32, } precipflag_t; // Map Object definition. typedef struct mobj_s diff --git a/src/p_saveg.c b/src/p_saveg.c index d1ec8e5a..17d28302 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1661,8 +1661,7 @@ static void P_NetArchiveThinkers(void) for (th = thinkercap.next; th != &thinkercap; th = th->next) { if (!(th->function.acp1 == (actionf_p1)P_RemoveThinkerDelayed - || th->function.acp1 == (actionf_p1)P_RainThinker - || th->function.acp1 == (actionf_p1)P_SnowThinker)) + || th->function.acp1 == (actionf_p1)P_NullPrecipThinker)) numsaved++; if (th->function.acp1 == (actionf_p1)P_MobjThinker) @@ -1671,8 +1670,7 @@ static void P_NetArchiveThinkers(void) continue; } #ifdef PARANOIA - else if (th->function.acp1 == (actionf_p1)P_RainThinker - || th->function.acp1 == (actionf_p1)P_SnowThinker); + else if (th->function.acp1 == (actionf_p1)P_NullPrecipThinker); #endif else if (th->function.acp1 == (actionf_p1)T_MoveCeiling) { diff --git a/src/p_spec.c b/src/p_spec.c index c62c3b20..ff6691a9 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2039,8 +2039,7 @@ void P_SwitchWeather(INT32 weathernum) for (think = thinkercap.next; think != &thinkercap; think = think->next) { - if ((think->function.acp1 != (actionf_p1)P_SnowThinker) - && (think->function.acp1 != (actionf_p1)P_RainThinker)) + if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) continue; // not a precipmobj thinker precipmobj = (precipmobj_t *)think; @@ -2056,14 +2055,12 @@ void P_SwitchWeather(INT32 weathernum) for (think = thinkercap.next; think != &thinkercap; think = think->next) { + if (think->function.acp1 != (actionf_p1)P_NullPrecipThinker) + continue; // not a precipmobj thinker + precipmobj = (precipmobj_t *)think; + if (swap == PRECIP_RAIN) // Snow To Rain { - if (!(think->function.acp1 == (actionf_p1)P_SnowThinker - || think->function.acp1 == (actionf_p1)P_NullPrecipThinker)) - continue; // not a precipmobj thinker - - precipmobj = (precipmobj_t *)think; - precipmobj->flags = mobjinfo[MT_RAIN].flags; st = &states[mobjinfo[MT_RAIN].spawnstate]; precipmobj->state = st; @@ -2074,18 +2071,13 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->precipflags &= ~PCF_INVISIBLE; - think->function.acp1 = (actionf_p1)P_RainThinker; + precipmobj->precipflags |= PCF_RAIN; + //think->function.acp1 = (actionf_p1)P_RainThinker; } else if (swap == PRECIP_SNOW) // Rain To Snow { INT32 z; - if (!(think->function.acp1 == (actionf_p1)P_RainThinker - || think->function.acp1 == (actionf_p1)P_NullPrecipThinker)) - continue; // not a precipmobj thinker - - precipmobj = (precipmobj_t *)think; - precipmobj->flags = mobjinfo[MT_SNOWFLAKE].flags; z = M_RandomByte(); @@ -2103,19 +2095,13 @@ void P_SwitchWeather(INT32 weathernum) precipmobj->frame = st->frame; precipmobj->momz = mobjinfo[MT_SNOWFLAKE].speed; - precipmobj->precipflags &= ~PCF_INVISIBLE; + precipmobj->precipflags &= ~(PCF_INVISIBLE|PCF_RAIN); - think->function.acp1 = (actionf_p1)P_SnowThinker; + //think->function.acp1 = (actionf_p1)P_SnowThinker; } else if (swap == PRECIP_BLANK || swap == PRECIP_STORM_NORAIN) // Remove precip, but keep it around for reuse. { - if (!(think->function.acp1 == (actionf_p1)P_RainThinker - || think->function.acp1 == (actionf_p1)P_SnowThinker)) - continue; - - precipmobj = (precipmobj_t *)think; - - think->function.acp1 = (actionf_p1)P_NullPrecipThinker; + //think->function.acp1 = (actionf_p1)P_NullPrecipThinker; precipmobj->precipflags |= PCF_INVISIBLE; } diff --git a/src/p_tick.c b/src/p_tick.c index f4bc5932..5ba74707 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -56,12 +56,12 @@ void Command_Numthinkers_f(void) CONS_Printf(M_GetText("numthinkers <#>: Count number of thinkers\n")); CONS_Printf( "\t1: P_MobjThinker\n" - "\t2: P_RainThinker\n" - "\t3: P_SnowThinker\n" - "\t4: P_NullPrecipThinker\n" - "\t5: T_Friction\n" - "\t6: T_Pusher\n" - "\t7: P_RemoveThinkerDelayed\n"); + /*"\t2: P_RainThinker\n" + "\t3: P_SnowThinker\n"*/ + "\t2: P_NullPrecipThinker\n" + "\t3: T_Friction\n" + "\t4: T_Pusher\n" + "\t5: P_RemoveThinkerDelayed\n"); return; } @@ -73,27 +73,27 @@ void Command_Numthinkers_f(void) action = (actionf_p1)P_MobjThinker; CONS_Printf(M_GetText("Number of %s: "), "P_MobjThinker"); break; - case 2: + /*case 2: action = (actionf_p1)P_RainThinker; CONS_Printf(M_GetText("Number of %s: "), "P_RainThinker"); break; case 3: action = (actionf_p1)P_SnowThinker; CONS_Printf(M_GetText("Number of %s: "), "P_SnowThinker"); - break; - case 4: + break;*/ + case 2: action = (actionf_p1)P_NullPrecipThinker; CONS_Printf(M_GetText("Number of %s: "), "P_NullPrecipThinker"); break; - case 5: + case 3: action = (actionf_p1)T_Friction; CONS_Printf(M_GetText("Number of %s: "), "T_Friction"); break; - case 6: + case 4: action = (actionf_p1)T_Pusher; CONS_Printf(M_GetText("Number of %s: "), "T_Pusher"); break; - case 7: + case 5: action = (actionf_p1)P_RemoveThinkerDelayed; CONS_Printf(M_GetText("Number of %s: "), "P_RemoveThinkerDelayed"); break; diff --git a/src/r_things.c b/src/r_things.c index 0b176416..910a52b3 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1451,6 +1451,17 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) return; } + // okay, we can't return now except for vertical clipping... this is a hack, but weather isn't networked, so it should be ok + if (!(thing->precipflags & PCF_THUNK)) + { + if (thing->precipflags & PCF_RAIN) + P_RainThinker(thing); + else + P_SnowThinker(thing); + thing->precipflags |= PCF_THUNK; + } + + //SoM: 3/17/2000: Disregard sprites that are out of view.. gzt = thing->z + spritecachedinfo[lump].topoffset; gz = gzt - spritecachedinfo[lump].height; @@ -1569,8 +1580,10 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) approx_dist = P_AproxDistance(viewx-thing->x, viewy-thing->y); - if (approx_dist <= limit_dist) - R_ProjectSprite(thing); + if (approx_dist > limit_dist) + continue; + + R_ProjectSprite(thing); } } else @@ -1591,8 +1604,10 @@ void R_AddSprites(sector_t *sec, INT32 lightlevel) approx_dist = P_AproxDistance(viewx-precipthing->x, viewy-precipthing->y); - if (approx_dist <= limit_dist) - R_ProjectPrecipitationSprite(precipthing); + if (approx_dist > limit_dist) + continue; + + R_ProjectPrecipitationSprite(precipthing); } } else From def090c9f0245c148d2313c30c4ef398578d1738 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 7 Oct 2018 14:45:03 -0400 Subject: [PATCH 096/194] Move the ifdef --- src/sdl/mixer_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index d1083518..1b0974b1 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -52,11 +52,11 @@ #ifndef _FILE_OFFSET_BITS #define _FILE_OFFSET_BITS 0 #endif -#endif #ifdef HAVE_ZLIB #include "zlib.h" #endif +#endif UINT8 sound_started = false; From 232a7ae7b713c5c5854d0d0205a4fbd5dea9ee47 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 7 Oct 2018 14:52:25 -0400 Subject: [PATCH 097/194] Change order of the ifdef --- src/sdl/mixer_sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 1b0974b1..c4d2a8b0 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -39,6 +39,7 @@ #define GME_TREBLE 5.0 #define GME_BASS 1.0 +#ifdef HAVE_ZLIB #ifndef _MSC_VER #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE @@ -53,10 +54,9 @@ #define _FILE_OFFSET_BITS 0 #endif -#ifdef HAVE_ZLIB #include "zlib.h" -#endif -#endif +#endif // HAVE_ZLIB +#endif // HAVE_LIBGME UINT8 sound_started = false; From 027e6e8e3c91777efa302c63ab5eab23e315925d Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Sun, 7 Oct 2018 15:00:48 -0400 Subject: [PATCH 098/194] Change win_snd.c also --- src/win32/win_snd.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index bc04bd6d..58644457 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -18,13 +18,12 @@ #define GME_TREBLE 5.0 #define GME_BASS 1.0 +#ifdef HAVE_ZLIB #ifndef _MSC_VER -#ifndef _WII #ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE #endif #endif -#endif #ifndef _LFS64_LARGEFILE #define _LFS64_LARGEFILE @@ -34,10 +33,9 @@ #define _FILE_OFFSET_BITS 0 #endif -#ifdef HAVE_ZLIB #include "zlib.h" -#endif -#endif +#endif // HAVE_ZLIB +#endif // HAVE_LIBGME static FMOD_SYSTEM *fsys; static FMOD_SOUND *music_stream; From 1324e0bfcd945651a90c339042523d4f35e89a24 Mon Sep 17 00:00:00 2001 From: toaster Date: Mon, 8 Oct 2018 18:50:17 +0100 Subject: [PATCH 099/194] * Fix a memory leak regarding implementation of SOC_ (improperly copypasted code from LUA_LoadLump!!) * Optimise the repeated strlen usage into a single call, which is stored for later. --- src/lua_script.c | 12 +++++++----- src/w_wad.c | 15 ++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/lua_script.c b/src/lua_script.c index ce96878b..1c1b01f6 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -182,19 +182,21 @@ void LUA_LoadLump(UINT16 wad, UINT16 lump) { MYFILE f; char *name; + size_t len; f.wad = wad; f.size = W_LumpLengthPwad(wad, lump); f.data = Z_Malloc(f.size, PU_LUA, NULL); W_ReadLumpPwad(wad, lump, f.data); f.curpos = f.data; - name = malloc(strlen(wadfiles[wad]->filename)+10); + len = strlen(wadfiles[wad]->filename); + name = malloc(len+10); strcpy(name, wadfiles[wad]->filename); - if (!fasticmp(&name[strlen(name) - 4], ".lua")) { + if (!fasticmp(&name[len - 4], ".lua")) { // If it's not a .lua file, copy the lump name in too. - name[strlen(wadfiles[wad]->filename)] = '|'; - M_Memcpy(name+strlen(wadfiles[wad]->filename)+1, wadfiles[wad]->lumpinfo[lump].name, 8); - name[strlen(wadfiles[wad]->filename)+9] = '\0'; + name[len] = '|'; + M_Memcpy(name+len+1, wadfiles[wad]->lumpinfo[lump].name, 8); + name[len+9] = '\0'; } LUA_LoadFile(&f, name); diff --git a/src/w_wad.c b/src/w_wad.c index 3a828559..3f0082a1 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -194,16 +194,21 @@ static inline void W_LoadDehackedLumps(UINT16 wadnum) for (lump = 0; lump < wadfiles[wadnum]->numlumps; lump++, lump_p++) if (memcmp(lump_p->name,"SOC_",4)==0) // Check for generic SOC lump { // shameless copy+paste of code from LUA_LoadLump - char *name = malloc(strlen(wadfiles[wadnum]->filename)+10); + size_t len = strlen(wadfiles[wadnum]->filename); + char *name = malloc(len+10); + strcpy(name, wadfiles[wadnum]->filename); - if (!fasticmp(&name[strlen(name) - 4], ".soc")) { + if (!fasticmp(&name[len - 4], ".soc")) { // If it's not a .soc file, copy the lump name in too. - name[strlen(wadfiles[wadnum]->filename)] = '|'; - M_Memcpy(name+strlen(wadfiles[wadnum]->filename)+1, lump_p->name, 8); - name[strlen(wadfiles[wadnum]->filename)+9] = '\0'; + name[len] = '|'; + M_Memcpy(name+len+1, lump_p->name, 8); + name[len+9] = '\0'; } + CONS_Printf(M_GetText("Loading SOC from %s\n"), name); DEH_LoadDehackedLumpPwad(wadnum, lump); + + free(name); } else if (memcmp(lump_p->name,"MAINCFG",8)==0) // Check for MAINCFG { From 497314fdc44551a46395f41cd579d845d92b270e Mon Sep 17 00:00:00 2001 From: Sryder Date: Tue, 9 Oct 2018 19:43:18 +0100 Subject: [PATCH 100/194] Tiny fix so that joystick2 being closed can let the JoystickSubSystem close before game close. No memory leak here, just a very tiny thing I noticed. --- src/sdl/i_system.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index f92cd4b6..7b14f1f1 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1154,6 +1154,7 @@ static void I_ShutdownJoystick2(void) D_PostEvent(&event); } + joystick2_started = 0; JoyReset(&JoyInfo2); if (!joystick_started && !joystick2_started && SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { From b9b0a8110c307bdf8457fa66a83a193ad0008461 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 16 Nov 2016 18:43:25 +0000 Subject: [PATCH 101/194] Add R_Draw2sMultiPatchTranslucentColumn_8, for columns of multi-patch textures used as midtextures on two-sided linedefs with both transparency AND translucency ...that was a mouthful --- src/r_draw.h | 1 + src/r_draw8.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/r_segs.c | 2 ++ src/screen.c | 2 ++ src/screen.h | 1 + 5 files changed, 103 insertions(+) diff --git a/src/r_draw.h b/src/r_draw.h index 6d85bd6a..9cf7e9d5 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -161,6 +161,7 @@ void R_DrawSplat_8(void); void R_DrawTranslucentSplat_8(void); void R_DrawTranslucentSpan_8(void); void R_Draw2sMultiPatchColumn_8(void); +void R_Draw2sMultiPatchTranslucentColumn_8(void); void R_DrawFogSpan_8(void); void R_DrawFogColumn_8(void); void R_DrawColumnShadowed_8(void); diff --git a/src/r_draw8.c b/src/r_draw8.c index 800f28b6..e5dbe707 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -203,6 +203,103 @@ void R_Draw2sMultiPatchColumn_8(void) } } +void R_Draw2sMultiPatchTranslucentColumn_8(void) +{ + INT32 count; + register UINT8 *dest; + register fixed_t frac; + fixed_t fracstep; + + count = dc_yh - dc_yl; + + if (count < 0) // Zero length, column does not exceed a pixel. + return; + +#ifdef RANGECHECK + if ((unsigned)dc_x >= (unsigned)vid.width || dc_yl < 0 || dc_yh >= vid.height) + return; +#endif + + // Framebuffer destination address. + // Use ylookup LUT to avoid multiply with ScreenWidth. + // Use columnofs LUT for subwindows? + + //dest = ylookup[dc_yl] + columnofs[dc_x]; + dest = &topleft[dc_yl*vid.width + dc_x]; + + count++; + + // Determine scaling, which is the only mapping to be done. + fracstep = dc_iscale; + //frac = dc_texturemid + (dc_yl - centery)*fracstep; + frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); + + // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. + // This is as fast as it gets. + { + register const UINT8 *source = dc_source; + register const UINT8 *transmap = dc_transmap; + register const lighttable_t *colormap = dc_colormap; + register INT32 heightmask = dc_texheight-1; + register UINT8 val; + if (dc_texheight & heightmask) // not a power of 2 -- killough + { + heightmask++; + heightmask <<= FRACBITS; + + if (frac < 0) + while ((frac += heightmask) < 0); + else + while (frac >= heightmask) + frac -= heightmask; + + do + { + // Re-map color indices from wall texture column + // using a lighting/special effects LUT. + // heightmask is the Tutti-Frutti fix + val = source[frac>>FRACBITS]; + + if (val != TRANSPARENTPIXEL) + *dest = colormap[*(transmap + (val<<8) + (*dest))]; + + dest += vid.width; + + // Avoid overflow. + if (fracstep > 0x7FFFFFFF - frac) + frac += fracstep - heightmask; + else + frac += fracstep; + + while (frac >= heightmask) + frac -= heightmask; + } while (--count); + } + else + { + while ((count -= 2) >= 0) // texture height is a power of 2 + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + *dest = colormap[*(transmap + (val<<8) + (*dest))]; + dest += vid.width; + frac += fracstep; + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + *dest = colormap[*(transmap + (val<<8) + (*dest))]; + dest += vid.width; + frac += fracstep; + } + if (count & 1) + { + val = source[(frac>>FRACBITS) & heightmask]; + if (val != TRANSPARENTPIXEL) + *dest = colormap[*(transmap + (val<<8) + (*dest))]; + } + } + } +} + /** \brief The R_DrawShadeColumn_8 function Experiment to make software go faster. Taken from the Boom source */ diff --git a/src/r_segs.c b/src/r_segs.c index 502ff330..40184bdd 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -271,6 +271,8 @@ static void R_Render2sidedMultiPatchColumn(column_t *column) if (colfunc == wallcolfunc) twosmultipatchfunc(); + else if (colfunc == fuzzcolfunc) + twosmultipatchtransfunc(); else colfunc(); } diff --git a/src/screen.c b/src/screen.c index 2780edb6..58c38993 100644 --- a/src/screen.c +++ b/src/screen.c @@ -49,6 +49,7 @@ void (*splatfunc)(void); // span drawer w/ transparency void (*basespanfunc)(void); // default span func for color mode void (*transtransfunc)(void); // translucent translated column drawer void (*twosmultipatchfunc)(void); // for cols with transparent pixels +void (*twosmultipatchtransfunc)(void); // for cols with transparent pixels AND translucency // ------------------ // global video state @@ -127,6 +128,7 @@ void SCR_SetMode(void) fuzzcolfunc = R_DrawTranslucentColumn_8; walldrawerfunc = R_DrawWallColumn_8; twosmultipatchfunc = R_Draw2sMultiPatchColumn_8; + twosmultipatchtransfunc = R_Draw2sMultiPatchTranslucentColumn_8; #ifdef RUSEASM if (R_ASM) { diff --git a/src/screen.h b/src/screen.h index 2dff4590..a61de7f9 100644 --- a/src/screen.h +++ b/src/screen.h @@ -136,6 +136,7 @@ extern void (*basespanfunc)(void); extern void (*splatfunc)(void); extern void (*transtransfunc)(void); extern void (*twosmultipatchfunc)(void); +extern void (*twosmultipatchtransfunc)(void); // ----- // CPUID From 72ab305bf4672edc9ead8a1004fcf1ab1f7b7cd5 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 10 Oct 2018 14:59:44 +0100 Subject: [PATCH 102/194] Change when and specifically what colormap[] is applied to in R_Draw2sMultiPatchTranslucentColumn_8 --- src/r_draw8.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index e5dbe707..f9c5b7ad 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -261,7 +261,7 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) val = source[frac>>FRACBITS]; if (val != TRANSPARENTPIXEL) - *dest = colormap[*(transmap + (val<<8) + (*dest))]; + *dest = *(transmap + (colormap[val]<<8) + (*dest)); dest += vid.width; @@ -281,12 +281,12 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) - *dest = colormap[*(transmap + (val<<8) + (*dest))]; + *dest = *(transmap + (colormap[val]<<8) + (*dest)); dest += vid.width; frac += fracstep; val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) - *dest = colormap[*(transmap + (val<<8) + (*dest))]; + *dest = *(transmap + (colormap[val]<<8) + (*dest)); dest += vid.width; frac += fracstep; } @@ -294,7 +294,7 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) { val = source[(frac>>FRACBITS) & heightmask]; if (val != TRANSPARENTPIXEL) - *dest = colormap[*(transmap + (val<<8) + (*dest))]; + *dest = *(transmap + (colormap[val]<<8) + (*dest)); } } } From 4b7af892e1b7ddda002d3d5a3867a19b4d502285 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 14 Apr 2017 17:45:27 +0100 Subject: [PATCH 103/194] Moved most of d_netcmd.h's 2P mouse consvar externs to the files with their 1P counterparts --- src/d_netcmd.h | 5 ----- src/g_game.h | 1 + src/g_input.h | 1 + 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index d8fae72f..8a15136c 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -40,11 +40,6 @@ extern consvar_t cv_usemouse2; #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) extern consvar_t cv_mouse2opt; #endif -extern consvar_t cv_invertmouse2; -extern consvar_t cv_alwaysfreelook2; -extern consvar_t cv_mousemove2; -extern consvar_t cv_mousesens2; -extern consvar_t cv_mouseysens2; // normally in p_mobj but the .h is not read extern consvar_t cv_itemrespawntime; diff --git a/src/g_game.h b/src/g_game.h index ada82404..448d2855 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -56,6 +56,7 @@ extern INT16 rw_maximums[NUM_WEAPONS]; // used in game menu extern consvar_t cv_crosshair, cv_crosshair2; extern consvar_t cv_invertmouse, cv_alwaysfreelook, cv_mousemove; +extern consvar_t cv_invertmouse2, cv_alwaysfreelook2, cv_mousemove2; extern consvar_t cv_sideaxis,cv_turnaxis,cv_moveaxis,cv_lookaxis,cv_fireaxis,cv_firenaxis; extern consvar_t cv_sideaxis2,cv_turnaxis2,cv_moveaxis2,cv_lookaxis2,cv_fireaxis2,cv_firenaxis2; extern consvar_t cv_ghost_bestscore, cv_ghost_besttime, cv_ghost_bestrings, cv_ghost_last, cv_ghost_guest; diff --git a/src/g_input.h b/src/g_input.h index d6533932..2f86e592 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -126,6 +126,7 @@ typedef enum // mouse values are used once extern consvar_t cv_mousesens, cv_mouseysens; +extern consvar_t cv_mousesens2, cv_mouseysens2; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity From e2a4c59e2190a92acb00921d783a43f484e39253 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 14 Apr 2017 18:02:35 +0100 Subject: [PATCH 104/194] cv_controlperkey probably belongs in g_input.h too --- src/d_netcmd.h | 1 - src/g_input.h | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 8a15136c..08cdfd2e 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -32,7 +32,6 @@ extern consvar_t cv_joyport2; #endif extern consvar_t cv_joyscale; extern consvar_t cv_joyscale2; -extern consvar_t cv_controlperkey; // splitscreen with second mouse extern consvar_t cv_mouse2port; diff --git a/src/g_input.h b/src/g_input.h index 2f86e592..f42ad89d 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -127,6 +127,7 @@ typedef enum // mouse values are used once extern consvar_t cv_mousesens, cv_mouseysens; extern consvar_t cv_mousesens2, cv_mouseysens2; +extern consvar_t cv_controlperkey; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity From 933508db89376993f49ec8e074e8c5afd5edec90 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 14 Apr 2017 18:14:15 +0100 Subject: [PATCH 105/194] Moved screenshot/movie consvar externs to m_misc.h --- src/d_netcmd.h | 12 +----------- src/m_misc.h | 7 +++++++ 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 08cdfd2e..2731ca7f 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -115,17 +115,7 @@ extern consvar_t cv_maxping; extern consvar_t cv_skipmapcheck; -extern consvar_t cv_sleep, cv_screenshot_option, cv_screenshot_folder; - -extern consvar_t cv_moviemode; - -extern consvar_t cv_zlib_level, cv_zlib_memory, cv_zlib_strategy; - -extern consvar_t cv_zlib_window_bits, cv_zlib_levela, cv_zlib_memorya; - -extern consvar_t cv_zlib_strategya, cv_zlib_window_bitsa; - -extern consvar_t cv_apng_delay; +extern consvar_t cv_sleep; typedef enum { diff --git a/src/m_misc.h b/src/m_misc.h index dc540dc1..5bd7401e 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -19,6 +19,7 @@ #include "tables.h" #include "d_event.h" // Screenshot responder +#include "command.h" typedef enum { MM_OFF = 0, @@ -28,6 +29,12 @@ typedef enum { } moviemode_t; extern moviemode_t moviemode; +extern consvar_t cv_screenshot_option, cv_screenshot_folder; +extern consvar_t cv_moviemode; +extern consvar_t cv_zlib_memory, cv_zlib_level, cv_zlib_strategy, cv_zlib_window_bits; +extern consvar_t cv_zlib_memorya, cv_zlib_levela, cv_zlib_strategya, cv_zlib_window_bitsa; +extern consvar_t cv_apng_delay; + void M_StartMovie(void); void M_SaveFrame(void); void M_StopMovie(void); From 0ad0f8afc451d172fb36f8f2b1a0e14021bbcd18 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 14 Apr 2017 19:00:46 +0100 Subject: [PATCH 106/194] Move analog consvars to g_game.h --- src/d_netcmd.h | 3 --- src/g_game.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 2731ca7f..40c806a3 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -71,9 +71,6 @@ extern consvar_t cv_autobalance; extern consvar_t cv_teamscramble; extern consvar_t cv_scrambleonchange; -extern consvar_t cv_useranalog, cv_useranalog2; -extern consvar_t cv_analog, cv_analog2; - extern consvar_t cv_netstat; #ifdef WALLSPLATS extern consvar_t cv_splats; diff --git a/src/g_game.h b/src/g_game.h index 448d2855..ba414269 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -57,6 +57,8 @@ extern INT16 rw_maximums[NUM_WEAPONS]; extern consvar_t cv_crosshair, cv_crosshair2; extern consvar_t cv_invertmouse, cv_alwaysfreelook, cv_mousemove; extern consvar_t cv_invertmouse2, cv_alwaysfreelook2, cv_mousemove2; +extern consvar_t cv_useranalog, cv_useranalog2; +extern consvar_t cv_analog, cv_analog2; extern consvar_t cv_sideaxis,cv_turnaxis,cv_moveaxis,cv_lookaxis,cv_fireaxis,cv_firenaxis; extern consvar_t cv_sideaxis2,cv_turnaxis2,cv_moveaxis2,cv_lookaxis2,cv_fireaxis2,cv_firenaxis2; extern consvar_t cv_ghost_bestscore, cv_ghost_besttime, cv_ghost_bestrings, cv_ghost_last, cv_ghost_guest; From 38ec0cc50aa595f22e6e1f5ee19352cd42da355d Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 14 Apr 2017 19:56:51 +0100 Subject: [PATCH 107/194] These convar externs aren't moving files, I'm just shifting them up to live with their relatives --- src/d_netcmd.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 40c806a3..e0308948 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -20,6 +20,12 @@ // console vars extern consvar_t cv_playername; extern consvar_t cv_playercolor; +extern consvar_t cv_skin; +// secondary splitscreen player +extern consvar_t cv_playername2; +extern consvar_t cv_playercolor2; +extern consvar_t cv_skin2; + #ifdef SEENAMES extern consvar_t cv_seenames, cv_allowseenames; #endif @@ -47,13 +53,6 @@ extern consvar_t cv_itemrespawn; extern consvar_t cv_flagtime; extern consvar_t cv_suddendeath; -extern consvar_t cv_skin; - -// secondary splitscreen player -extern consvar_t cv_playername2; -extern consvar_t cv_playercolor2; -extern consvar_t cv_skin2; - extern consvar_t cv_touchtag; extern consvar_t cv_hidetime; From a4419abfdc21d0d0ec69e3d73528a4c9bb68205e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 25 Jan 2017 19:36:32 +0000 Subject: [PATCH 108/194] debugfile is only used by DEBUGFILE code, no need to declare/define it for anything else --- src/d_net.c | 2 ++ src/doomstat.h | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 643c41ac..8de5cf08 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -49,7 +49,9 @@ doomcom_t *doomcom = NULL; /// \brief network packet data, points inside doomcom doomdata_t *netbuffer = NULL; +#ifdef DEBUGFILE FILE *debugfile = NULL; // put some net info in a file during the game +#endif #define MAXREBOUND 8 static doomdata_t reboundstore[MAXREBOUND]; diff --git a/src/doomstat.h b/src/doomstat.h index 8072a155..341cc70a 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -445,19 +445,17 @@ extern mapthing_t *redctfstarts[MAXPLAYERS]; // CTF #if defined (macintosh) #define DEBFILE(msg) I_OutputMsg(msg) -extern FILE *debugfile; #else #define DEBUGFILE #ifdef DEBUGFILE #define DEBFILE(msg) { if (debugfile) { fputs(msg, debugfile); fflush(debugfile); } } -extern FILE *debugfile; #else #define DEBFILE(msg) {} -extern FILE *debugfile; #endif #endif #ifdef DEBUGFILE +extern FILE *debugfile; extern INT32 debugload; #endif From 61a29bed853a737f79fb5aac2c1ceb4ddd758aeb Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Feb 2017 22:41:15 +0000 Subject: [PATCH 109/194] Remove unused sscount variable (it's only set to 0 in software, and only ++'d in OpenGL, what kind of sense does that make?) --- src/hardware/hw_bsp.c | 2 -- src/hardware/hw_main.c | 1 - src/r_main.c | 5 ----- src/r_state.h | 3 --- 4 files changed, 11 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 17eb8761..a32609fc 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -564,8 +564,6 @@ static inline void HWR_SubsecPoly(INT32 num, poly_t *poly) subsector_t *sub; seg_t *lseg; - sscount++; - sub = &subsectors[num]; count = sub->numlines; lseg = &segs[sub->firstline]; diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 871a6a49..ecb70a0f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -3264,7 +3264,6 @@ static void HWR_Subsector(size_t num) if (num < numsubsectors) { - sscount++; // subsector sub = &subsectors[num]; // sector diff --git a/src/r_main.c b/src/r_main.c index f2a0c889..6c92983f 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -60,7 +60,6 @@ fixed_t projectiony; // aspect ratio // just for profiling purposes size_t framecount; -size_t sscount; size_t loopcount; fixed_t viewx, viewy, viewz; @@ -964,8 +963,6 @@ void R_SkyboxFrame(player_t *player) viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - sscount = 0; - // recalc necessary stuff for mouseaiming // slopes are already calculated for the full possible view (which is 4*viewheight). @@ -1089,8 +1086,6 @@ void R_SetupFrame(player_t *player, boolean skybox) viewsin = FINESINE(viewangle>>ANGLETOFINESHIFT); viewcos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - sscount = 0; - // recalc necessary stuff for mouseaiming // slopes are already calculated for the full possible view (which is 4*viewheight). diff --git a/src/r_state.h b/src/r_state.h index 49d0457b..ac3e1fa4 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -108,7 +108,4 @@ extern angle_t rw_normalangle; // angle to line origin extern angle_t rw_angle1; -// Segs count? -extern size_t sscount; - #endif From 07dd527e7e58e06ce621e80357bef7ae91424f76 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Feb 2017 22:56:08 +0000 Subject: [PATCH 110/194] Removed unused function prototypes in d_main.h Also corrected what appears to be a typo in some comments above? --- src/d_main.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/d_main.h b/src/d_main.h index 6dc273b1..d73b19d1 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -34,7 +34,7 @@ void D_SRB2Loop(void) FUNCNORETURN; // D_SRB2Main() // Not a globally visible function, just included for source reference, // calls all startup code, parses command line options. -// If not overrided by user input, calls N_AdvanceDemo. +// If not overrided by user input, calls D_AdvanceDemo. // void D_SRB2Main(void); @@ -51,9 +51,6 @@ const char *D_Home(void); // // BASE LEVEL // -void D_PageTicker(void); -// pagename is lumpname of a 320x200 patch to fill the screen -void D_PageDrawer(const char *pagename); void D_AdvanceDemo(void); void D_StartTitle(void); From 91b2f5e570b1b3783b54ca014a11ed07d0570ef4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Feb 2017 23:24:12 +0000 Subject: [PATCH 111/194] "t" is not needed to take out fencepost cases from viewangletox --- src/r_main.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 6c92983f..d1cd71b3 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -491,9 +491,6 @@ static void R_InitTextureMapping(void) // Take out the fencepost cases from viewangletox. for (i = 0; i < FINEANGLES/2; i++) { - t = FixedMul(FINETANGENT(i), focallength); - t = centerx - t; - if (viewangletox[i] == -1) viewangletox[i] = 0; else if (viewangletox[i] == viewwidth+1) From 49c5a6f7e474ff6aa30a726ae7cbcf9e224fb533 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 11 Feb 2017 23:28:42 +0000 Subject: [PATCH 112/194] Remove unused "runcount" variable from p_local.h --- src/p_local.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/p_local.h b/src/p_local.h index 1fd7ada0..b82bcf0e 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -68,7 +68,6 @@ // both the head and tail of the thinker list extern thinker_t thinkercap; -extern INT32 runcount; void P_InitThinkers(void); void P_AddThinker(thinker_t *thinker); From ef78c942f798e0d736cc84de8b912889d9232fbc Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 15 Feb 2017 21:16:56 +0000 Subject: [PATCH 113/194] Remove unused ObjectPlace_OnChange prototype (from when Objectplace was a consvar, which it is not anymore) --- src/d_netcmd.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index d8fae72f..023bbd09 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -212,7 +212,6 @@ void Command_ExitGame_f(void); void Command_Retry_f(void); void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore void D_MapChange(INT32 pmapnum, INT32 pgametype, boolean pultmode, boolean presetplayers, INT32 pdelay, boolean pskipprecutscene, boolean pfromlevelselect); -void ObjectPlace_OnChange(void); void ItemFinder_OnChange(void); void D_SetPassword(const char *pw); From 9c464742b7d0b10b35ef27dcdad2e72d33e4f8da Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 22 Feb 2017 21:07:29 +0000 Subject: [PATCH 114/194] Remove "playerdeadview" variable; it's not been used for its stated purpose for who knows how long now Besides rankings popping up when you die just sounds weird anyway, maybe I'm just used to SRB2 not doing it I guess --- src/d_clisrv.c | 2 -- src/d_main.c | 1 - src/f_finale.c | 6 ------ src/g_game.c | 1 - src/hu_stuff.h | 3 --- src/p_user.c | 9 --------- 6 files changed, 22 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 6e22dde2..95003823 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1568,8 +1568,6 @@ static void CL_LoadReceivedSavegame(void) automapactive = false; // load a base level - playerdeadview = false; - if (P_LoadNetGame()) { const INT32 actnum = mapheaderinfo[gamemap-1]->actnum; diff --git a/src/d_main.c b/src/d_main.c index df339875..f807e307 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -720,7 +720,6 @@ void D_StartTitle(void) maptol = 0; gameaction = ga_nothing; - playerdeadview = false; displayplayer = consoleplayer = 0; //demosequence = -1; gametype = GT_COOP; diff --git a/src/f_finale.c b/src/f_finale.c index a8b27bb8..fb1387c1 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -442,7 +442,6 @@ void F_StartIntro(void) G_SetGamestate(GS_INTRO); gameaction = ga_nothing; - playerdeadview = false; paused = false; CON_ToggleOff(); CON_ClearHUD(); @@ -1130,7 +1129,6 @@ void F_StartCredits(void) } gameaction = ga_nothing; - playerdeadview = false; paused = false; CON_ToggleOff(); CON_ClearHUD(); @@ -1277,7 +1275,6 @@ void F_StartGameEvaluation(void) G_SaveGame((UINT32)cursaveslot); gameaction = ga_nothing; - playerdeadview = false; paused = false; CON_ToggleOff(); CON_ClearHUD(); @@ -1388,7 +1385,6 @@ void F_StartGameEnd(void) G_SetGamestate(GS_GAMEEND); gameaction = ga_nothing; - playerdeadview = false; paused = false; CON_ToggleOff(); CON_ClearHUD(); @@ -1591,7 +1587,6 @@ void F_StartContinue(void) gameaction = ga_nothing; keypressed = false; - playerdeadview = false; paused = false; CON_ToggleOff(); CON_ClearHUD(); @@ -1760,7 +1755,6 @@ void F_StartCustomCutscene(INT32 cutscenenum, boolean precutscene, boolean reset G_SetGamestate(GS_CUTSCENE); gameaction = ga_nothing; - playerdeadview = false; paused = false; CON_ToggleOff(); diff --git a/src/g_game.c b/src/g_game.c index 4f1c49b4..0e8c14f6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3616,7 +3616,6 @@ void G_InitNew(UINT8 pultmode, const char *mapname, boolean resetplayer, boolean mapmusflags |= MUSIC_RELOADRESET; ultimatemode = pultmode; - playerdeadview = false; automapactive = false; imcontinuing = false; diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 7b22f33f..5356ba8a 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -78,9 +78,6 @@ extern boolean chat_on; // set true whenever the tab rankings are being shown for any reason extern boolean hu_showscores; -// P_DeathThink sets this true to show scores while dead, in multiplayer -extern boolean playerdeadview; - // init heads up data at game startup. void HU_Init(void); diff --git a/src/p_user.c b/src/p_user.c index 7abf8534..7e206930 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8648,8 +8648,6 @@ void P_DoPityCheck(player_t *player) // P_PlayerThink // -boolean playerdeadview; // show match/chaos/tag/capture the flag rankings while in death view - void P_PlayerThink(player_t *player) { ticcmd_t *cmd; @@ -8838,10 +8836,6 @@ void P_PlayerThink(player_t *player) if (player->playerstate == PST_DEAD) { player->mo->flags2 &= ~MF2_SHADOW; - // show the multiplayer rankings while dead - if (player == &players[displayplayer]) - playerdeadview = true; - P_DeathThink(player); return; @@ -8862,9 +8856,6 @@ void P_PlayerThink(player_t *player) player->lives = cv_startinglives.value; } - if (player == &players[displayplayer]) - playerdeadview = false; - if ((gametype == GT_RACE || gametype == GT_COMPETITION) && leveltime < 4*TICRATE) { cmd->buttons &= BT_USE; // Remove all buttons except BT_USE From b3faed190b4838ee88f88d75524ad228b690f195 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 11 Oct 2018 16:29:43 -0400 Subject: [PATCH 115/194] Move commands and console variable into s_sound.c --- src/d_netcmd.c | 95 ------------------------------------------------ src/d_netcmd.h | 6 +--- src/s_sound.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/s_sound.h | 1 + 4 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index bf26ca61..a8e02bab 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -128,8 +128,6 @@ FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void); static void Command_Playintro_f(void); static void Command_Displayplayer_f(void); -static void Command_Tunes_f(void); -static void Command_RestartAudio_f(void); static void Command_ExitLevel_f(void); static void Command_Showmap_f(void); @@ -319,7 +317,6 @@ consvar_t cv_overtime = {"overtime", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, consvar_t cv_rollingdemos = {"rollingdemos", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_timetic = {"timerres", "Normal", CV_SAVE, timetic_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // use tics in display -consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t pointlimit_cons_t[] = {{0, "MIN"}, {999999990, "MAX"}, {0, NULL}}; consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, pointlimit_cons_t, @@ -668,9 +665,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_ghost_guest); COM_AddCommand("displayplayer", Command_Displayplayer_f); - COM_AddCommand("tunes", Command_Tunes_f); - COM_AddCommand("restartaudio", Command_RestartAudio_f); - CV_RegisterVar(&cv_resetmusic); // FIXME: not to be here.. but needs be done for config loading CV_RegisterVar(&cv_usegamma); @@ -3881,95 +3875,6 @@ static void Command_Displayplayer_f(void) CONS_Printf(M_GetText("Displayplayer is %d\n"), displayplayer); } -static void Command_Tunes_f(void) -{ - const char *tunearg; - UINT16 tunenum, track = 0; - const size_t argc = COM_Argc(); - - if (argc < 2) //tunes slot ... - { - CONS_Printf("tunes [track] [speed] / <-show> / <-default> / <-none>:\n"); - CONS_Printf(M_GetText("Play an arbitrary music lump. If a map number is used, 'MAP##M' is played.\n")); - CONS_Printf(M_GetText("If the format supports multiple songs, you can specify which one to play.\n\n")); - CONS_Printf(M_GetText("* With \"-show\", shows the currently playing tune and track.\n")); - CONS_Printf(M_GetText("* With \"-default\", returns to the default music for the map.\n")); - CONS_Printf(M_GetText("* With \"-none\", any music playing will be stopped.\n")); - return; - } - - tunearg = COM_Argv(1); - tunenum = (UINT16)atoi(tunearg); - track = 0; - - if (!strcasecmp(tunearg, "-show")) - { - CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), - mapmusname, (mapmusflags & MUSIC_TRACKMASK)); - return; - } - if (!strcasecmp(tunearg, "-none")) - { - S_StopMusic(); - return; - } - else if (!strcasecmp(tunearg, "-default")) - { - tunearg = mapheaderinfo[gamemap-1]->musname; - track = mapheaderinfo[gamemap-1]->mustrack; - } - else if (!tunearg[2] && toupper(tunearg[0]) >= 'A' && toupper(tunearg[0]) <= 'Z') - tunenum = (UINT16)M_MapNumber(tunearg[0], tunearg[1]); - - if (tunenum && tunenum >= 1036) - { - CONS_Alert(CONS_NOTICE, M_GetText("Valid music slots are 1 to 1035.\n")); - return; - } - if (!tunenum && strlen(tunearg) > 6) // This is automatic -- just show the error just in case - CONS_Alert(CONS_NOTICE, M_GetText("Music name too long - truncated to six characters.\n")); - - if (argc > 2) - track = (UINT16)atoi(COM_Argv(2))-1; - - if (tunenum) - snprintf(mapmusname, 7, "%sM", G_BuildMapName(tunenum)); - else - strncpy(mapmusname, tunearg, 7); - mapmusname[6] = 0; - mapmusflags = (track & MUSIC_TRACKMASK); - - S_ChangeMusic(mapmusname, mapmusflags, true); - - if (argc > 3) - { - float speed = (float)atof(COM_Argv(3)); - if (speed > 0.0f) - S_SpeedMusic(speed); - } -} - -static void Command_RestartAudio_f(void) -{ - if (dedicated) // No point in doing anything if game is a dedicated server. - return; - - S_StopMusic(); - I_ShutdownMusic(); - I_ShutdownSound(); - I_StartupSound(); - I_InitMusic(); - -// These must be called or no sound and music until manually set. - - I_SetSfxVolume(cv_soundvolume.value); - I_SetDigMusicVolume(cv_digmusicvolume.value); - I_SetMIDIMusicVolume(cv_midimusicvolume.value); - if (Playing()) // Gotta make sure the player is in a level - P_RestoreMusic(&players[consoleplayer]); - -} - /** Quits a game and returns to the title screen. * */ diff --git a/src/d_netcmd.h b/src/d_netcmd.h index d8fae72f..7427252d 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -109,8 +109,6 @@ extern consvar_t cv_startinglives; // for F_finale.c extern consvar_t cv_rollingdemos; -extern consvar_t cv_resetmusic; - extern consvar_t cv_ringslinger, cv_soundtest; extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; @@ -219,6 +217,4 @@ void D_SetPassword(const char *pw); // used for the player setup menu UINT8 CanChangeSkin(INT32 playernum); -#endif - - +#endif \ No newline at end of file diff --git a/src/s_sound.c b/src/s_sound.c index 76ee4c64..33c61405 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -36,6 +36,7 @@ extern INT32 msg_id; #include "d_main.h" #include "r_sky.h" // skyflatnum #include "p_local.h" // camera info +#include "m_misc.h" // for tunes command #ifdef HW3SOUND // 3D Sound Interface @@ -46,6 +47,8 @@ static INT32 S_AdjustSoundParams(const mobj_t *listener, const mobj_t *source, I CV_PossibleValue_t soundvolume_cons_t[] = {{0, "MIN"}, {31, "MAX"}, {0, NULL}}; static void SetChannelsNum(void); +static void Command_Tunes_f(void); +static void Command_RestartAudio_f(void); // commands for music and sound servers #ifdef MUSSERV @@ -89,6 +92,7 @@ consvar_t cv_numChannels = {"snd_channels", "32", CV_SAVE|CV_CALL, CV_Unsigned, #endif static consvar_t surround = {"surround", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; #define S_MAX_VOLUME 127 @@ -243,6 +247,11 @@ void S_RegisterSoundStuff(void) #endif CV_RegisterVar(&surround); CV_RegisterVar(&cv_samplerate); + CV_RegisterVar(&cv_resetmusic); + + COM_AddCommand("tunes", Command_Tunes_f); + COM_AddCommand("restartaudio", Command_RestartAudio_f); + #if defined (macintosh) && !defined (HAVE_SDL) // mp3 playlist stuff { @@ -1431,3 +1440,92 @@ void S_ResumeAudio(void) // resume cd music I_ResumeCD(); } + +static void Command_Tunes_f(void) +{ + const char *tunearg; + UINT16 tunenum, track = 0; + const size_t argc = COM_Argc(); + + if (argc < 2) //tunes slot ... + { + CONS_Printf("tunes [track] [speed] / <-show> / <-default> / <-none>:\n"); + CONS_Printf(M_GetText("Play an arbitrary music lump. If a map number is used, 'MAP##M' is played.\n")); + CONS_Printf(M_GetText("If the format supports multiple songs, you can specify which one to play.\n\n")); + CONS_Printf(M_GetText("* With \"-show\", shows the currently playing tune and track.\n")); + CONS_Printf(M_GetText("* With \"-default\", returns to the default music for the map.\n")); + CONS_Printf(M_GetText("* With \"-none\", any music playing will be stopped.\n")); + return; + } + + tunearg = COM_Argv(1); + tunenum = (UINT16)atoi(tunearg); + track = 0; + + if (!strcasecmp(tunearg, "-show")) + { + CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), + mapmusname, (mapmusflags & MUSIC_TRACKMASK)); + return; + } + if (!strcasecmp(tunearg, "-none")) + { + S_StopMusic(); + return; + } + else if (!strcasecmp(tunearg, "-default")) + { + tunearg = mapheaderinfo[gamemap-1]->musname; + track = mapheaderinfo[gamemap-1]->mustrack; + } + else if (!tunearg[2] && toupper(tunearg[0]) >= 'A' && toupper(tunearg[0]) <= 'Z') + tunenum = (UINT16)M_MapNumber(tunearg[0], tunearg[1]); + + if (tunenum && tunenum >= 1036) + { + CONS_Alert(CONS_NOTICE, M_GetText("Valid music slots are 1 to 1035.\n")); + return; + } + if (!tunenum && strlen(tunearg) > 6) // This is automatic -- just show the error just in case + CONS_Alert(CONS_NOTICE, M_GetText("Music name too long - truncated to six characters.\n")); + + if (argc > 2) + track = (UINT16)atoi(COM_Argv(2))-1; + + if (tunenum) + snprintf(mapmusname, 7, "%sM", G_BuildMapName(tunenum)); + else + strncpy(mapmusname, tunearg, 7); + mapmusname[6] = 0; + mapmusflags = (track & MUSIC_TRACKMASK); + + S_ChangeMusic(mapmusname, mapmusflags, true); + + if (argc > 3) + { + float speed = (float)atof(COM_Argv(3)); + if (speed > 0.0f) + S_SpeedMusic(speed); + } +} + +static void Command_RestartAudio_f(void) +{ + if (dedicated) // No point in doing anything if game is a dedicated server. + return; + + S_StopMusic(); + I_ShutdownMusic(); + I_ShutdownSound(); + I_StartupSound(); + I_InitMusic(); + +// These must be called or no sound and music until manually set. + + I_SetSfxVolume(cv_soundvolume.value); + I_SetDigMusicVolume(cv_digmusicvolume.value); + I_SetMIDIMusicVolume(cv_midimusicvolume.value); + if (Playing()) // Gotta make sure the player is in a level + P_RestoreMusic(&players[consoleplayer]); + +} \ No newline at end of file diff --git a/src/s_sound.h b/src/s_sound.h index 39ec769a..083815e1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -25,6 +25,7 @@ extern consvar_t stereoreverse; extern consvar_t cv_soundvolume, cv_digmusicvolume, cv_midimusicvolume; extern consvar_t cv_numChannels; +extern consvar_t cv_resetmusic; #ifdef SNDSERV extern consvar_t sndserver_cmd, sndserver_arg; From 450b536147b6bf36f879ee0a5ae9164d32f15c72 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Thu, 11 Oct 2018 20:11:37 -0400 Subject: [PATCH 116/194] Remove the condition in restartaudio command. No longer needed as S_RegisterSoundStuff will return early if in dedicated mode. --- src/s_sound.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 33c61405..a79e56ce 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -1511,9 +1511,6 @@ static void Command_Tunes_f(void) static void Command_RestartAudio_f(void) { - if (dedicated) // No point in doing anything if game is a dedicated server. - return; - S_StopMusic(); I_ShutdownMusic(); I_ShutdownSound(); @@ -1527,5 +1524,4 @@ static void Command_RestartAudio_f(void) I_SetMIDIMusicVolume(cv_midimusicvolume.value); if (Playing()) // Gotta make sure the player is in a level P_RestoreMusic(&players[consoleplayer]); - } \ No newline at end of file From bedfed2f000a65476dece41cfedadfeb4b72d04c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 15:37:11 +0100 Subject: [PATCH 117/194] Move shared code here instead of duplicating it for both dc_numlights and non-dc_numlights rendering code Also added a few comments, and include the out of range check in the "shared code" above --- src/r_segs.c | 97 +++++++++++++++++++++++----------------------------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index 502ff330..d2600681 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -1039,6 +1039,45 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { if (maskedtexturecol[dc_x] != INT16_MAX) { + // Calculate bounds + // clamp the values if necessary to avoid overflows and rendering glitches caused by them +#ifdef ESLOPE + if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; + else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; + else sprtopscreen = windowtop = CLAMPMIN; + if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; + else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; + else sprbotscreen = windowbottom = CLAMPMIN; + + top_frac += top_step; + bottom_frac += bottom_step; +#else + sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); + sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; +#endif + + // SoM: If column is out of range, why bother with it?? + if (windowbottom < topbounds || windowtop > bottombounds) + { + if (dc_numlights) + { + for (i = 0; i < dc_numlights; i++) + { + rlight = &dc_lightlist[i]; + rlight->height += rlight->heightstep; + if (rlight->flags & FF_CUTLEVEL) + rlight->botheight += rlight->botheightstep; + } + } + spryscale += rw_scalestep; + continue; + } + + dc_iscale = 0xffffffffu / (unsigned)spryscale; + + // Get data for the column + col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); + // SoM: New code does not rely on R_DrawColumnShadowed_8 which // will (hopefully) put less strain on the stack. if (dc_numlights) @@ -1049,40 +1088,6 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) INT32 solid = 0; INT32 lighteffect = 0; -#ifdef ESLOPE - if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; - else sprtopscreen = windowtop = CLAMPMIN; - if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; - else sprbotscreen = windowbottom = CLAMPMIN; - - top_frac += top_step; - bottom_frac += bottom_step; -#else - sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); - sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; -#endif - - // SoM: If column is out of range, why bother with it?? - if (windowbottom < topbounds || windowtop > bottombounds) - { - for (i = 0; i < dc_numlights; i++) - { - rlight = &dc_lightlist[i]; - rlight->height += rlight->heightstep; - if (rlight->flags & FF_CUTLEVEL) - rlight->botheight += rlight->botheightstep; - } - spryscale += rw_scalestep; - continue; - } - - dc_iscale = 0xffffffffu / (unsigned)spryscale; - - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); - for (i = 0; i < dc_numlights; i++) { // Check if the current light effects the colormap/lightlevel @@ -1101,7 +1106,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) pindex = FixedMul(spryscale, FixedDiv(640, vid.width))>>LIGHTSCALESHIFT; - if (pindex >= MAXLIGHTSCALE) + if (pindex >= MAXLIGHTSCALE) pindex = MAXLIGHTSCALE-1; if (pfloor->flags & FF_FOG) @@ -1162,6 +1167,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (windowbottom >= sprbotscreen) { windowbottom = sprbotscreen; + // draw the texture colfunc_2s (col); for (i++; i < dc_numlights; i++) { @@ -1172,6 +1178,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) } continue; } + // draw the texture colfunc_2s (col); if (solid) windowtop = bheight; @@ -1181,6 +1188,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) dc_colormap = rlight->rcolormap; } windowbottom = sprbotscreen; + // draw the texture, if there is any space left if (windowtop < windowbottom) colfunc_2s (col); @@ -1200,26 +1208,7 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) if (pfloor->flags & FF_FOG && pfloor->master->frontsector->extra_colormap) dc_colormap = pfloor->master->frontsector->extra_colormap->colormap + (dc_colormap - colormaps); -#ifdef ESLOPE - if (top_frac > (INT64)CLAMPMAX) sprtopscreen = windowtop = CLAMPMAX; - else if (top_frac > (INT64)CLAMPMIN) sprtopscreen = windowtop = (fixed_t)top_frac; - else sprtopscreen = windowtop = CLAMPMIN; - if (bottom_frac > (INT64)CLAMPMAX) sprbotscreen = windowbottom = CLAMPMAX; - else if (bottom_frac > (INT64)CLAMPMIN) sprbotscreen = windowbottom = (fixed_t)bottom_frac; - else sprbotscreen = windowbottom = CLAMPMIN; - - top_frac += top_step; - bottom_frac += bottom_step; -#else - sprtopscreen = windowtop = (centeryfrac - FixedMul((dc_texturemid - offsetvalue), spryscale)); - sprbotscreen = windowbottom = FixedMul(*pfloor->topheight - *pfloor->bottomheight, spryscale) + sprtopscreen; -#endif - - dc_iscale = 0xffffffffu / (unsigned)spryscale; - // draw the texture - col = (column_t *)((UINT8 *)R_GetColumn(texnum,maskedtexturecol[dc_x]) - 3); - colfunc_2s (col); spryscale += rw_scalestep; } From 80cbad61c0bbdc9b6c37e3774fae67a7bcf958a7 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 18:57:40 +0100 Subject: [PATCH 118/194] Do lightlist height stepping *after* the heights are used by the FOF rendering code, not before (yes, I caught that they remove a heightstep beforehand for FOFs, but that wasn't done for midtextures it seems?) Additionally add some macros for repeated slope end assignments and overflow tests --- src/r_segs.c | 87 ++++++++++++++++++++-------------------------------- 1 file changed, 33 insertions(+), 54 deletions(-) diff --git a/src/r_segs.c b/src/r_segs.c index d2600681..58d8a968 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -590,8 +590,8 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) else rlight->rcolormap = xwalllights[pindex]; - rlight->height += rlight->heightstep; height = rlight->height; + rlight->height += rlight->heightstep; if (height <= windowtop) { @@ -827,26 +827,21 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) light = &frontsector->lightlist[i]; rlight = &dc_lightlist[p]; #ifdef ESLOPE - if (light->slope) { - leftheight = P_GetZAt(light->slope, ds->leftpos.x, ds->leftpos.y); - rightheight = P_GetZAt(light->slope, ds->rightpos.x, ds->rightpos.y); - } else - leftheight = rightheight = light->height; - if (*pfloor->b_slope) { - pfloorleft = P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y); - pfloorright = P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y); - } else - pfloorleft = pfloorright = *pfloor->bottomheight; +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, ds->leftpos.x, ds->leftpos.y); \ + end2 = P_GetZAt(slope, ds->rightpos.x, ds->rightpos.y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(light->slope, leftheight, rightheight, light->height) + SLOPEPARAMS(*pfloor->b_slope, pfloorleft, pfloorright, *pfloor->bottomheight) if (leftheight < pfloorleft && rightheight < pfloorright) continue; - if (*pfloor->t_slope) { - pfloorleft = P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y); - pfloorright = P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y); - } else - pfloorleft = pfloorright = *pfloor->topheight; + SLOPEPARAMS(*pfloor->t_slope, pfloorleft, pfloorright, *pfloor->topheight) if (leftheight > pfloorleft && rightheight > pfloorright && i+1 < dc_numlights) { @@ -859,17 +854,17 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) leftheight -= viewz; rightheight -= viewz; - overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; - overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; +#define OVERFLOWTEST(height, scale) \ + overflow_test = (INT64)centeryfrac - (((INT64)height*scale)>>FRACBITS); \ + if (overflow_test < 0) overflow_test = -overflow_test; \ + if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + + OVERFLOWTEST(leftheight, ds->scale1) + OVERFLOWTEST(rightheight, ds->scale2) rlight->height = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->heightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); - rlight->height -= rlight->heightstep; #else if (light->height < *pfloor->bottomheight) continue; @@ -879,36 +874,28 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) lheight = light->height;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : light->height; rlight->heightstep = -FixedMul (rw_scalestep, (lheight - viewz)); - rlight->height = (centeryfrac) - FixedMul((lheight - viewz), spryscale) - rlight->heightstep; + rlight->height = (centeryfrac) - FixedMul((lheight - viewz), spryscale); #endif rlight->flags = light->flags; if (light->flags & FF_CUTLEVEL) { #ifdef ESLOPE - if (*light->caster->b_slope) { - leftheight = P_GetZAt(*light->caster->b_slope, ds->leftpos.x, ds->leftpos.y); - rightheight = P_GetZAt(*light->caster->b_slope, ds->rightpos.x, ds->rightpos.y); - } else - leftheight = rightheight = *light->caster->bottomheight; + SLOPEPARAMS(*light->caster->b_slope, leftheight, rightheight, *light->caster->bottomheight) leftheight -= viewz; rightheight -= viewz; - overflow_test = (INT64)centeryfrac - (((INT64)leftheight*ds->scale1)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; - overflow_test = (INT64)centeryfrac - (((INT64)rightheight*ds->scale2)>>FRACBITS); - if (overflow_test < 0) overflow_test = -overflow_test; - if ((UINT64)overflow_test&0xFFFFFFFF80000000ULL) continue; + OVERFLOWTEST(leftheight, ds->scale1) + OVERFLOWTEST(rightheight, ds->scale2) +#undef OVERFLOWTEST rlight->botheight = (centeryfrac) - FixedMul(leftheight, ds->scale1); rlight->botheightstep = (centeryfrac) - FixedMul(rightheight, ds->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); - rlight->botheight -= rlight->botheightstep; #else lheight = *light->caster->bottomheight;// > *pfloor->topheight ? *pfloor->topheight + FRACUNIT : *light->caster->bottomheight; rlight->botheightstep = -FixedMul (rw_scalestep, (lheight - viewz)); - rlight->botheight = (centeryfrac) - FixedMul((lheight - viewz), spryscale) - rlight->botheightstep; + rlight->botheight = (centeryfrac) - FixedMul((lheight - viewz), spryscale); #endif } @@ -1001,21 +988,13 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) { fixed_t left_top, right_top, left_bottom, right_bottom; - if (*pfloor->t_slope) - { - left_top = P_GetZAt(*pfloor->t_slope, ds->leftpos.x, ds->leftpos.y) - viewz; - right_top = P_GetZAt(*pfloor->t_slope, ds->rightpos.x, ds->rightpos.y) - viewz; - } - else - left_top = right_top = *pfloor->topheight - viewz; - - if (*pfloor->b_slope) - { - left_bottom = P_GetZAt(*pfloor->b_slope, ds->leftpos.x, ds->leftpos.y) - viewz; - right_bottom = P_GetZAt(*pfloor->b_slope, ds->rightpos.x, ds->rightpos.y) - viewz; - } - else - left_bottom = right_bottom = *pfloor->bottomheight - viewz; + SLOPEPARAMS(*pfloor->t_slope, left_top, right_top, *pfloor->topheight) + SLOPEPARAMS(*pfloor->b_slope, left_bottom, right_bottom, *pfloor->bottomheight) +#undef SLOPEPARAMS + left_top -= viewz; + right_top -= viewz; + left_bottom -= viewz; + right_bottom -= viewz; // using INT64 to avoid 32bit overflow top_frac = (INT64)centeryfrac - (((INT64)left_top * ds->scale1) >> FRACBITS); @@ -1145,13 +1124,13 @@ void R_RenderThickSideRange(drawseg_t *ds, INT32 x1, INT32 x2, ffloor_t *pfloor) else solid = 0; - rlight->height += rlight->heightstep; height = rlight->height; + rlight->height += rlight->heightstep; if (solid) { - rlight->botheight += rlight->botheightstep; bheight = rlight->botheight - (FRACUNIT >> 1); + rlight->botheight += rlight->botheightstep; } if (height <= windowtop) From 6184f91dd3bd82164282c7379d457ffcea5e5a8c Mon Sep 17 00:00:00 2001 From: Sryder Date: Sat, 13 Oct 2018 23:01:11 +0100 Subject: [PATCH 119/194] Add an int to I_PlaySound to tell an interface which channel number SRB2 is using. I've voided this out on other sound interfaces than SDL Mixer ones because I'm both not sure whether they need it, and not sure how to make them work with it if they do. --- src/djgppdos/i_sound.c | 4 +++- src/dummy/i_sound.c | 3 ++- src/i_sound.h | 2 +- src/nds/i_sound.c | 3 ++- src/s_sound.c | 4 ++-- src/sdl/mixer_sound.c | 4 ++-- src/sdl/sdl_sound.c | 3 ++- src/sdl12/mixer_sound.c | 4 ++-- src/sdl12/sdl_sound.c | 3 ++- src/win32/win_snd.c | 3 ++- src/win32ce/win_snd.c | 4 +++- 11 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index 88fc807f..f1e2ad2b 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -165,9 +165,11 @@ INT32 I_StartSound ( sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, - INT32 priority ) + INT32 priority + INT32 channel) { int voice; + (void)channel; if (nosound) return 0; diff --git a/src/dummy/i_sound.c b/src/dummy/i_sound.c index 51dbb610..143da186 100644 --- a/src/dummy/i_sound.c +++ b/src/dummy/i_sound.c @@ -23,13 +23,14 @@ void I_UpdateSound(void){}; // SFX I/O // -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { (void)id; (void)vol; (void)sep; (void)pitch; (void)priority; + (void)channel; return -1; } diff --git a/src/i_sound.h b/src/i_sound.h index 084479ee..098c9be1 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -64,7 +64,7 @@ void I_ShutdownSound(void); \return sfx handle */ -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority); +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel); /** \brief Stops a sound channel. diff --git a/src/nds/i_sound.c b/src/nds/i_sound.c index 8dea4ad7..a17c7f66 100644 --- a/src/nds/i_sound.c +++ b/src/nds/i_sound.c @@ -21,13 +21,14 @@ void I_ShutdownSound(void){} // SFX I/O // -INT32 I_StartSound(sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, INT32 priority) +INT32 I_StartSound(sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, INT32 priority, INT32 channel) { (void)id; (void)vol; (void)sep; (void)pitch; (void)priority; + (void)channel; return -1; } diff --git a/src/s_sound.c b/src/s_sound.c index 76ee4c64..3b35b36f 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -529,7 +529,7 @@ void S_StartSoundAtVolume(const void *origin_p, sfxenum_t sfx_id, INT32 volume) // Assigns the handle to one of the channels in the // mix/output buffer. - channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority); + channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority, cnum); } dontplay: @@ -579,7 +579,7 @@ dontplay: // Assigns the handle to one of the channels in the // mix/output buffer. - channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority); + channels[cnum].handle = I_StartSound(sfx_id, volume, sep, pitch, priority, cnum); } void S_StartSound(const void *origin, sfxenum_t sfx_id) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index cfdb3230..4b4ad3e6 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -419,10 +419,10 @@ void I_FreeSfx(sfxinfo_t *sfx) sfx->lumpnum = LUMPERROR; } -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { UINT8 volume = (((UINT16)vol + 1) * (UINT16)sfx_volume) / 62; // (256 * 31) / 62 == 127 - INT32 handle = Mix_PlayChannel(-1, S_sfx[id].data, 0); + INT32 handle = Mix_PlayChannel(channel, S_sfx[id].data, 0); Mix_Volume(handle, volume); Mix_SetPanning(handle, min((UINT16)(0xff-sep)<<1, 0xff), min((UINT16)(sep)<<1, 0xff)); (void)pitch; // Mixer can't handle pitch diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 6c70c163..a7c8383a 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -604,10 +604,11 @@ void I_FreeSfx(sfxinfo_t * sfx) // Pitching (that is, increased speed of playback) // is set, but currently not used by mixing. // -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { (void)priority; (void)pitch; + (void)channel; if (nosound) return 0; diff --git a/src/sdl12/mixer_sound.c b/src/sdl12/mixer_sound.c index 542a6716..daf09ab9 100644 --- a/src/sdl12/mixer_sound.c +++ b/src/sdl12/mixer_sound.c @@ -376,10 +376,10 @@ void I_FreeSfx(sfxinfo_t *sfx) sfx->data = NULL; } -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { UINT8 volume = (((UINT16)vol + 1) * (UINT16)sfx_volume) / 62; // (256 * 31) / 62 == 127 - INT32 handle = Mix_PlayChannel(-1, S_sfx[id].data, 0); + INT32 handle = Mix_PlayChannel(channel, S_sfx[id].data, 0); Mix_Volume(handle, volume); Mix_SetPanning(handle, min((UINT16)(0xff-sep)<<1, 0xff), min((UINT16)(sep)<<1, 0xff)); (void)pitch; // Mixer can't handle pitch diff --git a/src/sdl12/sdl_sound.c b/src/sdl12/sdl_sound.c index 6ba83104..01a27153 100644 --- a/src/sdl12/sdl_sound.c +++ b/src/sdl12/sdl_sound.c @@ -621,10 +621,11 @@ void I_FreeSfx(sfxinfo_t * sfx) // Pitching (that is, increased speed of playback) // is set, but currently not used by mixing. // -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { (void)priority; (void)pitch; + (void)channel; if (nosound) return 0; diff --git a/src/win32/win_snd.c b/src/win32/win_snd.c index 58644457..e50a4737 100644 --- a/src/win32/win_snd.c +++ b/src/win32/win_snd.c @@ -353,12 +353,13 @@ void I_FreeSfx(sfxinfo_t *sfx) sfx->data = NULL; } -INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority) +INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, UINT8 pitch, UINT8 priority, INT32 channel) { FMOD_SOUND *sound; FMOD_CHANNEL *chan; INT32 i; float frequency; + (void)channel; sound = (FMOD_SOUND *)S_sfx[id].data; I_Assert(sound != NULL); diff --git a/src/win32ce/win_snd.c b/src/win32ce/win_snd.c index f9c65217..a58bbc3c 100644 --- a/src/win32ce/win_snd.c +++ b/src/win32ce/win_snd.c @@ -538,7 +538,8 @@ INT32 I_StartSound (sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, - INT32 priority) + INT32 priority + INT32 channel) { HRESULT hr; LPDIRECTSOUNDBUFFER dsbuffer; @@ -549,6 +550,7 @@ INT32 I_StartSound (sfxenum_t id, #ifdef SURROUND LPDIRECTSOUNDBUFFER dssurround; #endif + (void)channel; if (nosound) return -1; From 3886888b3014da650aa2ae5bd843b8ef7dcea28f Mon Sep 17 00:00:00 2001 From: Sryder Date: Sun, 14 Oct 2018 10:14:07 +0100 Subject: [PATCH 120/194] Fix missing commas and missed interface --- src/android/i_sound.c | 3 ++- src/djgppdos/i_sound.c | 2 +- src/win32ce/win_snd.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/android/i_sound.c b/src/android/i_sound.c index ecf96f2f..77f8e6a5 100644 --- a/src/android/i_sound.c +++ b/src/android/i_sound.c @@ -21,13 +21,14 @@ void I_ShutdownSound(void){} // SFX I/O // -INT32 I_StartSound(sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, INT32 priority) +INT32 I_StartSound(sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, INT32 priority, INT32 channel) { (void)id; (void)vol; (void)sep; (void)pitch; (void)priority; + (void)channel; return -1; } diff --git a/src/djgppdos/i_sound.c b/src/djgppdos/i_sound.c index f1e2ad2b..ec6f4412 100644 --- a/src/djgppdos/i_sound.c +++ b/src/djgppdos/i_sound.c @@ -165,7 +165,7 @@ INT32 I_StartSound ( sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, - INT32 priority + INT32 priority, INT32 channel) { int voice; diff --git a/src/win32ce/win_snd.c b/src/win32ce/win_snd.c index a58bbc3c..14ce4add 100644 --- a/src/win32ce/win_snd.c +++ b/src/win32ce/win_snd.c @@ -538,7 +538,7 @@ INT32 I_StartSound (sfxenum_t id, INT32 vol, INT32 sep, INT32 pitch, - INT32 priority + INT32 priority, INT32 channel) { HRESULT hr; From 87afae9cf598922543e36df9efb16230bee36006 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sun, 21 Oct 2018 15:15:54 +0100 Subject: [PATCH 121/194] Fix unarchiving of mapheader_t userdata Lua variables --- src/lua_script.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index 1c1b01f6..9b87f0c2 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -853,7 +853,7 @@ static UINT8 UnArchiveValue(int TABLESINDEX) LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_SECTOR); break; case ARCH_MAPHEADER: - LUA_PushUserdata(gL, §ors[READUINT16(save_p)], META_MAPHEADER); + LUA_PushUserdata(gL, mapheaderinfo[READUINT16(save_p)], META_MAPHEADER); break; case ARCH_TEND: return 1; From ab38e6cebb7765e1fe0ce846e2a30deab285e7d2 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 13 Oct 2018 20:44:01 +0100 Subject: [PATCH 122/194] Creating a quick get_WSAErrorStr function to act as a wrapper for FormatMessageA so we can string-ify Winsock errors properly Untested! --- src/i_tcp.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/i_tcp.c b/src/i_tcp.c index 6488e984..9febd56f 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -262,6 +262,28 @@ static void wattcp_outch(char s) } #endif +#ifdef USE_WINSOCK +// stupid microsoft makes things complicated +static inline char *get_WSAErrorStr(int e) +{ + char *buf = NULL; + + FormatMessageA( + FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + (DWORD)e, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + (LPTSTR)&buf, + 0, NULL); + + return buf; +} +#undef strerror +#define strerror get_WSAErrorStr +#endif + #ifdef USE_WINSOCK2 #define inet_ntop inet_ntopA #define HAVE_NTOP From 3b39a25adec80437e56f8a6d886d220786a889f6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 15:49:04 +0100 Subject: [PATCH 123/194] Save the result of errno (aka WSAGetLastError() for WinSock) as soon as possible, to prevent anything in SOCK_GetNodeAddress resetting the value to 0 while trying to print the message for the error itself! --- src/i_tcp.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 9febd56f..6a212786 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -781,9 +781,13 @@ static void SOCK_Send(void) &clientaddress[doomcom->remotenode].any, d); } - if (c == ERRSOCKET && errno != ECONNREFUSED && errno != EWOULDBLOCK) - I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, - SOCK_GetNodeAddress(doomcom->remotenode), errno, strerror(errno)); + if (c == ERRSOCKET) + { + int e = errno; // save error code so it can't be modified later + if (e != ECONNREFUSED && e != EWOULDBLOCK) + I_Error("SOCK_Send, error sending to node %d (%s) #%u: %s", doomcom->remotenode, + SOCK_GetNodeAddress(doomcom->remotenode), e, strerror(e)); + } } #endif From e4e76f83c3e6c4de8ac467667df7daf05d2d9582 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:09:14 +0100 Subject: [PATCH 124/194] Use temporary buffer with a max size of 255 bytes instead of having Microsoft's FormatMessageA alloc one for us. Also, provide a fallback message in case no message was available for some reason --- src/i_tcp.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 6a212786..c054b3a4 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -266,17 +266,22 @@ static void wattcp_outch(char s) // stupid microsoft makes things complicated static inline char *get_WSAErrorStr(int e) { - char *buf = NULL; + char buf[256]; // allow up to 255 bytes + + buf[0] = '\0'; FormatMessageA( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)e, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&buf, - 0, NULL); + (LPTSTR)buf, + sizeof (buf), + NULL); + + if (!buf[0]) // provide a fallback error message if no message is available for some reason + sprintf(buf, "Unknown error"); return buf; } From bb3d850bbfaf9fe9c333e1c0c4a79706ec878c8c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:27:00 +0100 Subject: [PATCH 125/194] static the buffer, forgot to do this earlier --- src/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index c054b3a4..43dba4aa 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -266,7 +266,7 @@ static void wattcp_outch(char s) // stupid microsoft makes things complicated static inline char *get_WSAErrorStr(int e) { - char buf[256]; // allow up to 255 bytes + static char buf[256]; // allow up to 255 bytes buf[0] = '\0'; From 9fb301ecb587ed933f300cc9b65f23f8072e9d57 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 16:47:56 +0100 Subject: [PATCH 126/194] don't bother with inlining the function, on second thoughts --- src/i_tcp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 43dba4aa..0728c7aa 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -264,7 +264,7 @@ static void wattcp_outch(char s) #ifdef USE_WINSOCK // stupid microsoft makes things complicated -static inline char *get_WSAErrorStr(int e) +static char *get_WSAErrorStr(int e) { static char buf[256]; // allow up to 255 bytes From 29d8e34d03f0508cc75aa887a73d724b79837db6 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 5 Sep 2016 22:14:51 +0100 Subject: [PATCH 127/194] Call V_DoPostProcessor only in software mode (it cancels itself in OGL anyway) --- src/d_main.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 17053267..78e370cc 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -417,10 +417,13 @@ static void D_Display(void) } // Image postprocessing effect - if (postimgtype) - V_DoPostProcessor(0, postimgtype, postimgparam); - if (postimgtype2) - V_DoPostProcessor(1, postimgtype2, postimgparam2); + if (rendermode == render_soft) + { + if (postimgtype) + V_DoPostProcessor(0, postimgtype, postimgparam); + if (postimgtype2) + V_DoPostProcessor(1, postimgtype2, postimgparam2); + } } if (lastdraw) From b150e842fc4920b9298219ededd21f931c9de7f4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 5 Nov 2016 20:40:48 +0000 Subject: [PATCH 128/194] Add MD2_INDENT and MD2_VERSION so we can cleanly check that it's a valid MD2 from magic number/version --- src/hardware/hw_md2.c | 4 ++-- src/hardware/hw_md2.h | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 756d5a09..42f2afb2 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -304,8 +304,8 @@ static md2_model_t *md2_readModel(const char *filename) // initialize model and read header if (fread(&model->header, sizeof (model->header), 1, file) != 1 - || model->header.magic != - (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I')) + || model->header.magic != MD2_IDENT + || model->header.version != MD2_VERSION) { fclose(file); free(model); diff --git a/src/hardware/hw_md2.h b/src/hardware/hw_md2.h index 5a7e6d2b..299d1240 100644 --- a/src/hardware/hw_md2.h +++ b/src/hardware/hw_md2.h @@ -23,6 +23,11 @@ #include "hw_glob.h" +// magic number "IDP2" or 844121161 +#define MD2_IDENT (INT32)(('2' << 24) + ('P' << 16) + ('D' << 8) + 'I') +// model version +#define MD2_VERSION 8 + #define MD2_MAX_TRIANGLES 8192 #define MD2_MAX_VERTICES 4096 #define MD2_MAX_TEXCOORDS 4096 From 67a29225585bb2b978009d86ac3825021708d3bf Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 5 Nov 2016 20:51:48 +0000 Subject: [PATCH 129/194] Ensure file is closed whenever MD2 reading errors happen --- src/hardware/hw_md2.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/hardware/hw_md2.c b/src/hardware/hw_md2.c index 42f2afb2..cb33562d 100644 --- a/src/hardware/hw_md2.c +++ b/src/hardware/hw_md2.c @@ -319,6 +319,7 @@ static md2_model_t *md2_readModel(const char *filename) { \ CONS_Alert(CONS_ERROR, "md2_readModel: %s has too many " msgname " (# found: %d, maximum: %d)\n", filename, field, max); \ md2_freeModel (model); \ + fclose(file); \ return 0; \ } @@ -340,6 +341,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->skins, sizeof (md2_skin_t), model->header.numSkins, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -353,6 +355,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->texCoords, sizeof (md2_textureCoordinate_t), model->header.numTexCoords, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -366,6 +369,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->triangles, sizeof (md2_triangle_t), model->header.numTriangles, file)) { md2_freeModel (model); + fclose(file); return 0; } } @@ -378,6 +382,7 @@ static md2_model_t *md2_readModel(const char *filename) if (!model->frames) { md2_freeModel (model); + fclose(file); return 0; } @@ -391,6 +396,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(frame, 1, model->header.frameSize, file)) { md2_freeModel (model); + fclose(file); return 0; } @@ -416,6 +422,7 @@ static md2_model_t *md2_readModel(const char *filename) fread(model->glCommandBuffer, sizeof (INT32), model->header.numGlCommands, file)) { md2_freeModel (model); + fclose(file); return 0; } } From 787d5b598dd9e681b1896d2f99cfb59a5c9fcc3c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 3 Jun 2017 21:40:41 +0100 Subject: [PATCH 130/194] gr_correcttricks fix: don't check if top/bottom textures are missing for sloped sectors, just ignore and cancel the hack This fixes GFZ2's mysterious flying flats at the ramp to the big room --- src/hardware/hw_trick.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/hardware/hw_trick.c b/src/hardware/hw_trick.c index e9ba19ef..7a92859f 100644 --- a/src/hardware/hw_trick.c +++ b/src/hardware/hw_trick.c @@ -507,6 +507,14 @@ static boolean areToptexturesMissing(sector_t *thisSector) if (!frontSector || !backSector) continue; +#ifdef ESLOPE + if (frontSector->c_slope || backSector->c_slope) // the slope's height can be completely different from original ceiling height + { + nomiss++; + break; + } +#endif + sider = &sides[thisElem->line->sidenum[0]]; sidel = &sides[thisElem->line->sidenum[1]]; @@ -555,6 +563,14 @@ static boolean areBottomtexturesMissing(sector_t *thisSector) if (frontSector == NULL || backSector == NULL) continue; +#ifdef ESLOPE + if (frontSector->f_slope || backSector->f_slope) // the slope's height can be completely different from original floor height + { + nomiss++; + break; + } +#endif + sider = &sides[thisElem->line->sidenum[0]]; sidel = &sides[thisElem->line->sidenum[1]]; From 2107aab666b8147571ae5d63824412130a5cf50f Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 26 Jun 2017 10:51:19 +0100 Subject: [PATCH 131/194] Moved my added slope checks in hw_trick.c to isCeilingFloating/isFloorFloating I also optimised those two functions while I was there (why keep a "floating" variable when setting it to false guarantees the functions return false?) --- src/hardware/hw_trick.c | 86 ++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 58 deletions(-) diff --git a/src/hardware/hw_trick.c b/src/hardware/hw_trick.c index 7a92859f..44c07a6b 100644 --- a/src/hardware/hw_trick.c +++ b/src/hardware/hw_trick.c @@ -507,14 +507,6 @@ static boolean areToptexturesMissing(sector_t *thisSector) if (!frontSector || !backSector) continue; -#ifdef ESLOPE - if (frontSector->c_slope || backSector->c_slope) // the slope's height can be completely different from original ceiling height - { - nomiss++; - break; - } -#endif - sider = &sides[thisElem->line->sidenum[0]]; sidel = &sides[thisElem->line->sidenum[1]]; @@ -563,14 +555,6 @@ static boolean areBottomtexturesMissing(sector_t *thisSector) if (frontSector == NULL || backSector == NULL) continue; -#ifdef ESLOPE - if (frontSector->f_slope || backSector->f_slope) // the slope's height can be completely different from original floor height - { - nomiss++; - break; - } -#endif - sider = &sides[thisElem->line->sidenum[0]]; sidel = &sides[thisElem->line->sidenum[1]]; @@ -603,15 +587,14 @@ static boolean areBottomtexturesMissing(sector_t *thisSector) static boolean isCeilingFloating(sector_t *thisSector) { sector_t *adjSector, *refSector = NULL, *frontSector, *backSector; - boolean floating = true; linechain_t *thisElem, *nextElem; if (!thisSector) return false; - nextElem = thisSector->sectorLines; + nextElem = thisSector->sectorLines; - while (NULL != nextElem) // walk through chain + while (nextElem) // walk through chain { thisElem = nextElem; nextElem = thisElem->next; @@ -625,10 +608,12 @@ static boolean isCeilingFloating(sector_t *thisSector) adjSector = frontSector; if (!adjSector) // assume floating sectors have surrounding sectors - { - floating = false; - break; - } + return false; + +#ifdef ESLOPE + if (adjSector->c_slope) // Don't bother with slopes + return false; +#endif if (!refSector) { @@ -637,23 +622,15 @@ static boolean isCeilingFloating(sector_t *thisSector) } // if adjacent sector has same height or more than one adjacent sector exists -> stop - if (thisSector->ceilingheight == adjSector->ceilingheight || - refSector != adjSector) - { - floating = false; - break; - } + if (thisSector->ceilingheight == adjSector->ceilingheight || refSector != adjSector) + return false; } // now check for walltextures - if (floating) - { - if (!areToptexturesMissing(thisSector)) - { - floating = false; - } - } - return floating; + if (!areToptexturesMissing(thisSector)) + return false; + + return true; } // @@ -663,7 +640,6 @@ static boolean isCeilingFloating(sector_t *thisSector) static boolean isFloorFloating(sector_t *thisSector) { sector_t *adjSector, *refSector = NULL, *frontSector, *backSector; - boolean floating = true; linechain_t *thisElem, *nextElem; if (!thisSector) @@ -684,36 +660,30 @@ static boolean isFloorFloating(sector_t *thisSector) else adjSector = frontSector; - if (NULL == adjSector) // assume floating sectors have surrounding sectors - { - floating = false; - break; - } + if (!adjSector) // assume floating sectors have surrounding sectors + return false; - if (NULL == refSector) +#ifdef ESLOPE + if (adjSector->f_slope) // Don't bother with slopes + return false; +#endif + + if (!refSector) { refSector = adjSector; continue; } // if adjacent sector has same height or more than one adjacent sector exists -> stop - if (thisSector->floorheight == adjSector->floorheight || - refSector != adjSector) - { - floating = false; - break; - } + if (thisSector->floorheight == adjSector->floorheight || refSector != adjSector) + return false; } // now check for walltextures - if (floating) - { - if (!areBottomtexturesMissing(thisSector)) - { - floating = false; - } - } - return floating; + if (!areBottomtexturesMissing(thisSector)) + return false; + + return true; } // From 1cf2ce63c061f5288b088120c981e45ea613c399 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 26 Jun 2017 11:12:26 +0100 Subject: [PATCH 132/194] More optimising and otherwise fixing bizarre formatting in hw_trick.c --- src/hardware/hw_trick.c | 56 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/src/hardware/hw_trick.c b/src/hardware/hw_trick.c index 44c07a6b..97d86b94 100644 --- a/src/hardware/hw_trick.c +++ b/src/hardware/hw_trick.c @@ -107,17 +107,17 @@ static void releaseLineChains(void) for (i = 0; i < numsectors; i++) { - sector = §ors[i]; - nextElem = sector->sectorLines; + sector = §ors[i]; + nextElem = sector->sectorLines; - while (nextElem) - { - thisElem = nextElem; - nextElem = thisElem->next; - free(thisElem); - } + while (nextElem) + { + thisElem = nextElem; + nextElem = thisElem->next; + free(thisElem); + } - sector->sectorLines = NULL; + sector->sectorLines = NULL; } } @@ -397,7 +397,7 @@ static void sortStacklist(sector_t *sector) i = 0; finished = true; - while (NULL != *(list+i+1)) + while (*(list+i+1)) { sec1 = *(list+i); sec2 = *(list+i+1); @@ -438,7 +438,7 @@ static double calcLineoutLength(sector_t *sector) double length = 0.0L; chain = sector->sectorLines; - while (NULL != chain) // sum up lengths of all lines + while (chain) // sum up lengths of all lines { length += lineLength(chain->line); chain = chain->next; @@ -454,7 +454,7 @@ static void calcLineouts(sector_t *sector) size_t secCount = 0; sector_t *encSector = *(sector->stackList); - while (NULL != encSector) + while (encSector) { if (encSector->lineoutLength < 0.0L) // if length has not yet been calculated { @@ -552,7 +552,7 @@ static boolean areBottomtexturesMissing(sector_t *thisSector) if (frontSector == backSector) // skip damn renderer tricks here continue; - if (frontSector == NULL || backSector == NULL) + if (!frontSector || !backSector) continue; sider = &sides[thisElem->line->sidenum[0]]; @@ -645,7 +645,7 @@ static boolean isFloorFloating(sector_t *thisSector) if (!thisSector) return false; - nextElem = thisSector->sectorLines; + nextElem = thisSector->sectorLines; while (nextElem) // walk through chain { @@ -693,14 +693,12 @@ static fixed_t estimateCeilHeight(sector_t *thisSector) { sector_t *adjSector; - if (!thisSector || - !thisSector->sectorLines || - !thisSector->sectorLines->line) + if (!thisSector || !thisSector->sectorLines || !thisSector->sectorLines->line) return 0; adjSector = thisSector->sectorLines->line->frontsector; if (adjSector == thisSector) - adjSector = thisSector->sectorLines->line->backsector; + adjSector = thisSector->sectorLines->line->backsector; if (!adjSector) return 0; @@ -715,17 +713,15 @@ static fixed_t estimateFloorHeight(sector_t *thisSector) { sector_t *adjSector; - if (!thisSector || - !thisSector->sectorLines || - !thisSector->sectorLines->line) - return 0; + if (!thisSector || !thisSector->sectorLines || !thisSector->sectorLines->line) + return 0; adjSector = thisSector->sectorLines->line->frontsector; if (adjSector == thisSector) - adjSector = thisSector->sectorLines->line->backsector; + adjSector = thisSector->sectorLines->line->backsector; - if (NULL == adjSector) - return 0; + if (!adjSector) + return 0; return adjSector->floorheight; } @@ -831,18 +827,12 @@ void HWR_CorrectSWTricks(void) // correct height of floating sectors if (isCeilingFloating(floatSector)) { - fixed_t corrheight; - - corrheight = estimateCeilHeight(floatSector); - floatSector->virtualCeilingheight = corrheight; + floatSector->virtualCeilingheight = estimateCeilHeight(floatSector); floatSector->virtualCeiling = true; } if (isFloorFloating(floatSector)) { - fixed_t corrheight; - - corrheight = estimateFloorHeight(floatSector); - floatSector->virtualFloorheight = corrheight; + floatSector->virtualFloorheight = estimateFloorHeight(floatSector); floatSector->virtualFloor = true; } } From 90cfa5ef16d9e283cf4b23be70d9ad3f7a6f41f7 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 7 Nov 2016 21:55:56 +0000 Subject: [PATCH 133/194] Make new pv1/pv2 seg pointers, so AdjustSeg doesn't modify the v1/v2 pointers directly anymore Yes I know they're void * in r_defs.h's seg_t definition, it's quicker than trying to figure out if including hardware/hw_glob.h is a good idea or not --- src/hardware/hw_bsp.c | 12 ++++---- src/hardware/hw_main.c | 64 +++++++++++++++++++++--------------------- src/p_setup.c | 1 + src/r_defs.h | 3 ++ 4 files changed, 42 insertions(+), 38 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index a32609fc..97baec66 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -914,7 +914,7 @@ static void AdjustSegs(void) } if (nearv1 <= NEARDIST*NEARDIST) // share vertice with segs - lseg->v1 = (vertex_t *)&(p->pts[v1found]); + lseg->pv1 = &(p->pts[v1found]); else { // BP: here we can do better, using PointInSeg and compute @@ -925,24 +925,24 @@ static void AdjustSegs(void) polyvertex_t *pv = HWR_AllocVertex(); pv->x = FIXED_TO_FLOAT(lseg->v1->x); pv->y = FIXED_TO_FLOAT(lseg->v1->y); - lseg->v1 = (vertex_t *)pv; + lseg->pv1 = pv; } if (nearv2 <= NEARDIST*NEARDIST) - lseg->v2 = (vertex_t *)&(p->pts[v2found]); + lseg->pv2 = &(p->pts[v2found]); else { polyvertex_t *pv = HWR_AllocVertex(); pv->x = FIXED_TO_FLOAT(lseg->v2->x); pv->y = FIXED_TO_FLOAT(lseg->v2->y); - lseg->v2 = (vertex_t *)pv; + lseg->pv2 = pv; } // recompute length { float x,y; - x = ((polyvertex_t *)lseg->v2)->x - ((polyvertex_t *)lseg->v1)->x + x = ((polyvertex_t *)lseg->pv2)->x - ((polyvertex_t *)lseg->pv1)->x + FIXED_TO_FLOAT(FRACUNIT/2); - y = ((polyvertex_t *)lseg->v2)->y - ((polyvertex_t *)lseg->v1)->y + y = ((polyvertex_t *)lseg->pv2)->y - ((polyvertex_t *)lseg->pv1)->y + FIXED_TO_FLOAT(FRACUNIT/2); lseg->flength = (float)hypot(x, y); // BP: debug see this kind of segs diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index ecb70a0f..85ddff08 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -856,11 +856,11 @@ static void HWR_DrawSegsSplats(FSurfaceInfo * pSurf) M_ClearBox(segbbox); M_AddToBox(segbbox, - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); M_AddToBox(segbbox, - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); splat = (wallsplat_t *)gr_curline->linedef->splats; for (; splat; splat = splat->next) @@ -1367,10 +1367,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; - vs.x = ((polyvertex_t *)gr_curline->v1)->x; - vs.y = ((polyvertex_t *)gr_curline->v1)->y; - ve.x = ((polyvertex_t *)gr_curline->v2)->x; - ve.y = ((polyvertex_t *)gr_curline->v2)->y; + vs.x = ((polyvertex_t *)gr_curline->pv1)->x; + vs.y = ((polyvertex_t *)gr_curline->pv1)->y; + ve.x = ((polyvertex_t *)gr_curline->pv2)->x; + ve.y = ((polyvertex_t *)gr_curline->pv2)->y; #ifdef ESLOPE v1x = FLOAT_TO_FIXED(vs.x); @@ -2456,7 +2456,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + highfrac = HWR_ClipViewSegment(start->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(0, highfrac); } // Now adjust the clip size. @@ -2480,8 +2480,8 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); - highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); + highfrac = HWR_ClipViewSegment((next+1)->first+1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, highfrac); } next++; @@ -2515,7 +2515,7 @@ static void HWR_ClipSolidWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(next->last-1, (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, 1); } } @@ -2578,8 +2578,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) else { highfrac = HWR_ClipViewSegment(min(start->first + 1, - start->last), (polyvertex_t *)gr_curline->v1, - (polyvertex_t *)gr_curline->v2); + start->last), (polyvertex_t *)gr_curline->pv1, + (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(0, highfrac); } } @@ -2598,8 +2598,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) } else { - lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); - highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->v1, (polyvertex_t *)gr_curline->v2); + lowfrac = HWR_ClipViewSegment(max(start->last-1,start->first), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); + highfrac = HWR_ClipViewSegment(min((start+1)->first+1,(start+1)->last), (polyvertex_t *)gr_curline->pv1, (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, highfrac); } start++; @@ -2629,8 +2629,8 @@ static void HWR_ClipPassWallSegment(INT32 first, INT32 last) else { lowfrac = HWR_ClipViewSegment(max(start->last - 1, - start->first), (polyvertex_t *)gr_curline->v1, - (polyvertex_t *)gr_curline->v2); + start->first), (polyvertex_t *)gr_curline->pv1, + (polyvertex_t *)gr_curline->pv2); HWR_StoreWallRange(lowfrac, 1); } } @@ -2691,10 +2691,10 @@ static void HWR_AddLine(seg_t * line) gr_curline = line; // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y)); - angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y)); + angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); + angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), + FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); // Clip to view edges. span = angle1 - angle2; @@ -2736,8 +2736,8 @@ static void HWR_AddLine(seg_t * line) float fx1,fx2,fy1,fy2; //BP: test with a better projection than viewangletox[R_PointToAngle(angle)] // do not enable this at release 4 mul and 2 div - fx1 = ((polyvertex_t *)(line->v1))->x-gr_viewx; - fy1 = ((polyvertex_t *)(line->v1))->y-gr_viewy; + fx1 = ((polyvertex_t *)(line->pv1))->x-gr_viewx; + fy1 = ((polyvertex_t *)(line->pv1))->y-gr_viewy; fy2 = (fx1 * gr_viewcos + fy1 * gr_viewsin); if (fy2 < 0) // the point is back @@ -2745,8 +2745,8 @@ static void HWR_AddLine(seg_t * line) else fx1 = gr_windowcenterx + (fx1 * gr_viewsin - fy1 * gr_viewcos) * gr_centerx / fy2; - fx2 = ((polyvertex_t *)(line->v2))->x-gr_viewx; - fy2 = ((polyvertex_t *)(line->v2))->y-gr_viewy; + fx2 = ((polyvertex_t *)(line->pv2))->x-gr_viewx; + fy2 = ((polyvertex_t *)(line->pv2))->y-gr_viewy; fy1 = (fx2 * gr_viewcos + fy2 * gr_viewsin); if (fy1 < 0) // the point is back @@ -2789,10 +2789,10 @@ static void HWR_AddLine(seg_t * line) fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->v2)->y); + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); #define SLOPEPARAMS(slope, end1, end2, normalheight) \ if (slope) { \ end1 = P_GetZAt(slope, v1x, v1y); \ @@ -2987,8 +2987,8 @@ static inline void HWR_AddPolyObjectSegs(void) pv2->x = FIXED_TO_FLOAT(gr_fakeline->v2->x); pv2->y = FIXED_TO_FLOAT(gr_fakeline->v2->y); - gr_fakeline->v1 = (vertex_t *)pv1; - gr_fakeline->v2 = (vertex_t *)pv2; + gr_fakeline->pv1 = pv1; + gr_fakeline->pv2 = pv2; HWR_AddLine(gr_fakeline); } diff --git a/src/p_setup.c b/src/p_setup.c index 17a6797f..f00781a5 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -451,6 +451,7 @@ static void P_LoadSegs(lumpnum_t lumpnum) //Hurdler: 04/12/2000: for now, only used in hardware mode li->lightmaps = NULL; // list of static lightmap for this seg } + li->pv1 = li->pv2 = NULL; #endif li->angle = (SHORT(ml->angle))< Date: Wed, 21 Dec 2016 22:10:27 +0000 Subject: [PATCH 134/194] Hack to make sure even (extra)subsectors without planepolys have segs adjusted this fixes a crash in (old) GFZ2 at the ramp as a result of creating pv1/pv2. This probably means before pv1/pv2 there could have been some silly typecasting from vertex_t to polyvertex_t to get fixed vertex coords and such... --- src/hardware/hw_bsp.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 97baec66..fa5bce30 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -878,8 +878,8 @@ static void AdjustSegs(void) count = subsectors[i].numlines; lseg = &segs[subsectors[i].firstline]; p = extrasubsectors[i].planepoly; - if (!p) - continue; + //if (!p) + //continue; for (; count--; lseg++) { float distv1,distv2,tmp; @@ -892,27 +892,29 @@ static void AdjustSegs(void) continue; #endif - for (j = 0; j < p->numpts; j++) - { - distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x); - tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y); - distv1 = distv1*distv1+tmp*tmp; - if (distv1 <= nearv1) + if (p) { + for (j = 0; j < p->numpts; j++) { - v1found = j; - nearv1 = distv1; - } - // the same with v2 - distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); - tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); - distv2 = distv2*distv2+tmp*tmp; - if (distv2 <= nearv2) - { - v2found = j; - nearv2 = distv2; + distv1 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v1->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v1->y); + distv1 = distv1*distv1+tmp*tmp; + if (distv1 <= nearv1) + { + v1found = j; + nearv1 = distv1; + } + // the same with v2 + distv2 = p->pts[j].x - FIXED_TO_FLOAT(lseg->v2->x); + tmp = p->pts[j].y - FIXED_TO_FLOAT(lseg->v2->y); + distv2 = distv2*distv2+tmp*tmp; + if (distv2 <= nearv2) + { + v2found = j; + nearv2 = distv2; + } } } - if (nearv1 <= NEARDIST*NEARDIST) + if (p && nearv1 <= NEARDIST*NEARDIST) // share vertice with segs lseg->pv1 = &(p->pts[v1found]); else @@ -927,7 +929,7 @@ static void AdjustSegs(void) pv->y = FIXED_TO_FLOAT(lseg->v1->y); lseg->pv1 = pv; } - if (nearv2 <= NEARDIST*NEARDIST) + if (p && nearv2 <= NEARDIST*NEARDIST) lseg->pv2 = &(p->pts[v2found]); else { From 3d88ee9d55385f5281108f90a4fea63ce4a8ad2e Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 21 Dec 2016 22:31:09 +0000 Subject: [PATCH 135/194] Added missing checks in HWR_AddLine from the software version, move v** vars to the top since R_PointToAngle calls use the same values anyway --- src/hardware/hw_main.c | 49 ++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 85ddff08..d4b2832f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2685,16 +2685,21 @@ static void HWR_AddLine(seg_t * line) // SoM: Backsector needs to be run through R_FakeFlat static sector_t tempsec; + fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t + if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; gr_curline = line; + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); + // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y)); - angle2 = R_PointToAngle(FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x), - FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y)); + angle1 = R_PointToAngle(v1x, v1y); + angle2 = R_PointToAngle(v2x, v2y); // Clip to view edges. span = angle1 - angle2; @@ -2785,14 +2790,9 @@ static void HWR_AddLine(seg_t * line) #ifdef ESLOPE if (gr_frontsector->f_slope || gr_frontsector->c_slope || gr_backsector->f_slope || gr_backsector->c_slope) { - fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends - v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); - v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); - v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); - v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); #define SLOPEPARAMS(slope, end1, end2, normalheight) \ if (slope) { \ end1 = P_GetZAt(slope, v1x, v1y); \ @@ -2813,6 +2813,13 @@ static void HWR_AddLine(seg_t * line) goto clipsolid; } + // Check for automap fix. + if (backc1 <= backf1 && backc2 <= backf2 + && ((backc1 >= frontc1 && backc2 >= frontc2) || gr_curline->sidedef->toptexture) + && ((backf1 <= frontf1 && backf2 >= frontf2) || gr_curline->sidedef->bottomtexture) + && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) + goto clipsolid; + // Window. if (backc1 != frontc1 || backc2 != frontc2 || backf1 != frontf1 || backf2 != frontf2) @@ -2828,6 +2835,13 @@ static void HWR_AddLine(seg_t * line) gr_backsector->floorheight >= gr_frontsector->ceilingheight) goto clipsolid; + // Check for automap fix. + if (gr_backsector->ceilingheight <= gr_backsector->floorheight + && ((gr_backsector->ceilingheight >= gr_frontsector->ceilingheight) || gr_curline->sidedef->toptexture) + && ((gr_backsector->floorheight <= gr_backsector->floorheight) || gr_curline->sidedef->bottomtexture) + && (gr_backsector->ceilingpic != skyflatnum || gr_frontsector->ceilingpic != skyflatnum)) + goto clipsolid; + // Window. if (gr_backsector->ceilingheight != gr_frontsector->ceilingheight || gr_backsector->floorheight != gr_frontsector->floorheight) @@ -2849,8 +2863,21 @@ static void HWR_AddLine(seg_t * line) && gr_backsector->c_slope == gr_frontsector->c_slope #endif && gr_backsector->lightlevel == gr_frontsector->lightlevel - && gr_curline->sidedef->midtexture == 0 - && !gr_backsector->ffloors && !gr_frontsector->ffloors) + && !gr_curline->sidedef->midtexture + // Check offsets too! + && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs + && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs + && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle + && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs + && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs + && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle + // Consider altered lighting. + && gr_backsector->floorlightsec == gr_frontsector->floorlightsec + && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec + // Consider colormaps + && gr_backsector->extra_colormap == gr_frontsector->extra_colormap + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || gr_frontsector->tag == gr_backsector->tag)) // SoM: For 3D sides... Boris, would you like to take a // crack at rendering 3D sides? You would need to add the // above check and add code to HWR_StoreWallRange... From aebcf3520b8814b11b694b571cb7c4352ced637b Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 12 Jan 2017 21:43:37 +0000 Subject: [PATCH 136/194] Remove pointless drawtextured variable and redundant fake planes checks (R_FakeFlat would already have made gr_frontsector/backsector something else if they were) --- src/hardware/hw_main.c | 98 ++++++++---------------------------------- 1 file changed, 19 insertions(+), 79 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index d4b2832f..7e815258 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -323,9 +323,6 @@ static angle_t gr_xtoviewangle[MAXVIDWIDTH+1]; // test change fov when looking up/down but bsp projection messup :( //#define NOCRAPPYMLOOK -/// \note crappy -#define drawtextured true - // base values set at SetViewSize static float gr_basecentery; @@ -1378,44 +1375,21 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) v2x = FLOAT_TO_FIXED(ve.x); v2y = FLOAT_TO_FIXED(ve.y); #endif - - if (gr_frontsector->heightsec != -1) - { #ifdef ESLOPE - worldtop = worldtopslope = sectors[gr_frontsector->heightsec].ceilingheight; - worldbottom = worldbottomslope = sectors[gr_frontsector->heightsec].floorheight; -#else - worldtop = sectors[gr_frontsector->heightsec].ceilingheight; - worldbottom = sectors[gr_frontsector->heightsec].floorheight; -#endif - } - else - { -#ifdef ESLOPE - if (gr_frontsector->c_slope) - { - worldtop = P_GetZAt(gr_frontsector->c_slope, v1x, v1y); - worldtopslope = P_GetZAt(gr_frontsector->c_slope, v2x, v2y); - } - else - { - worldtop = worldtopslope = gr_frontsector->ceilingheight; - } - if (gr_frontsector->f_slope) - { - worldbottom = P_GetZAt(gr_frontsector->f_slope, v1x, v1y); - worldbottomslope = P_GetZAt(gr_frontsector->f_slope, v2x, v2y); - } - else - { - worldbottom = worldbottomslope = gr_frontsector->floorheight; - } +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, v1x, v1y); \ + end2 = P_GetZAt(slope, v2x, v2y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(gr_frontsector->c_slope, worldtop, worldtopslope, gr_frontsector->ceilingheight) + SLOPEPARAMS(gr_frontsector->f_slope, worldbottom, worldbottomslope, gr_frontsector->floorheight) #else - worldtop = gr_frontsector->ceilingheight; - worldbottom = gr_frontsector->floorheight; + worldtop = gr_frontsector->ceilingheight; + worldbottom = gr_frontsector->floorheight; #endif - } // remember vertices ordering // 3--2 @@ -1430,7 +1404,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[2].z = wallVerts[1].z = ve.y; wallVerts[0].w = wallVerts[1].w = wallVerts[2].w = wallVerts[3].w = 1.0f; - if (drawtextured) { // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; @@ -1459,43 +1432,15 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) { INT32 gr_toptexture, gr_bottomtexture; // two sided line - if (gr_backsector->heightsec != -1) - { -#ifdef ESLOPE - worldhigh = worldhighslope = sectors[gr_backsector->heightsec].ceilingheight; - worldlow = worldlowslope = sectors[gr_backsector->heightsec].floorheight; -#else - worldhigh = sectors[gr_backsector->heightsec].ceilingheight; - worldlow = sectors[gr_backsector->heightsec].floorheight; -#endif - } - else - { -#ifdef ESLOPE - if (gr_backsector->c_slope) - { - worldhigh = P_GetZAt(gr_backsector->c_slope, v1x, v1y); - worldhighslope = P_GetZAt(gr_backsector->c_slope, v2x, v2y); - } - else - { - worldhigh = worldhighslope = gr_backsector->ceilingheight; - } - if (gr_backsector->f_slope) - { - worldlow = P_GetZAt(gr_backsector->f_slope, v1x, v1y); - worldlowslope = P_GetZAt(gr_backsector->f_slope, v2x, v2y); - } - else - { - worldlow = worldlowslope = gr_backsector->floorheight; - } +#ifdef ESLOPE + SLOPEPARAMS(gr_backsector->c_slope, worldhigh, worldhighslope, gr_backsector->ceilingheight) + SLOPEPARAMS(gr_backsector->f_slope, worldlow, worldlowslope, gr_backsector->floorheight) +#undef SLOPEPARAMS #else - worldhigh = gr_backsector->ceilingheight; - worldlow = gr_backsector->floorheight; + worldhigh = gr_backsector->ceilingheight; + worldlow = gr_backsector->floorheight; #endif - } // hack to allow height changes in outdoor areas // This is what gets rid of the upper textures if there should be sky @@ -1519,7 +1464,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) worldhigh < worldtop ) && gr_toptexture) { - if (drawtextured) { fixed_t texturevpegtop; // top @@ -1600,7 +1544,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) #endif worldlow > worldbottom) && gr_bottomtexture) //only if VISIBLE!!! { - if (drawtextured) { fixed_t texturevpegbottom = 0; // bottom @@ -1792,7 +1735,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) h = min(highcut, polytop); l = max(polybottom, lowcut); - if (drawtextured) { // PEGGING #ifdef ESLOPE @@ -1848,7 +1790,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) h = min(highcut, polytop); l = max(polybottom, lowcut); - if (drawtextured) { // PEGGING if (!!(gr_linedef->flags & ML_DONTPEGBOTTOM) ^ !!(gr_linedef->flags & ML_EFFECT3)) @@ -2039,7 +1980,6 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) gr_midtexture = R_GetTextureNum(gr_sidedef->midtexture); if (gr_midtexture) { - if (drawtextured) { fixed_t texturevpeg; // PEGGING @@ -2180,7 +2120,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = 0; } - else if (drawtextured) + else { fixed_t texturevpeg; @@ -2316,7 +2256,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) wallVerts[0].s = wallVerts[3].s = 0; wallVerts[2].s = wallVerts[1].s = 0; } - else if (drawtextured) + else { grTex = HWR_GetTexture(texnum); From 32077897b6af08a28e1fe28b9a2b9ef14393672f Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 27 Oct 2018 19:58:51 +0100 Subject: [PATCH 137/194] Removed all remaining traces of VID_X11 code in hw_drv.h and hw_data.h, the macro is no longer used by Linux etc versions of SRB2. Unlike the rest of the commits in this branch (as of writing), I didn't make this commit between 1 and 2 years ago, I made it right now ;) --- src/hardware/hw_data.h | 4 ---- src/hardware/hw_drv.h | 15 --------------- 2 files changed, 19 deletions(-) diff --git a/src/hardware/hw_data.h b/src/hardware/hw_data.h index d76fcc1c..4bbc578e 100644 --- a/src/hardware/hw_data.h +++ b/src/hardware/hw_data.h @@ -26,10 +26,6 @@ #include #endif -#if defined (VID_X11) && !defined (HAVE_SDL) -#include -#endif - #include "../doomdef.h" //THIS MUST DISAPPEAR!!! #include "hw_glide.h" diff --git a/src/hardware/hw_drv.h b/src/hardware/hw_drv.h index a5ac8200..e2fa90eb 100644 --- a/src/hardware/hw_drv.h +++ b/src/hardware/hw_drv.h @@ -32,10 +32,6 @@ // STANDARD DLL EXPORTS // ========================================================================== -#ifdef HAVE_SDL -#undef VID_X11 -#endif - EXPORT boolean HWRAPI(Init) (I_Error_t ErrorFunction); #ifndef HAVE_SDL EXPORT void HWRAPI(Shutdown) (void); @@ -43,9 +39,6 @@ EXPORT void HWRAPI(Shutdown) (void); #ifdef _WINDOWS EXPORT void HWRAPI(GetModeList) (vmode_t **pvidmodes, INT32 *numvidmodes); #endif -#ifdef VID_X11 -EXPORT Window HWRAPI(HookXwin) (Display *, INT32, INT32, boolean); -#endif #if defined (PURESDL) || defined (macintosh) EXPORT void HWRAPI(SetPalette) (INT32 *, RGBA_t *gamma); #else @@ -71,10 +64,6 @@ EXPORT void HWRAPI(SetTransform) (FTransform *ptransform); EXPORT INT32 HWRAPI(GetTextureUsed) (void); EXPORT INT32 HWRAPI(GetRenderVersion) (void); -#ifdef VID_X11 // ifdef to be removed as soon as windoze supports that as well -// metzgermeister: added for Voodoo detection -EXPORT char *HWRAPI(GetRenderer) (void); -#endif #ifdef SHUFFLE #define SCREENVERTS 10 EXPORT void HWRAPI(PostImgRedraw) (float points[SCREENVERTS][SCREENVERTS][2]); @@ -115,10 +104,6 @@ struct hwdriver_s #ifdef _WINDOWS GetModeList pfnGetModeList; #endif -#ifdef VID_X11 - HookXwin pfnHookXwin; - GetRenderer pfnGetRenderer; -#endif #ifndef HAVE_SDL Shutdown pfnShutdown; #endif From 3d0daf220282bf88673894d42b537e1a6a21c3ee Mon Sep 17 00:00:00 2001 From: Louis-Antoine Date: Mon, 29 Oct 2018 00:49:23 +0100 Subject: [PATCH 138/194] Fix desynch when toggling analog mode or flipcam Special thanks to Lat' for asking weird questions --- src/d_clisrv.c | 12 ------------ src/d_netcmd.c | 8 ++++---- src/g_game.c | 10 ---------- src/r_main.c | 10 ---------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 7d0e44b4..fc80e56b 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3097,12 +3097,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) displayplayer = newplayernum; secondarydisplayplayer = newplayernum; DEBFILE("spawning me\n"); - // Apply player flags as soon as possible! - players[newplayernum].pflags &= ~(PF_FLIPCAM|PF_ANALOGMODE); - if (cv_flipcam.value) - players[newplayernum].pflags |= PF_FLIPCAM; - if (cv_analog.value) - players[newplayernum].pflags |= PF_ANALOGMODE; } else { @@ -3110,12 +3104,6 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) DEBFILE("spawning my brother\n"); if (botingame) players[newplayernum].bot = 1; - // Same goes for player 2 when relevant - players[newplayernum].pflags &= ~(PF_FLIPCAM|PF_ANALOGMODE); - if (cv_flipcam2.value) - players[newplayernum].pflags |= PF_FLIPCAM; - if (cv_analog2.value) - players[newplayernum].pflags |= PF_ANALOGMODE; } D_SendPlayerConfig(); addedtogame = true; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 673d64fd..e4ac8d9b 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1369,9 +1369,9 @@ void SendWeaponPref(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (players[consoleplayer].pflags & PF_FLIPCAM) + if (cv_flipcam.value) buf[0] |= 1; - if (players[consoleplayer].pflags & PF_ANALOGMODE) + if (cv_analog.value) buf[0] |= 2; SendNetXCmd(XD_WEAPONPREF, buf, 1); } @@ -1381,9 +1381,9 @@ void SendWeaponPref2(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (players[secondarydisplayplayer].pflags & PF_FLIPCAM) + if (cv_flipcam2.value) buf[0] |= 1; - if (players[secondarydisplayplayer].pflags & PF_ANALOGMODE) + if (cv_analog2.value) buf[0] |= 2; SendNetXCmd2(XD_WEAPONPREF, buf, 1); } diff --git a/src/g_game.c b/src/g_game.c index d3c55e0c..e2f35ad1 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -1575,11 +1575,6 @@ static void Analog_OnChange(void) return; } - if (cv_analog.value) - players[consoleplayer].pflags |= PF_ANALOGMODE; - else - players[consoleplayer].pflags &= ~PF_ANALOGMODE; - SendWeaponPref(); } @@ -1600,11 +1595,6 @@ static void Analog2_OnChange(void) return; } - if (cv_analog2.value) - players[secondarydisplayplayer].pflags |= PF_ANALOGMODE; - else - players[secondarydisplayplayer].pflags &= ~PF_ANALOGMODE; - SendWeaponPref2(); } diff --git a/src/r_main.c b/src/r_main.c index e50e8001..7d5d1699 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -222,21 +222,11 @@ static void ChaseCam2_OnChange(void) static void FlipCam_OnChange(void) { - if (cv_flipcam.value) - players[consoleplayer].pflags |= PF_FLIPCAM; - else - players[consoleplayer].pflags &= ~PF_FLIPCAM; - SendWeaponPref(); } static void FlipCam2_OnChange(void) { - if (cv_flipcam2.value) - players[secondarydisplayplayer].pflags |= PF_FLIPCAM; - else - players[secondarydisplayplayer].pflags &= ~PF_FLIPCAM; - SendWeaponPref2(); } From 834a5e6b3530a5ed3cc89b3528b8f35ea8689b55 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 Oct 2018 12:06:22 +0000 Subject: [PATCH 139/194] V_DrawFixedPatch: Tinker with the left/top offsets code so that V_OFFSET can support V_FLIP --- src/v_video.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 802a4d38..0d80dc50 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -406,22 +406,35 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t colfrac = FixedDiv(FRACUNIT, fdup); rowfrac = FixedDiv(FRACUNIT, fdup); - if (scrn & V_OFFSET) // Crosshair shit + // So it turns out offsets aren't scaled in V_NOSCALESTART unless V_OFFSET is applied ...poo, that's terrible + // For now let's just at least give V_OFFSET the ability to support V_FLIP + // I'll probably make a better fix for 2.2 where I don't have to worry about breaking existing support for stuff + // -- Monster Iestyn 29/10/18 { - y -= FixedMul((SHORT(patch->topoffset)*dupy)<leftoffset)*dupx)<topoffset)<width) - SHORT(patch->leftoffset))<width) - SHORT(patch->leftoffset))<leftoffset)<leftoffset)<topoffset)< Date: Mon, 29 Oct 2018 12:36:09 +0000 Subject: [PATCH 140/194] Make V_OFFSET no thing without V_NOSCALESTART, to remove any potential glitches with using it on its own --- src/v_video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v_video.c b/src/v_video.c index 0d80dc50..b5abd009 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -426,7 +426,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? offsety = FixedMul(SHORT(patch->topoffset)< Date: Mon, 29 Oct 2018 13:29:16 +0000 Subject: [PATCH 141/194] HWR_DrawFixedPatch: Add V_OFFSET support for V_FLIP in hardware code as well, also add missing SHORTs for gpatch fields --- src/hardware/hw_draw.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 84081dd2..ad41c68d 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -179,18 +179,29 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - if (option & V_OFFSET) + // See my comments in v_video.c's V_DrawFixedPatch + // -- Monster Iestyn 29/10/18 { - cx -= (float)gpatch->leftoffset * dupx * fscale; - cy -= (float)gpatch->topoffset * dupy * fscale; - } - else - { - cy -= (float)gpatch->topoffset * fscale; + float offsetx = 0.0f, offsety = 0.0f; + + // left offset if (option & V_FLIP) - cx -= ((float)gpatch->width - (float)gpatch->leftoffset) * fscale; + offsetx = (float)(SHORT(gpatch->width) - SHORT(gpatch->leftoffset)) * fscale; else - cx -= (float)gpatch->leftoffset * fscale; + offsetx = (float)SHORT(gpatch->leftoffset) * fscale; + + // top offset + // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? + offsety = (float)SHORT(patch->topoffset) * fscale; + + if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs + { + offsetx *= dupx; + offsety *= dupy; + } + + cx -= offsetx; + cy -= offsety; } if (option & V_SPLITSCREEN) @@ -237,13 +248,13 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, if (pscale != FRACUNIT) { - fwidth = (float)gpatch->width * fscale * dupx; - fheight = (float)gpatch->height * fscale * dupy; + fwidth = (float)SHORT(gpatch->width) * fscale * dupx; + fheight = (float)SHORT(gpatch->height) * fscale * dupy; } else { - fwidth = (float)gpatch->width * dupx; - fheight = (float)gpatch->height * dupy; + fwidth = (float)SHORT(gpatch->width) * dupx; + fheight = (float)SHORT(gpatch->height) * dupy; } // positions of the cx, cy, are between 0 and vid.width/vid.height now, we need them to be between -1 and 1 From b022ff02a5859dd597cc67c40367085fee40ac4c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 29 Oct 2018 13:34:54 +0000 Subject: [PATCH 142/194] add missing SHORTs in HWR_DrawPatch and HWR_DrawCroppedPatch as well --- src/hardware/hw_draw.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index ad41c68d..ffd15686 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -112,10 +112,10 @@ void HWR_DrawPatch(GLPatch_t *gpatch, INT32 x, INT32 y, INT32 option) if (option & V_NOSCALESTART) sdupx = sdupy = 2.0f; - v[0].x = v[3].x = (x*sdupx-gpatch->leftoffset*pdupx)/vid.width - 1; - v[2].x = v[1].x = (x*sdupx+(gpatch->width-gpatch->leftoffset)*pdupx)/vid.width - 1; - v[0].y = v[1].y = 1-(y*sdupy-gpatch->topoffset*pdupy)/vid.height; - v[2].y = v[3].y = 1-(y*sdupy+(gpatch->height-gpatch->topoffset)*pdupy)/vid.height; + v[0].x = v[3].x = (x*sdupx-SHORT(gpatch->leftoffset)*pdupx)/vid.width - 1; + v[2].x = v[1].x = (x*sdupx+(SHORT(gpatch->width)-SHORT(gpatch->leftoffset))*pdupx)/vid.width - 1; + v[0].y = v[1].y = 1-(y*sdupy-SHORT(gpatch->topoffset)*pdupy)/vid.height; + v[2].y = v[3].y = 1-(y*sdupy+(SHORT(gpatch->height)-SHORT(gpatch->topoffset))*pdupy)/vid.height; v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; @@ -352,8 +352,8 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal dupx = dupy = (dupx < dupy ? dupx : dupy); fscale = FIXED_TO_FLOAT(pscale); - cy -= (float)gpatch->topoffset * fscale; - cx -= (float)gpatch->leftoffset * fscale; + cy -= (float)SHORT(gpatch->topoffset) * fscale; + cx -= (float)SHORT(gpatch->leftoffset) * fscale; if (!(option & V_NOSCALESTART)) { @@ -403,11 +403,11 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal if (fheight > h - sy) fheight = h - sy; - if (fwidth > gpatch->width) - fwidth = gpatch->width; + if (fwidth > SHORT(gpatch->width)) + fwidth = SHORT(gpatch->width); - if (fheight > gpatch->height) - fheight = gpatch->height; + if (fheight > SHORT(gpatch->height)) + fheight = SHORT(gpatch->height); if (pscale != FRACUNIT) { @@ -437,10 +437,10 @@ void HWR_DrawCroppedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscal v[0].z = v[1].z = v[2].z = v[3].z = 1.0f; - v[0].sow = v[3].sow = ((sx)/(float)gpatch->width )*gpatch->max_s; - v[2].sow = v[1].sow = ((w )/(float)gpatch->width )*gpatch->max_s; - v[0].tow = v[1].tow = ((sy)/(float)gpatch->height)*gpatch->max_t; - v[2].tow = v[3].tow = ((h )/(float)gpatch->height)*gpatch->max_t; + v[0].sow = v[3].sow = ((sx)/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[2].sow = v[1].sow = ((w )/(float)SHORT(gpatch->width) )*gpatch->max_s; + v[0].tow = v[1].tow = ((sy)/(float)SHORT(gpatch->height))*gpatch->max_t; + v[2].tow = v[3].tow = ((h )/(float)SHORT(gpatch->height))*gpatch->max_t; flags = BLENDMODE|PF_Clip|PF_NoZClip|PF_NoDepthTest; From 2fa0896fd020ef2eb83a42561344fe888df06588 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 30 Oct 2018 13:44:01 +0000 Subject: [PATCH 143/194] Fix an error I made in HWR_DrawFixedPatch --- src/hardware/hw_draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index ffd15686..33f5e031 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -192,7 +192,7 @@ void HWR_DrawFixedPatch(GLPatch_t *gpatch, fixed_t x, fixed_t y, fixed_t pscale, // top offset // TODO: make some kind of vertical version of V_FLIP, maybe by deprecating V_OFFSET in future?!? - offsety = (float)SHORT(patch->topoffset) * fscale; + offsety = (float)SHORT(gpatch->topoffset) * fscale; if ((option & (V_NOSCALESTART|V_OFFSET)) == (V_NOSCALESTART|V_OFFSET)) // Multiply by dupx/dupy for crosshairs { From 22e8dd1f9da40d0447531f848ae4cbbdd18b869c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 30 Oct 2018 14:22:21 +0000 Subject: [PATCH 144/194] now that V_FLIP's effects are always supported in V_DrawFixedPatch, there's no need for the "flip" variable anymore --- src/v_video.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index b5abd009..933ec0f0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -331,7 +331,6 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t { UINT8 (*patchdrawfunc)(const UINT8*, const UINT8*, fixed_t); UINT32 alphalevel = 0; - boolean flip = false; fixed_t col, ofs, colfrac, rowfrac, fdup; INT32 dupx, dupy; @@ -415,10 +414,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t // left offset if (scrn & V_FLIP) - { - flip = true; offsetx = FixedMul((SHORT(patch->width) - SHORT(patch->leftoffset))<leftoffset)<>FRACBITS) < SHORT(patch->width); col += colfrac, ++offx, desttop++) { INT32 topdelta, prevdelta = -1; - if (flip) // offx is measured from right edge instead of left + if (scrn & V_FLIP) // offx is measured from right edge instead of left { if (x+pwidth-offx < 0) // don't draw off the left of the screen (WRAP PREVENTION) break; @@ -534,7 +530,7 @@ void V_DrawFixedPatch(fixed_t x, fixed_t y, fixed_t pscale, INT32 scrn, patch_t prevdelta = topdelta; source = (const UINT8 *)(column) + 3; dest = desttop; - if (flip) + if (scrn & V_FLIP) dest = deststart + (destend - desttop); dest += FixedInt(FixedMul(topdelta< Date: Thu, 1 Nov 2018 14:47:19 -0400 Subject: [PATCH 145/194] Update copyright info on some files --- src/sdl/i_system.c | 3 +++ src/sdl/i_video.c | 2 ++ src/sdl/mixer_sound.c | 8 ++++++++ src/sdl12/mixer_sound.c | 8 ++++++++ 4 files changed, 21 insertions(+) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7b14f1f1..0ec8a980 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1,8 +1,11 @@ // Emacs style mode select -*- C++ -*- +// +// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // // Copyright (C) 1993-1996 by id Software, Inc. // Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 2014-2018 by Sonic Team Junior. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 30ef1b27..c0ec9988 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1,8 +1,10 @@ // Emacs style mode select -*- C++ -*- +// SONIC ROBO BLAST 2 //----------------------------------------------------------------------------- // // Copyright (C) 1993-1996 by id Software, Inc. // Portions Copyright (C) 1998-2000 by DooM Legacy Team. +// Copyright (C) 2014-2018 by Sonic Team Junior. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 4d86d7a3..bbd1fcee 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -1,3 +1,11 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2014-2018 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- /// \file /// \brief SDL Mixer interface for sound diff --git a/src/sdl12/mixer_sound.c b/src/sdl12/mixer_sound.c index daf09ab9..dcae19b0 100644 --- a/src/sdl12/mixer_sound.c +++ b/src/sdl12/mixer_sound.c @@ -1,3 +1,11 @@ +// SONIC ROBO BLAST 2 +//----------------------------------------------------------------------------- +// Copyright (C) 2008-2018 by Sonic Team Junior. +// +// This program is free software distributed under the +// terms of the GNU General Public License, version 2. +// See the 'LICENSE' file for more details. +//----------------------------------------------------------------------------- /// \file /// \brief SDL Mixer interface for sound From 0f37411e2bda94bd496f6fbbe6edd1a1d43dbc32 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Fri, 2 Nov 2018 20:48:12 +0000 Subject: [PATCH 146/194] Make sure handles of files opened by W_LoadWadFile are closed if we abort loading the files for whatever reason. ESPECIALLY if the file is already loaded in SRB2, that's just silly. --- src/w_wad.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/w_wad.c b/src/w_wad.c index 3f0082a1..3789eab5 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -381,6 +381,8 @@ UINT16 W_LoadWadFile(const char *filename) if (fread(&header, 1, sizeof header, handle) < sizeof header) { CONS_Alert(CONS_ERROR, M_GetText("Can't read wad header from %s because %s\n"), filename, strerror(ferror(handle))); + if (handle) + fclose(handle); return INT16_MAX; } @@ -391,6 +393,8 @@ UINT16 W_LoadWadFile(const char *filename) && memcmp(header.identification, "SDLL", 4) != 0) { CONS_Alert(CONS_ERROR, M_GetText("%s does not have a valid WAD header\n"), filename); + if (handle) + fclose(handle); return INT16_MAX; } @@ -405,6 +409,8 @@ UINT16 W_LoadWadFile(const char *filename) { CONS_Alert(CONS_ERROR, M_GetText("Wadfile directory in %s is corrupted (%s)\n"), filename, strerror(ferror(handle))); free(fileinfov); + if (handle) + fclose(handle); return INT16_MAX; } @@ -462,6 +468,8 @@ UINT16 W_LoadWadFile(const char *filename) if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); + if (handle) + fclose(handle); return INT16_MAX; } } From 1cc8619c9e155a06f39821473c84b25ff11b0fac Mon Sep 17 00:00:00 2001 From: MPC Date: Mon, 5 Nov 2018 20:40:51 -0200 Subject: [PATCH 147/194] Minor remote viewpoint bugfixes. --- src/p_mobj.c | 5 +++-- src/p_user.c | 18 +++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 2a29c32a..e94c4ff8 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3506,14 +3506,15 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled if (player->pflags & PF_FLIPCAM && !(player->pflags & PF_NIGHTSMODE) && player->mo->eflags & MFE_VERTICALFLIP) postimg = postimg_flip; - else if (player->awayviewtics) + else if (player->awayviewtics && player->awayviewmobj != NULL) // Camera must obviously exist { camera_t dummycam; dummycam.subsector = player->awayviewmobj->subsector; dummycam.x = player->awayviewmobj->x; dummycam.y = player->awayviewmobj->y; dummycam.z = player->awayviewmobj->z; - dummycam.height = 40*FRACUNIT; // alt view height is 20*FRACUNIT + //dummycam.height = 40*FRACUNIT; // alt view height is 20*FRACUNIT + dummycam.height = 0; // Why? Remote viewpoint cameras have no height. // Are we in water? if (P_CameraCheckWater(&dummycam)) postimg = postimg_water; diff --git a/src/p_user.c b/src/p_user.c index 7e206930..34191cdf 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8365,16 +8365,12 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall // Make player translucent if camera is too close (only in single player). if (!(multiplayer || netgame) && !splitscreen) { - fixed_t vx = 0, vy = 0; - if (player->awayviewtics) { + fixed_t vx = thiscam->x, vy = thiscam->y; + if (player->awayviewtics && player->awayviewmobj != NULL) // Camera must obviously exist + { vx = player->awayviewmobj->x; vy = player->awayviewmobj->y; } - else - { - vx = thiscam->x; - vy = thiscam->y; - } if (P_AproxDistance(vx - player->mo->x, vy - player->mo->y) < FixedMul(48*FRACUNIT, mo->scale)) player->mo->flags2 |= MF2_SHADOW; @@ -8710,8 +8706,9 @@ void P_PlayerThink(player_t *player) if (player->flashcount) player->flashcount--; - if (player->awayviewtics) - player->awayviewtics--; + // By the time P_MoveChaseCamera is called, this might be zero. Do not do it here. + //if (player->awayviewtics) + // player->awayviewtics--; /// \note do this in the cheat code if (player->pflags & PF_NOCLIP) @@ -9489,6 +9486,9 @@ void P_PlayerAfterThink(player_t *player) } } + if (player->awayviewtics) + player->awayviewtics--; + // spectator invisibility and nogravity. if ((netgame || multiplayer) && player->spectator) { From f66979ba1a3f2b2ea8bb07bc7c31e09094c6e1ec Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Nov 2018 21:00:38 +0000 Subject: [PATCH 148/194] P_NullPrecipThinker no longer should have FUNCMATH (though I'm not sure if it should have had it in the first place anyway) --- src/p_mobj.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.h b/src/p_mobj.h index 620028d8..56d9b6da 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -445,7 +445,7 @@ boolean P_SupermanLook4Players(mobj_t *actor); void P_DestroyRobots(void); void P_SnowThinker(precipmobj_t *mobj); void P_RainThinker(precipmobj_t *mobj); -FUNCMATH void P_NullPrecipThinker(precipmobj_t *mobj); +void P_NullPrecipThinker(precipmobj_t *mobj); void P_RemovePrecipMobj(precipmobj_t *mobj); void P_SetScale(mobj_t *mobj, fixed_t newscale); void P_XYMovement(mobj_t *mo); From 4a4e07e1385ddb1c707e431e6be928cc16a1c724 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Nov 2018 21:21:36 +0000 Subject: [PATCH 149/194] D_PostEvent_end is only used by Allegro (used by the DOS port) to help timers work, so check for PC_DOS in preprocessor code. Also remove FUNCMATH from said function. --- src/d_main.c | 2 +- src/d_main.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 17053267..037aeccf 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -170,7 +170,7 @@ void D_PostEvent(const event_t *ev) eventhead = (eventhead+1) & (MAXEVENTS-1); } // just for lock this function -#ifndef DOXYGEN +#if defined (PC_DOS) && !defined (DOXYGEN) void D_PostEvent_end(void) {}; #endif diff --git a/src/d_main.h b/src/d_main.h index d73b19d1..4c9c99ea 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -40,8 +40,8 @@ void D_SRB2Main(void); // Called by IO functions when input is detected. void D_PostEvent(const event_t *ev); -#ifndef DOXYGEN -FUNCMATH void D_PostEvent_end(void); // delimiter for locking memory +#if defined (PC_DOS) && !defined (DOXYGEN) +void D_PostEvent_end(void); // delimiter for locking memory #endif void D_ProcessEvents(void); From b3e8a1ed88961acad8d45a59c3003af08ccb6b5c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Nov 2018 21:37:42 +0000 Subject: [PATCH 150/194] HU_Start should not have FUNCMATH, it has side effects --- src/hu_stuff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hu_stuff.h b/src/hu_stuff.h index 5356ba8a..a5c81e6e 100644 --- a/src/hu_stuff.h +++ b/src/hu_stuff.h @@ -84,7 +84,7 @@ void HU_Init(void); void HU_LoadGraphics(void); // reset heads up when consoleplayer respawns. -FUNCMATH void HU_Start(void); +void HU_Start(void); boolean HU_Responder(event_t *ev); From c47f0045d6a60b41faceff3edd17be58b244c601 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 7 Nov 2018 21:45:27 +0000 Subject: [PATCH 151/194] ST_Ticker also should not have FUNCMATH, as it also has side effects --- src/st_stuff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.h b/src/st_stuff.h index c11559d2..6fafca40 100644 --- a/src/st_stuff.h +++ b/src/st_stuff.h @@ -24,7 +24,7 @@ // // Called by main loop. -FUNCMATH void ST_Ticker(void); +void ST_Ticker(void); // Called by main loop. void ST_Drawer(void); From 0bdbdd1b1ed1ffbb15b99664d037fd5f83b7ad12 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 16:26:55 +0000 Subject: [PATCH 152/194] Remove FUNCMATH from functions with a void return value or args, or examine variables other than their args (which could be modified) --- src/dehacked.c | 2 +- src/f_finale.c | 1 + src/f_finale.h | 2 +- src/r_plane.h | 2 +- src/r_splats.h | 4 ---- src/screen.c | 4 ---- src/sdl/i_cdmus.c | 14 +++++++------- src/sdl/i_system.c | 16 ++++++++-------- src/sdl/i_video.c | 6 +++--- src/sdl/mixer_sound.c | 4 ++-- src/sdl/sdl_sound.c | 2 +- src/sdl12/sdl_sound.c | 2 +- 12 files changed, 26 insertions(+), 33 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index b7e874b1..2fed963f 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -7769,7 +7769,7 @@ fixed_t get_number(const char *word) #endif } -void FUNCMATH DEH_Check(void) +void DEH_Check(void) { #if defined(_DEBUG) || defined(PARANOIA) const size_t dehstates = sizeof(STATE_LIST)/sizeof(const char*); diff --git a/src/f_finale.c b/src/f_finale.c index fb1387c1..a50e4a5b 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1401,6 +1401,7 @@ void F_StartGameEnd(void) // void F_GameEndDrawer(void) { + // this function does nothing } // diff --git a/src/f_finale.h b/src/f_finale.h index 1f23643b..8ee02bdf 100644 --- a/src/f_finale.h +++ b/src/f_finale.h @@ -35,7 +35,7 @@ void F_CutsceneTicker(void); void F_TitleDemoTicker(void); // Called by main loop. -FUNCMATH void F_GameEndDrawer(void); +void F_GameEndDrawer(void); void F_IntroDrawer(void); void F_TitleScreenDrawer(void); diff --git a/src/r_plane.h b/src/r_plane.h index 16c8c12a..dff58669 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -87,7 +87,7 @@ extern lighttable_t **planezlight; extern fixed_t *yslope; extern fixed_t distscale[MAXVIDWIDTH]; -FUNCMATH void R_InitPlanes(void); +void R_InitPlanes(void); void R_PortalStoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale); void R_PortalRestoreClipValues(INT32 start, INT32 end, INT16 *ceil, INT16 *floor, fixed_t *scale); void R_ClearPlanes(void); diff --git a/src/r_splats.h b/src/r_splats.h index c0ba6881..349d8fa7 100644 --- a/src/r_splats.h +++ b/src/r_splats.h @@ -63,11 +63,7 @@ typedef struct floorsplat_s fixed_t P_SegLength(seg_t *seg); // call at P_SetupLevel() -#if !(defined (WALLSPLATS) || defined (FLOORSPLATS)) -FUNCMATH void R_ClearLevelSplats(void); -#else void R_ClearLevelSplats(void); -#endif #ifdef WALLSPLATS void R_AddWallSplat(line_t *wallline, INT16 sectorside, const char *patchname, fixed_t top, diff --git a/src/screen.c b/src/screen.c index 58c38993..fdd8eb7b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -71,11 +71,7 @@ consvar_t cv_scr_depth = {"scr_depth", "16 bits", CV_SAVE, scr_depth_cons_t, NUL #endif consvar_t cv_renderview = {"renderview", "On", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -#ifdef DIRECTFULLSCREEN -static FUNCMATH void SCR_ChangeFullscreen (void); -#else static void SCR_ChangeFullscreen (void); -#endif consvar_t cv_fullscreen = {"fullscreen", "Yes", CV_SAVE|CV_CALL, CV_YesNo, SCR_ChangeFullscreen, 0, NULL, NULL, 0, 0, NULL}; diff --git a/src/sdl/i_cdmus.c b/src/sdl/i_cdmus.c index 3105f512..5d086e73 100644 --- a/src/sdl/i_cdmus.c +++ b/src/sdl/i_cdmus.c @@ -12,19 +12,19 @@ consvar_t cd_volume = {"cd_volume","31",CV_SAVE,soundvolume_cons_t, NULL, 0, NUL consvar_t cdUpdate = {"cd_update","1",CV_SAVE, NULL, NULL, 0, NULL, NULL, 0, 0, NULL}; -FUNCMATH void I_InitCD(void){} +void I_InitCD(void){} -FUNCMATH void I_StopCD(void){} +void I_StopCD(void){} -FUNCMATH void I_PauseCD(void){} +void I_PauseCD(void){} -FUNCMATH void I_ResumeCD(void){} +void I_ResumeCD(void){} -FUNCMATH void I_ShutdownCD(void){} +void I_ShutdownCD(void){} -FUNCMATH void I_UpdateCD(void){} +void I_UpdateCD(void){} -FUNCMATH void I_PlayCD(UINT8 track, UINT8 looping) +void I_PlayCD(UINT8 track, UINT8 looping) { (void)track; (void)looping; diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 7b14f1f1..9a2baf31 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -1927,14 +1927,14 @@ void I_StartupMouse2(void) // // I_Tactile // -FUNCMATH void I_Tactile(FFType pFFType, const JoyFF_t *FFEffect) +void I_Tactile(FFType pFFType, const JoyFF_t *FFEffect) { // UNUSED. (void)pFFType; (void)FFEffect; } -FUNCMATH void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) +void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) { // UNUSED. (void)pFFType; @@ -1945,7 +1945,7 @@ FUNCMATH void I_Tactile2(FFType pFFType, const JoyFF_t *FFEffect) */ static ticcmd_t emptycmd; -FUNCMATH ticcmd_t *I_BaseTiccmd(void) +ticcmd_t *I_BaseTiccmd(void) { return &emptycmd; } @@ -1954,7 +1954,7 @@ FUNCMATH ticcmd_t *I_BaseTiccmd(void) */ static ticcmd_t emptycmd2; -FUNCMATH ticcmd_t *I_BaseTiccmd2(void) +ticcmd_t *I_BaseTiccmd2(void) { return &emptycmd2; } @@ -2048,7 +2048,7 @@ tic_t I_GetTime (void) // //I_StartupTimer // -FUNCMATH void I_StartupTimer(void) +void I_StartupTimer(void) { #ifdef _WIN32 // for win2k time bug @@ -2147,11 +2147,11 @@ void I_WaitVBL(INT32 count) SDL_Delay(count); } -FUNCMATH void I_BeginRead(void) +void I_BeginRead(void) { } -FUNCMATH void I_EndRead(void) +void I_EndRead(void) { } @@ -2939,5 +2939,5 @@ const CPUInfoFlags *I_CPUInfo(void) } // note CPUAFFINITY code used to reside here -FUNCMATH void I_RegisterSysCommands(void) {} +void I_RegisterSysCommands(void) {} #endif diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 30ef1b27..db88f452 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1053,7 +1053,7 @@ void I_SetPalette(RGBA_t *palette) } // return number of fullscreen + X11 modes -FUNCMATH INT32 VID_NumModes(void) +INT32 VID_NumModes(void) { if (USE_FULLSCREEN && numVidModes != -1) return numVidModes - firstEntry; @@ -1061,7 +1061,7 @@ FUNCMATH INT32 VID_NumModes(void) return MAXWINMODES; } -FUNCMATH const char *VID_GetModeName(INT32 modeNum) +const char *VID_GetModeName(INT32 modeNum) { #if 0 if (USE_FULLSCREEN && numVidModes != -1) // fullscreen modes @@ -1091,7 +1091,7 @@ FUNCMATH const char *VID_GetModeName(INT32 modeNum) return &vidModeName[modeNum][0]; } -FUNCMATH INT32 VID_GetModeForSize(INT32 w, INT32 h) +INT32 VID_GetModeForSize(INT32 w, INT32 h) { int i; for (i = 0; i < MAXWINMODES; i++) diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 4d86d7a3..f36f0869 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -135,7 +135,7 @@ void I_ShutdownSound(void) #endif } -FUNCMATH void I_UpdateSound(void) +void I_UpdateSound(void) { } @@ -504,7 +504,7 @@ static void mix_gme(void *udata, Uint8 *stream, int len) /// Music System /// ------------------------ -FUNCMATH void I_InitMusic(void) +void I_InitMusic(void) { } diff --git a/src/sdl/sdl_sound.c b/src/sdl/sdl_sound.c index 9f8a3e29..f4796cd8 100644 --- a/src/sdl/sdl_sound.c +++ b/src/sdl/sdl_sound.c @@ -219,7 +219,7 @@ static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio #endif } -FUNCMATH static inline Uint16 Snd_LowerRate(Uint16 sr) +static inline Uint16 Snd_LowerRate(Uint16 sr) { if (sr <= audio.freq) // already lowered rate? return sr; // good then diff --git a/src/sdl12/sdl_sound.c b/src/sdl12/sdl_sound.c index 01a27153..ed1afd8e 100644 --- a/src/sdl12/sdl_sound.c +++ b/src/sdl12/sdl_sound.c @@ -236,7 +236,7 @@ static void Snd_UnlockAudio(void) //Alam: Unlock audio data and reinstall audio #endif } -FUNCMATH static inline Uint16 Snd_LowerRate(Uint16 sr) +static inline Uint16 Snd_LowerRate(Uint16 sr) { if (sr <= audio.freq) // already lowered rate? return sr; // good then From 5c61c405514206b6e7b8b46f5322920519efa5f1 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 16:31:20 +0000 Subject: [PATCH 153/194] Clean up doomtype.h a bit, add indenting and comments to make some preprocessor code more readable --- src/doomtype.h | 129 +++++++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 59 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index a711b466..3631eb51 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -44,12 +44,13 @@ typedef long ssize_t; /* Older Visual C++ headers don't have the Win64-compatible typedefs... */ -#if ((_MSC_VER <= 1200) && (!defined(DWORD_PTR))) -#define DWORD_PTR DWORD -#endif - -#if ((_MSC_VER <= 1200) && (!defined(PDWORD_PTR))) -#define PDWORD_PTR PDWORD +#if (_MSC_VER <= 1200) + #ifndef DWORD_PTR + #define DWORD_PTR DWORD + #endif + #ifndef PDWORD_PTR + #define PDWORD_PTR PDWORD + #endif #endif #elif defined (_arch_dreamcast) // KOS Dreamcast #include @@ -102,7 +103,7 @@ typedef long ssize_t; #ifdef _MSC_VER #if (_MSC_VER <= 1800) // MSVC 2013 and back #define snprintf _snprintf -#if (_MSC_VER <= 1200) // MSVC 2012 and back +#if (_MSC_VER <= 1200) // MSVC 6.0 and back #define vsnprintf _vsnprintf #endif #endif @@ -185,7 +186,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz); //faB: clean that up !! #if defined( _MSC_VER) && (_MSC_VER >= 1800) // MSVC 2013 and forward - #include "stdbool.h" + #include "stdbool.h" #elif (defined (_WIN32) || (defined (_WIN32_WCE) && !defined (__GNUC__))) && !defined (_XBOX) #define false FALSE // use windows types #define true TRUE @@ -275,58 +276,68 @@ typedef UINT32 tic_t; #endif #ifdef __GNUC__ // __attribute__ ((X)) -#define FUNCNORETURN __attribute__ ((noreturn)) -#if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && defined (__MINGW32__) -#include "inttypes.h" -#if 0 //defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO > 0 -#define FUNCPRINTF __attribute__ ((format(gnu_printf, 1, 2))) -#define FUNCDEBUG __attribute__ ((format(gnu_printf, 2, 3))) -#define FUNCIERROR __attribute__ ((format(gnu_printf, 1, 2),noreturn)) -#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -#define FUNCPRINTF __attribute__ ((format(ms_printf, 1, 2))) -#define FUNCDEBUG __attribute__ ((format(ms_printf, 2, 3))) -#define FUNCIERROR __attribute__ ((format(ms_printf, 1, 2),noreturn)) -#else -#define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) -#define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) -#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) -#endif -#else -#define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) -#define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) -#define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) -#endif -#ifndef FUNCIERROR -#define FUNCIERROR __attribute__ ((noreturn)) -#endif -#define FUNCMATH __attribute__((const)) -#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) -#define FUNCDEAD __attribute__ ((deprecated)) -#define FUNCINLINE __attribute__((always_inline)) -#define FUNCNONNULL __attribute__((nonnull)) -#endif -#define FUNCNOINLINE __attribute__((noinline)) -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) -#ifdef __i386__ // i386 only -#define FUNCTARGET(X) __attribute__ ((__target__ (X))) -#endif -#endif -#if defined (__MINGW32__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) -#define ATTRPACK __attribute__((packed, gcc_struct)) -#else -#define ATTRPACK __attribute__((packed)) -#endif -#define ATTRUNUSED __attribute__((unused)) -#ifdef _XBOX -#define FILESTAMP I_OutputMsg("%s:%d\n",__FILE__,__LINE__); -#define XBOXSTATIC static -#endif + #define FUNCNORETURN __attribute__ ((noreturn)) + + #if ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) && defined (__MINGW32__) // MinGW, >= GCC 4.1 + #include "inttypes.h" + #if 0 //defined (__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO > 0 + #define FUNCPRINTF __attribute__ ((format(gnu_printf, 1, 2))) + #define FUNCDEBUG __attribute__ ((format(gnu_printf, 2, 3))) + #define FUNCIERROR __attribute__ ((format(gnu_printf, 1, 2),noreturn)) + #elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4 + #define FUNCPRINTF __attribute__ ((format(ms_printf, 1, 2))) + #define FUNCDEBUG __attribute__ ((format(ms_printf, 2, 3))) + #define FUNCIERROR __attribute__ ((format(ms_printf, 1, 2),noreturn)) + #else + #define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) + #define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) + #define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) + #endif + #else + #define FUNCPRINTF __attribute__ ((format(printf, 1, 2))) + #define FUNCDEBUG __attribute__ ((format(printf, 2, 3))) + #define FUNCIERROR __attribute__ ((format(printf, 1, 2),noreturn)) + #endif + + #ifndef FUNCIERROR + #define FUNCIERROR __attribute__ ((noreturn)) + #endif + + #define FUNCMATH __attribute__((const)) + + #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) // >= GCC 3.1 + #define FUNCDEAD __attribute__ ((deprecated)) + #define FUNCINLINE __attribute__((always_inline)) + #define FUNCNONNULL __attribute__((nonnull)) + #endif + + #define FUNCNOINLINE __attribute__((noinline)) + + #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4) // >= GCC 4.4 + #ifdef __i386__ // i386 only + #define FUNCTARGET(X) __attribute__ ((__target__ (X))) + #endif + #endif + + #if defined (__MINGW32__) && ((__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) // MinGW, >= GCC 3.4 + #define ATTRPACK __attribute__((packed, gcc_struct)) + #else + #define ATTRPACK __attribute__((packed)) + #endif + + #define ATTRUNUSED __attribute__((unused)) + + // Xbox-only macros + #ifdef _XBOX + #define FILESTAMP I_OutputMsg("%s:%d\n",__FILE__,__LINE__); + #define XBOXSTATIC static + #endif #elif defined (_MSC_VER) -#define ATTRNORETURN __declspec(noreturn) -#define ATTRINLINE __forceinline -#if _MSC_VER > 1200 -#define ATTRNOINLINE __declspec(noinline) -#endif + #define ATTRNORETURN __declspec(noreturn) + #define ATTRINLINE __forceinline + #if _MSC_VER > 1200 // >= MSVC 6.0 + #define ATTRNOINLINE __declspec(noinline) + #endif #endif #ifndef FUNCPRINTF From fd20bbb54e5882f43f006bcf60f653455f55ab11 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 17:05:35 +0000 Subject: [PATCH 154/194] More doomtype.h cleaning up: * Move the misc types in the file to bottom, so that ATTRPACK at least is usable for RGBA_t * Include endian.h, so that UINT2RGBA can be defined correctly for big endian builds * Add more comments to make clear the main sections of the file --- src/doomtype.h | 77 ++++++++++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/doomtype.h b/src/doomtype.h index 3631eb51..67c279aa 100644 --- a/src/doomtype.h +++ b/src/doomtype.h @@ -98,6 +98,8 @@ typedef long ssize_t; #define NOIPX #endif +/* Strings and some misc platform specific stuff */ + #if defined (_MSC_VER) || defined (__OS2__) // Microsoft VisualC++ #ifdef _MSC_VER @@ -179,6 +181,8 @@ size_t strlcpy(char *dst, const char *src, size_t siz); // not the number of bytes in the buffer. #define STRBUFCPY(dst,src) strlcpy(dst, src, sizeof dst) +/* Boolean type definition */ + // \note __BYTEBOOL__ used to be set above if "macintosh" was defined, // if macintosh's version of boolean type isn't needed anymore, then isn't this macro pointless now? #ifndef __BYTEBOOL__ @@ -241,39 +245,7 @@ size_t strlcpy(char *dst, const char *src, size_t siz); #define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */ #endif -union FColorRGBA -{ - UINT32 rgba; - struct - { - UINT8 red; - UINT8 green; - UINT8 blue; - UINT8 alpha; - } s; -} ATTRPACK; -typedef union FColorRGBA RGBA_t; - -typedef enum -{ - postimg_none, - postimg_water, - postimg_motion, - postimg_flip, - postimg_heat -} postimg_t; - -typedef UINT32 lumpnum_t; // 16 : 16 unsigned long (wad num: lump num) -#define LUMPERROR UINT32_MAX - -typedef UINT32 tic_t; -#define INFTICS UINT32_MAX - -#ifdef _BIG_ENDIAN -#define UINT2RGBA(a) a -#else -#define UINT2RGBA(a) (UINT32)((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|(((UINT32)a&0xff000000)>>24) -#endif +/* Compiler-specific attributes and other macros */ #ifdef __GNUC__ // __attribute__ ((X)) #define FUNCNORETURN __attribute__ ((noreturn)) @@ -391,4 +363,43 @@ typedef UINT32 tic_t; #ifndef FILESTAMP #define FILESTAMP #endif + +/* Miscellaneous types that don't fit anywhere else (Can this be changed?) */ + +union FColorRGBA +{ + UINT32 rgba; + struct + { + UINT8 red; + UINT8 green; + UINT8 blue; + UINT8 alpha; + } s; +} ATTRPACK; +typedef union FColorRGBA RGBA_t; + +typedef enum +{ + postimg_none, + postimg_water, + postimg_motion, + postimg_flip, + postimg_heat +} postimg_t; + +typedef UINT32 lumpnum_t; // 16 : 16 unsigned long (wad num: lump num) +#define LUMPERROR UINT32_MAX + +typedef UINT32 tic_t; +#define INFTICS UINT32_MAX + +#include "endian.h" // This is needed to make sure the below macro acts correctly in big endian builds + +#ifdef SRB2_BIG_ENDIAN +#define UINT2RGBA(a) a +#else +#define UINT2RGBA(a) (UINT32)((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|(((UINT32)a&0xff000000)>>24) +#endif + #endif //__DOOMTYPE__ From fa80d6179978b1d8c88eda73d1efde1f4194c2d4 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 17:16:54 +0000 Subject: [PATCH 155/194] byteptr.h: include endian.h to help define WRITE/READ macros correctly according to endianness --- src/byteptr.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/byteptr.h b/src/byteptr.h index 410d7c00..364e6520 100644 --- a/src/byteptr.h +++ b/src/byteptr.h @@ -15,7 +15,9 @@ #define DEALIGNED #endif -#ifndef _BIG_ENDIAN +#include "endian.h" + +#ifndef SRB2_BIG_ENDIAN // // Little-endian machines // @@ -75,7 +77,7 @@ #define READANGLE(p) *((angle_t *)p)++ #endif -#else //_BIG_ENDIAN +#else //SRB2_BIG_ENDIAN // // definitions for big-endian machines with alignment constraints. // @@ -144,7 +146,7 @@ FUNCINLINE static ATTRINLINE UINT32 readulong(void *ptr) #define READCHAR(p) ({ char *p_tmp = ( char *)p; char b = *p_tmp; p_tmp++; p = (void *)p_tmp; b; }) #define READFIXED(p) ({ fixed_t *p_tmp = (fixed_t *)p; fixed_t b = readlong(p); p_tmp++; p = (void *)p_tmp; b; }) #define READANGLE(p) ({ angle_t *p_tmp = (angle_t *)p; angle_t b = readulong(p); p_tmp++; p = (void *)p_tmp; b; }) -#endif //_BIG_ENDIAN +#endif //SRB2_BIG_ENDIAN #undef DEALIGNED From f50f10ef307fe2a09a2d2fb84cb368ea10b89567 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 8 Nov 2018 20:09:00 +0000 Subject: [PATCH 156/194] d_main.c: remove the _MAX_PATH define, the file hasn't used it since v2.0 --- src/d_main.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 037aeccf..15b144dd 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -761,10 +761,6 @@ static inline void D_CleanFile(void) } } -#ifndef _MAX_PATH -#define _MAX_PATH MAX_WADPATH -#endif - // ========================================================================== // Identify the SRB2 version, and IWAD file to use. // ========================================================================== From e937d1bacb1fd157244bfe2f203db0216b65a0e1 Mon Sep 17 00:00:00 2001 From: Steel Titanium Date: Fri, 9 Nov 2018 16:01:29 -0500 Subject: [PATCH 157/194] Update readme --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index d1607145..7d92ab30 100644 --- a/README.md +++ b/README.md @@ -13,8 +13,6 @@ - libupnp (Linux/OS X only) - libgme (Linux/OS X only) -Warning: 64-bit builds are not netgame compatible with 32-bit builds. Use at your own risk. - ## Compiling See [SRB2 Wiki/Source code compiling](http://wiki.srb2.org/wiki/Source_code_compiling) From a733a29f4c5889251192184870cc451cacd9dc96 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 9 Jan 2017 22:13:26 +0000 Subject: [PATCH 158/194] Starting work on porting hw_clip.c/h code, Makefiles and CMake can compile them at least Other notes: * Renamed all new functions to have HWR_ prefix instead of gld_, for consistency * HWR_FrustrumSetup and HWR_SphereInFrustum are disabled and require HAVE_SPHEREFRUSTRUM. This is because 1) SRB2CB did not need the code, so presumably neither will we, and 2) there are some OpenGL API functions used there that due to our way of using OpenGL we don't use outside of r_opengl.c, which makes dealing with HWR_FrustrumSetup complicated in theory * The new clipping functions are not added to OpenGL's "main" rendering code itself just yet, they're just available to use now once hw_clip.h is included --- src/CMakeLists.txt | 2 + src/Makefile | 12 +- src/hardware/hw_clip.c | 465 +++++++++++++++++++++++++++++++++++++++++ src/hardware/hw_clip.h | 24 +++ 4 files changed, 497 insertions(+), 6 deletions(-) create mode 100644 src/hardware/hw_clip.c create mode 100644 src/hardware/hw_clip.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 46a42a92..0602de9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -350,6 +350,7 @@ if(${SRB2_CONFIG_HWRENDER}) set(SRB2_HWRENDER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_light.c ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c @@ -358,6 +359,7 @@ if(${SRB2_CONFIG_HWRENDER}) ) set (SRB2_HWRENDER_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h diff --git a/src/Makefile b/src/Makefile index 7a67c3f0..b159de3b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -269,7 +269,7 @@ ifndef DC endif OPTS+=-DHWRENDER OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \ - $(OBJDIR)/hw_main.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o + $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o $(OBJDIR)/hw_trick.o endif ifdef NOHS @@ -719,7 +719,7 @@ ifdef MINGW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@ @@ -727,7 +727,7 @@ else $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@ @@ -880,7 +880,7 @@ ifndef NOHW $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ @@ -888,7 +888,7 @@ $(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h $(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ @@ -896,7 +896,7 @@ $(OBJDIR)/ogl_win.o: hardware/r_opengl/ogl_win.c hardware/r_opengl/r_opengl.h \ $(OBJDIR)/r_minigl.o: hardware/r_minigl/r_minigl.c hardware/r_opengl/r_opengl.h \ doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \ command.h hardware/hw_data.h hardware/hw_glide.h hardware/hw_defs.h \ - hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h am_map.h \ + hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h am_map.h \ d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \ p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h $(CC) $(CFLAGS) $(WFLAGS) -D_WINDOWS -mwindows -c $< -o $@ diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c new file mode 100644 index 00000000..47cbbfa2 --- /dev/null +++ b/src/hardware/hw_clip.c @@ -0,0 +1,465 @@ +/* Emacs style mode select -*- C++ -*- + *----------------------------------------------------------------------------- + * + * + * PrBoom: a Doom port merged with LxDoom and LSDLDoom + * based on BOOM, a modified and improved DOOM engine + * Copyright (C) 1999 by + * id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman + * Copyright (C) 1999-2000 by + * Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze + * Copyright 2005, 2006 by + * Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * DESCRIPTION: + * + *--------------------------------------------------------------------- + */ + +/* + * + ** gl_clipper.cpp + ** + ** Handles visibility checks. + ** Loosely based on the JDoom clipper. + ** + **--------------------------------------------------------------------------- + ** Copyright 2003 Tim Stump + ** 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 +#include "../v_video.h" +#include "hw_clip.h" +#include "hw_glob.h" +#include "../r_state.h" +#include "../tables.h" +#include "r_opengl/r_opengl.h" + +#ifdef HAVE_SPHEREFRUSTRUM +static GLdouble viewMatrix[16]; +static GLdouble projMatrix[16]; +float frustum[6][4]; +#endif + +typedef struct clipnode_s + { + struct clipnode_s *prev, *next; + angle_t start, end; + } clipnode_t; + +clipnode_t *freelist; +clipnode_t *clipnodes; +clipnode_t *cliphead; + +static clipnode_t * HWR_clipnode_GetNew(void); +static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end); +static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); +static void HWR_clipper_AddClipRange(angle_t start, angle_t end); +static void HWR_clipper_RemoveRange(clipnode_t * range); +static void HWR_clipnode_Free(clipnode_t *node); + +static clipnode_t * HWR_clipnode_GetNew(void) +{ + if (freelist) + { + clipnode_t * p = freelist; + freelist = p->next; + return p; + } + else + { + return (clipnode_t*)malloc(sizeof(clipnode_t)); + } +} + +static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end) +{ + clipnode_t * c = HWR_clipnode_GetNew(); + c->start = start; + c->end = end; + c->next = c->prev=NULL; + return c; +} + +boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) +{ + if(startAngle > endAngle) + { + return (HWR_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || HWR_clipper_IsRangeVisible(0, endAngle)); + } + + return HWR_clipper_IsRangeVisible(startAngle, endAngle); +} + +static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) +{ + clipnode_t *ci; + ci = cliphead; + + if (endAngle == 0 && ci && ci->start == 0) + return false; + + while (ci != NULL && ci->start < endAngle) + { + if (startAngle >= ci->start && endAngle <= ci->end) + { + return false; + } + ci = ci->next; + } + + return true; +} + +static void HWR_clipnode_Free(clipnode_t *node) +{ + node->next = freelist; + freelist = node; +} + +static void HWR_clipper_RemoveRange(clipnode_t *range) +{ + if (range == cliphead) + { + cliphead = cliphead->next; + } + else + { + if (range->prev) + { + range->prev->next = range->next; + } + if (range->next) + { + range->next->prev = range->prev; + } + } + + HWR_clipnode_Free(range); +} + +void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) +{ + if(startangle > endangle) + { + // The range has to added in two parts. + HWR_clipper_AddClipRange(startangle, ANGLE_MAX); + HWR_clipper_AddClipRange(0, endangle); + } + else + { + // Add the range as usual. + HWR_clipper_AddClipRange(startangle, endangle); + } +} + +static void HWR_clipper_AddClipRange(angle_t start, angle_t end) +{ + clipnode_t *node, *temp, *prevNode, *node2, *delnode; + + if (cliphead) + { + //check to see if range contains any old ranges + node = cliphead; + while (node != NULL && node->start < end) + { + if (node->start >= start && node->end <= end) + { + temp = node; + node = node->next; + HWR_clipper_RemoveRange(temp); + } + else + { + if (node->start <= start && node->end >= end) + { + return; + } + else + { + node = node->next; + } + } + } + + //check to see if range overlaps a range (or possibly 2) + node = cliphead; + while (node != NULL && node->start <= end) + { + if (node->end >= start) + { + // we found the first overlapping node + if (node->start > start) + { + // the new range overlaps with this node's start point + node->start = start; + } + if (node->end < end) + { + node->end = end; + } + + node2 = node->next; + while (node2 && node2->start <= node->end) + { + if (node2->end > node->end) + { + node->end = node2->end; + } + + delnode = node2; + node2 = node2->next; + HWR_clipper_RemoveRange(delnode); + } + return; + } + node = node->next; + } + + //just add range + node = cliphead; + prevNode = NULL; + temp = HWR_clipnode_NewRange(start, end); + while (node != NULL && node->start < end) + { + prevNode = node; + node = node->next; + } + temp->next = node; + if (node == NULL) + { + temp->prev = prevNode; + if (prevNode) + { + prevNode->next = temp; + } + if (!cliphead) + { + cliphead = temp; + } + } + else + { + if (node == cliphead) + { + cliphead->prev = temp; + cliphead = temp; + } + else + { + temp->prev = prevNode; + prevNode->next = temp; + node->prev = temp; + } + } + } + else + { + temp = HWR_clipnode_NewRange(start, end); + cliphead = temp; + return; + } +} + +void HWR_clipper_Clear(void) +{ + clipnode_t *node = cliphead; + clipnode_t *temp; + + while (node != NULL) + { + temp = node; + node = node->next; + HWR_clipnode_Free(temp); + } + + cliphead = NULL; +} + +#define RMUL (1.6f/1.333333f) + +angle_t HWR_FrustumAngle(void) +{ + double floatangle; + angle_t a1; + + float tilt = (float)fabs(((double)(int)aimingangle) / ANG1); + + // NEWCLIP TODO: SRB2CBTODO: make a global render_fov for this function + + float render_fov = FIXED_TO_FLOAT(cv_grfov.value); + float render_fovratio = (float)BASEVIDWIDTH / (float)BASEVIDHEIGHT; // SRB2CBTODO: NEWCLIPTODO: Is this right? + float render_multiplier = 64.0f / render_fovratio / RMUL; + + if (tilt > 90.0f) + { + tilt = 90.0f; + } + + // If the pitch is larger than this you can look all around at a FOV of 90 + if (abs(aimingangle) > 46 * ANG1) + return 0xffffffff; + + // ok, this is a gross hack that barely works... + // but at least it doesn't overestimate too much... + floatangle = 2.0f + (45.0f + (tilt / 1.9f)) * (float)render_fov * 48.0f / render_multiplier / 90.0f; + a1 = ANG1 * (int)floatangle; + if (a1 >= ANGLE_180) + return 0xffffffff; + return a1; +} + +// SRB2CB I don't think used any of this stuff, let's disable for now since SRB2 probably doesn't want it either +// compiler complains about (p)glGetDoublev anyway, in case anyone wants this +// only r_opengl.c can use the base gl funcs as it turns out, that's a problem for whoever wants sphere frustum checks +// btw to renable define HAVE_SPHEREFRUSTRUM in hw_clip.h +#ifdef HAVE_SPHEREFRUSTRUM +// +// HWR_FrustrumSetup +// + +#define CALCMATRIX(a, b, c, d, e, f, g, h)\ +(float)(viewMatrix[a] * projMatrix[b] + \ +viewMatrix[c] * projMatrix[d] + \ +viewMatrix[e] * projMatrix[f] + \ +viewMatrix[g] * projMatrix[h]) + +#define NORMALIZE_PLANE(i)\ +t = (float)sqrt(\ +frustum[i][0] * frustum[i][0] + \ +frustum[i][1] * frustum[i][1] + \ +frustum[i][2] * frustum[i][2]); \ +frustum[i][0] /= t; \ +frustum[i][1] /= t; \ +frustum[i][2] /= t; \ +frustum[i][3] /= t + +void HWR_FrustrumSetup(void) +{ + float t; + float clip[16]; + + pglGetDoublev(GL_PROJECTION_MATRIX, projMatrix); + pglGetDoublev(GL_MODELVIEW_MATRIX, viewMatrix); + + clip[0] = CALCMATRIX(0, 0, 1, 4, 2, 8, 3, 12); + clip[1] = CALCMATRIX(0, 1, 1, 5, 2, 9, 3, 13); + clip[2] = CALCMATRIX(0, 2, 1, 6, 2, 10, 3, 14); + clip[3] = CALCMATRIX(0, 3, 1, 7, 2, 11, 3, 15); + + clip[4] = CALCMATRIX(4, 0, 5, 4, 6, 8, 7, 12); + clip[5] = CALCMATRIX(4, 1, 5, 5, 6, 9, 7, 13); + clip[6] = CALCMATRIX(4, 2, 5, 6, 6, 10, 7, 14); + clip[7] = CALCMATRIX(4, 3, 5, 7, 6, 11, 7, 15); + + clip[8] = CALCMATRIX(8, 0, 9, 4, 10, 8, 11, 12); + clip[9] = CALCMATRIX(8, 1, 9, 5, 10, 9, 11, 13); + clip[10] = CALCMATRIX(8, 2, 9, 6, 10, 10, 11, 14); + clip[11] = CALCMATRIX(8, 3, 9, 7, 10, 11, 11, 15); + + clip[12] = CALCMATRIX(12, 0, 13, 4, 14, 8, 15, 12); + clip[13] = CALCMATRIX(12, 1, 13, 5, 14, 9, 15, 13); + clip[14] = CALCMATRIX(12, 2, 13, 6, 14, 10, 15, 14); + clip[15] = CALCMATRIX(12, 3, 13, 7, 14, 11, 15, 15); + + // Right plane + frustum[0][0] = clip[ 3] - clip[ 0]; + frustum[0][1] = clip[ 7] - clip[ 4]; + frustum[0][2] = clip[11] - clip[ 8]; + frustum[0][3] = clip[15] - clip[12]; + NORMALIZE_PLANE(0); + + // Left plane + frustum[1][0] = clip[ 3] + clip[ 0]; + frustum[1][1] = clip[ 7] + clip[ 4]; + frustum[1][2] = clip[11] + clip[ 8]; + frustum[1][3] = clip[15] + clip[12]; + NORMALIZE_PLANE(1); + + // Bottom plane + frustum[2][0] = clip[ 3] + clip[ 1]; + frustum[2][1] = clip[ 7] + clip[ 5]; + frustum[2][2] = clip[11] + clip[ 9]; + frustum[2][3] = clip[15] + clip[13]; + NORMALIZE_PLANE(2); + + // Top plane + frustum[3][0] = clip[ 3] - clip[ 1]; + frustum[3][1] = clip[ 7] - clip[ 5]; + frustum[3][2] = clip[11] - clip[ 9]; + frustum[3][3] = clip[15] - clip[13]; + NORMALIZE_PLANE(3); + + // Far plane + frustum[4][0] = clip[ 3] - clip[ 2]; + frustum[4][1] = clip[ 7] - clip[ 6]; + frustum[4][2] = clip[11] - clip[10]; + frustum[4][3] = clip[15] - clip[14]; + NORMALIZE_PLANE(4); + + // Near plane + frustum[5][0] = clip[ 3] + clip[ 2]; + frustum[5][1] = clip[ 7] + clip[ 6]; + frustum[5][2] = clip[11] + clip[10]; + frustum[5][3] = clip[15] + clip[14]; + NORMALIZE_PLANE(5); +} + +boolean HWR_SphereInFrustum(float x, float y, float z, float radius) +{ + int p; + + for (p = 0; p < 4; p++) + { + if (frustum[p][0] * x + + frustum[p][1] * y + + frustum[p][2] * z + + frustum[p][3] <= -radius) + { + return false; + } + } + return true; +} +#endif diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h new file mode 100644 index 00000000..c55041b7 --- /dev/null +++ b/src/hardware/hw_clip.h @@ -0,0 +1,24 @@ +/* + * hw_clip.h + * SRB2CB + * + * PrBoom's OpenGL clipping + * + * + */ + +// OpenGL BSP clipping +#include "../doomdef.h" +#include "../tables.h" +#include "../doomtype.h" + +//#define HAVE_SPHEREFRUSTRUM // enable if you want HWR_SphereInFrustum and related code + +boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); +void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); +void HWR_clipper_Clear(void); +angle_t HWR_FrustumAngle(void); +#ifdef HAVE_SPHEREFRUSTRUM +void HWR_FrustrumSetup(void); +boolean HWR_SphereInFrustum(float x, float y, float z, float radius); +#endif From 1e98e3b4f20ae9517a66e79f2a464cbcda9e28b7 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 10 Jan 2017 18:01:03 +0000 Subject: [PATCH 159/194] More progress, NEWCLIP added to doomdef.h, sadly it actually all lags the game so I've disabled it for now Other notes: * on second thought I'll keep the hw_clip functions' gld prefixes rather than HWR, not like it matters either way * despite the extra lag it does fix the issues with translucent walls and such when displayed at different vertical angles, such as with the GFZ1 waterfall --- src/doomdef.h | 7 ++ src/hardware/hw_clip.c | 62 +++++------ src/hardware/hw_clip.h | 14 +-- src/hardware/hw_main.c | 240 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 280 insertions(+), 43 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index 7f641558..e5fa3a48 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -502,4 +502,11 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// \note Required for proper collision with moving sloped surfaces that have sector specials on them. //#define SECTORSPECIALSAFTERTHINK +/// FINALLY some real clipping that doesn't make walls dissappear AND speeds the game up +/// (that was the original comment from SRB2CB, sadly it is a lie and actually slows game down) +/// on the bright side it fixes some weird issues with translucent walls +/// \note SRB2CB port. +/// SRB2CB itself ported this from PrBoom+ +//#define NEWCLIP + #endif // __DOOMDEF__ diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 47cbbfa2..8b01cabd 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -92,14 +92,14 @@ clipnode_t *freelist; clipnode_t *clipnodes; clipnode_t *cliphead; -static clipnode_t * HWR_clipnode_GetNew(void); -static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end); -static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); -static void HWR_clipper_AddClipRange(angle_t start, angle_t end); -static void HWR_clipper_RemoveRange(clipnode_t * range); -static void HWR_clipnode_Free(clipnode_t *node); +static clipnode_t * gld_clipnode_GetNew(void); +static clipnode_t * gld_clipnode_NewRange(angle_t start, angle_t end); +static boolean gld_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle); +static void gld_clipper_AddClipRange(angle_t start, angle_t end); +static void gld_clipper_RemoveRange(clipnode_t * range); +static void gld_clipnode_Free(clipnode_t *node); -static clipnode_t * HWR_clipnode_GetNew(void) +static clipnode_t * gld_clipnode_GetNew(void) { if (freelist) { @@ -113,26 +113,26 @@ static clipnode_t * HWR_clipnode_GetNew(void) } } -static clipnode_t * HWR_clipnode_NewRange(angle_t start, angle_t end) +static clipnode_t * gld_clipnode_NewRange(angle_t start, angle_t end) { - clipnode_t * c = HWR_clipnode_GetNew(); + clipnode_t * c = gld_clipnode_GetNew(); c->start = start; c->end = end; c->next = c->prev=NULL; return c; } -boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) +boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) { if(startAngle > endAngle) { - return (HWR_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || HWR_clipper_IsRangeVisible(0, endAngle)); + return (gld_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || gld_clipper_IsRangeVisible(0, endAngle)); } - return HWR_clipper_IsRangeVisible(startAngle, endAngle); + return gld_clipper_IsRangeVisible(startAngle, endAngle); } -static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) +static boolean gld_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) { clipnode_t *ci; ci = cliphead; @@ -152,13 +152,13 @@ static boolean HWR_clipper_IsRangeVisible(angle_t startAngle, angle_t endAngle) return true; } -static void HWR_clipnode_Free(clipnode_t *node) +static void gld_clipnode_Free(clipnode_t *node) { node->next = freelist; freelist = node; } -static void HWR_clipper_RemoveRange(clipnode_t *range) +static void gld_clipper_RemoveRange(clipnode_t *range) { if (range == cliphead) { @@ -176,25 +176,25 @@ static void HWR_clipper_RemoveRange(clipnode_t *range) } } - HWR_clipnode_Free(range); + gld_clipnode_Free(range); } -void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) +void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle) { if(startangle > endangle) { // The range has to added in two parts. - HWR_clipper_AddClipRange(startangle, ANGLE_MAX); - HWR_clipper_AddClipRange(0, endangle); + gld_clipper_AddClipRange(startangle, ANGLE_MAX); + gld_clipper_AddClipRange(0, endangle); } else { // Add the range as usual. - HWR_clipper_AddClipRange(startangle, endangle); + gld_clipper_AddClipRange(startangle, endangle); } } -static void HWR_clipper_AddClipRange(angle_t start, angle_t end) +static void gld_clipper_AddClipRange(angle_t start, angle_t end) { clipnode_t *node, *temp, *prevNode, *node2, *delnode; @@ -208,7 +208,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) { temp = node; node = node->next; - HWR_clipper_RemoveRange(temp); + gld_clipper_RemoveRange(temp); } else { @@ -250,7 +250,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) delnode = node2; node2 = node2->next; - HWR_clipper_RemoveRange(delnode); + gld_clipper_RemoveRange(delnode); } return; } @@ -260,7 +260,7 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) //just add range node = cliphead; prevNode = NULL; - temp = HWR_clipnode_NewRange(start, end); + temp = gld_clipnode_NewRange(start, end); while (node != NULL && node->start < end) { prevNode = node; @@ -296,13 +296,13 @@ static void HWR_clipper_AddClipRange(angle_t start, angle_t end) } else { - temp = HWR_clipnode_NewRange(start, end); + temp = gld_clipnode_NewRange(start, end); cliphead = temp; return; } } -void HWR_clipper_Clear(void) +void gld_clipper_Clear(void) { clipnode_t *node = cliphead; clipnode_t *temp; @@ -311,7 +311,7 @@ void HWR_clipper_Clear(void) { temp = node; node = node->next; - HWR_clipnode_Free(temp); + gld_clipnode_Free(temp); } cliphead = NULL; @@ -319,7 +319,7 @@ void HWR_clipper_Clear(void) #define RMUL (1.6f/1.333333f) -angle_t HWR_FrustumAngle(void) +angle_t gld_FrustumAngle(void) { double floatangle; angle_t a1; @@ -356,7 +356,7 @@ angle_t HWR_FrustumAngle(void) // btw to renable define HAVE_SPHEREFRUSTRUM in hw_clip.h #ifdef HAVE_SPHEREFRUSTRUM // -// HWR_FrustrumSetup +// gld_FrustrumSetup // #define CALCMATRIX(a, b, c, d, e, f, g, h)\ @@ -375,7 +375,7 @@ frustum[i][1] /= t; \ frustum[i][2] /= t; \ frustum[i][3] /= t -void HWR_FrustrumSetup(void) +void gld_FrustrumSetup(void) { float t; float clip[16]; @@ -446,7 +446,7 @@ void HWR_FrustrumSetup(void) NORMALIZE_PLANE(5); } -boolean HWR_SphereInFrustum(float x, float y, float z, float radius) +boolean gld_SphereInFrustum(float x, float y, float z, float radius) { int p; diff --git a/src/hardware/hw_clip.h b/src/hardware/hw_clip.h index c55041b7..3ba26e5e 100644 --- a/src/hardware/hw_clip.h +++ b/src/hardware/hw_clip.h @@ -12,13 +12,13 @@ #include "../tables.h" #include "../doomtype.h" -//#define HAVE_SPHEREFRUSTRUM // enable if you want HWR_SphereInFrustum and related code +//#define HAVE_SPHEREFRUSTRUM // enable if you want gld_SphereInFrustum and related code -boolean HWR_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); -void HWR_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); -void HWR_clipper_Clear(void); -angle_t HWR_FrustumAngle(void); +boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle); +void gld_clipper_SafeAddClipRange(angle_t startangle, angle_t endangle); +void gld_clipper_Clear(void); +angle_t gld_FrustumAngle(void); #ifdef HAVE_SPHEREFRUSTRUM -void HWR_FrustrumSetup(void); -boolean HWR_SphereInFrustum(float x, float y, float z, float radius); +void gld_FrustrumSetup(void); +boolean gld_SphereInFrustum(float x, float y, float z, float radius); #endif diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7e815258..c10f4bf1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -44,6 +44,10 @@ #endif #include "hw_md2.h" +#ifdef NEWCLIP +#include "hw_clip.h" +#endif + #define R_FAKEFLOORS #define HWPRECIP #define SORTING @@ -99,8 +103,9 @@ CV_PossibleValue_t granisotropicmode_cons_t[] = {{1, "MIN"}, {16, "MAX"}, {0, NU boolean drawsky = true; // needs fix: walls are incorrectly clipped one column less +#ifndef NEWCLIP static consvar_t cv_grclipwalls = {"gr_clipwalls", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; - +#endif //development variables for diverse uses static consvar_t cv_gralpha = {"gr_alpha", "160", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_grbeta = {"gr_beta", "0", 0, CV_Unsigned, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -1030,6 +1035,7 @@ static void HWR_ProjectWall(wallVert3D * wallVerts, // (in fact a clipping plane that has a constant, so can clip with simple 2d) // with the wall segment // +#ifndef NEWCLIP static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) { float num, den; @@ -1058,6 +1064,7 @@ static float HWR_ClipViewSegment(INT32 x, polyvertex_t *v1, polyvertex_t *v2) return num / den; } +#endif // // HWR_SplitWall @@ -1333,7 +1340,11 @@ static void HWR_DrawSkyWall(wallVert3D *wallVerts, FSurfaceInfo *Surf, fixed_t b // Anything between means the wall segment has been clipped with solidsegs, // reducing wall overdraw to a minimum // +#ifdef NEWCLIP +static void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom +#else static void HWR_StoreWallRange(double startfrac, double endfrac) +#endif { wallVert3D wallVerts[4]; v2d_t vs, ve; // start, end vertices of 2d line (view from above) @@ -1358,8 +1369,10 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) extracolormap_t *colormap; FSurfaceInfo Surf; +#ifndef NEWCLIP if (startfrac > endfrac) return; +#endif gr_sidedef = gr_curline->sidedef; gr_linedef = gr_curline->linedef; @@ -1408,15 +1421,19 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // x offset the texture fixed_t texturehpeg = gr_sidedef->textureoffset + gr_curline->offset; +#ifndef NEWCLIP // clip texture s start/end coords with solidsegs if (startfrac > 0.0f && startfrac < 1.0f) cliplow = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * startfrac); else +#endif cliplow = (float)texturehpeg; +#ifndef NEWCLIP if (endfrac > 0.0f && endfrac < 1.0f) cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT) * endfrac); else +#endif cliphigh = (float)(texturehpeg + (gr_curline->flength*FRACUNIT)); } @@ -2325,6 +2342,135 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) //Hurdler: end of 3d-floors test } +// From PrBoom: +// +// e6y: Check whether the player can look beyond this line +// +#ifdef NEWCLIP +// Don't modify anything here, just check +// Kalaron: Modified for sloped linedefs +static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacksector) +{ + fixed_t frontf1,frontf2, frontc1, frontc2; // front floor/ceiling ends + fixed_t backf1, backf2, backc1, backc2; // back floor ceiling ends + + // GZDoom method of sloped line clipping + +#ifdef ESLOPE + if (afrontsector->f_slope || afrontsector->c_slope || abacksector->f_slope || abacksector->c_slope) + { + fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t + v1x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->x); + v1y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv1)->y); + v2x = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->x); + v2y = FLOAT_TO_FIXED(((polyvertex_t *)gr_curline->pv2)->y); +#define SLOPEPARAMS(slope, end1, end2, normalheight) \ + if (slope) { \ + end1 = P_GetZAt(slope, v1x, v1y); \ + end2 = P_GetZAt(slope, v2x, v2y); \ + } else \ + end1 = end2 = normalheight; + + SLOPEPARAMS(afrontsector->f_slope, frontf1, frontf2, afrontsector->floorheight) + SLOPEPARAMS(afrontsector->c_slope, frontc1, frontc2, afrontsector->ceilingheight) + SLOPEPARAMS( abacksector->f_slope, backf1, backf2, abacksector->floorheight) + SLOPEPARAMS( abacksector->c_slope, backc1, backc2, abacksector->ceilingheight) +#undef SLOPEPARAMS + } + else +#endif + { + frontf1 = frontf2 = afrontsector->floorheight; + frontc1 = frontc2 = afrontsector->ceilingheight; + backf1 = backf2 = abacksector->floorheight; + backc1 = backc2 = abacksector->ceilingheight; + } + + // now check for closed sectors! + if (backc1 <= frontf1 && backc2 <= frontf2) + { + if (!seg->sidedef->toptexture) + return false; + + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + return true; + } + + if (backf1 >= frontc1 && backf2 >= frontc2) + { + if (!seg->sidedef->bottomtexture) + return false; + + // properly render skies (consider door "open" if both floors are sky): + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + return true; + } + + if (backc1 <= backf1 && backc2 <= backf2) + { + // preserve a kind of transparent door/lift special effect: + if (backc1 < frontc1 || backc2 < frontc2) + { + if (!seg->sidedef->toptexture) + return false; + } + if (backf1 > frontf1 || backf2 > frontf2) + { + if (!seg->sidedef->bottomtexture) + return false; + } + if (abacksector->ceilingpic == skyflatnum && afrontsector->ceilingpic == skyflatnum) + return false; + + if (abacksector->floorpic == skyflatnum && afrontsector->floorpic == skyflatnum) + return false; + + return true; + } + + + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if ( +#ifdef POLYOBJECTS + !seg->polyseg && +#endif + gr_backsector->ceilingpic == gr_frontsector->ceilingpic + && gr_backsector->floorpic == gr_frontsector->floorpic +#ifdef ESLOPE + && gr_backsector->f_slope == gr_frontsector->f_slope + && gr_backsector->c_slope == gr_frontsector->c_slope +#endif + && gr_backsector->lightlevel == gr_frontsector->lightlevel + && !gr_curline->sidedef->midtexture + // Check offsets too! + && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs + && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs + && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle + && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs + && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs + && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle + // Consider altered lighting. + && gr_backsector->floorlightsec == gr_frontsector->floorlightsec + && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec + // Consider colormaps + && gr_backsector->extra_colormap == gr_frontsector->extra_colormap + && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) + || gr_frontsector->tag == gr_backsector->tag)) + { + return false; + } + + + return false; +} +#else //Hurdler: just like in r_bsp.c #if 1 #define MAXSEGS MAXVIDWIDTH/2+1 @@ -2610,6 +2756,7 @@ static void HWR_ClearClipSegs(void) gr_solidsegs[1].last = 0x7fffffff; hw_newend = gr_solidsegs+2; } +#endif // NEWCLIP // -----------------+ // HWR_AddLine : Clips the given segment and adds any visible pieces to the line list. @@ -2618,17 +2765,20 @@ static void HWR_ClearClipSegs(void) // -----------------+ static void HWR_AddLine(seg_t * line) { - INT32 x1, x2; angle_t angle1, angle2; +#ifndef NEWCLIP + INT32 x1, x2; angle_t span, tspan; +#endif // SoM: Backsector needs to be run through R_FakeFlat static sector_t tempsec; fixed_t v1x, v1y, v2x, v2y; // the seg's vertexes as fixed_t - +#ifdef POLYOBJECTS if (line->polyseg && !(line->polyseg->flags & POF_RENDERSIDES)) return; +#endif gr_curline = line; @@ -2641,6 +2791,18 @@ static void HWR_AddLine(seg_t * line) angle1 = R_PointToAngle(v1x, v1y); angle2 = R_PointToAngle(v2x, v2y); +#ifdef NEWCLIP + // PrBoom: Back side, i.e. backface culling - read: endAngle >= startAngle! + if (angle2 - angle1 < ANGLE_180) + return; + + // PrBoom: use REAL clipping math YAYYYYYYY!!! + + if (!gld_clipper_SafeCheckRange(angle2, angle1)) + { + return; + } +#else // Clip to view edges. span = angle1 - angle2; @@ -2719,8 +2881,35 @@ static void HWR_AddLine(seg_t * line) return; } */ +#endif + gr_backsector = line->backsector; +#ifdef NEWCLIP + if (!line->backsector) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + else + { + gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); + if (line->frontsector == line->backsector) + { + if (!line->sidedef->midtexture) + { + //e6y: nothing to do here! + //return; + } + } + if (CheckClip(line, gr_frontsector, gr_backsector)) + { + gld_clipper_SafeAddClipRange(angle2, angle1); + } + } + + HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D + return; +#else // Single sided line? if (!gr_backsector) goto clipsolid; @@ -2835,6 +3024,7 @@ clipsolid: if (x1 == x2) goto clippass; HWR_ClipSolidWallSegment(x1, x2-1); +#endif } // HWR_CheckBBox @@ -2846,9 +3036,13 @@ clipsolid: static boolean HWR_CheckBBox(fixed_t *bspcoord) { - INT32 boxpos, sx1, sx2; + INT32 boxpos; fixed_t px1, py1, px2, py2; - angle_t angle1, angle2, span, tspan; + angle_t angle1, angle2; +#ifndef NEWCLIP + INT32 sx1, sx2; + angle_t span, tspan; +#endif // Find the corners of the box // that define the edges from current viewpoint. @@ -2874,6 +3068,11 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) px2 = bspcoord[checkcoord[boxpos][2]]; py2 = bspcoord[checkcoord[boxpos][3]]; +#ifdef NEWCLIP + angle1 = R_PointToAngle(px1, py1); + angle2 = R_PointToAngle(px2, py2); + return gld_clipper_SafeCheckRange(angle2, angle1); +#else // check clip list for an open space angle1 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px1>>1, py1>>1) - dup_viewangle; angle2 = R_PointToAngle2(dup_viewx>>1, dup_viewy>>1, px2>>1, py2>>1) - dup_viewangle; @@ -2921,6 +3120,7 @@ static boolean HWR_CheckBBox(fixed_t *bspcoord) return false; return HWR_ClipToSolidSegs(sx1, sx2 - 1); +#endif } #ifdef POLYOBJECTS @@ -5694,7 +5894,19 @@ if (0) #ifdef SORTING drawcount = 0; #endif +#ifdef NEWCLIP + if (rendermode == render_opengl) + { + angle_t a1 = gld_FrustumAngle(); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); +#ifdef HAVE_SPHEREFRUSTRUM + gld_FrustrumSetup(); +#endif + } +#else HWR_ClearClipSegs(); +#endif //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes @@ -5704,6 +5916,7 @@ if (0) HWR_RenderBSPNode((INT32)numnodes-1); +#ifndef NEWCLIP // Make a viewangle int so we can render things based on mouselook if (player == &players[consoleplayer]) viewangle = localaiming; @@ -5730,6 +5943,7 @@ if (0) dup_viewangle += ANGLE_90; } +#endif // Check for new console commands. NetUpdate(); @@ -5901,7 +6115,19 @@ if (0) #ifdef SORTING drawcount = 0; #endif +#ifdef NEWCLIP + if (rendermode == render_opengl) + { + angle_t a1 = gld_FrustumAngle(); + gld_clipper_Clear(); + gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); +#ifdef HAVE_SPHEREFRUSTRUM + gld_FrustrumSetup(); +#endif + } +#else HWR_ClearClipSegs(); +#endif //04/01/2000: Hurdler: added for T&L // Actually it only works on Walls and Planes @@ -5911,6 +6137,7 @@ if (0) HWR_RenderBSPNode((INT32)numnodes-1); +#ifndef NEWCLIP // Make a viewangle int so we can render things based on mouselook if (player == &players[consoleplayer]) viewangle = localaiming; @@ -5937,6 +6164,7 @@ if (0) dup_viewangle += ANGLE_90; } +#endif // Check for new console commands. NetUpdate(); @@ -6079,7 +6307,9 @@ static inline void HWR_AddEngineCommands(void) { // engine state variables //CV_RegisterVar(&cv_grzbuffer); +#ifndef NEWCLIP CV_RegisterVar(&cv_grclipwalls); +#endif // engine development mode variables // - usage may vary from version to version.. From c4569e61a8feab59eb5635daf536e9605048a176 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 10 Jan 2017 20:07:02 +0000 Subject: [PATCH 160/194] Made some efforts to improve efficiency of new code, hard to tell if I've made it better or worse though honestly R_IsEmptyLine is now a thing too btw --- src/hardware/hw_main.c | 94 +++++++++--------------------------------- src/r_bsp.c | 60 ++++++++++++++------------- src/r_bsp.h | 1 + 3 files changed, 52 insertions(+), 103 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index c10f4bf1..c148e7c4 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2347,6 +2347,7 @@ static void HWR_StoreWallRange(double startfrac, double endfrac) // e6y: Check whether the player can look beyond this line // #ifdef NEWCLIP +boolean checkforemptylines = true; // Don't modify anything here, just check // Kalaron: Modified for sloped linedefs static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacksector) @@ -2389,6 +2390,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks // now check for closed sectors! if (backc1 <= frontf1 && backc2 <= frontf2) { + checkforemptylines = false; if (!seg->sidedef->toptexture) return false; @@ -2400,6 +2402,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (backf1 >= frontc1 && backf2 >= frontc2) { + checkforemptylines = false; if (!seg->sidedef->bottomtexture) return false; @@ -2412,6 +2415,7 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks if (backc1 <= backf1 && backc2 <= backf2) { + checkforemptylines = false; // preserve a kind of transparent door/lift special effect: if (backc1 < frontc1 || backc2 < frontc2) { @@ -2432,41 +2436,12 @@ static boolean CheckClip(seg_t * seg, sector_t * afrontsector, sector_t * abacks return true; } - - // Reject empty lines used for triggers and special events. - // Identical floor and ceiling on both sides, - // identical light levels on both sides, - // and no middle texture. - if ( -#ifdef POLYOBJECTS - !seg->polyseg && -#endif - gr_backsector->ceilingpic == gr_frontsector->ceilingpic - && gr_backsector->floorpic == gr_frontsector->floorpic -#ifdef ESLOPE - && gr_backsector->f_slope == gr_frontsector->f_slope - && gr_backsector->c_slope == gr_frontsector->c_slope -#endif - && gr_backsector->lightlevel == gr_frontsector->lightlevel - && !gr_curline->sidedef->midtexture - // Check offsets too! - && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs - && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs - && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle - && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs - && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs - && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle - // Consider altered lighting. - && gr_backsector->floorlightsec == gr_frontsector->floorlightsec - && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec - // Consider colormaps - && gr_backsector->extra_colormap == gr_frontsector->extra_colormap - && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || gr_frontsector->tag == gr_backsector->tag)) - { - return false; - } - + if (backc1 != frontc1 || backc2 != frontc2 + || backf1 != frontf1 || backf2 != frontf2) + { + checkforemptylines = false; + return false; + } return false; } @@ -2802,6 +2777,8 @@ static void HWR_AddLine(seg_t * line) { return; } + + checkforemptylines = true; #else // Clip to view edges. span = angle1 - angle2; @@ -2893,18 +2870,17 @@ static void HWR_AddLine(seg_t * line) else { gr_backsector = R_FakeFlat(gr_backsector, &tempsec, NULL, NULL, true); - if (line->frontsector == line->backsector) - { - if (!line->sidedef->midtexture) - { - //e6y: nothing to do here! - //return; - } - } if (CheckClip(line, gr_frontsector, gr_backsector)) { gld_clipper_SafeAddClipRange(angle2, angle1); + checkforemptylines = false; } + // Reject empty lines used for triggers and special events. + // Identical floor and ceiling on both sides, + // identical light levels on both sides, + // and no middle texture. + if (checkforemptylines && R_IsEmptyLine(line, gr_frontsector, gr_backsector)) + return; } HWR_ProcessSeg(); // Doesn't need arguments because they're defined globally :D @@ -2981,38 +2957,8 @@ static void HWR_AddLine(seg_t * line) // Identical floor and ceiling on both sides, // identical light levels on both sides, // and no middle texture. - if ( -#ifdef POLYOBJECTS - !line->polyseg && -#endif - gr_backsector->ceilingpic == gr_frontsector->ceilingpic - && gr_backsector->floorpic == gr_frontsector->floorpic -#ifdef ESLOPE - && gr_backsector->f_slope == gr_frontsector->f_slope - && gr_backsector->c_slope == gr_frontsector->c_slope -#endif - && gr_backsector->lightlevel == gr_frontsector->lightlevel - && !gr_curline->sidedef->midtexture - // Check offsets too! - && gr_backsector->floor_xoffs == gr_frontsector->floor_xoffs - && gr_backsector->floor_yoffs == gr_frontsector->floor_yoffs - && gr_backsector->floorpic_angle == gr_frontsector->floorpic_angle - && gr_backsector->ceiling_xoffs == gr_frontsector->ceiling_xoffs - && gr_backsector->ceiling_yoffs == gr_frontsector->ceiling_yoffs - && gr_backsector->ceilingpic_angle == gr_frontsector->ceilingpic_angle - // Consider altered lighting. - && gr_backsector->floorlightsec == gr_frontsector->floorlightsec - && gr_backsector->ceilinglightsec == gr_frontsector->ceilinglightsec - // Consider colormaps - && gr_backsector->extra_colormap == gr_frontsector->extra_colormap - && ((!gr_frontsector->ffloors && !gr_backsector->ffloors) - || gr_frontsector->tag == gr_backsector->tag)) - // SoM: For 3D sides... Boris, would you like to take a - // crack at rendering 3D sides? You would need to add the - // above check and add code to HWR_StoreWallRange... - { + if (R_IsEmptyLine(curline, frontsector, backsector)) return; - } clippass: if (x1 == x2) diff --git a/src/r_bsp.c b/src/r_bsp.c index abb11204..4ce89f00 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -365,6 +365,36 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, return sec; } +boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back) +{ + return ( +#ifdef POLYOBJECTS + !line->polyseg && +#endif + back->ceilingpic == front->ceilingpic + && back->floorpic == front->floorpic +#ifdef ESLOPE + && back->f_slope == front->f_slope + && back->c_slope == front->c_slope +#endif + && back->lightlevel == front->lightlevel + && !line->sidedef->midtexture + // Check offsets too! + && back->floor_xoffs == front->floor_xoffs + && back->floor_yoffs == front->floor_yoffs + && back->floorpic_angle == front->floorpic_angle + && back->ceiling_xoffs == front->ceiling_xoffs + && back->ceiling_yoffs == front->ceiling_yoffs + && back->ceilingpic_angle == front->ceilingpic_angle + // Consider altered lighting. + && back->floorlightsec == front->floorlightsec + && back->ceilinglightsec == front->ceilinglightsec + // Consider colormaps + && back->extra_colormap == front->extra_colormap + && ((!front->ffloors && !back->ffloors) + || front->tag == back->tag)); +} + // // R_AddLine // Clips the given segment and adds any visible pieces to the line list. @@ -526,36 +556,8 @@ static void R_AddLine(seg_t *line) // Identical floor and ceiling on both sides, identical light levels on both sides, // and no middle texture. - if ( -#ifdef POLYOBJECTS - !line->polyseg && -#endif - backsector->ceilingpic == frontsector->ceilingpic - && backsector->floorpic == frontsector->floorpic -#ifdef ESLOPE - && backsector->f_slope == frontsector->f_slope - && backsector->c_slope == frontsector->c_slope -#endif - && backsector->lightlevel == frontsector->lightlevel - && !curline->sidedef->midtexture - // Check offsets too! - && backsector->floor_xoffs == frontsector->floor_xoffs - && backsector->floor_yoffs == frontsector->floor_yoffs - && backsector->floorpic_angle == frontsector->floorpic_angle - && backsector->ceiling_xoffs == frontsector->ceiling_xoffs - && backsector->ceiling_yoffs == frontsector->ceiling_yoffs - && backsector->ceilingpic_angle == frontsector->ceilingpic_angle - // Consider altered lighting. - && backsector->floorlightsec == frontsector->floorlightsec - && backsector->ceilinglightsec == frontsector->ceilinglightsec - // Consider colormaps - && backsector->extra_colormap == frontsector->extra_colormap - && ((!frontsector->ffloors && !backsector->ffloors) - || frontsector->tag == backsector->tag)) - { + if (R_IsEmptyLine(line, frontsector, backsector)) return; - } - clippass: R_ClipPassWallSegment(x1, x2 - 1); diff --git a/src/r_bsp.h b/src/r_bsp.h index e871b5dd..80824831 100644 --- a/src/r_bsp.h +++ b/src/r_bsp.h @@ -50,6 +50,7 @@ extern polyobj_t **po_ptrs; // temp ptr array to sort polyobject pointers sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, INT32 *ceilinglightlevel, boolean back); +boolean R_IsEmptyLine(seg_t *line, sector_t *front, sector_t *back); INT32 R_GetPlaneLight(sector_t *sector, fixed_t planeheight, boolean underside); void R_Prep3DFloors(sector_t *sector); From 8ba0f2a177086a26313aac58eb8ff4b2ecc95c09 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Thu, 12 Jan 2017 21:44:27 +0000 Subject: [PATCH 161/194] clipping code didn't seem so bad this time (at least compared to without), let's enable it now? --- src/doomdef.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doomdef.h b/src/doomdef.h index e5fa3a48..ff09144e 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -507,6 +507,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// on the bright side it fixes some weird issues with translucent walls /// \note SRB2CB port. /// SRB2CB itself ported this from PrBoom+ -//#define NEWCLIP +#define NEWCLIP #endif // __DOOMDEF__ From 3608f73d39a60fe79c368691f8171a20691ea4ce Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Mon, 16 Jan 2017 15:48:07 +0000 Subject: [PATCH 162/194] Updated SRB2.cbp for hw_clip.c/h --- SRB2.cbp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/SRB2.cbp b/SRB2.cbp index 74ec96c6..5aa623fa 100644 --- a/SRB2.cbp +++ b/SRB2.cbp @@ -1174,6 +1174,39 @@ HW3SOUND for 3D hardware sound support