From 0eacda7494555518490ec8f27a7cc618185a06f5 Mon Sep 17 00:00:00 2001 From: SteelT Date: Thu, 8 Feb 2024 01:26:07 -0500 Subject: [PATCH 01/18] discord.c: Fix joinSecret memory leak --- src/discord.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/discord.c b/src/discord.c index a5e5f59c9..fd820bdfa 100644 --- a/src/discord.c +++ b/src/discord.c @@ -474,6 +474,7 @@ void DRPC_UpdatePresence(void) char charname[11+SKINNAMESIZE+1]; boolean joinSecretSet = false; + char *clientJoinSecret = NULL; DiscordRichPresence discordPresence; memset(&discordPresence, 0, sizeof(discordPresence)); @@ -530,7 +531,8 @@ void DRPC_UpdatePresence(void) // Grab the host's IP for joining. if ((join = DRPC_GetServerIP()) != NULL) { - discordPresence.joinSecret = DRPC_XORIPString(join); + clientJoinSecret = DRPC_XORIPString(join); + discordPresence.joinSecret = clientJoinSecret; joinSecretSet = true; } } @@ -712,6 +714,7 @@ void DRPC_UpdatePresence(void) } Discord_UpdatePresence(&discordPresence); + free(clientJoinSecret); } #endif // HAVE_DISCORDRPC From 090580badf456a86e4ca4b4260fabd4e3eacf0b1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 17 Oct 2026 17:17:49 +0200 Subject: [PATCH 02/18] replace number with COM_SPLITSCREEN --- src/command.c | 1 + src/lua_consolelib.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 3ba7a2972..74a41abff 100644 --- a/src/command.c +++ b/src/command.c @@ -1739,6 +1739,7 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) // send the value of the variable UINT8 buf[128]; UINT8 *p = buf; + if (!(server || (IsPlayerAdmin(consoleplayer)))) { CONS_Alert(CONS_NOTICE, "Only the server or admin can change: %s %s\n", var->name, var->string); diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 0f6b74f88..f82a6191e 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -182,14 +182,19 @@ void COM_Lua_f(void) len = (argc+1)*256; buf = malloc(len); + if (buf == NULL) + I_Error("Failed to allocate buffer for COM_Lua_f"); + p = buf; WRITEUINT8(p, argc); for (i = 0; i < argc; i++) WRITESTRINGN(p, COM_Argv(i), 255); - if (flags & 2) + + if (flags & COM_SPLITSCREEN) SendNetXCmdForPlayer(1, XD_LUACMD, buf, p-buf); else SendNetXCmd(XD_LUACMD, buf, p-buf); + free(buf); return; } From f4ac08d09f1d2f124aad16ff14321acf26c344ce Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 Oct 2026 12:46:47 +0100 Subject: [PATCH 03/18] some smaller mobj related things mostly cleanup and correctness fixes for phobos build --- src/k_kart.c | 8 +-- src/p_mobj.c | 135 +++++++++++++++++++++++++++++---------------------- src/p_mobj.h | 8 ++- src/p_user.c | 2 +- 4 files changed, 85 insertions(+), 68 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 86ae4f135..703df187f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3343,8 +3343,8 @@ static void K_StretchPlayerGravity(player_t *player) mobj_t *pmo = player->mo; - fixed_t tempxscale = pmo->realxscale; - fixed_t tempyscale = pmo->realyscale; + const fixed_t tempxscale = pmo->realxscale; + const fixed_t tempyscale = pmo->realyscale; stretchScaleFactor = FixedDiv(mapobjectscale*60, cv_gravstretch.value); stretchScaleFactor = min(stretchScaleFactor, MAXSTRETCHDIV); @@ -3398,8 +3398,8 @@ static void K_SaltySquish(player_t *player) mobj_t *pmo = player->mo; - fixed_t tempxscale = pmo->realxscale; - fixed_t tempyscale = pmo->realyscale; + const fixed_t tempxscale = pmo->realxscale; + const fixed_t tempyscale = pmo->realyscale; if (pmo->stretchslam > 0) { diff --git a/src/p_mobj.c b/src/p_mobj.c index c58ed2e89..7639b4c09 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -9187,6 +9187,12 @@ static boolean P_MobjPushableThink(mobj_t *mobj) static void P_FiringThink(mobj_t *mobj) { + if (!mobj->target) + return; + + if (mobj->health <= 0) + return; + if (mobj->state->action == (actionf_p1)A_Boss1Laser) { var1 = mobj->state->var1; @@ -9249,7 +9255,12 @@ void P_MobjThinker(mobj_t *mobj) mobj->flags2 &= ~MF2_PUSHED; mobj->eflags &= ~(MFE_SPRUNG|MFE_JUSTBOUNCEDWALL); +#ifdef PHOBOS_BUILD + P_SetTarget(&tmfloorthing, NULL); + P_SetTarget(&tmhitthing, NULL); +#else tmfloorthing = tmhitthing = NULL; +#endif // do NOT trigger linedef executors for "local" mobjs if (!mobj->islocal) @@ -9265,8 +9276,13 @@ void P_MobjThinker(mobj_t *mobj) } if (mobj->scale != mobj->destscale) + { P_MobjScaleThink(mobj); // Slowly scale up/down to reach your destscale. + if (P_MobjWasRemovedCompat(mobj)) + return; + } + if (!mobj->player) { if (mobj->type == MT_GHOST && mobj->fuse > 0 // Not guaranteed to be MF_SCENERY or not MF_SCENERY! @@ -9311,6 +9327,21 @@ void P_MobjThinker(mobj_t *mobj) { if (!P_MobjDeadThink(mobj)) return; + + // Fading tile + if (mobj->type >= MT_BOUNCEPICKUP && mobj->type <= MT_GRENADEPICKUP) + { + INT32 value = mobj->info->damage/10; + value = mobj->fuse/value; + value = 10-value; + value--; + + if (value <= 0) + value = 1; + + mobj->frame &= ~FF_TRANSMASK; + mobj->frame |= value << FF_TRANSSHIFT; + } } else { @@ -9321,7 +9352,7 @@ void P_MobjThinker(mobj_t *mobj) if (P_MobjWasRemoved(mobj)) return; - if (mobj->flags2 & MF2_FIRING && mobj->target && mobj->health > 0) + if (mobj->flags2 & MF2_FIRING) P_FiringThink(mobj); if (mobj->flags & MF_AMBIENT) @@ -9388,23 +9419,27 @@ void P_MobjThinker(mobj_t *mobj) P_ButteredSlope(mobj); } - if (mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->health && - P_CheckDeathPitCollide(mobj)) // extra pit check in case these didn't have momz + if (mobj->health) { - P_KillMobj(mobj, NULL, NULL); - return; - } - - // Crush enemies! - if (mobj->ceilingz - mobj->floorz < mobj->height) - { - if (((mobj->flags & (MF_ENEMY|MF_BOSS) && mobj->flags & MF_SHOOTABLE) || mobj->type == MT_EGGSHIELD) && - !(mobj->flags & MF_NOCLIPHEIGHT) && - mobj->health > 0) + // extra pit check in case these didn't have momz + if ((mobj->flags & (MF_ENEMY|MF_BOSS)) && + P_CheckDeathPitCollide(mobj)) { P_KillMobj(mobj, NULL, NULL); return; } + + // Crush enemies! + if ((mobj->ceilingz - mobj->floorz) < mobj->height) + { + if ((((mobj->flags & (MF_ENEMY|MF_BOSS)) && (mobj->flags & MF_SHOOTABLE)) || mobj->type == MT_EGGSHIELD) && + !(mobj->flags & MF_NOCLIPHEIGHT) && + mobj->health > 0) + { + P_KillMobj(mobj, NULL, NULL); + return; + } + } } if (P_MobjWasRemovedCompat(mobj)) @@ -9412,24 +9447,6 @@ void P_MobjThinker(mobj_t *mobj) // Can end up here if a player dies. P_CycleMobjState(mobj); - - if (P_MobjWasRemoved(mobj)) - return; - - if ((mobj->health == 0) && // Fading tile - (mobj->type >= MT_BOUNCEPICKUP && mobj->type <= MT_GRENADEPICKUP)) - { - INT32 value = mobj->info->damage/10; - value = mobj->fuse/value; - value = 10-value; - value--; - - if (value <= 0) - value = 1; - - mobj->frame &= ~FF_TRANSMASK; - mobj->frame |= value << FF_TRANSSHIFT; - } } // Quick, optimized function for the Rail Rings @@ -9683,20 +9700,13 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type) // All mobjs are created at 100% scale. mobj->scale = FRACUNIT; - mobj->destscale = mobj->scale; - mobj->scalespeed = FRACUNIT/12; - - if (mapobjectscale != FRACUNIT) //&& !(mobj->type == MT_BLACKEGGMAN) - { - mobj->destscale = mapobjectscale; - mobj->scalespeed = mapobjectscale/12; - } + mobj->destscale = mapobjectscale; + mobj->scalespeed = mapobjectscale/12; // Sprite rendering mobj->blendmode = AST_TRANSLUCENT; - mobj->realxscale = mobj->realyscale = mobj->scale; - mobj->spritexscale = mobj->realxscale; - mobj->spriteyscale = mobj->realyscale; + mobj->realxscale = mobj->realyscale = + mobj->spritexscale = mobj->spriteyscale = mobj->scale; // set subsector and/or block links P_SetThingPosition(mobj); @@ -10138,20 +10148,13 @@ mobj_t *P_SpawnShadowMobj(mobj_t * caster) // All mobjs are created at 100% scale. mobj->scale = FRACUNIT; - mobj->destscale = mobj->scale; - mobj->scalespeed = FRACUNIT/12; - - if (mapobjectscale != FRACUNIT) //&& !(mobj->type == MT_BLACKEGGMAN) - { - mobj->destscale = mapobjectscale; - mobj->scalespeed = mapobjectscale/12; - } + mobj->destscale = mapobjectscale; + mobj->scalespeed = mapobjectscale/12; // Sprite rendering mobj->blendmode = AST_TRANSLUCENT; - mobj->realxscale = mobj->realyscale = mobj->scale; - mobj->spritexscale = mobj->realxscale; - mobj->spriteyscale = mobj->realyscale; + mobj->realxscale = mobj->realyscale = + mobj->spritexscale = mobj->spriteyscale = mobj->scale; // set subsector and/or block links P_SetThingPosition(mobj); @@ -10251,7 +10254,9 @@ static precipmobj_t *P_SpawnPrecipMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype P_CalculatePrecipFloor(mobj); if (mobj->floorz != starting_floorz) - mobj->precipflags |= PCF_FOF; + { + ; //mobj->precipflags |= PCF_FOF; + } else { const INT32 special = GETSECSPECIAL(mobj->subsector->sector->special, 1); @@ -10385,7 +10390,13 @@ void P_RemoveMobj(mobj_t *mobj) // clear the reference from the mapthing if (mobj->spawnpoint) + { +#ifdef PHOBOS_BUILD + P_SetTarget(&mobj->spawnpoint->mobj, NULL); +#else mobj->spawnpoint->mobj = NULL; +#endif + } R_RemoveMobjInterpolator(mobj); @@ -10596,6 +10607,9 @@ void P_PrecipitationEffects(void) P_SpawnLightningFlash(ss); // Spawn a quick flash thinker } + if (sound_disabled) + return; // Sound off? D'aw, no fun. + const mobj_t *pmo = players[displayplayers[0]].mo; // Local effects from here on out! @@ -10603,9 +10617,6 @@ void P_PrecipitationEffects(void) if (!playeringame[displayplayers[0]] || !pmo) return; - if (sound_disabled) - return; // Sound off? D'aw, no fun. - const boolean sounds_rain = ((cv_drawdist_precip.value != 0) && rainsfx && (!leveltime || leveltime % 80 == 1)); if (!sounds_rain && !sounds_thunder) @@ -10853,7 +10864,9 @@ void P_SpawnPlayer(INT32 playernum) mobj_t *mobj; if (p->playerstate == PST_REBORN) + { G_PlayerReborn(playernum); + } for (i = 0; i < MAXPLAYERS; i++) { @@ -10927,9 +10940,15 @@ void P_SpawnPlayer(INT32 playernum) } mobj = P_SpawnMobj(0, 0, 0, MT_PLAYER); + I_Assert(mobj != NULL); + +#ifdef PHOBOS_BUILD + mobj->player = p; + P_SetTarget(&p->mo, mobj); +#else (mobj->player = p)->mo = mobj; - //P_SetTarget(&p->mo, mobj); +#endif mobj->angle = mobj->old_angle = 0; diff --git a/src/p_mobj.h b/src/p_mobj.h index d05457052..2080ab451 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -258,12 +258,10 @@ typedef enum // PRECIPITATION flags ?! ?! ?! // typedef enum { - PCF_INVISIBLE = 1, // Don't draw. + PCF_INVISIBLE = 1, // Don't draw. PCF_PIT = 1<<1, // Above pit. - PCF_FOF = 1<<2, // Above FOF. - PCF_MOVINGFOF = 1<<3, // Above MOVING FOF (this means we need to keep floorz up to date...) - PCF_SPLASH = 1<<4, // Splashed on the ground, return to the ceiling after the animation's over - PCF_THUNK = 1<<5, // Ran the thinker this tic. + PCF_SPLASH = 1<<2, // Splashed on the ground, return to the ceiling after the animation's over + PCF_THUNK = 1<<3, // Ran the thinker this tic. } precipflag_t; diff --git a/src/p_user.c b/src/p_user.c index dd43d41fe..a79163308 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -91,7 +91,7 @@ void P_InstaThrust(mobj_t *mo, angle_t angle, fixed_t move) mo->momx = FixedMul(move, FINECOSINE(angle)); if (!twodmo(mo)) - mo->momy = FixedMul(move,FINESINE(angle)); + mo->momy = FixedMul(move, FINESINE(angle)); } void P_InstaThrustEvenIn2D(mobj_t *mo, angle_t angle, fixed_t move) From 2210bd4e2d3288361537d94c9c21eafdf92b276e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 31 Oct 2026 12:49:05 +0100 Subject: [PATCH 04/18] opengl: fix opaque fof planes checking the wrong sector for encore remap it should check its own "master" sector for remap behavior NOT the sector it resides in note: i did not change the ceiling/floor behavior here as i noticed there might be more issues than this with fofs --- src/hardware/hw_main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 25acb72bc..4efaf513e 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2962,7 +2962,7 @@ static void HWR_Subsector(size_t num) } else { - HWR_GetFlat(flatlump, R_NoEncore(gl_frontsector, !bottom)); + HWR_GetFlat(flatlump, R_NoEncore(rover->master->frontsector, !bottom)); light = R_GetPlaneLight(gl_frontsector, centerHeight, underside); HWR_RenderPlane(sub, &extrasubsectors[num], !bottom, roverheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, flatlump, From 07427b391e0704a66c02afd708038ce7b9b4cca7 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 1 Nov 2026 17:28:30 +0100 Subject: [PATCH 05/18] dont run horizonline code on fofs in opengl this currently does NOT work anyways and just wastes time for nothing on some maps --- src/hardware/hw_main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 4efaf513e..e05d923ee 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -610,7 +610,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool fflatsize = 1024.0f; flatflag = 1023; break; - case 262144:// 512x512 lump + case 262144: // 512x512 lump fflatsize = 512.0f; flatflag = 511; break; @@ -721,7 +721,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool HWR_ProcessPolygon(&Surf, planeVerts, nrPlaneVerts, PolyFlags, shader, false); - if (gl_maphashorizonlines && subsector && cv_glhorizonlines.value) + if (gl_maphashorizonlines && subsector && !FOFsector && cv_glhorizonlines.value) { // Horizon lines FOutVector horizonpts[6]; @@ -742,7 +742,6 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool line_t* ld = line->linedef; - // this check sucks and is a hotspot lel if (LIKELY(ld->special != HORIZONSPECIAL)) continue; From c44d6f6aeb07da9d643ccf5d311bfab0c854c5ea Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Nov 2026 14:31:53 +0100 Subject: [PATCH 06/18] update HWR precache stuff not much but matches stuff i did for blan --- src/hardware/hw_cache.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 13354bda4..95e5d7822 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -625,13 +625,9 @@ static void HWR_PrecacheLevelFlats(void) // lookup for flats that may´ve been already loaded flatcheck flatpresent; size_t i; -#if 0 - size_t j; -#endif INT32 k; - // this kinda messes up encore remapping behavior at times - // so just disable it for now ig + // FIXME: this needs to account for FOFs to properly work #ifdef GLENCORE if (encoremap) { @@ -650,6 +646,7 @@ static void HWR_PrecacheLevelFlats(void) // go through all sectors to determine if it should be remapped for encore for (i = 0; i < numsectors; i++) { + size_t j; sector_t *sec = §ors[i]; // gotta check sector floor and ceiling @@ -738,7 +735,7 @@ static void HWR_PrecacheLevelTextures(void) { const line_t *line = &lines[i]; #ifdef GLENCORE - const int noencoremap = ((encoremap && (line->flags & ML_TFERLINE)) ? 2 : 1); + const boolean noencoremap = (encoremap && (line->flags & ML_TFERLINE)); #endif // two sides for (j = 0; j < 2; j++) @@ -755,25 +752,27 @@ static void HWR_PrecacheLevelTextures(void) { const INT32 texnum = sidetex[f]; - if (texnum < 0 || texnum >= (signed)gl_numtextures) + if (texnum < 0 || (unsigned)texnum >= gl_numtextures) continue; - if (texturepresent[texnum]) - continue; + if (!(texturepresent[texnum] & 1)) + { + texturepresent[texnum] |= 1; + HWR_GetTexture(texnum, false); + } #ifdef GLENCORE - texturepresent[texnum] = 1|noencoremap; -#else - texturepresent[texnum] = 1; -#endif - HWR_GetTexture(texnum, false); -#ifdef GLENCORE - if (noencoremap & 2) + if (noencoremap + && !(texturepresent[texnum] & 2)) + { + texturepresent[texnum] |= 2; HWR_GetTexture(texnum, true); + } #endif } } } + // check for animated textures for (anim = anims; anim < lastanim; anim++) { if (!anim->istexture) @@ -792,6 +791,7 @@ static void HWR_PrecacheLevelTextures(void) { HWR_GetTexture(animtexnum, false); } + #ifdef GLENCORE if (texpresent & 2) { @@ -913,7 +913,7 @@ GLMapTexture_t *HWR_GetTexture(INT32 tex, boolean noencore) GLMapTexture_t *gltex; GLMipmap_t *glMipmap; - if (tex < 0 || tex >= (signed)gl_numtextures) + if (tex < 0 || (unsigned)tex >= gl_numtextures) { #ifdef PARANOIA I_Error("HWR_GetTexture: Invalid texture ID %d", tex); From 1ba4fe99a75d0fcc66c85f533127a1de4f124eb9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Nov 2026 14:38:38 +0100 Subject: [PATCH 07/18] fix fof noencore ceiling checks being flipped in opengl renderer matches software now even if most custom maps were made with opengl in mind, stuff did not work anyways for years so this shouldnt hopefully cause any issues --- src/hardware/hw_main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index e05d923ee..67c7d5817 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2961,7 +2961,7 @@ static void HWR_Subsector(size_t num) } else { - HWR_GetFlat(flatlump, R_NoEncore(rover->master->frontsector, !bottom)); + HWR_GetFlat(flatlump, R_NoEncore(rover->master->frontsector, bottom)); light = R_GetPlaneLight(gl_frontsector, centerHeight, underside); HWR_RenderPlane(sub, &extrasubsectors[num], !bottom, roverheight, HWR_RippleBlend(gl_frontsector, rover, false)|PF_Occlude, *gl_frontsector->lightlist[light].lightlevel, flatlump, @@ -4286,7 +4286,10 @@ static void HWR_RenderDrawNodes(void) gl_frontsector = NULL; if (!(plane->blend & PF_NoTexture)) - HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, plane->isceiling)); + { + const boolean ceiling = plane->FOFSector ? !plane->isceiling : plane->isceiling; // match software! + HWR_GetFlat(plane->lumpnum, R_NoEncore(plane->FOFSector, ceiling)); + } HWR_RenderPlane(NULL, plane->xsub, plane->isceiling, plane->fixedheight, plane->blend, plane->lightlevel, plane->lumpnum, plane->FOFSector, plane->alpha, plane->planecolormap); From e5c6cb635d6b9f43afc715946d5dbf945414b01b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Nov 2026 14:40:48 +0100 Subject: [PATCH 08/18] make teleporter handling in P_ProcessLineSpecial a little less ugly lulul --- src/p_spec.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index bc6267a7c..6752528a1 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1962,13 +1962,19 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (!dest) return; + const angle_t ang = (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle; + const boolean dontstopmove = (line->flags & ML_EFFECT4) == ML_EFFECT4; + if (bot) - P_Teleport(bot, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, (line->flags & ML_BLOCKMONSTERS) == 0, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(bot, dest->x, dest->y, dest->z, ang, (line->flags & ML_BLOCKMONSTERS) == 0, dontstopmove); + if (line->flags & ML_BLOCKMONSTERS) - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, false, (line->flags & ML_EFFECT4) == ML_EFFECT4); + { + P_Teleport(mo, dest->x, dest->y, dest->z, ang, false, dontstopmove); + } else { - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, true, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(mo, dest->x, dest->y, dest->z, ang, true, dontstopmove); // Play the 'bowrwoosh!' sound S_StartSound(dest, sfx_mixup); } From 5183baed44e4d93cbe1e0345a0d87ac9f4ad6cb5 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Nov 2026 14:40:01 +0100 Subject: [PATCH 09/18] make HWR_ApplyDispoffset a little less ugly lol --- src/hardware/hw_main.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 67c7d5817..f862cf18e 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3459,8 +3459,12 @@ static inline void HWR_ApplyDispoffset(gl_vissprite_t *spr, FOutVector *wallVert { HWR_RotateSpritePolyToAim(spr, wallVerts, false, papersprite); - const float sprdist = sqrtf((spr->x1 - gl_viewx)*(spr->x1 - gl_viewx) + (spr->z1 - gl_viewy)*(spr->z1 - gl_viewy) + (spr->gzt - gl_viewz)*(spr->gzt - gl_viewz)); - const float distfact = ((2.0f*spr->dispoffset) + 20.0f) / sprdist; + const float f_xdiff = (spr->x1 - gl_viewx); + const float f_ydiff = (spr->z1 - gl_viewy); + const float f_zdiff = (spr->gzt - gl_viewz); + + const float sprdist = sqrtf((f_xdiff*f_xdiff) + (f_ydiff*f_ydiff) + (f_zdiff*f_zdiff)); + const float distfact = ((2.0f * spr->dispoffset) + 20.0f) / sprdist; for (size_t i = 0; i < 4; i++) { From 51adf8869c8a3dd414ffa869d20415ab5a4f6ab5 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 2 Nov 2026 14:58:40 +0100 Subject: [PATCH 10/18] HWR_PrecacheLevelTextures should also skip texture number 0 whoopsie --- src/hardware/hw_cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 95e5d7822..3b7704cee 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -752,7 +752,7 @@ static void HWR_PrecacheLevelTextures(void) { const INT32 texnum = sidetex[f]; - if (texnum < 0 || (unsigned)texnum >= gl_numtextures) + if (texnum <= 0 || (unsigned)texnum >= gl_numtextures) continue; if (!(texturepresent[texnum] & 1)) From 9682ab59c9beed3a08277d1f3dc557597085f570 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 3 Nov 2026 23:56:22 +0300 Subject: [PATCH 11/18] Make M_CheckParm thread-safe, it is called from different thread in http-mserv.c for example --- src/m_argv.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/m_argv.c b/src/m_argv.c index 36c73d61c..6219b191d 100644 --- a/src/m_argv.c +++ b/src/m_argv.c @@ -13,6 +13,13 @@ #include +#ifdef HAVE_THREADS +#include +#define local_for_thread thread_local +#else +#define local_for_thread +#endif + #include "doomdef.h" #include "command.h" #include "m_argv.h" @@ -31,8 +38,11 @@ char **myargv = NULL; boolean myargmalloc = false; /** \brief founded the parm + * + * thread_local because it can potentially be used from multiple threads (global variables aaaaaa) + * (myargc and myargv don't have to be thread_local because they are never modified after being set up) */ -static INT32 found; +static local_for_thread INT32 found; /** \brief The M_CheckParm function @@ -91,7 +101,7 @@ INT32 M_CheckProtoParam(const char *check) const char *M_GetProtoParam(void) { INT32 i; - static char *string; + char *string; for (i = 1; i < myargc; i++) { From 3adcf608c3c597386d78b7d143e5b99424c54f80 Mon Sep 17 00:00:00 2001 From: Indev Date: Wed, 4 Nov 2026 01:06:18 +0300 Subject: [PATCH 12/18] (Hopefully) fix race condition in replay hut It was probably caused by menupath being modified when replay load thread is in the middle of checking it, now the check for "valid" replay load thread is simpler. Also as comment says, there still are few reported data races for replaynamesloaded but i THINK it should be fine, since the only "data race" that could be harmful here is replaynamesloaded switching from true to false, which would mean demolist_all is suddenly invalidated, and that shouldn't be possible because we only switch replaynamesloaded from true to false inside main thread while also locking the "search mutex" (this is so wordy lol) --- src/m_menu.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 06eb773b6..2c8a625ad 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3984,6 +3984,10 @@ menudemo_t *demolist = NULL; // Replays that that have been checked to match wit menudemo_t *demolist_all = NULL; // All replays size_t demolist_all_size = 0; boolean replaynamesloaded = false; +// Whenever we start a replay load thread, we increment this number and then thread will remember current value, +// and by the end it will compare it with current value, and if it is equal it means thread can store data it has loaded. +// If it's not equal, that means we started more than one thread (left and re-entered menu for example) +size_t replaythreadnum = 0; #ifdef HAVE_THREADS I_mutex replayquerymutex; @@ -4013,12 +4017,14 @@ static SINT8 replayScrollDelay = TICRATE, replayScrollDir = 1; static void ReplayNamesLoadThread(void* userdata) { + (void)userdata; + Lock_search_state(); size_t demolist_all_size_local = demolist_all_size; menudemo_t *demolist_all_local = (menudemo_t*)malloc(sizeof(menudemo_t)*demolist_all_size_local); memcpy(demolist_all_local, demolist_all, sizeof(menudemo_t)*demolist_all_size_local); - char *replaydirpath = (char*)userdata; + size_t localreplaythreadnum = replaythreadnum; Unlock_search_state(); @@ -4038,7 +4044,7 @@ static void ReplayNamesLoadThread(void* userdata) Lock_search_state(); - if (fastcmp(menupath, replaydirpath) && demolist_all) + if (replaythreadnum == localreplaythreadnum && demolist_all) { memcpy(demolist_all, demolist_all_local, sizeof(menudemo_t)*demolist_all_size); replaynamesloaded = true; @@ -4047,22 +4053,20 @@ static void ReplayNamesLoadThread(void* userdata) Unlock_search_state(); // Was allocated before thread start, we need to free it - free(replaydirpath); free(demolist_all_local); } static void LoadReplayNames(void) { - char *replaydirpath = strdup(menupath); - Lock_search_state(); + replaythreadnum++; replaynamesloaded = false; Unlock_search_state(); #ifdef HAVE_THREADS - I_spawn_thread("replay-names-load", ReplayNamesLoadThread, replaydirpath); + I_spawn_thread("replay-names-load", ReplayNamesLoadThread, NULL); #else - ReplayNamesLoadThread(replaydirpath); + ReplayNamesLoadThread(NULL); #endif } @@ -4101,8 +4105,12 @@ static void M_HutCheckReplays(size_t maxnum) // Mark as done replayqueryfound = replayquerycheck = sizedirmenu; + Lock_search_state(); + memcpy(demolist, demolist_all, sizeof(menudemo_t) * sizedirmenu); + Unlock_search_state(); + return; } @@ -4251,13 +4259,15 @@ static boolean M_HandleReplayHutQuery(INT32 choice) char tmp[MAXREPLAYQUERY+1]; memcpy(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1); - Lock_search_state(); + // Honestly not sure if locks for replaynamesloaded are necessary... + // Thread sanitizer does report race condition whenever replaynamesloaded is accessed without lock + // but really it is only ever set to false in main thread and only set to true in replay load thread, + // and both are done via locks. If replaynamesloaded is true, it is never gonna suddenly switch from true to false + // while we're in main thread, and if it would switch from false to true it is not really a big deal, we will just skip + // 1 frame where replay names were loaded + if (!replaynamesloaded) - { - Unlock_search_state(); return false; - } - Unlock_search_state(); if (M_TextInputHandle(&replayqueryinput, choice)) { From eba1cfb94de43ff1e602a31e63994100c67fc2b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 4 Nov 2026 00:18:52 +0100 Subject: [PATCH 13/18] remove "flatcheck" from HWR_PrecacheLevelFlats in practice this did nothing really would be more useful for encore but that aint working for us so whatever --- src/hardware/hw_cache.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/src/hardware/hw_cache.c b/src/hardware/hw_cache.c index 3b7704cee..d50076813 100644 --- a/src/hardware/hw_cache.c +++ b/src/hardware/hw_cache.c @@ -614,16 +614,8 @@ void HWR_FreeMapTextures(void) gl_numtextures = 0; } -#define NAME flatcheck -#define KEY_TY UINT32 -#define HASH_FN vt_hash_integer -#define CMPR_FN vt_cmpr_integer -#include "../verstable.h" - static void HWR_PrecacheLevelFlats(void) { - // lookup for flats that may´ve been already loaded - flatcheck flatpresent; size_t i; INT32 k; @@ -635,9 +627,6 @@ static void HWR_PrecacheLevelFlats(void) } #endif - flatcheck_init(&flatpresent); - flatcheck_reserve(&flatpresent, numlevelflats); - // special case for encore #if 0 #ifdef GLENCORE @@ -689,11 +678,7 @@ static void HWR_PrecacheLevelFlats(void) { const levelflat_t *levelflat = &levelflats[i]; - if (flatcheck_is_end(flatcheck_get(&flatpresent, levelflat->lumpnum))) - { - HWR_GetFlat(levelflat->lumpnum, false); - flatcheck_insert(&flatpresent, levelflat->lumpnum); - } + HWR_GetFlat(levelflat->lumpnum, false); if (levelflat->speed) // is it an animated flat ? { @@ -701,17 +686,11 @@ static void HWR_PrecacheLevelFlats(void) for (k = 0; k < levelflat->numpics; k++) { lumpnum_t lump = levelflat->baselumpnum + k; - if (flatcheck_is_end(flatcheck_get(&flatpresent, lump))) - { - HWR_GetFlat(lump, false); - flatcheck_insert(&flatpresent, lump); - } + HWR_GetFlat(lump, false); } } } } - - flatcheck_cleanup(&flatpresent); } static void HWR_PrecacheLevelTextures(void) From cb5d3ab4e1bfc883d833894f21852b0012e9fd64 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 4 Nov 2026 01:38:15 +0100 Subject: [PATCH 14/18] add compile flag for building with thread sanitizer indev noticed thats a thing that exists wouldve been quite useful a bunch of times before lol also some fixes for the other sanitizer flags --- src/CMakeLists.txt | 2 ++ src/Makefile | 23 ++++++++++++++++++----- src/dedicated/CMakeLists.txt | 11 ++++++++--- src/sdl/CMakeLists.txt | 11 ++++++++--- 4 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2618d4077..d4296d362 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -246,6 +246,8 @@ set(SRB2_CONFIG_ASAN OFF CACHE BOOL "Compile with AddressSanitizer (libasan).") set(SRB2_CONFIG_UBSAN OFF CACHE BOOL "Compile with UndefinedBehaviorSanitizer (libubsan).") +set(SRB2_CONFIG_TSAN OFF CACHE BOOL + "Compile with ThreadSanitizer (libtsan).") set(SRB2_CONFIG_MUMBLE ON CACHE BOOL "Enable Mumble support") diff --git a/src/Makefile b/src/Makefile index 27831946a..159d3f7d0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -75,6 +75,7 @@ # PROFILEMODE=1 - Enable performance profiling (gprof). # USEASAN=1 - Enable building with Address Sanitizer. # USEUBSAN=1 - Enable building with Undefined Behavior Sanitizer. +# USETSAN=1 - Enable building with Thread Sanitizer. # NOLIBBACKTRACE=1 - Disable using Libbacktrace for crashlog traces. # # General flags for building: @@ -261,23 +262,35 @@ debug_opts=-D_DEBUG else # build a normal optimized version debug_opts=-DNDEBUG opts+=-O3 -ifndef NOLTO -# compile with LTO -opts+=-flto=auto -libs+=-flto=auto -endif endif ifdef USEASAN # compile with asan opts+=-O1 -fsanitize=address -fno-omit-frame-pointer -fno-common libs+=-fsanitize=address +NOLTO=1 endif ifdef USEUBSAN # compile with ubsan opts+=-O1 -fsanitize=undefined -fno-omit-frame-pointer libs+=-fsanitize=undefined +NOLTO=1 +endif + +ifdef USETSAN +# compile with tsan +opts+=-O1 -fsanitize=thread -fno-omit-frame-pointer +libs+=-fsanitize=thread +NOLTO=1 +endif + +ifndef DEBUGMODE +ifndef NOLTO +# compile with LTO +opts+=-flto=auto +libs+=-flto=auto +endif endif ifdef USEJEMALLOC diff --git a/src/dedicated/CMakeLists.txt b/src/dedicated/CMakeLists.txt index 38fb179f0..923f55596 100644 --- a/src/dedicated/CMakeLists.txt +++ b/src/dedicated/CMakeLists.txt @@ -119,20 +119,25 @@ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS ) -if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) +if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE AND NOT SRB2_CONFIG_ASAN AND NOT SRB2_CONFIG_UBSAN AND NOT SRB2_CONFIG_TSAN) set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() if(SRB2_CONFIG_ASAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=address -fno-omit-frame-pointer -fno-common) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() if(SRB2_CONFIG_UBSAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=undefined -fno-omit-frame-pointer) target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) endif() +if(SRB2_CONFIG_TSAN) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=thread -fno-omit-frame-pointer) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=thread) +endif() + ## strip debug symbols into separate file when using gcc # if(CMAKE_COMPILER_IS_GNUCC) # if(${CMAKE_BUILD_TYPE} MATCHES Debug) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 664010072..866d2bc55 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -233,20 +233,25 @@ if(${SDL2_FOUND}) -DHAVE_THREADS ) - if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE) + if(SRB2_CONFIG_LTO AND NOT SRB2_CONFIG_DEBUGMODE AND NOT SRB2_CONFIG_ASAN AND NOT SRB2_CONFIG_UBSAN AND NOT SRB2_CONFIG_TSAN) set_property(TARGET SRB2SDL2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() if(SRB2_CONFIG_ASAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=address) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=address -fno-omit-frame-pointer -fno-common) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() if(SRB2_CONFIG_UBSAN) - target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=undefined -fno-omit-frame-pointer) target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) endif() + if(SRB2_CONFIG_TSAN) + target_compile_options(SRB2SDL2 PRIVATE -O1 -fsanitize=thread -fno-omit-frame-pointer) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=thread) + endif() + if(NOT SRB2_CONFIG_MUMBLE) target_compile_options(SRB2SDL2 PRIVATE -DNOMUMBLE) endif() From d43b60ad8346a0593ce98ecafeee84eba70ba050 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:37:38 +0100 Subject: [PATCH 15/18] fix blendmodes and line translucency on polyobject sides in gl this is also how vanilla kart handled this code eitherways --- src/hardware/hw_main.cpp | 70 +++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index f862cf18e..d00b42918 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1239,46 +1239,44 @@ static inline boolean HWR_BlendMidtextureSurface(FSurfaceInfo *pSurf) pSurf->PolyColor.s.alpha = 0xFF; - if (LIKELY(!gl_curline->polyseg)) - { - // check if linedef alpha is within range - const boolean linealpha = (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT); + // check if linedef alpha is within range + const boolean linealpha = (gl_linedef->alpha >= 0 && gl_linedef->alpha < FRACUNIT); - // set alpha for transparent walls - switch (gl_linedef->special) - { - // Translucent linedef types - case 102: - case 121 ... 125: - case 141 ... 145: - case 174: - case 175: - case 192: - case 195: - case 221: - case 253: - case 256: - if (gl_linedef->blendmode && linealpha) + // set alpha for transparent walls + switch (gl_linedef->special) + { + // Translucent linedef types + case 102: + case 121 ... 125: + case 141 ... 145: + case 174: + case 175: + case 192: + case 195: + case 221: + case 253: + case 256: + if (gl_linedef->blendmode && linealpha) + blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Translucent; + break; + default: + if (gl_linedef->blendmode) + { + if (linealpha) blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); else - blendmode = PF_Translucent; - break; - default: - if (gl_linedef->blendmode) - { - if (linealpha) - blendmode = HWR_SurfaceBlend(gl_linedef->blendmode, R_GetLinedefTransTable(gl_linedef->alpha), pSurf); - else - blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); - } - else if (linealpha) - blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), pSurf); - else - blendmode = PF_Masked; - break; - } + blendmode = HWR_GetBlendModeFlag(gl_linedef->blendmode); + } + else if (linealpha) + blendmode = HWR_TranstableToAlpha(R_GetLinedefTransTable(gl_linedef->alpha), pSurf); + else + blendmode = PF_Masked; + break; } - else if (gl_curline->polyseg->translucency > 0) + + if (gl_curline->polyseg && gl_curline->polyseg->translucency > 0) { // Polyobject translucency is shared between all of its lines if (gl_curline->polyseg->translucency >= NUMTRANSMAPS) // wall not drawn From b8aaf63b201fce485b53a130a96db4d339e77efb Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:32:22 +0100 Subject: [PATCH 16/18] use "rawlinedef" when checking for seg issues smth smth byte order or whatever but is consistent with the rest of the code anyways --- src/p_setup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/p_setup.c b/src/p_setup.c index 14a911743..ea4295df4 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -570,13 +570,13 @@ static void P_LoadSegs(UINT8 *data) if (seg->sidedef == &sides[seg->linedef->sidenum[0]]) { - seg->v1 = lines[ms->linedef].v1; - seg->v2 = lines[ms->linedef].v2; + seg->v1 = lines[rawlinedef].v1; + seg->v2 = lines[rawlinedef].v2; } else { - seg->v1 = lines[ms->linedef].v2; - seg->v2 = lines[ms->linedef].v1; + seg->v1 = lines[rawlinedef].v2; + seg->v2 = lines[rawlinedef].v1; } } else @@ -584,7 +584,6 @@ static void P_LoadSegs(UINT8 *data) seg->v1 = &vertexes[v1]; seg->v2 = &vertexes[v2]; } - #ifdef HWRENDER if (rendermode == render_opengl) { @@ -597,7 +596,6 @@ static void P_LoadSegs(UINT8 *data) //seg->fv2.z = FixedToFloat(seg->v2->z); } #endif - seg->length = P_SegLength(seg); P_UpdateSegLightOffset(seg); From c1a0b97c54c8498f87588597667f1d0be3165072 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:33:40 +0100 Subject: [PATCH 17/18] add checks for missing bsp lumps not sure why there werent any, the other map lumps have those, and a corrupted file may have those missing also which would just crash instead of telling you wtf is wrong --- src/p_setup.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/p_setup.c b/src/p_setup.c index ea4295df4..ee2130279 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2094,6 +2094,13 @@ static void P_LoadMapBSP(const virtres_t* virt) virtlump_t* virtsegs = vres_Find(virt, "SEGS"); virtlump_t* virtnodes = vres_Find(virt, "NODES"); + if (!virtssectors) + I_Error("SSECTORS lump not found"); + if (!virtsegs) + I_Error("SEGS lump not found"); + if (!virtnodes) + I_Error("NODES lump not found"); + numsubsectors = virtssectors->size / sizeof(mapsubsector_t); numnodes = virtnodes->size / sizeof(mapnode_t); numsegs = virtsegs->size / sizeof(mapseg_t); From e54b6a780d56b0308527aed84fc136999d4a3076 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 5 Nov 2026 15:31:25 +0100 Subject: [PATCH 18/18] "fix" skywalls on hadal trench and candy lake this whole sky handling is just incredibly stupid and wouldve been such an easy fix, but here we go this is just more stupid hacks but i really dont feel bad here since the code already hacked around a bunch of shit just hoping this wont cause any issues on some maps and needs testing sigh --- src/hardware/hw_main.cpp | 44 ++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index d00b42918..80549f240 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1383,7 +1383,8 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom // two sided line if (gl_backsector) { - INT32 gl_toptexture = 0, gl_bottomtexture = 0; + const INT32 gl_toptexture = R_GetTextureNum(gl_sidedef->toptexture); + const INT32 gl_bottomtexture = R_GetTextureNum(gl_sidedef->bottomtexture); fixed_t texturevpeg; @@ -1394,7 +1395,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (!gl_curline->polyseg) // Don't do it for polyobjects { // Sky Ceilings - wallVerts[3].y = wallVerts[2].y = FLOATMAX; + wallVerts[2].y = wallVerts[3].y = FLOATMAX; // draw to top of map space auto draw_sky_walls = [] (int vert1, int vert2, fixed_t world, fixed_t worldslope, auto& wwallVerts, auto& sSurf) FUNCINLINE @@ -1404,6 +1405,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_DrawSkyWall(wwallVerts, &sSurf); }; + // worldtop = front ceiling + // worldhigh = back ceiling + if (gl_frontsector->ceilingpic == skyflatnum) { if (gl_backsector->ceilingpic == skyflatnum) @@ -1422,6 +1426,17 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom worldtop = worldhigh; worldtopslope = worldhighslope; } + else if (!gl_toptexture && + (worldhigh <= worldtop && worldhighslope <= worldtopslope) && // Assuming ESLOPE is always on with my changes + (worldhigh != worldtop || worldhighslope != worldtopslope)) + { + // Only the frontsector is sky. + // If there's no upper texture, extend the sky wall + // down to the lower of the two ceilings. + fixed_t top = std::min(worldtop, worldhigh); + fixed_t topslope = std::min(worldtopslope, worldhighslope); + draw_sky_walls(0, 1, top, topslope, wallVerts, Surf); + } else { // Only the frontsector is sky, just draw a skywall from the front ceiling @@ -1434,8 +1449,11 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom draw_sky_walls(0, 1, worldtop, worldtopslope, wallVerts, Surf); } + // worldbottom = front floor + // worldlow = back floor + // Sky Floors - wallVerts[0].y = wallVerts[1].y = FLOATMIN; + wallVerts[0].y = wallVerts[1].y = FLOATMIN; // draw to bottom of map space if (gl_frontsector->floorpic == skyflatnum) { @@ -1447,7 +1465,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if ((worldlow >= worldbottom && worldlowslope >= worldbottomslope) && (worldlow != worldbottom || worldlowslope != worldbottomslope) // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race - && !(gl_sidedef->bottomtexture)) + && !(gl_bottomtexture)) { draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); } @@ -1458,15 +1476,25 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom draw_sky_walls(3, 2, worldbottom, worldbottomslope, wallVerts, Surf); } } - else if ((gl_backsector->floorpic == skyflatnum) && !(gl_sidedef->bottomtexture)) + else if ((gl_backsector->floorpic == skyflatnum) && !(gl_bottomtexture)) { // Only the backsector has sky, just draw a skywall from the back floor if there's no bottomtexture draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); } + else if (gl_frontsector->ceilingpic == skyflatnum && + gl_backsector->ceilingpic == skyflatnum && + (worldlow >= worldbottom && worldlowslope >= worldbottomslope) + && (worldlow != worldbottom || worldlowslope != worldbottomslope) + // Removing the second line above will render more rarely visible skywalls. Example: Cave garden ceiling in Dark race + && !(gl_bottomtexture)) + { + // Both ceilings are sky, but neither floor is sky. + // If there's a lower wall gap without a bottom texture, + // draw a skywall from the backsector's higher floor. + draw_sky_walls(3, 2, worldlow, worldlowslope, wallVerts, Surf); + } } - gl_toptexture = R_GetTextureNum(gl_sidedef->toptexture); - // check TOP TEXTURE if (gl_toptexture && (worldhighslope < worldtopslope || worldhigh < worldtop)) { @@ -1530,8 +1558,6 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom HWR_ProjectWall(wallVerts, &Surf, PF_Masked, lightnum, colormap); } - gl_bottomtexture = R_GetTextureNum(gl_sidedef->bottomtexture); - // check BOTTOM TEXTURE if (gl_bottomtexture && (worldlowslope > worldbottomslope || worldlow > worldbottom)) {