From e63f68e732e8e5382dbed8c33771892b16f317ff Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 8 Jun 2025 22:01:41 +0200 Subject: [PATCH] fix portal clipping being completely completely broken on kart maps truly amazing --- src/r_portal.c | 29 +++++++++++++++++++++++++++++ src/r_portal.h | 1 + src/r_segs.cpp | 6 +++--- src/w_wad.c | 4 ++-- 4 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/r_portal.c b/src/r_portal.c index f5e9874d6..416dc4b6f 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -37,6 +37,32 @@ void Portal_InitList (void) portal_base = portal_cap = NULL; } +/** Store the clipping window for a portal in its given range. + * + * The window is copied from the current window at the time + * the function is called, so it is useful for converting one-sided + * lines into portals. + */ +void Portal_ClipRange (portal_t* portal) +{ + INT32 start = portal->start; + INT32 end = portal->end; + INT16 *ceil = portal->ceilingclip; + INT16 *floor = portal->floorclip; + fixed_t *scale = portal->frontscale; + + INT32 i; + for (i = 0; i < end-start; i++) + { + *ceil = ceilingclip[start+i]; + ceil++; + *floor = floorclip[start+i]; + floor++; + *scale = frontscale[start+i]; + scale++; + } +} + /** Apply the clipping window from a portal. */ void Portal_ClipApply (const portal_t* portal) @@ -158,6 +184,9 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con portal->clipline = line2; + if (mapnamespace == MNS_SRB2KART) + Portal_ClipRange(portal); + g_portal = portal; // this tells R_StoreWallRange that curline is a portal seg } diff --git a/src/r_portal.h b/src/r_portal.h index 60bde34bc..05fe3d977 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -58,6 +58,7 @@ void Portal_Remove (portal_t* portal); void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, const INT32 x2); void Portal_AddSkybox (const visplane_t* plane); +void Portal_ClipRange (portal_t* portal); void Portal_ClipApply (const portal_t* portal); void Portal_AddSkyboxPortals (void); diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 7197ee609..0565d5256 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1596,7 +1596,7 @@ static void R_RenderSegLoop (drawcolumndata_t* dc) // Portal line // Spans the entire height of a single-sided line or // the "window" of a double-sided line. - if (g_portal) + if (g_portal && (mapnamespace != MNS_SRB2KART)) { I_Assert(rw_x >= g_portal->start && rw_x < g_portal->end); i = rw_x - g_portal->start; @@ -2245,7 +2245,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || frontsector->extra_colormap != backsector->extra_colormap || (frontsector->ffloors != backsector->ffloors && !Tag_Compare(&frontsector->tags, &backsector->tags)) // Portals block traversal behind them - || g_portal + || (g_portal && mapnamespace != MNS_SRB2KART) // Highlighting death pits || (cv_debugfinishline.value && frontsector->damagetype != backsector->damagetype)) { @@ -2283,7 +2283,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) || frontsector->extra_colormap != backsector->extra_colormap || (frontsector->ffloors != backsector->ffloors && !Tag_Compare(&frontsector->tags, &backsector->tags)) // Portals block traversal behind them - || g_portal + || (g_portal && mapnamespace != MNS_SRB2KART) // Highlighting death pits || (cv_debugfinishline.value && frontsector->damagetype != backsector->damagetype)) { diff --git a/src/w_wad.c b/src/w_wad.c index 6fa3f1a80..2d669bd37 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -1402,7 +1402,7 @@ lumpnum_t W_CheckNumForName(const char *name) INT32 i; UINT32 hash = name ? quickncasehash(name, 8) : 0; lumpnum_t check = INT16_MAX; - + if (name == NULL) return LUMPERROR; @@ -1454,7 +1454,7 @@ lumpnum_t W_CheckNumForLongName(const char *name) INT32 i; UINT32 hash = name ? quickncasehash(name, 8) : 0; lumpnum_t check = INT16_MAX; - + if (name == NULL) return LUMPERROR;