From b7ffaf424384e4ea882b132964b07fd6e486d332 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 11 Jan 2024 20:13:13 +0300 Subject: [PATCH 01/16] Warn about possible crash for vanilla when failing to spawn mapthing --- src/p_mobj.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_mobj.c b/src/p_mobj.c index 541529c9e..b577ac32d 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11507,7 +11507,7 @@ void P_SpawnMapThing(mapthing_t *mthing) mobj = P_SpawnMobj(x, y, z, i); if (!mobj || P_MobjWasRemoved(mobj)) { - CONS_Alert(CONS_WARNING, "Failed to spawn map thing #%d at %d, %d\n", mthing->type, x>>FRACBITS, y>>FRACBITS); + CONS_Alert(CONS_ERROR, "Failed to spawn map thing #%d at %d, %d. This will crash vanilla clients!\n", mthing->type, x>>FRACBITS, y>>FRACBITS); return; } From 0a6a40741b35b7ab00a733f8bdb2f65be7ad049c Mon Sep 17 00:00:00 2001 From: Indev Date: Fri, 12 Jan 2024 14:55:40 +0300 Subject: [PATCH 02/16] Don't reload addfilelocal'd files if md5 matches --- src/w_wad.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 6739d7824..4989f497b 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -769,13 +769,10 @@ UINT16 W_InitFile(const char *filename, const char *lumpname, UINT16 *wadnump, b { if (!memcmp(wadfiles[i]->md5sum, md5sum, 16)) { - if (!local) { - CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); - if (handle) - fclose(handle); - return INT16_MAX; - } - CONS_Alert(CONS_WARNING, M_GetText("%s is a local skin that is already loaded\n"), filename); + CONS_Alert(CONS_ERROR, M_GetText("%s is already loaded\n"), filename); + if (handle) + fclose(handle); + return INT16_MAX; } } #endif From e1f821e121c5032fbafee7d0eefc9f2cbd3efc20 Mon Sep 17 00:00:00 2001 From: hayaunderscore Date: Sun, 26 Nov 2023 10:16:16 +0800 Subject: [PATCH 03/16] Localskins on replays --- src/g_game.c | 29 +++++++++++++++++++++++++++-- src/g_game.h | 1 + src/r_things.c | 2 ++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 38f063f62..dceaafa29 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3012,6 +3012,9 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) } P_MovePlayerToSpawn(playernum, spawnpoint); + // TODO: This is so dumb. + demo_extradata[playernum] |= DXD_LOCALSKIN; + #ifdef HAVE_BLUA LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :) #endif @@ -3347,7 +3350,7 @@ void G_AddPlayer(INT32 playernum) p->jointime = 0; p->playerstate = PST_REBORN; - demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN; // Set everything + demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN|DXD_LOCALSKIN; // Set everything } void G_ExitLevel(void) @@ -5346,7 +5349,14 @@ void G_ReadDemoExtraData(void) else if (G_RaceGametype()) P_CheckRacers(); // also SRB2Kart } - + if (extradata & DXD_LOCALSKIN) + { + // TODO: Does this work just fine? + M_Memcpy(name, demo_p, 16); + //CONS_Printf("Loaded localskin data from replay: %s\n", name); + demo_p += 16; + SetLocalPlayerSkin(p, name, NULL); + } p = READUINT8(demo_p); } @@ -5433,6 +5443,21 @@ void G_WriteDemoExtraData(void) else WRITEUINT8(demo_p, DXD_PST_PLAYING); } + if (demo_extradata[i] & DXD_LOCALSKIN) + { + // Skin + memset(name, 0, 16); + // check for different localskin conditions + if (players[i].skinlocal && players[i].localskin > 0) + strncpy(name, localskins[players[i].localskin - 1].name, 16); + else if (!players[i].skinlocal && players[i].localskin > 0) + strncpy(name, skins[players[i].localskin - 1].name, 16); + else + strncpy(name, "none", 16); + //CONS_Printf("Saved localskin data to replay: %s\n", name); + M_Memcpy(demo_p,name,16); + demo_p += 16; + } } demo_extradata[i] = 0; diff --git a/src/g_game.h b/src/g_game.h index b45e42875..372801f65 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -297,6 +297,7 @@ extern UINT8 demo_writerng; #define DXD_NAME 0x04 // name changed #define DXD_COLOR 0x08 // color changed #define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game +#define DXD_LOCALSKIN 0x20 // localskin changed #define DXD_PST_PLAYING 0x01 #define DXD_PST_SPECTATING 0x02 diff --git a/src/r_things.c b/src/r_things.c index 41bd5c6e1..498c46bf4 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3274,6 +3274,8 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) CV_StealthSet(cvar, "none"); } } + + demo_extradata[playernum] |= DXD_LOCALSKIN; } // Same as SetPlayerSkin, but uses the skin #. From 76a233148b508a48c93f88a7f27f7521a066f230 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 14 Jan 2024 18:03:20 +0300 Subject: [PATCH 04/16] Restore old speedometer offset cvar names Changed from "speed" to "spdm" in refactor accidently oops --- src/g_game.h | 2 +- src/k_kart.c | 8 ++++---- src/m_menu.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index b45e42875..a57468a2e 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -141,7 +141,7 @@ DECL_HUD_OFFSET(item); // Item box DECL_HUD_OFFSET(time); // Time DECL_HUD_OFFSET(laps); // Number of laps DECL_HUD_OFFSET(dnft); // Countdown (did not finish timer) -DECL_HUD_OFFSET(spdm); // Speedometer +DECL_HUD_OFFSET(speed); // Speedometer DECL_HUD_OFFSET(posi); // Position in race DECL_HUD_OFFSET(face); // Mini rankings DECL_HUD_OFFSET(stcd); // Starting countdown diff --git a/src/k_kart.c b/src/k_kart.c index 46d891890..3170bc143 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -40,7 +40,7 @@ IMPL_HUD_OFFSET(item); // Item box IMPL_HUD_OFFSET(time); // Time IMPL_HUD_OFFSET(laps); // Number of laps IMPL_HUD_OFFSET(dnft); // Countdown (did not finish timer) -IMPL_HUD_OFFSET(spdm); // Speedometer +IMPL_HUD_OFFSET(speed); // Speedometer IMPL_HUD_OFFSET(posi); // Position in race IMPL_HUD_OFFSET(face); // Mini rankings IMPL_HUD_OFFSET(stcd); // Starting countdown @@ -685,7 +685,7 @@ void K_RegisterKartStuff(void) REG_HUD_OFFSET(time); // Time REG_HUD_OFFSET(laps); // Number of laps REG_HUD_OFFSET(dnft); // Countdown (did not finish timer) - REG_HUD_OFFSET(spdm); // Speedometer + REG_HUD_OFFSET(speed); // Speedometer REG_HUD_OFFSET(posi); // Position in race REG_HUD_OFFSET(face); // Mini rankings REG_HUD_OFFSET(stcd); // Starting countdown @@ -7451,8 +7451,8 @@ static void K_initKartHUD(void) LAPS_X = 9 + cv_laps_xoffset.value; // 9 LAPS_Y = BASEVIDHEIGHT - 29 + cv_laps_yoffset.value; // 171 // Speedometer - SPDM_X = 9 + cv_spdm_xoffset.value; // 9 - SPDM_Y = BASEVIDHEIGHT - 45 + cv_spdm_yoffset.value; // 155 + SPDM_X = 9 + cv_speed_xoffset.value; // 9 + SPDM_Y = BASEVIDHEIGHT - 45 + cv_speed_yoffset.value; // 155 // Position Number POSI_X = BASEVIDWIDTH - 9 + cv_posi_xoffset.value; // 268 POSI_Y = BASEVIDHEIGHT - 9 + cv_posi_yoffset.value; // 138 diff --git a/src/m_menu.c b/src/m_menu.c index c46cf9cca..d851801a4 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2120,8 +2120,8 @@ static menuitem_t OP_HudOffsetMenu[] = {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_laps_yoffset, 60}, {IT_HEADER, NULL, "Speedometer", NULL, 70}, - {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_spdm_xoffset, 75}, - {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_spdm_yoffset, 80}, + {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_speed_xoffset, 75}, + {IT_STRING | IT_CVAR, NULL, "Vertical Offset", &cv_speed_yoffset, 80}, {IT_HEADER, NULL, "Mini Rankings", NULL, 90}, {IT_STRING | IT_CVAR, NULL, "Horizontal Offset", &cv_face_xoffset, 95}, From d0761d00441fa62f1a1c25ae3145df8870244a82 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 21:29:14 +0100 Subject: [PATCH 05/16] background for missing 4th player screen in 4 player splitscreen just like software does c: --- src/hardware/hw_main.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 9ba76a32b..a0999bfd1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6177,6 +6177,20 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) gr_windowcenterx += gr_viewwidth; } + if (splitscreen == 2 && player == &players[displayplayers[2]]) + { + // V_DrawPatchFill, but for the fourth screen only + GLPatch_t *gpatch = W_CachePatchName("SRB2BACK", PU_CACHE); + INT32 dupz = (vid.dupx < vid.dupy ? vid.dupx : vid.dupy); + INT32 x, y, pw = SHORT(gpatch->width) * dupz, ph = SHORT(gpatch->height) * dupz; + + for (x = vid.width>>1; x < vid.width; x += pw) + { + for (y = vid.height>>1; y < vid.height; y += ph) + V_DrawScaledPatch(x, y, V_NOSCALESTART, gpatch); + } + } + // check for new console commands. NetUpdate(); From 2ffe7aa854f1b92c188753c27698c4f25cb42a20 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:13:30 +0100 Subject: [PATCH 06/16] use hwr_drawpatch to fix compiler warning and casting wrong things --- src/hardware/hw_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index a0999bfd1..be4a6ca0d 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -6187,7 +6187,7 @@ void HWR_RenderFrame(INT32 viewnumber, player_t *player, boolean skybox) for (x = vid.width>>1; x < vid.width; x += pw) { for (y = vid.height>>1; y < vid.height; y += ph) - V_DrawScaledPatch(x, y, V_NOSCALESTART, gpatch); + HWR_DrawStretchyFixedPatch(gpatch, (x)< Date: Sun, 14 Jan 2024 22:30:27 +0100 Subject: [PATCH 07/16] remove gr_vhseffect cvar the vhs effect can be toggled off in opengl with cv_vhseffect anyways, so having cvars to do the same thing is kinda unecessary --- src/hardware/hw_main.c | 3 --- src/hardware/hw_main.h | 1 - src/m_menu.c | 7 +------ src/v_video.c | 2 +- 4 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index be4a6ca0d..8ecc6975f 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -124,7 +124,6 @@ consvar_t cv_secbright = {"secbright", "0", CV_SAVE, secbright_cons_t, consvar_t cv_grfovchange = {"gr_fovchange", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_grvhseffect = {"gr_vhseffect", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; // values for the far clipping plane static float clipping_distances[] = {1024.0f, 2048.0f, 4096.0f, 6144.0f, 8192.0f, 12288.0f, 16384.0f}; @@ -6392,8 +6391,6 @@ void HWR_AddCommands(void) CV_RegisterVar(&cv_grpaletteshader); CV_RegisterVar(&cv_grflashpal); - - CV_RegisterVar(&cv_grvhseffect); } // -------------------------------------------------------------------------- diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index 3dc18ccf8..6a62295f8 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -198,7 +198,6 @@ extern consvar_t cv_grflashpal; extern consvar_t cv_grportals; extern consvar_t cv_nostencil; extern consvar_t cv_secbright; -extern consvar_t cv_grvhseffect; extern CV_PossibleValue_t granisotropicmode_cons_t[]; diff --git a/src/m_menu.c b/src/m_menu.c index d851801a4..a35b68a7d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1443,8 +1443,7 @@ static menuitem_t OP_ExpOptionsMenu[] = {IT_STRING | IT_CVAR, NULL, "FFloorclip", &cv_ffloorclip, 85}, {IT_STRING | IT_CVAR, NULL, "Spriteclip", &cv_spriteclip, 95}, #ifdef HWRENDER - {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 65}, - {IT_STRING | IT_CVAR, NULL, "VHS effect", &cv_grvhseffect, 75}, + {IT_STRING | IT_CVAR, NULL, "Screen Textures", &cv_grscreentextures, 75}, {IT_STRING | IT_CVAR, NULL, "Splitwall/Slope texture fix", &cv_splitwallfix, 95}, {IT_STRING | IT_CVAR, NULL, "Slope midtexture peg fix", &cv_slopepegfix, 105}, @@ -1463,7 +1462,6 @@ static const char* OP_ExpTooltips[] = "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", - "Show a VHS-like effect when the game is paused or youre rewinding replays.", "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.", @@ -1481,7 +1479,6 @@ enum op_exp_sprclip, #ifdef HWRENDER op_exp_grscrtx, - op_exp_grvhs, op_exp_spltwal, op_exp_pegging, op_exp_fofzfight, @@ -4426,7 +4423,6 @@ void M_Init(void) { OP_VideoOptionsMenu[op_video_ogl].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_grscrtx].status = IT_DISABLED; - OP_ExpOptionsMenu[op_exp_grvhs].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_spltwal].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_pegging].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_fofzfight].status = IT_DISABLED; @@ -4434,7 +4430,6 @@ void M_Init(void) } if (rendermode == render_opengl){ - OP_ExpOptionsMenu[op_exp_vhs].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_ffclip].status = IT_DISABLED; OP_ExpOptionsMenu[op_exp_sprclip].status = IT_DISABLED; } diff --git a/src/v_video.c b/src/v_video.c index 28a02bcff..53a41c216 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1205,7 +1205,7 @@ void V_DrawVhsEffect(boolean rewind) if (downbary > vid.height) downbary = -barsize; #ifdef HWRENDER - if ((rendermode == render_opengl) && (cv_grvhseffect.value)) + if (rendermode == render_opengl) { HWR_RenderVhsEffect(upbary, downbary, updistort, downdistort, barsize); return; From c1223d767d1e6503ed165f434c7b78961b53aade Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:39:50 +0100 Subject: [PATCH 08/16] remove this hacky stuff, just dont interpolate it it barely looked any better, it was actually just faster than it shouldve been --- src/v_video.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index 53a41c216..c1f1e21f0 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -1186,21 +1186,12 @@ void V_DrawVhsEffect(boolean rewind) if (rewind) V_DrawVhsEffect(false); // experimentation - if (R_UsingFrameInterpolation()) // omg i fucking hate interp so much, its a bit smoother but still not great whatever, atleast like this shit wont completely go nuts when youre on high framerates + if (renderisnewtic) { - if (renderisnewtic) - { - upbary -= FixedMul(vid.dupy * (rewind ? 3 : 1.8f), 22937*3); - downbary += FixedMul(vid.dupy * (rewind ? 2 : 1), 22937*3); - } - } - else - { - upbary -= vid.dupy * (rewind ? 3 : 1.8f); - downbary += vid.dupy * (rewind ? 2 : 1); + upbary -= (vid.dupy * (rewind ? 3 : 1.8f)); + downbary += (vid.dupy * (rewind ? 2 : 1)); } - if (upbary < -barsize) upbary = vid.height; if (downbary > vid.height) downbary = -barsize; From d2bf2bc5810a92bf64e8f8b5329a9d730eb2a298 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:53:20 +0100 Subject: [PATCH 09/16] forgor --- src/v_video.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/v_video.c b/src/v_video.c index c1f1e21f0..f54bddfdc 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -20,8 +20,6 @@ #include "r_draw.h" #include "console.h" -#include "r_fps.h" //vhs effect stuff - #include "i_video.h" // rendermode #include "z_zone.h" #include "m_misc.h" From 79a594f6eede26f3beb65616bbe84c29b4a9640d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 22:57:00 +0100 Subject: [PATCH 10/16] tooltips greenres fixed by nepdisk c: --- src/m_menu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index a35b68a7d..11fa9624d 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1457,14 +1457,14 @@ static const char* OP_ExpTooltips[] = NULL, "Should weather be interpolated? Weather should look about the\nsame but perform a bit better when disabled.", "When weather is on this will cut the object amount used in half.", - "Show a VHS-like effect when the game is paused or youre rewinding replays.", + "Show a VHS-like effect when the game is paused\n or youre rewinding replays.", "Hides 3DFloors which are not visible\npotentially resulting in a performance boost.", "Hides Sprites which are not visible\npotentially resulting in a performance boost.", #ifdef HWRENDER "Should the game do Screen Textures? Provides a good boost to frames\nat the cost of some visual effects not working when disabled.", - "Fixes issues that resulted in Textures sticking from the ground sometimes.\n This may be CPU heavy and result in worse performance in some cases.", + "Fixes issues that resulted in Textures sticking from the\nground sometimes.\nThis may be CPU heavy and result in worse performance in some cases.", "Fixes issues that resulted in Textures not being properly skewed\n example: Fences on slopes that didnt show proper.\n This may be CPU heavy and result in worse performance in some cases.", - "Fixes issues that resulted in Textures on Floor over Floors ZFighting heavily.", + "Fixes issues that resulted in Textures on Floor over Floors\nZFighting heavily.", "Toggle for FOF wall cutoff with slopes.", #endif }; From a36e633555f317947fc5fa3ef8d03fe47d4ad732 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 14 Jan 2024 23:49:48 +0100 Subject: [PATCH 11/16] Revert "Optimize HWR_RenderBatches polygon sorting" This reverts commit 5201ccd6d203e8b81434edc12368c41a9f83f24f. --- src/hardware/r_opengl/r_opengl.c | 58 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index 7ef8aed94..2fbd9071e 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2390,7 +2390,7 @@ int finalVertexArrayAllocSize = 65536; PolygonArrayEntry* polygonArray = NULL;// contains the polygon data from DrawPolygon, waiting to be processed int polygonArraySize = 0; -PolygonArrayEntry **polygonArraySorted = NULL;// contains sorted pointers to polygonArray +UINT32* polygonIndexArray = NULL;// contains sorting pointers for polygonArray int polygonArrayAllocSize = 65536; FOutVector* unsortedVertexArray = NULL;// contains unsorted vertices and texture coordinates from DrawPolygon @@ -2406,7 +2406,7 @@ EXPORT void HWRAPI(StartBatching) (void) finalVertexArray = malloc(finalVertexArrayAllocSize * sizeof(FOutVector)); finalVertexIndexArray = malloc(finalVertexArrayAllocSize * 3 * sizeof(UINT32)); polygonArray = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry)); - polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(UINT32)); unsortedVertexArray = malloc(unsortedVertexArrayAllocSize * sizeof(FOutVector)); } // drawing functions will now collect the drawing data instead of passing it to opengl @@ -2416,8 +2416,10 @@ EXPORT void HWRAPI(StartBatching) (void) static int comparePolygons(const void *p1, const void *p2) { - PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; @@ -2433,7 +2435,7 @@ static int comparePolygons(const void *p1, const void *p2) // skywalls and horizon lines must retain their order for horizon lines to work if (shader1 == -1 && shader2 == -1) - return poly1 - poly2; + return index1 - index2; diff = poly1->texNum - poly2->texNum; if (diff != 0) return diff; @@ -2464,8 +2466,10 @@ static int comparePolygons(const void *p1, const void *p2) static int comparePolygonsNoShaders(const void *p1, const void *p2) { - PolygonArrayEntry *poly1 = *(PolygonArrayEntry *const *)p1; - PolygonArrayEntry *poly2 = *(PolygonArrayEntry *const *)p2; + unsigned int index1 = *(const unsigned int*)p1; + unsigned int index2 = *(const unsigned int*)p2; + PolygonArrayEntry* poly1 = &polygonArray[index1]; + PolygonArrayEntry* poly2 = &polygonArray[index2]; int diff; INT64 diff64; @@ -2480,7 +2484,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2) // skywalls and horizon lines must retain their order for horizon lines to work if (texNum1 == 0 && texNum2 == 0) - return poly1 - poly2; + return index1 - index2; diff = poly1->polyFlags - poly2->polyFlags; if (diff != 0) return diff; @@ -2497,7 +2501,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i int finalVertexWritePos = 0;// position in finalVertexArray int finalIndexWritePos = 0;// position in finalVertexIndexArray - int polygonReadPos = 0;// position in polygonArraySorted + int polygonReadPos = 0;// position in polygonIndexArray GLuint currentShader; GLuint currentTexture; @@ -2523,19 +2527,19 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i *sNumPolys = polygonArraySize; *sNumCalls = *sNumVerts = 0; *sNumShaders = *sNumTextures = *sNumPolyFlags = *sNumColors = 1; - // init polygonArraySorted + // init polygonIndexArray for (i = 0; i < polygonArraySize; i++) { - polygonArraySorted[i] = &polygonArray[i]; + polygonIndexArray[i] = i; } // sort polygons //CONS_Printf("qsort polys\n"); *sSortTime = I_GetPreciseTime(); if (gl_allowshaders) - qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygons); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygons); else - qsort(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), comparePolygonsNoShaders); + qsort(polygonIndexArray, polygonArraySize, sizeof(unsigned int), comparePolygonsNoShaders); *sSortTime = I_GetPreciseTime() - *sSortTime; //CONS_Printf("sort done\n"); // sort order @@ -2547,10 +2551,10 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i *sDrawTime = I_GetPreciseTime(); - currentShader = polygonArraySorted[0]->shader; - currentTexture = polygonArraySorted[0]->texNum; - currentPolyFlags = polygonArraySorted[0]->polyFlags; - currentSurfaceInfo = polygonArraySorted[0]->surf; + currentShader = polygonArray[polygonIndexArray[0]].shader; + currentTexture = polygonArray[polygonIndexArray[0]].texNum; + currentPolyFlags = polygonArray[polygonIndexArray[0]].polyFlags; + currentSurfaceInfo = polygonArray[polygonIndexArray[0]].surf; // For now, will sort and track the colors. Vertex attributes could be used instead of uniforms // and a color array could replace the color calls. @@ -2628,8 +2632,8 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i // reset write pos // repeat loop - PolygonArrayEntry *entry = polygonArraySorted[polygonReadPos++]; - int numVerts = entry->numVerts; + int index = polygonIndexArray[polygonReadPos++]; + int numVerts = polygonArray[index].numVerts; // before writing, check if there is enough room // using 'while' instead of 'if' here makes sure that there will *always* be enough room. // probably never will this loop run more than once though @@ -2654,7 +2658,7 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i } //CONS_Printf("write verts to final\n"); // write the vertices of the polygon - memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[entry->vertsIndex], + memcpy(&finalVertexArray[finalVertexWritePos], &unsortedVertexArray[polygonArray[index].vertsIndex], numVerts * sizeof(FOutVector)); // write the indexes, pointing to the fan vertexes but in triangles format firstIndex = finalVertexWritePos; @@ -2676,11 +2680,11 @@ EXPORT void HWRAPI(RenderBatches) (precise_t *sSortTime, precise_t *sDrawTime, i { //CONS_Printf("state change check\n"); // check if a state change is required, set the change bools and next vars - PolygonArrayEntry *nextEntry = polygonArraySorted[polygonReadPos]; - nextShader = nextEntry->shader; - nextTexture = nextEntry->texNum; - nextPolyFlags = nextEntry->polyFlags; - nextSurfaceInfo = nextEntry->surf; + int nextIndex = polygonIndexArray[polygonReadPos]; + nextShader = polygonArray[nextIndex].shader; + nextTexture = polygonArray[nextIndex].texNum; + nextPolyFlags = polygonArray[nextIndex].polyFlags; + nextSurfaceInfo = polygonArray[nextIndex].surf; if (nextPolyFlags & PF_NoTexture) nextTexture = 0; if (currentShader != nextShader) @@ -2885,8 +2889,8 @@ EXPORT void HWRAPI(DrawPolygon) (FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUI free(polygonArray); polygonArray = new_array; // also need to redo the index array, dont need to copy it though - free(polygonArraySorted); - polygonArraySorted = malloc(polygonArrayAllocSize * sizeof(PolygonArrayEntry *)); + free(polygonIndexArray); + polygonIndexArray = malloc(polygonArrayAllocSize * sizeof(unsigned int)); } while (unsortedVertexArraySize + (int)iNumPts > unsortedVertexArrayAllocSize) From 2093bf27b9e3b89595569e9cb69ef89c9086fd64 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:12:40 +0100 Subject: [PATCH 12/16] clean up drawfill transparency --- src/hardware/hw_draw.c | 5 ++--- src/v_video.c | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c index 99c90243e..8feb7c050 100644 --- a/src/hardware/hw_draw.c +++ b/src/hardware/hw_draw.c @@ -1074,10 +1074,9 @@ void HWR_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 color) else if (alphalevel == 14) Surf.PolyColor.s.alpha = softwaretranstogl[hudtrans]; else if (alphalevel == 15) Surf.PolyColor.s.alpha = softwaretranstogl_hi[hudtrans]; else Surf.PolyColor.s.alpha = softwaretranstogl[10-alphalevel]; - HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } - else - HWD.pfnDrawPolygon(&Surf, v, 4, PF_Modulated|PF_NoTexture|PF_NoDepthTest, false); + + HWD.pfnDrawPolygon(&Surf, v, 4, PF_NoTexture|PF_Modulated|PF_Translucent|PF_NoDepthTest, false); } #ifdef HAVE_PNG diff --git a/src/v_video.c b/src/v_video.c index f54bddfdc..d0ccefa1e 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -698,8 +698,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) { UINT8 *dest; const UINT8 *deststop; - INT32 u, v; - UINT32 alphalevel = 0; + UINT32 alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT); if (rendermode == render_none) return; @@ -776,7 +775,7 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) dest = screens[0] + y*vid.width + x; deststop = screens[0] + vid.rowbytes * vid.height; - if ((alphalevel = ((c & V_ALPHAMASK) >> V_ALPHASHIFT))) + if (alphalevel) { if (alphalevel == 13) alphalevel = hudminusalpha[cv_translucenthud.value]; @@ -790,21 +789,20 @@ void V_DrawFill(INT32 x, INT32 y, INT32 w, INT32 h, INT32 c) } c &= 255; - - if (!alphalevel) { + + if (alphalevel) + { + const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<= 0) && dest < deststop; dest += vid.width) + { + for (x = 0; x < w; x++) + dest[x] = fadetable[dest[x]]; + } + } + else + { for (;(--h >= 0) && dest < deststop; dest += vid.width) memset(dest, c, w * vid.bpp); - } else { // holy fuck i hope this doesent break lmao - const UINT8 *fadetable = ((UINT8 *)transtables + ((alphalevel-1)<y) ? y : x - w = clip(w,vid.width); - h = clip(h,vid.height); -#undef clip - for (v = 0; v < h; v++, dest += vid.width) { - for (u = 0; u < w; u++) { - dest[u] = fadetable[dest[u]]; - } - } } } From be3a57c8abb11a114d03e5925524307914304c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:59:04 +0100 Subject: [PATCH 13/16] proper big room fix no idea what i was doing here, pointtoangle64 does all we need, no need for a hacky 64bit pointtoangleex --- src/hardware/hw_main.c | 8 ++++---- src/r_bsp.c | 8 ++++---- src/r_main.c | 43 +++++++++++++++++------------------------- src/r_main.h | 2 +- 4 files changed, 26 insertions(+), 35 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 8ecc6975f..b2a4bdde8 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -2891,8 +2891,8 @@ void HWR_AddLine(seg_t *line) } // OPTIMIZE: quickly reject orthogonal back sides. - angle1 = R_PointToAngleEx64(viewx, viewy, v1x, v1y); - angle2 = R_PointToAngleEx64(viewx, viewy, v2x, v2y); + angle1 = R_PointToAngle64(v1x, v1y); + angle2 = R_PointToAngle64(v2x, v2y); // do an extra culling check when rendering portals // check if any line vertex is on the viewable side of the portal target line @@ -3085,8 +3085,8 @@ boolean HWR_CheckBBox(fixed_t *bspcoord) if (mindist > current_bsp_culling_distance) return false; } - angle1 = R_PointToAngleEx64(viewx, viewy, px1, py1); - angle2 = R_PointToAngleEx64(viewx, viewy, px2, py2); + angle1 = R_PointToAngle64(px1, py1); + angle2 = R_PointToAngle64(px2, py2); return gld_clipper_SafeCheckRange(angle2, angle1); } diff --git a/src/r_bsp.c b/src/r_bsp.c index 795ef459c..8750c2ee3 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -410,8 +410,8 @@ static void R_AddLine(seg_t *line) return; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngle64(line->v1->x, line->v1->y); + angle2 = R_PointToAngle64(line->v2->x, line->v2->y); curline = line; // Clip to view edges. @@ -613,8 +613,8 @@ static boolean R_CheckBBox(const fixed_t *bspcoord) check = checkcoord[boxpos]; // big room fix - angle1 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[0]], bspcoord[check[1]]) - viewangle; - angle2 = R_PointToAngleEx64(viewx, viewy, bspcoord[check[2]], bspcoord[check[3]]) - viewangle; + angle1 = R_PointToAngle64(bspcoord[check[0]], bspcoord[check[1]]) - viewangle; + angle2 = R_PointToAngle64(bspcoord[check[2]], bspcoord[check[3]]) - viewangle; if ((signed)angle1 < (signed)angle2) { diff --git a/src/r_main.c b/src/r_main.c index 08bd34cb6..f067558e4 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -395,6 +395,23 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y) 0; } +// This version uses 64-bit variables to avoid overflows with large values. +angle_t R_PointToAngle64(INT64 x, INT64 y) +{ + return (y -= viewy, (x -= viewx) || y) ? + x >= 0 ? + y >= 0 ? + (x > y) ? tantoangle[SlopeDivEx(y,x)] : // octant 0 + ANGLE_90-tantoangle[SlopeDivEx(x,y)] : // octant 1 + x > (y = -y) ? 0-tantoangle[SlopeDivEx(y,x)] : // octant 8 + ANGLE_270+tantoangle[SlopeDivEx(x,y)] : // octant 7 + y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDivEx(y,x)] : // octant 3 + ANGLE_90 + tantoangle[SlopeDivEx(x,y)] : // octant 2 + (x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDivEx(y,x)] : // octant 4 + ANGLE_270-tantoangle[SlopeDivEx(x,y)] : // octant 5 + 0; +} + angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) { return (y -= pviewy, (x -= pviewx) || y) ? @@ -489,32 +506,6 @@ angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1) 0; } -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1) -{ - INT64 dx = x1 - x2; - INT64 dy = y1 - y2; - - // Check for potential overflow or underflow - if (dx < INT64_MIN || dx > INT64_MAX || dy < INT64_MIN || dy > INT64_MAX) - { - x1 = (INT64)(dx / 2 + x2); - y1 = (INT64)(dy / 2 + y2); - } - - return (y1 -= y2, (x1 -= x2) || y1) ? - x1 >= 0 ? - y1 >= 0 ? - (x1 > y1) ? tantoangle[SlopeDivEx(y1, x1)] : // octant 0 - ANGLE_90 - tantoangle[SlopeDivEx(x1, y1)] : // octant 1 - x1 > (y1 = -y1) ? 0 - tantoangle[SlopeDivEx(y1, x1)] : // octant 8 - ANGLE_270 + tantoangle[SlopeDivEx(x1, y1)] : // octant 7 - y1 >= 0 ? (x1 = -x1) > y1 ? ANGLE_180 - tantoangle[SlopeDivEx(y1, x1)] : // octant 3 - ANGLE_90 + tantoangle[SlopeDivEx(x1, y1)] : // octant 2 - (x1 = -x1) > (y1 = -y1) ? ANGLE_180 + tantoangle[SlopeDivEx(y1, x1)] : // octant 4 - ANGLE_270 - tantoangle[SlopeDivEx(x1, y1)] : // octant 5 - 0; -} - // // R_ScaleFromGlobalAngle // Returns the texture mapping scale for the current line (horizontal span) diff --git a/src/r_main.h b/src/r_main.h index 6a7ea7da6..dadb1c9cf 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -68,9 +68,9 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; INT32 R_PointOnSide(fixed_t x, fixed_t y, node_t *node); INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line); angle_t R_PointToAngle(fixed_t x, fixed_t y); +angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PointToAngleEx(INT32 x2, INT32 y2, INT32 x1, INT32 y1); -angle_t R_PointToAngleEx64(INT64 x2, INT64 y2, INT64 x1, INT64 y1); fixed_t R_PointToDist(fixed_t x, fixed_t y); fixed_t R_PointToDist2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); angle_t R_PlayerSliptideAngle(player_t *player); From 48320b5f96d1cb98c6b72618a1a1aa234f4a6db9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 08:35:45 +0100 Subject: [PATCH 14/16] this can be static --- src/r_things.c | 2 +- src/r_things.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 498c46bf4..e7670ce88 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2669,7 +2669,7 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) // R_ClipVisSprite // Clips vissprites without drawing, so that portals can work. -Red -void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) +static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2) { drawseg_t *ds; INT32 x; diff --git a/src/r_things.h b/src/r_things.h index 966ff3df1..823bad9a8 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -182,7 +182,6 @@ typedef struct vissprite_s extern UINT32 visspritecount, numvisiblesprites; void R_ClipSprites(void); -void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2); UINT8 *R_GetSpriteTranslation(vissprite_t *vis); From 7edfdf932577b8576776ade8ea2f49b715bbe084 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 13:47:13 +0100 Subject: [PATCH 15/16] forgor --- src/hardware/hw_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index b2a4bdde8..49a9a6ce7 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -5945,8 +5945,8 @@ static void HWR_PortalClipping(gl_portal_t *portal) line_t *line = &lines[portal->clipline]; - angle1 = R_PointToAngleEx64(viewx, viewy, line->v1->x, line->v1->y); - angle2 = R_PointToAngleEx64(viewx, viewy, line->v2->x, line->v2->y); + angle1 = R_PointToAngleEx(viewx, viewy, line->v1->x, line->v1->y); + angle2 = R_PointToAngleEx(viewx, viewy, line->v2->x, line->v2->y); // clip things that are not inside the portal window from our viewpoint gld_clipper_SafeAddClipRange(angle2, angle1); From e2a4fdc39525109b64e799671fd6b9cb9913abfc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 15 Jan 2024 15:57:17 +0100 Subject: [PATCH 16/16] Revert "Localskins on replays" This reverts commit e1f821e121c5032fbafee7d0eefc9f2cbd3efc20. --- src/g_game.c | 29 ++--------------------------- src/g_game.h | 1 - src/r_things.c | 2 -- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index dceaafa29..38f063f62 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -3012,9 +3012,6 @@ void G_SpawnPlayer(INT32 playernum, boolean starpost) } P_MovePlayerToSpawn(playernum, spawnpoint); - // TODO: This is so dumb. - demo_extradata[playernum] |= DXD_LOCALSKIN; - #ifdef HAVE_BLUA LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :) #endif @@ -3350,7 +3347,7 @@ void G_AddPlayer(INT32 playernum) p->jointime = 0; p->playerstate = PST_REBORN; - demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN|DXD_LOCALSKIN; // Set everything + demo_extradata[playernum] |= DXD_PLAYSTATE|DXD_COLOR|DXD_NAME|DXD_SKIN; // Set everything } void G_ExitLevel(void) @@ -5349,14 +5346,7 @@ void G_ReadDemoExtraData(void) else if (G_RaceGametype()) P_CheckRacers(); // also SRB2Kart } - if (extradata & DXD_LOCALSKIN) - { - // TODO: Does this work just fine? - M_Memcpy(name, demo_p, 16); - //CONS_Printf("Loaded localskin data from replay: %s\n", name); - demo_p += 16; - SetLocalPlayerSkin(p, name, NULL); - } + p = READUINT8(demo_p); } @@ -5443,21 +5433,6 @@ void G_WriteDemoExtraData(void) else WRITEUINT8(demo_p, DXD_PST_PLAYING); } - if (demo_extradata[i] & DXD_LOCALSKIN) - { - // Skin - memset(name, 0, 16); - // check for different localskin conditions - if (players[i].skinlocal && players[i].localskin > 0) - strncpy(name, localskins[players[i].localskin - 1].name, 16); - else if (!players[i].skinlocal && players[i].localskin > 0) - strncpy(name, skins[players[i].localskin - 1].name, 16); - else - strncpy(name, "none", 16); - //CONS_Printf("Saved localskin data to replay: %s\n", name); - M_Memcpy(demo_p,name,16); - demo_p += 16; - } } demo_extradata[i] = 0; diff --git a/src/g_game.h b/src/g_game.h index 6491472e6..a57468a2e 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -297,7 +297,6 @@ extern UINT8 demo_writerng; #define DXD_NAME 0x04 // name changed #define DXD_COLOR 0x08 // color changed #define DXD_PLAYSTATE 0x10 // state changed between playing, spectating, or not in-game -#define DXD_LOCALSKIN 0x20 // localskin changed #define DXD_PST_PLAYING 0x01 #define DXD_PST_SPECTATING 0x02 diff --git a/src/r_things.c b/src/r_things.c index e7670ce88..b9fb384f8 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -3274,8 +3274,6 @@ void SetLocalPlayerSkin(INT32 playernum, const char *skinname, consvar_t *cvar) CV_StealthSet(cvar, "none"); } } - - demo_extradata[playernum] |= DXD_LOCALSKIN; } // Same as SetPlayerSkin, but uses the skin #.