From 20cdec33fb90e9cef9b47ccad8201d2b1e979564 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 19 Jul 2025 22:42:00 +0200 Subject: [PATCH 01/28] fix https://github.com/Indev450/SRB2Kart-Saturn/issues/190 doing it like this, so potentially wonky socked maps dont show up if its disabled --- src/m_menu.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index bab4e4b10..0000fae90 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5721,8 +5721,16 @@ boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt) { case LLM_CREATESERVER: // Should the map be hidden? <-- well imma wanna toggle it, its just annoying being unable to select hell maps in mapselect - if ((mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) && (gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE))) // map hell - return cv_showallmaps.value; + + if (mapheaderinfo[mapnum]->menuflags & LF2_HIDEINMENU && mapnum+1 != gamemap) + { + if (cv_showallmaps.value && + ((gt == GT_RACE && (mapheaderinfo[mapnum]->typeoflevel & TOL_RACE)) || // race map hell + ((gt == GT_MATCH || gt == GT_TEAMMATCH) && (mapheaderinfo[mapnum]->typeoflevel & TOL_MATCH)))) // battle map hell + return true; + else + return false; + } // same goes here, just show every map if i want to if (M_MapLocked(mapnum+1)) // not unlocked From e102d218ff0e85ba10be60631781ba2419b23eea Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 19 Jul 2025 22:54:28 +0200 Subject: [PATCH 02/28] add toggle for quake screenshake effects TODO: make an accessability option menu for certain effects --- src/p_local.h | 2 ++ src/p_tick.c | 6 +++--- src/p_user.c | 2 ++ src/r_main.cpp | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index 38dcc006b..944879fa8 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -158,6 +158,8 @@ extern consvar_t cv_tiltsmoothing; extern consvar_t cv_actionmovie; +extern consvar_t cv_screenquake; + extern consvar_t cv_lookbackmom[MAXSPLITSCREENPLAYERS]; extern consvar_t cv_verticallook[MAXSPLITSCREENPLAYERS]; diff --git a/src/p_tick.c b/src/p_tick.c index 5e1af1b68..9664d50be 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -573,7 +573,7 @@ static void P_RunQuakes(void) { fixed_t ir; - if (quake.time <= 0) + if (!cv_screenquake.value || quake.time <= 0) { quake.x = quake.y = quake.z = quake.roll = 0; return; @@ -618,8 +618,8 @@ static inline void P_ResetSpriteStuff(void) if (!mo || (mo->sprite == SPR_NULL) || (mo->flags2 & MF2_DONTDRAW) || (mo->type == MT_SHADOW)) continue; - mo->spritexscale = mo->realxscale; - mo->spriteyscale = mo->realyscale; + mo->spritexscale = mo->realxscale; + mo->spriteyscale = mo->realyscale; mo->spritexoffset = mo->realxoffset; mo->spriteyoffset = mo->realyoffset; } diff --git a/src/p_user.c b/src/p_user.c index 3dff40e0a..7f643a9ef 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3044,6 +3044,8 @@ consvar_t cv_tiltsmoothing = {"tiltsmoothing", "32", CV_SAVE, CV_Natural, NULL, consvar_t cv_actionmovie = {"actionmovie", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_screenquake = {"quakescreenshake", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; + static CV_PossibleValue_t lookbackmom_cons_t[] = {{0, "Off"}, {1, "On"}, {2, "Double"}, {0, NULL}}; consvar_t cv_lookbackmom[MAXSPLITSCREENPLAYERS] = { diff --git a/src/r_main.cpp b/src/r_main.cpp index fa4425f19..cef57ad2e 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1578,6 +1578,8 @@ void R_RegisterEngineStuff(void) CV_RegisterVar(&cv_tiltsmoothing); CV_RegisterVar(&cv_actionmovie); + CV_RegisterVar(&cv_screenquake); + CV_RegisterVar(&cv_driftsparkpulse); CV_RegisterVar(&cv_gravstretch); CV_RegisterVar(&cv_sloperoll); From fdd19632bfda63b0290271303698f7ce4ccb6fe4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Jul 2025 18:32:37 +0200 Subject: [PATCH 03/28] Use R_RenderSegLoop if the back sector has any 3D floor planes fixes issues in northern district zone --- src/r_segs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 6bc139a2d..02159d40d 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -2888,7 +2888,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) didsolidcol = false; - if (!segtextured && !numffloors) + if (!segtextured && !numffloors && !numbackffloors) { if (markfloor || markceiling) R_MarkSegBounds(); From f3c8ff19b987cf3c4bef9b93435269cad7d33c92 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 21 Jul 2025 19:10:47 +0200 Subject: [PATCH 04/28] remove redundant R_SetColumnFunc call this would only be needed if we had brightmap support, but like this it just sets the column function to what it already is --- src/r_segs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 02159d40d..848483c97 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -1166,7 +1166,7 @@ static void R_DrawWallColumn(drawcolumndata_t* dc, INT32 yl, INT32 yh, fixed_t m dc->source = R_GetColumn(texture, texturecolumn); dc->texheight = textureheight[texture] >> FRACBITS; dc->sourcelength = dc->texheight; - R_SetColumnFunc(colfunctype); + //R_SetColumnFunc(colfunctype); coldrawfunc_t* colfunccopy = colfunc; drawcolumndata_t dc_copy = *dc; if (remap) From 1e879dc4325344fe9a454df14ad7b93cc14dbb6a Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 29 May 2025 17:58:25 +0200 Subject: [PATCH 05/28] let Z_CheckHeap print file and line of where it occured like its supposed to lel --- src/z_zone.c | 22 +++++++++++----------- src/z_zone.h | 8 +++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index 548c1e025..f1d1114e3 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -394,11 +394,11 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb * \param lowtag The lowest tag to consider. * \param hightag The highest tag to consider. */ -void Z_FreeTags(INT32 lowtag, INT32 hightag) +void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line) { memblock_t *block, *next; - Z_CheckHeap(420); + Z_CheckHeap2(file, line); for (block = head.next; block != &head; block = next) { next = block->next; // get link before freeing @@ -468,7 +468,7 @@ void Z_CheckMemCleanup(void) * \param i Identifies from where in the code Z_CheckHeap was called. * \author Graue */ -void Z_CheckHeap(INT32 i) +void Z_CheckHeap2(const char *file, INT32 line) { memblock_t *block; UINT32 blocknumon = 0; @@ -498,11 +498,11 @@ void Z_CheckHeap(INT32 i) #endif if (block->user != NULL && *(block->user) != given) { - I_Error("Z_CheckHeap %d: block %u" + I_Error("Z_CheckHeap %s %d: block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " doesn't have a proper user", i, blocknumon + " doesn't have a proper user", file, line, blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -510,11 +510,11 @@ void Z_CheckHeap(INT32 i) } if (block->next->prev != block) { - I_Error("Z_CheckHeap %d: block %u" + I_Error("Z_CheckHeap %s %d: block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper backlink", i, blocknumon + " lacks proper backlink", file, line, blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -522,11 +522,11 @@ void Z_CheckHeap(INT32 i) } if (block->prev->next != block) { - I_Error("Z_CheckHeap %d: block %u" + I_Error("Z_CheckHeap %s %d: block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper forward link", i, blocknumon + " lacks proper forward link", file, line, blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -534,11 +534,11 @@ void Z_CheckHeap(INT32 i) } if (block->id != ZONEID) { - I_Error("Z_CheckHeap %d: block %u" + I_Error("Z_CheckHeap %s %d: block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " have the wrong ID", i, blocknumon + " have the wrong ID", file, line, blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif diff --git a/src/z_zone.h b/src/z_zone.h index ab908bfec..2d0888e36 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -114,8 +114,9 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb // Free all memory by tag // these don't give line numbers for ZDEBUG currently though // (perhaps this should be changed in future?) -#define Z_FreeTag(tagnum) Z_FreeTags(tagnum, tagnum) -void Z_FreeTags(INT32 lowtag, INT32 hightag); +#define Z_FreeTag(tagnum) Z_FreeTags2(tagnum, tagnum, __FILE__, __LINE__) +#define Z_FreeTags(tagnum, tagnum2) Z_FreeTags2(tagnum, tagnum2, __FILE__, __LINE__) +void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line); // Iterate memory by tag #define Z_IterateTag(tagnum, func) Z_IterateTags(tagnum, tagnum, func) @@ -125,7 +126,8 @@ void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)); // Utility functions // void Z_CheckMemCleanup(void); -void Z_CheckHeap(INT32 i); +#define Z_CheckHeap(tag) Z_CheckHeap2(__FILE__, __LINE__) +void Z_CheckHeap2(const char *file, INT32 line); // // Zone memory modification From 4a4b5661f2e6f808e46147c4fb7db4048244acd5 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Jul 2025 17:24:43 +0200 Subject: [PATCH 06/28] move this stuff behind ZDEBUG --- src/z_zone.c | 64 +++++++++++++++++++++++++++++++++++++++++++++------- src/z_zone.h | 10 ++++++++ 2 files changed, 66 insertions(+), 8 deletions(-) diff --git a/src/z_zone.c b/src/z_zone.c index f1d1114e3..ad756ceaa 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -394,11 +394,19 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb * \param lowtag The lowest tag to consider. * \param hightag The highest tag to consider. */ +#ifdef ZDEBUG void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line) +#else +void Z_FreeTags(INT32 lowtag, INT32 hightag) +#endif { memblock_t *block, *next; +#ifdef ZDEBUG Z_CheckHeap2(file, line); +#else + Z_CheckHeap(420); +#endif for (block = head.next; block != &head; block = next) { next = block->next; // get link before freeing @@ -468,12 +476,20 @@ void Z_CheckMemCleanup(void) * \param i Identifies from where in the code Z_CheckHeap was called. * \author Graue */ +#ifdef ZDEBUG void Z_CheckHeap2(const char *file, INT32 line) +#else +void Z_CheckHeap(INT32 tag) +#endif { memblock_t *block; UINT32 blocknumon = 0; void *given; +#ifndef ZDEBUG + (void)tag; +#endif + for (block = head.next; block != &head; block = block->next) { blocknumon++; @@ -498,11 +514,19 @@ void Z_CheckHeap2(const char *file, INT32 line) #endif if (block->user != NULL && *(block->user) != given) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " doesn't have a proper user", file, line, blocknumon + " doesn't have a proper user" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -510,11 +534,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->next->prev != block) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper backlink", file, line, blocknumon + " lacks proper backlink" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -522,11 +554,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->prev->next != block) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " lacks proper forward link", file, line, blocknumon + " lacks proper forward link" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif @@ -534,11 +574,19 @@ void Z_CheckHeap2(const char *file, INT32 line) } if (block->id != ZONEID) { - I_Error("Z_CheckHeap %s %d: block %u" + I_Error("Z_CheckHeap" +#ifdef ZDEBUG + "at %s %d :" +#endif + "block %u" #ifdef ZDEBUG "(owned by %s:%d)" #endif - " have the wrong ID", file, line, blocknumon + " have the wrong ID" +#ifdef ZDEBUG + , file, line +#endif + , blocknumon #ifdef ZDEBUG , block->ownerfile, block->ownerline #endif diff --git a/src/z_zone.h b/src/z_zone.h index 2d0888e36..ba85f5746 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -114,9 +114,14 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb // Free all memory by tag // these don't give line numbers for ZDEBUG currently though // (perhaps this should be changed in future?) +#ifdef ZDEBUG #define Z_FreeTag(tagnum) Z_FreeTags2(tagnum, tagnum, __FILE__, __LINE__) #define Z_FreeTags(tagnum, tagnum2) Z_FreeTags2(tagnum, tagnum2, __FILE__, __LINE__) void Z_FreeTags2(INT32 lowtag, INT32 hightag, const char *file, INT32 line); +#else +#define Z_FreeTag(tagnum) Z_FreeTags(tagnum, tagnum) +void Z_FreeTags(INT32 lowtag, INT32 hightag); +#endif // Iterate memory by tag #define Z_IterateTag(tagnum, func) Z_IterateTags(tagnum, tagnum, func) @@ -126,8 +131,13 @@ void Z_IterateTags(INT32 lowtag, INT32 hightag, boolean (*iterfunc)(void *)); // Utility functions // void Z_CheckMemCleanup(void); + +#ifdef ZDEBUG #define Z_CheckHeap(tag) Z_CheckHeap2(__FILE__, __LINE__) void Z_CheckHeap2(const char *file, INT32 line); +#else +void Z_CheckHeap(INT32 tag); +#endif // // Zone memory modification From 38576082fba1080a255aac43ea1f8bb15587a7b2 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Jul 2025 17:31:44 +0200 Subject: [PATCH 07/28] move prints to ZDEBUG2 as it seems to be for this purpose --- src/z_zone.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/z_zone.c b/src/z_zone.c index ad756ceaa..bd97707c7 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -149,9 +149,12 @@ void Z_Free(void *ptr) #endif #endif -#ifdef ZDEBUG +#ifdef ZDEBUG2 // Write every Z_Free call to a debug file. CONS_Debug(DBG_MEMORY, "Z_Free at %s:%d\n", file, line); +#elif defined(ZDEBUG) + (void)file; + (void)line; #endif // anything that isn't by lua gets passed to lua just in case. @@ -358,8 +361,10 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb return NULL; #ifdef ZDEBUG +#ifdef ZDEBUG2 // Write every Z_Realloc call to a debug file. DEBFILE(va("Z_Realloc at %s:%d\n", file, line)); +#endif rez = Z_Malloc2(size, tag, user, alignbits, file, line); #else rez = Z_MallocAlign(size, tag, user, alignbits); From 7f3f332821e1a3df9260e90219dbbc49a3adf920 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Jul 2025 17:33:07 +0200 Subject: [PATCH 08/28] Remove aligned allocation functions --- src/i_tcp.c | 8 +- src/r_data.c | 301 +++++++++++++++++++++++++++++++++++++++++++++++-- src/r_draw.cpp | 6 +- src/w_wad.c | 2 +- src/z_zone.c | 49 ++++---- src/z_zone.h | 23 ++-- 6 files changed, 327 insertions(+), 62 deletions(-) diff --git a/src/i_tcp.c b/src/i_tcp.c index 8151abce0..34b96b899 100644 --- a/src/i_tcp.c +++ b/src/i_tcp.c @@ -1475,13 +1475,7 @@ static void AddBannedIndex(void) banned_size *= 2; } - banned = Z_ReallocAlign( - (void*) banned, - sizeof(banned_t) * banned_size, - PU_STATIC, - NULL, - sizeof(banned_t) * 8 - ); + banned = Z_Realloc((void*) banned, sizeof(banned_t) * banned_size, PU_STATIC, NULL); } numbans++; diff --git a/src/r_data.c b/src/r_data.c index f3731c3fc..f25173240 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1245,6 +1245,94 @@ static void R_InitSpriteLumps(void) Z_Malloc(max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); } +// +// R_CreateFadeColormaps +// + +static void R_CreateFadeColormaps(void) +{ + UINT8 px, fade; + RGBA_t rgba; + INT32 r, g, b; + size_t len, i; + + len = (256 * FADECOLORMAPROWS); + fadecolormap = Z_Malloc(len*2, PU_STATIC, NULL); + for (i = 0; i < len*2; i++) + fadecolormap[i] = (i%256); + + // Load in the light tables, now 64k aligned for smokie... + { + lumpnum_t lump = W_CheckNumForName("FADECMAP"); + lumpnum_t wlump = W_CheckNumForName("FADEWMAP"); + + // to black + if (lump != LUMPERROR) + W_ReadLumpHeader(lump, fadecolormap, len, 0U); + // to white + if (wlump != LUMPERROR) + W_ReadLumpHeader(wlump, fadecolormap+len, len, 0U); + + // missing "to white" colormap lump + if (lump != LUMPERROR && wlump == LUMPERROR) + goto makewhite; + // missing "to black" colormap lump + else if (lump == LUMPERROR && wlump != LUMPERROR) + goto makeblack; + // both lumps found + else if (lump != LUMPERROR && wlump != LUMPERROR) + return; + } + +#define GETCOLOR \ + px = colormaps[i%256]; \ + fade = (i/256) * (256 / FADECOLORMAPROWS); \ + rgba = V_GetMasterColor(px); + + // to black + makeblack: + for (i = 0; i < len; i++) + { + // find pixel and fade amount + GETCOLOR; + + // subtractive color blending + r = rgba.s.red - FADEREDFACTOR*fade/10; + g = rgba.s.green - FADEGREENFACTOR*fade/10; + b = rgba.s.blue - FADEBLUEFACTOR*fade/10; + + // clamp values + if (r < 0) r = 0; + if (g < 0) g = 0; + if (b < 0) b = 0; + + // find nearest color in palette + fadecolormap[i] = NearestColor(r,g,b); + } + + // to white + makewhite: + for (i = len; i < len*2; i++) + { + // find pixel and fade amount + GETCOLOR; + + // additive color blending + r = rgba.s.red + FADEREDFACTOR*fade/10; + g = rgba.s.green + FADEGREENFACTOR*fade/10; + b = rgba.s.blue + FADEBLUEFACTOR*fade/10; + + // clamp values + if (r > 255) r = 255; + if (g > 255) g = 255; + if (b > 255) b = 255; + + // find nearest color in palette + fadecolormap[i] = NearestColor(r,g,b); + } +#undef GETCOLOR +} + // // R_InitColormaps // @@ -1254,8 +1342,7 @@ static void R_InitColormaps(void) // Load in the light tables lump = W_GetNumForName("COLORMAP"); - //Z_MallocAlign(W_LumpLength (lump), PU_STATIC, NULL, 8); - colormaps = Z_MallocAlign((256 * 64), PU_STATIC, NULL, 8); + colormaps = Z_Malloc((256 * 64), PU_STATIC, NULL); W_ReadLump(lump, colormaps); // no need to init encoremap at this stage @@ -1296,7 +1383,7 @@ void R_ReInitColormaps(UINT16 num, lumpnum_t newencoremap) lighttable_t *colormap_p, *colormap_p2; size_t p, i; - encoremap = Z_MallocAlign(256 + 10, PU_LEVEL, NULL, 8); + encoremap = Z_Malloc(256 + 10, PU_LEVEL, NULL); W_ReadLump(newencoremap, encoremap); colormap_p = colormap_p2 = colormaps; colormap_p += (256 * 32); @@ -1337,12 +1424,207 @@ void R_ClearColormaps(void) memset(extra_colormaps, 0, sizeof (extra_colormaps)); } -/*INT32 R_ColormapNumForName(char *name) +// +// R_GetDefaultColormap() +// +extracolormap_t *R_GetDefaultColormap(void) { - lumpnum_t lump, i; +#ifdef COLORMAPREVERSELIST + extracolormap_t *exc; +#endif - if (num_extra_colormaps == MAXCOLORMAPS) - I_Error("R_ColormapNumForName: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); + if (!extra_colormaps) + return (extra_colormaps = R_CreateDefaultColormap(true)); + +#ifdef COLORMAPREVERSELIST + for (exc = extra_colormaps; exc->next; exc = exc->next); + return exc; +#else + return extra_colormaps; +#endif +} + +// +// R_CopyColormap() +// NOTE: The result colormap is not added to the extra_colormaps chain. You must do that yourself! +// +extracolormap_t *R_CopyColormap(extracolormap_t *extra_colormap, boolean lighttable) +{ + extracolormap_t *exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); + + if (!extra_colormap) + extra_colormap = R_GetDefaultColormap(); + + *exc = *extra_colormap; + exc->next = exc->prev = NULL; + +#ifdef EXTRACOLORMAPLUMPS + strncpy(exc->lumpname, extra_colormap->lumpname, 9); + + if (exc->lump != LUMPERROR && lighttable) + { + // aligned on 8 bit for asm code + exc->colormap = Z_Malloc(W_LumpLength(lump), PU_LEVEL, NULL); + W_ReadLump(lump, exc->colormap); + } + else +#endif + if (lighttable) + exc->colormap = R_CreateLightTable(exc); + else + exc->colormap = NULL; + + return exc; +} + +// +// R_AddColormapToList +// +// Sets prev/next chain for extra_colormaps var +// Copypasta from P_AddFFloorToList +// +void R_AddColormapToList(extracolormap_t *extra_colormap) +{ +#ifndef COLORMAPREVERSELIST + extracolormap_t *exc; +#endif + + if (!extra_colormaps) + { + extra_colormaps = extra_colormap; + extra_colormap->next = 0; + extra_colormap->prev = 0; + return; + } + +#ifdef COLORMAPREVERSELIST + extra_colormaps->prev = extra_colormap; + extra_colormap->next = extra_colormaps; + extra_colormaps = extra_colormap; + extra_colormap->prev = 0; +#else + for (exc = extra_colormaps; exc->next; exc = exc->next); + + exc->next = extra_colormap; + extra_colormap->prev = exc; + extra_colormap->next = 0; +#endif +} + +// +// R_CheckDefaultColormapByValues() +// +#ifdef EXTRACOLORMAPLUMPS +boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams, + INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump) +#else +boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams, + INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags) +#endif +{ + return ( + (!checkparams ? true : + (fadestart == 0 + && fadeend == 31 + && !flags) + ) + && (!checkrgba ? true : rgba == 0) + && (!checkfadergba ? true : (unsigned)fadergba == 0xFF000000) +#ifdef EXTRACOLORMAPLUMPS + && lump == LUMPERROR + && extra_colormap->lumpname[0] == 0 +#endif + ); +} + +boolean R_CheckDefaultColormap(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams) +{ + if (!extra_colormap) + return true; + +#ifdef EXTRACOLORMAPLUMPS + return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump); +#else + return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags); +#endif +} + +boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b, boolean checkrgba, boolean checkfadergba, boolean checkparams) +{ + // Treat NULL as default colormap + // We need this because what if one exc is a default colormap, and the other is NULL? They're really both equal. + if (!exc_a) + exc_a = R_GetDefaultColormap(); + if (!exc_b) + exc_b = R_GetDefaultColormap(); + + if (exc_a == exc_b) + return true; + + return ( + (!checkparams ? true : + (exc_a->fadestart == exc_b->fadestart + && exc_a->fadeend == exc_b->fadeend + && exc_a->flags == exc_b->flags) + ) + && (!checkrgba ? true : exc_a->rgba == exc_b->rgba) + && (!checkfadergba ? true : exc_a->fadergba == exc_b->fadergba) +#ifdef EXTRACOLORMAPLUMPS + && exc_a->lump == exc_b->lump + && !strncmp(exc_a->lumpname, exc_b->lumpname, 9) +#endif + ); +} + +// +// R_GetColormapFromListByValues() +// NOTE: Returns NULL if no match is found +// +#ifdef EXTRACOLORMAPLUMPS +extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump) +#else +extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags) +#endif +{ + extracolormap_t *exc; + UINT32 dbg_i = 0; + + for (exc = extra_colormaps; exc; exc = exc->next) + { + if (rgba == exc->rgba + && fadergba == exc->fadergba + && fadestart == exc->fadestart + && fadeend == exc->fadeend + && flags == exc->flags +#ifdef EXTRACOLORMAPLUMPS + && (lump != LUMPERROR && lump == exc->lump) +#endif + ) + { + CONS_Debug(DBG_RENDER, "Found Colormap %d: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", + dbg_i, R_GetRgbaR(rgba), R_GetRgbaG(rgba), R_GetRgbaB(rgba), R_GetRgbaA(rgba), + R_GetRgbaR(fadergba), R_GetRgbaG(fadergba), R_GetRgbaB(fadergba), R_GetRgbaA(fadergba)); + return exc; + } + dbg_i++; + } + return NULL; +} + +extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap) +{ +#ifdef EXTRACOLORMAPLUMPS + return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump); +#else + return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags); +#endif +} + +#ifdef EXTRACOLORMAPLUMPS +extracolormap_t *R_ColormapForName(char *name) +{ + lumpnum_t lump; + extracolormap_t *exc; lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps); if (lump == LUMPERROR) @@ -1354,8 +1636,7 @@ void R_ClearColormaps(void) foundcolormaps[num_extra_colormaps] = lump; - // aligned on 8 bit for asm code - extra_colormaps[num_extra_colormaps].colormap = Z_MallocAlign(W_LumpLength(lump), PU_LEVEL, NULL, 16); + extra_colormaps[num_extra_colormaps].colormap = Z_Malloc(W_LumpLength(lump), PU_LEVEL, NULL); W_ReadLump(lump, extra_colormaps[num_extra_colormaps].colormap); // We set all params of the colormap to normal because there @@ -1551,7 +1832,7 @@ INT32 R_CreateColormap(char *p1, char *p2, char *p3) } // Now allocate memory for the actual colormap array itself! - colormap_p = Z_MallocAlign((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL, 8); + colormap_p = Z_Malloc((256 * (encoremap ? 64 : 32)) + 10, PU_LEVEL, NULL); extra_colormaps[mapnum].colormap = (UINT8 *)colormap_p; // Calculate the palette index for each palette index, for each light level diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 23d512a19..e399fab0e 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -119,7 +119,7 @@ void R_InitTranslucencyTables(void) // Load here the transparency lookup tables 'TRANSx0' // NOTE: the TRANSx0 resources MUST BE aligned on 64k for the asm // optimised code (in other words, transtables pointer low word is 0) - transtables = static_cast(Z_MallocAlign(NUMTRANSTABLES*0x10000, PU_STATIC, NULL, 16)); + transtables = static_cast(Z_Malloc(NUMTRANSTABLES*0x10000, PU_STATIC, NULL)); W_ReadLump(W_GetNumForName("TRANS10"), transtables); W_ReadLump(W_GetNumForName("TRANS20"), transtables+0x10000); @@ -246,7 +246,7 @@ static void R_GenerateBlendTables(void) INT32 i; for (i = 0; i < NUMBLENDMAPS; i++) - blendtables[i] = static_cast(Z_MallocAlign(BlendTab_Count[i] * 0x10000, PU_STATIC, NULL, 16)); + blendtables[i] = static_cast(Z_Malloc(BlendTab_Count[i] * 0x10000, PU_STATIC, NULL)); InitColorLUT(&transtab_lut, pLocalPalette, false); @@ -365,7 +365,7 @@ static UINT8* RGetTranslationColormap(INT32 skinnum, skincolors_t color, UINT8 f // Generate the colormap if necessary if (!ret) { - ret = static_cast(Z_MallocAlign(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL, 8)); + ret = static_cast(Z_Malloc(NUM_PALETTE_ENTRIES, (flags & GTC_CACHE) ? PU_LEVEL : PU_STATIC, NULL)); K_GenerateKartColormap(ret, skinnum, color, local); //R_GenerateTranslationColormap(ret, skinnum, color); // SRB2kart // Cache the colormap if desired diff --git a/src/w_wad.c b/src/w_wad.c index 6490f561d..63071ea3b 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -611,7 +611,7 @@ static lumpinfo_t* ResGetLumpsZip (FILE* handle, UINT16* nlmp) fseek(handle, LONG(zend.cdiroffset), SEEK_SET); - char *cdir = (Z_MallocAlign(LONG(zend.cdirsize), PU_STATIC, &cdir, 7)); + char *cdir = Z_Malloc(LONG(zend.cdirsize), PU_STATIC, &cdir); if (fread(cdir, 1, LONG(zend.cdirsize), handle) < (UINT32)(LONG(zend.cdirsize))) { diff --git a/src/z_zone.c b/src/z_zone.c index bd97707c7..8647f91fa 100644 --- a/src/z_zone.c +++ b/src/z_zone.c @@ -205,7 +205,7 @@ static void *xm(size_t size) return p; } -/** The Z_MallocAlign function. +/** The Z_Malloc function. * Allocates a block of memory, adds it to a linked list so we can keep track of it. * * \param size Amount of memory to be allocated, in bytes. @@ -213,22 +213,19 @@ static void *xm(size_t size) * \param user The address of a pointer to the memory to be allocated. * When the memory is freed by Z_Free later, * the pointer at this address will then be automatically set to NULL. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. * \note You can pass Z_Malloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_CallocAlign, Z_ReallocAlign + * \sa Z_Calloc, Z_Realloc */ #ifdef ZDEBUG -void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, +void *Z_Malloc2(size_t size, INT32 tag, void *user, const char *file, INT32 line) #else -void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) +void *Z_Malloc(size_t size, INT32 tag, void *user) #endif { memblock_t *block; void *ptr; - (void)(alignbits); // no longer used, so silence warnings. TODO we should figure out a solution for this - #ifdef ZDEBUG2 CONS_Debug(DBG_MEMORY, "Z_Malloc %s:%d\n", file, line); #endif @@ -273,55 +270,53 @@ void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) return ptr; } -/** The Z_CallocAlign function. +/** The Z_Calloc function. * Allocates a block of memory, adds it to a linked list so we can keep track of it. - * Unlike Z_MallocAlign, this also initialises the bytes to zero. + * Unlike Z_Malloc, this also initialises the bytes to zero. * * \param size Amount of memory to be allocated, in bytes. * \param tag Purge tag. * \param user The address of a pointer to the memory to be allocated. * When the memory is freed by Z_Free later, * the pointer at this address will then be automatically set to NULL. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. * \note You can pass Z_Calloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_MallocAlign, Z_ReallocAlign + * \sa Z_Malloc, Z_Realloc */ #ifdef ZDEBUG -void *Z_Calloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) +void *Z_Calloc2(size_t size, INT32 tag, void *user, const char *file, INT32 line) #else -void *Z_CallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) +void *Z_Calloc(size_t size, INT32 tag, void *user) #endif { #ifdef VALGRIND_MEMPOOL_ALLOC Z_calloc = true; #endif #ifdef ZDEBUG - return memset(Z_Malloc2 (size, tag, user, alignbits, file, line), 0, size); + return memset(Z_Malloc2(size, tag, user, file, line), 0, size); #else - return memset(Z_MallocAlign(size, tag, user, alignbits ), 0, size); + return memset(Z_Malloc (size, tag, user ), 0, size); #endif } -/** The Z_ReallocAlign function. +/** The Z_Realloc function. * Reallocates a block of memory with a new size. * * \param ptr A pointer to allocated memory, * assumed to have been allocated with Z_Malloc/Z_Calloc. - * If NULL, this function instead acts as a wrapper for Z_CallocAlign. + * If NULL, this function instead acts as a wrapper for Z_Calloc. * \param size New size of memory block, in bytes. * If zero, then the memory is freed and NULL is returned. * \param tag New purge tag. * \param user The address of a pointer to the memory to be reallocated. * This can be a different user to the one originally assigned to the memory block. - * \param alignbits The alignment of the memory to be allocated, in bits. Can be 0. * \return A pointer to the reallocated memory. Can be NULL if memory was freed. * \note You can pass Z_Realloc() a NULL user if the tag is less than PU_PURGELEVEL. - * \sa Z_MallocAlign, Z_CallocAlign + * \sa Z_Malloc, Z_Calloc */ #ifdef ZDEBUG -void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) +void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, const char *file, INT32 line) #else -void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) +void *Z_Realloc(void *ptr, size_t size, INT32 tag, void *user) #endif { void *rez; @@ -341,9 +336,9 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb if (!ptr) { #ifdef ZDEBUG - return Z_Calloc2(size, tag, user, alignbits, file , line); + return Z_Calloc2(size, tag, user, file, line); #else - return Z_CallocAlign(size, tag, user, alignbits); + return Z_Calloc(size, tag, user); #endif } @@ -351,9 +346,9 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb #ifdef PARANOIA if (block->id != ZONEID) #ifdef ZDEBUG - I_Error("Z_ReallocAlign at %s:%d: wrong id", file, line); + I_Error("Z_Realloc at %s:%d: wrong id", file, line); #else - I_Error("Z_ReallocAlign: wrong id"); + I_Error("Z_Realloc: wrong id"); #endif #endif @@ -365,9 +360,9 @@ void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignb // Write every Z_Realloc call to a debug file. DEBFILE(va("Z_Realloc at %s:%d\n", file, line)); #endif - rez = Z_Malloc2(size, tag, user, alignbits, file, line); + rez = Z_Malloc2(size, tag, user, file, line); #else - rez = Z_MallocAlign(size, tag, user, alignbits); + rez = Z_Malloc(size, tag, user); #endif if (size < block->realsize) diff --git a/src/z_zone.h b/src/z_zone.h index ba85f5746..0599ef3f6 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -92,25 +92,20 @@ void Z_Init(void); // Z_Free and alloc with alignment #ifdef ZDEBUG #define Z_Free(p) Z_Free2(p, __FILE__, __LINE__) -#define Z_MallocAlign(s,t,u,a) Z_Malloc2(s, t, u, a, __FILE__, __LINE__) -#define Z_CallocAlign(s,t,u,a) Z_Calloc2(s, t, u, a, __FILE__, __LINE__) -#define Z_ReallocAlign(p,s,t,u,a) Z_Realloc2(p,s, t, u, a, __FILE__, __LINE__) +#define Z_Malloc(s,t,u) Z_Malloc2(s, t, u, __FILE__, __LINE__) +#define Z_Calloc(s,t,u) Z_Calloc2(s, t, u, __FILE__, __LINE__) +#define Z_Realloc(p,s,t,u) Z_Realloc2(p,s, t, u, __FILE__, __LINE__) void Z_Free2(void *ptr, const char *file, INT32 line); -void *Z_Malloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(1); -void *Z_Calloc2(size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(1); -void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits, const char *file, INT32 line) FUNCALLOC(2); +void *Z_Malloc2(size_t size, INT32 tag, void *user, const char *file, INT32 line) FUNCALLOC(1); +void *Z_Calloc2(size_t size, INT32 tag, void *user, const char *file, INT32 line) FUNCALLOC(1); +void *Z_Realloc2(void *ptr, size_t size, INT32 tag, void *user, const char *file, INT32 line) FUNCALLOC(2); #else void Z_Free(void *ptr); -void *Z_MallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(1); -void *Z_CallocAlign(size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(1); -void *Z_ReallocAlign(void *ptr, size_t size, INT32 tag, void *user, INT32 alignbits) FUNCALLOC(2); +void *Z_Malloc(size_t size, INT32 tag, void *user) FUNCALLOC(1); +void *Z_Calloc(size_t size, INT32 tag, void *user) FUNCALLOC(1); +void *Z_Realloc(void *ptr, size_t size, INT32 tag, void *user) FUNCALLOC(2); #endif -// Alloc with standard alignment -#define Z_Malloc(s,t,u) Z_MallocAlign(s, t, u, sizeof(void *)) -#define Z_Calloc(s,t,u) Z_CallocAlign(s, t, u, sizeof(void *)) -#define Z_Realloc(p,s,t,u) Z_ReallocAlign(p, s, t, u, sizeof(void *)) - // Free all memory by tag // these don't give line numbers for ZDEBUG currently though // (perhaps this should be changed in future?) From 3c78c5c57dfd5f18f19607c6e6f147cc7ec3fa0e Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 19 Jun 2025 16:26:18 +0200 Subject: [PATCH 09/28] ok git very cool --- src/r_data.c | 292 +-------------------------------------------------- 1 file changed, 5 insertions(+), 287 deletions(-) diff --git a/src/r_data.c b/src/r_data.c index f25173240..689c6541a 100644 --- a/src/r_data.c +++ b/src/r_data.c @@ -1245,94 +1245,6 @@ static void R_InitSpriteLumps(void) Z_Malloc(max_spritelumps*sizeof(*spritecachedinfo), PU_STATIC, &spritecachedinfo); } -// -// R_CreateFadeColormaps -// - -static void R_CreateFadeColormaps(void) -{ - UINT8 px, fade; - RGBA_t rgba; - INT32 r, g, b; - size_t len, i; - - len = (256 * FADECOLORMAPROWS); - fadecolormap = Z_Malloc(len*2, PU_STATIC, NULL); - for (i = 0; i < len*2; i++) - fadecolormap[i] = (i%256); - - // Load in the light tables, now 64k aligned for smokie... - { - lumpnum_t lump = W_CheckNumForName("FADECMAP"); - lumpnum_t wlump = W_CheckNumForName("FADEWMAP"); - - // to black - if (lump != LUMPERROR) - W_ReadLumpHeader(lump, fadecolormap, len, 0U); - // to white - if (wlump != LUMPERROR) - W_ReadLumpHeader(wlump, fadecolormap+len, len, 0U); - - // missing "to white" colormap lump - if (lump != LUMPERROR && wlump == LUMPERROR) - goto makewhite; - // missing "to black" colormap lump - else if (lump == LUMPERROR && wlump != LUMPERROR) - goto makeblack; - // both lumps found - else if (lump != LUMPERROR && wlump != LUMPERROR) - return; - } - -#define GETCOLOR \ - px = colormaps[i%256]; \ - fade = (i/256) * (256 / FADECOLORMAPROWS); \ - rgba = V_GetMasterColor(px); - - // to black - makeblack: - for (i = 0; i < len; i++) - { - // find pixel and fade amount - GETCOLOR; - - // subtractive color blending - r = rgba.s.red - FADEREDFACTOR*fade/10; - g = rgba.s.green - FADEGREENFACTOR*fade/10; - b = rgba.s.blue - FADEBLUEFACTOR*fade/10; - - // clamp values - if (r < 0) r = 0; - if (g < 0) g = 0; - if (b < 0) b = 0; - - // find nearest color in palette - fadecolormap[i] = NearestColor(r,g,b); - } - - // to white - makewhite: - for (i = len; i < len*2; i++) - { - // find pixel and fade amount - GETCOLOR; - - // additive color blending - r = rgba.s.red + FADEREDFACTOR*fade/10; - g = rgba.s.green + FADEGREENFACTOR*fade/10; - b = rgba.s.blue + FADEBLUEFACTOR*fade/10; - - // clamp values - if (r > 255) r = 255; - if (g > 255) g = 255; - if (b > 255) b = 255; - - // find nearest color in palette - fadecolormap[i] = NearestColor(r,g,b); - } -#undef GETCOLOR -} - // // R_InitColormaps // @@ -1424,207 +1336,12 @@ void R_ClearColormaps(void) memset(extra_colormaps, 0, sizeof (extra_colormaps)); } -// -// R_GetDefaultColormap() -// -extracolormap_t *R_GetDefaultColormap(void) +/*INT32 R_ColormapNumForName(char *name) { -#ifdef COLORMAPREVERSELIST - extracolormap_t *exc; -#endif + lumpnum_t lump, i; - if (!extra_colormaps) - return (extra_colormaps = R_CreateDefaultColormap(true)); - -#ifdef COLORMAPREVERSELIST - for (exc = extra_colormaps; exc->next; exc = exc->next); - return exc; -#else - return extra_colormaps; -#endif -} - -// -// R_CopyColormap() -// NOTE: The result colormap is not added to the extra_colormaps chain. You must do that yourself! -// -extracolormap_t *R_CopyColormap(extracolormap_t *extra_colormap, boolean lighttable) -{ - extracolormap_t *exc = Z_Calloc(sizeof (*exc), PU_LEVEL, NULL); - - if (!extra_colormap) - extra_colormap = R_GetDefaultColormap(); - - *exc = *extra_colormap; - exc->next = exc->prev = NULL; - -#ifdef EXTRACOLORMAPLUMPS - strncpy(exc->lumpname, extra_colormap->lumpname, 9); - - if (exc->lump != LUMPERROR && lighttable) - { - // aligned on 8 bit for asm code - exc->colormap = Z_Malloc(W_LumpLength(lump), PU_LEVEL, NULL); - W_ReadLump(lump, exc->colormap); - } - else -#endif - if (lighttable) - exc->colormap = R_CreateLightTable(exc); - else - exc->colormap = NULL; - - return exc; -} - -// -// R_AddColormapToList -// -// Sets prev/next chain for extra_colormaps var -// Copypasta from P_AddFFloorToList -// -void R_AddColormapToList(extracolormap_t *extra_colormap) -{ -#ifndef COLORMAPREVERSELIST - extracolormap_t *exc; -#endif - - if (!extra_colormaps) - { - extra_colormaps = extra_colormap; - extra_colormap->next = 0; - extra_colormap->prev = 0; - return; - } - -#ifdef COLORMAPREVERSELIST - extra_colormaps->prev = extra_colormap; - extra_colormap->next = extra_colormaps; - extra_colormaps = extra_colormap; - extra_colormap->prev = 0; -#else - for (exc = extra_colormaps; exc->next; exc = exc->next); - - exc->next = extra_colormap; - extra_colormap->prev = exc; - extra_colormap->next = 0; -#endif -} - -// -// R_CheckDefaultColormapByValues() -// -#ifdef EXTRACOLORMAPLUMPS -boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams, - INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump) -#else -boolean R_CheckDefaultColormapByValues(boolean checkrgba, boolean checkfadergba, boolean checkparams, - INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags) -#endif -{ - return ( - (!checkparams ? true : - (fadestart == 0 - && fadeend == 31 - && !flags) - ) - && (!checkrgba ? true : rgba == 0) - && (!checkfadergba ? true : (unsigned)fadergba == 0xFF000000) -#ifdef EXTRACOLORMAPLUMPS - && lump == LUMPERROR - && extra_colormap->lumpname[0] == 0 -#endif - ); -} - -boolean R_CheckDefaultColormap(extracolormap_t *extra_colormap, boolean checkrgba, boolean checkfadergba, boolean checkparams) -{ - if (!extra_colormap) - return true; - -#ifdef EXTRACOLORMAPLUMPS - return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump); -#else - return R_CheckDefaultColormapByValues(checkrgba, checkfadergba, checkparams, extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags); -#endif -} - -boolean R_CheckEqualColormaps(extracolormap_t *exc_a, extracolormap_t *exc_b, boolean checkrgba, boolean checkfadergba, boolean checkparams) -{ - // Treat NULL as default colormap - // We need this because what if one exc is a default colormap, and the other is NULL? They're really both equal. - if (!exc_a) - exc_a = R_GetDefaultColormap(); - if (!exc_b) - exc_b = R_GetDefaultColormap(); - - if (exc_a == exc_b) - return true; - - return ( - (!checkparams ? true : - (exc_a->fadestart == exc_b->fadestart - && exc_a->fadeend == exc_b->fadeend - && exc_a->flags == exc_b->flags) - ) - && (!checkrgba ? true : exc_a->rgba == exc_b->rgba) - && (!checkfadergba ? true : exc_a->fadergba == exc_b->fadergba) -#ifdef EXTRACOLORMAPLUMPS - && exc_a->lump == exc_b->lump - && !strncmp(exc_a->lumpname, exc_b->lumpname, 9) -#endif - ); -} - -// -// R_GetColormapFromListByValues() -// NOTE: Returns NULL if no match is found -// -#ifdef EXTRACOLORMAPLUMPS -extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags, lumpnum_t lump) -#else -extracolormap_t *R_GetColormapFromListByValues(INT32 rgba, INT32 fadergba, UINT8 fadestart, UINT8 fadeend, UINT8 flags) -#endif -{ - extracolormap_t *exc; - UINT32 dbg_i = 0; - - for (exc = extra_colormaps; exc; exc = exc->next) - { - if (rgba == exc->rgba - && fadergba == exc->fadergba - && fadestart == exc->fadestart - && fadeend == exc->fadeend - && flags == exc->flags -#ifdef EXTRACOLORMAPLUMPS - && (lump != LUMPERROR && lump == exc->lump) -#endif - ) - { - CONS_Debug(DBG_RENDER, "Found Colormap %d: rgba(%d,%d,%d,%d) fadergba(%d,%d,%d,%d)\n", - dbg_i, R_GetRgbaR(rgba), R_GetRgbaG(rgba), R_GetRgbaB(rgba), R_GetRgbaA(rgba), - R_GetRgbaR(fadergba), R_GetRgbaG(fadergba), R_GetRgbaB(fadergba), R_GetRgbaA(fadergba)); - return exc; - } - dbg_i++; - } - return NULL; -} - -extracolormap_t *R_GetColormapFromList(extracolormap_t *extra_colormap) -{ -#ifdef EXTRACOLORMAPLUMPS - return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags, extra_colormap->lump); -#else - return R_GetColormapFromListByValues(extra_colormap->rgba, extra_colormap->fadergba, extra_colormap->fadestart, extra_colormap->fadeend, extra_colormap->flags); -#endif -} - -#ifdef EXTRACOLORMAPLUMPS -extracolormap_t *R_ColormapForName(char *name) -{ - lumpnum_t lump; - extracolormap_t *exc; + if (num_extra_colormaps == MAXCOLORMAPS) + I_Error("R_ColormapNumForName: Too many colormaps! the limit is %d\n", MAXCOLORMAPS); lump = R_CheckNumForNameList(name, colormaplumps, numcolormaplumps); if (lump == LUMPERROR) @@ -1636,6 +1353,7 @@ extracolormap_t *R_ColormapForName(char *name) foundcolormaps[num_extra_colormaps] = lump; + // aligned on 8 bit for asm code extra_colormaps[num_extra_colormaps].colormap = Z_Malloc(W_LumpLength(lump), PU_LEVEL, NULL); W_ReadLump(lump, extra_colormaps[num_extra_colormaps].colormap); From 29cf728fac931ade533b11f932146c1afe55ca78 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 22 Jul 2025 17:29:25 +0200 Subject: [PATCH 10/28] enable ZDEBUG by default this is just quite useful honestly --- src/z_zone.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/z_zone.h b/src/z_zone.h index 0599ef3f6..adbabb37e 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -32,7 +32,7 @@ extern "C" { #define FUNCALLOC(x) #endif -//#define ZDEBUG +#define ZDEBUG // // Purge tags From 9a60441e546015cd09faf3a41136ebbfc1337978 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 23 Jul 2025 17:05:24 +0200 Subject: [PATCH 11/28] few more things for hw renderer just moving aaround some things and declaring more stuff as const --- src/hardware/hw_bsp.c | 5 ++-- src/hardware/hw_clip.c | 2 +- src/hardware/hw_main.cpp | 64 +++++++++++++++++++++------------------- 3 files changed, 38 insertions(+), 33 deletions(-) diff --git a/src/hardware/hw_bsp.c b/src/hardware/hw_bsp.c index 76231750c..9357d9f42 100644 --- a/src/hardware/hw_bsp.c +++ b/src/hardware/hw_bsp.c @@ -161,7 +161,7 @@ static boolean SameVertice (polyvertex_t *p1, polyvertex_t *p2) return false; #else #define DIVLINE_VERTEX_DIFF 0.45f - float ep = DIVLINE_VERTEX_DIFF; + static const float ep = DIVLINE_VERTEX_DIFF; if (fabsf( p2->x - p1->x ) > ep ) return false; if (fabsf( p2->y - p1->y ) > ep ) @@ -283,6 +283,7 @@ static void SplitPoly (fdivline_t *bsp, //splitting parametric line *backpoly = NULL; return; } + if (pe <= ps) I_Error("SplitPoly: invalid splitting line (%d %d)", ps, pe); @@ -368,7 +369,7 @@ static poly_t *CutOutSubsecPoly(seg_t *lseg, INT32 count, poly_t *poly) for (; count--; lseg++) { //x,y,dx,dy (like a divline) - line_t *line = lseg->linedef; + const line_t *line = lseg->linedef; // portal check if (!gl_maphasportals && line->special == PORTALSPECIAL && lseg->side == 0) diff --git a/src/hardware/hw_clip.c b/src/hardware/hw_clip.c index 0329ebc0e..346ed1d7c 100644 --- a/src/hardware/hw_clip.c +++ b/src/hardware/hw_clip.c @@ -121,7 +121,7 @@ static clipnode_t * gld_clipnode_NewRange(angle_t start, angle_t end) boolean gld_clipper_SafeCheckRange(angle_t startAngle, angle_t endAngle) { - if(startAngle > endAngle) + if (startAngle > endAngle) { return (gld_clipper_IsRangeVisible(startAngle, ANGLE_MAX) || gld_clipper_IsRangeVisible(0, endAngle)); } diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 0504c1597..067fc2b3a 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -1049,7 +1049,7 @@ static void HWR_SplitWall(sector_t *sector, FOutVector *wallVerts, INT32 texnum, if ((endtop < endrealbot) && (top < realbot)) return; - lightlist_t *list = sector->lightlist; + const lightlist_t *list = sector->lightlist; if (!(list[i].flags & FF_NOSHADE)) { @@ -1387,9 +1387,9 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[2].z = wallVerts[1].z = ve.y; // x offset the texture - fixed_t texturehpeg = gl_sidedef->textureoffset + gl_curline->offset; - float cliplow = (float)texturehpeg; - float cliphigh = (float)(texturehpeg + (gl_curline->flength*FRACUNIT)); + const fixed_t texturehpeg = gl_sidedef->textureoffset + gl_curline->offset; + const float cliplow = (float)texturehpeg; + const float cliphigh = (float)(texturehpeg + (gl_curline->flength*FRACUNIT)); FUINT lightnum = gl_frontsector->lightlevel; extracolormap_t *colormap = gl_frontsector->extra_colormap; @@ -1400,7 +1400,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom if (gl_frontsector) Surf.PolyColor.s.alpha = 255; - INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); + const INT32 gl_midtexture = R_GetTextureNum(gl_sidedef->midtexture); GLMapTexture_t *glTex = NULL; // two sided line @@ -1678,7 +1678,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom } // Find the wall's coordinates - fixed_t midtexheight = textureheight[gl_midtexture] * repeats; + const fixed_t midtexheight = textureheight[gl_midtexture] * repeats; if (gl_linedef->flags & ML_EFFECT2) { @@ -2004,6 +2004,7 @@ void HWR_ProcessSeg(void) // Sort of like GLWall::Process in GZDoom wallVerts[0].s = wallVerts[3].s = cliplow * glTex->scaleX; wallVerts[2].s = wallVerts[1].s = cliphigh * glTex->scaleX; } + FBITFIELD blendmode; if (roverflags & FF_FOG) @@ -3296,7 +3297,7 @@ static gl_vissprite_t gl_overflowsprite; static gl_vissprite_t *HWR_GetVisSprite(UINT32 num) { - UINT32 chunk = num >> VISSPRITECHUNKBITS; + const UINT32 chunk = num >> VISSPRITECHUNKBITS; // Allocate chunk if necessary if (!gl_visspritechunks[chunk]) @@ -3358,13 +3359,6 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t fixed_t slopez; float offset = 0; - // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again - const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); - if (spr->mobj) - this_scale = FixedToFloat(spr->mobj->scale); - if (hires) - this_scale = this_scale * FixedToFloat(K_GetMobjSkin(spr->mobj)->highresscale); - R_GetShadowZ(spr->mobj, &floorslope); mobjfloor = HWR_OpaqueFloorAtPos( @@ -3415,6 +3409,14 @@ static void HWR_DrawSpriteShadow(gl_vissprite_t *spr, patch_t *gpatch, GLPatch_t else floorheight = FixedInt(spr->mobj->z - mobjfloor); + // technically this_scale gets multiplied and added to sprite y/x scale, but this thing needs it for some crap so ill just throw it in here again + const boolean hires = (spr->mobj && spr->mobj->skin && K_GetMobjSkin(spr->mobj)->flags & SF_HIRES); + + if (spr->mobj) + this_scale = FixedToFloat(spr->mobj->scale); + if (hires) + this_scale = this_scale * FixedToFloat(K_GetMobjSkin(spr->mobj)->highresscale); + // create the sprite billboard // // 3--2 @@ -4147,8 +4149,8 @@ gl_vissprite_t* gl_vsprorder[MAXVISSPRITES]; // sorted and drawn together with transparent surfaces. static int CompareVisSprites(const void *p1, const void *p2) { - gl_vissprite_t* spr1 = *(gl_vissprite_t*const*)p1; - gl_vissprite_t* spr2 = *(gl_vissprite_t*const*)p2; + const gl_vissprite_t* spr1 = *(gl_vissprite_t*const*)p1; + const gl_vissprite_t* spr2 = *(gl_vissprite_t*const*)p2; int idiff; float fdiff; @@ -4326,8 +4328,8 @@ static void HWR_AddTransparentPolyobjectFloor(lumpnum_t lumpnum, polyobj_t *poly static int CompareDrawNodePlanes(const void *p1, const void *p2) { - INT32 n1 = *(const INT32*)p1; - INT32 n2 = *(const INT32*)p2; + const INT32 n1 = *(const INT32*)p1; + const INT32 n2 = *(const INT32*)p2; return ABS(drawnodes[n2].u.plane.fixedheight - viewz) - ABS(drawnodes[n1].u.plane.fixedheight - viewz); } @@ -4673,8 +4675,6 @@ static void HWR_ProjectSprite(mobj_t *thing) if (interp.spritexscale < 1 || interp.spriteyscale < 1) return; - const boolean papersprite = (thing->frame & FF_PAPERSPRITE); - INT32 blendmode; if (thing->frame & FF_BLENDMASK) blendmode = ((thing->frame & FF_BLENDMASK) >> FF_BLENDSHIFT) + 1; @@ -4688,6 +4688,8 @@ static void HWR_ProjectSprite(mobj_t *thing) return; } + const boolean papersprite = (thing->frame & FF_PAPERSPRITE); + // transform the origin point tr_x = FixedToFloat(interp.x); tr_y = FixedToFloat(interp.y); @@ -4715,12 +4717,6 @@ static void HWR_ProjectSprite(mobj_t *thing) rot = (thing->frame & FF_FRAMEMASK); -#ifdef ROTSPRITE - // determine here if sprite should rotate for optimization - const boolean sliprollrotate = (cv_sliptideroll.value && (thing->player && thing->player->sliproll)); - const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); -#endif - //Fab : 02-08-98: 'skin' override spritedef currently used for skin if ((thing->skin || thing->localskin) && thing->sprite == SPR_PLAY) { @@ -4759,6 +4755,12 @@ static void HWR_ProjectSprite(mobj_t *thing) I_Error("sprframes NULL for sprite %d\n", thing->sprite); #endif +#ifdef ROTSPRITE + // determine here if sprite should rotate for optimization + const boolean sliprollrotate = (cv_sliptideroll.value && (thing->player && thing->player->sliproll)); + const boolean shouldrotate = (interp.sloperoll || interp.slopepitch || interp.roll || interp.pitch || thing->rollangle || sliprollrotate); +#endif + if (sprframe->rotate != SRF_SINGLE || papersprite #ifdef ROTSPRITE || (shouldrotate) @@ -5202,13 +5204,13 @@ void HWR_BuildSkyDome(void) { int c, r; signed char yflip; - int row_count = 4; + static constexpr int row_count = 4; int col_count = 4; float delta; gl_sky_t *sky = &gl_sky; gl_skyvertex_t *vertex_p; - texture_t *texture = textures[texturetranslation[skytexture]]; + const texture_t *texture = textures[texturetranslation[skytexture]]; sky->detail = 16; col_count *= sky->detail; @@ -5417,7 +5419,7 @@ void HWR_SetTransform(float fpov) void HWR_ClearClipper(void) { - angle_t a1 = gld_FrustumAngle(gl_aimingangle); + const angle_t a1 = gld_FrustumAngle(gl_aimingangle); gld_clipper_Clear(); gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1); #ifdef HAVE_SPHEREFRUSTRUM @@ -5723,6 +5725,8 @@ void HWR_RenderPlayerView(void) HWR_RenderFrame(player, false); } +// Determine on mapload if current map has any Horizonlines present +// so we can avoid rather hot checks in HWR_Subsector static void HWR_CheckForHorizonLines(void) { size_t i; @@ -5976,7 +5980,7 @@ void HWR_Shutdown(void) static void HWR_RenderWall(FOutVector *wallVerts, FSurfaceInfo *pSurf, FBITFIELD blend, boolean fogwall, INT32 lightlevel, extracolormap_t *wallcolormap) { FBITFIELD blendmode = blend; - UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha + const UINT8 alpha = pSurf->PolyColor.s.alpha; // retain the alpha INT32 shader = SHADER_NONE; From 9fb3f4c9a36cce07ed4030e3852cec1d15ab586d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 24 Jul 2025 15:37:52 +0200 Subject: [PATCH 12/28] fix https://github.com/Indev450/SRB2Kart-Saturn/issues/191 was an oversight when i cleaned up the gamepad stuff a bit --- src/g_game.c | 65 +++++++++++++++++++++++++++------------------------ src/g_input.c | 28 +++++++--------------- src/g_input.h | 13 +++++++---- 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 201d0e013..83be4ecf4 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -681,47 +681,49 @@ INT32 JoyAxis(axis_input_e axissel, UINT8 player) INT32 axisval; boolean flp = false; + UINT8 pnum = player-1; + //find what axis to get switch (axissel) { case AXISTURN: - axisval = cv_turnaxis[player-1].value; + axisval = cv_turnaxis[pnum].value; break; case AXISMOVE: - axisval = cv_moveaxis[player-1].value; + axisval = cv_moveaxis[pnum].value; break; case AXISCAMTURN: - axisval = cv_camturnaxis[player-1].value; + axisval = cv_camturnaxis[pnum].value; break; case AXISCAMSTRAFE: - axisval = cv_camstrafeaxis[player-1].value; + axisval = cv_camstrafeaxis[pnum].value; break; case AXISBRAKE: - axisval = cv_brakeaxis[player-1].value; + axisval = cv_brakeaxis[pnum].value; break; case AXISAIM: - axisval = cv_aimaxis[player-1].value; + axisval = cv_aimaxis[pnum].value; break; case AXISLOOK: - axisval = cv_lookaxis[player-1].value; + axisval = cv_lookaxis[pnum].value; break; case AXISFIRE: - axisval = cv_fireaxis[player-1].value; + axisval = cv_fireaxis[pnum].value; break; case AXISDRIFT: - axisval = cv_driftaxis[player-1].value; + axisval = cv_driftaxis[pnum].value; break; case AXISLOOKBACK: - axisval = cv_lookbackaxis[player-1].value; + axisval = cv_lookbackaxis[pnum].value; break; case AXISCUSTOM1: - axisval = cv_custom1axis[player-1].value; + axisval = cv_custom1axis[pnum].value; break; case AXISCUSTOM2: - axisval = cv_custom2axis[player-1].value; + axisval = cv_custom2axis[pnum].value; break; case AXISCUSTOM3: - axisval = cv_custom3axis[player-1].value; + axisval = cv_custom3axis[pnum].value; break; default: return 0; @@ -732,44 +734,51 @@ INT32 JoyAxis(axis_input_e axissel, UINT8 player) axisval = -axisval; flp = true; } + if (axisval > JOYAXISSET*2 || axisval == 0) //not there in array or None return 0; - if (axisval%2) + if (axisval % 2) { axisval /= 2; - retaxis = joyxmove[axisval]; + retaxis = joyxmove[pnum][axisval]; if (retaxis < (-JOYAXISRANGE)) retaxis = -JOYAXISRANGE; if (retaxis > (+JOYAXISRANGE)) retaxis = +JOYAXISRANGE; - if (!Joystick[player-1].bGamepadStyle && axissel < AXISDEAD) + if (!Joystick[pnum].bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_xdeadzone[player-1].value) >> FRACBITS; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_xdeadzone[pnum].value) >> FRACBITS; if (abs(retaxis) <= jdeadzone) return 0; } - if (flp) retaxis = -retaxis; //flip it around + + if (flp) + retaxis = -retaxis; // flip it around + return retaxis; } else { axisval--; axisval /= 2; - retaxis = joyymove[axisval]; + retaxis = joyymove[pnum][axisval]; if (retaxis < (-JOYAXISRANGE)) retaxis = -JOYAXISRANGE; if (retaxis > (+JOYAXISRANGE)) retaxis = +JOYAXISRANGE; - if (!Joystick[player-1].bGamepadStyle && axissel < AXISDEAD) + if (!Joystick[pnum].bGamepadStyle && axissel < AXISDEAD) { - const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_ydeadzone[player-1].value) >> FRACBITS; + const INT32 jdeadzone = ((JOYAXISRANGE-1) * cv_ydeadzone[pnum].value) >> FRACBITS; if (abs(retaxis) <= jdeadzone) return 0; } - if (flp) retaxis = -retaxis; //flip it around + + if (flp) + retaxis = -retaxis; // flip it around + return retaxis; } } @@ -1216,15 +1225,9 @@ static void G_DoLoadLevel(boolean resetplayer) } // clear cmd building stuff - memset(gamekeydown, 0, sizeof (gamekeydown)); - - for (i = 0; i < JOYAXISSET; i++) - { - joyxmove[i] = joyymove[i] = 0; - joy2xmove[i] = joy2ymove[i] = 0; - joy3xmove[i] = joy3ymove[i] = 0; - joy4xmove[i] = joy4ymove[i] = 0; - } + memset(gamekeydown, 0, sizeof(gamekeydown)); + memset(joyxmove, 0, sizeof(joyxmove)); + memset(joyymove, 0, sizeof(joyymove)); mousex = mousey = 0; // clear hud messages remains (usually from game startup) diff --git a/src/g_input.c b/src/g_input.c index 8d5b38bf2..09ed3303a 100644 --- a/src/g_input.c +++ b/src/g_input.c @@ -114,8 +114,7 @@ INT32 mousex, mousey; INT32 mlooky; // like mousey but with a custom sensitivity for mlook // joystick values are repeated -INT32 joyxmove[JOYAXISSET], joyymove[JOYAXISSET], joy2xmove[JOYAXISSET], joy2ymove[JOYAXISSET], -joy3xmove[JOYAXISSET], joy3ymove[JOYAXISSET], joy4xmove[JOYAXISSET], joy4ymove[JOYAXISSET]; +INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET], joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET]; // current state of the keys: true if pushed UINT8 gamekeydown[NUMINPUTS]; @@ -187,32 +186,32 @@ void G_MapEventsToControls(event_t *ev) i = ev->data1; if (i >= JOYAXISSET || menuactive || CON_Ready() || chat_on) break; - if (ev->data2 != INT32_MAX) joyxmove[i] = ev->data2; - if (ev->data3 != INT32_MAX) joyymove[i] = ev->data3; + if (ev->data2 != INT32_MAX) joyxmove[0][i] = ev->data2; + if (ev->data3 != INT32_MAX) joyymove[0][i] = ev->data3; break; case ev_joystick2: // buttons are virtual keys i = ev->data1; if (i >= JOYAXISSET || menuactive) break; - if (ev->data2 != INT32_MAX) joy2xmove[i] = ev->data2; - if (ev->data3 != INT32_MAX) joy2ymove[i] = ev->data3; + if (ev->data2 != INT32_MAX) joyxmove[1][i] = ev->data2; + if (ev->data3 != INT32_MAX) joyymove[1][i] = ev->data3; break; case ev_joystick3: i = ev->data1; if (i >= JOYAXISSET) break; - if (ev->data2 != INT32_MAX) joy3xmove[i] = ev->data2; - if (ev->data3 != INT32_MAX) joy3ymove[i] = ev->data3; + if (ev->data2 != INT32_MAX) joyxmove[2][i] = ev->data2; + if (ev->data3 != INT32_MAX) joyymove[2][i] = ev->data3; break; case ev_joystick4: i = ev->data1; if (i >= JOYAXISSET) break; - if (ev->data2 != INT32_MAX) joy4xmove[i] = ev->data2; - if (ev->data3 != INT32_MAX) joy4ymove[i] = ev->data3; + if (ev->data2 != INT32_MAX) joyxmove[3][i] = ev->data2; + if (ev->data3 != INT32_MAX) joyymove[3][i] = ev->data3; break; default: @@ -258,15 +257,6 @@ void G_ResetControls(void) memset(joyxmove, 0, sizeof(joyxmove)); memset(joyymove, 0, sizeof(joyymove)); - memset(joy2xmove, 0, sizeof(joy2xmove)); - memset(joy2ymove, 0, sizeof(joy2ymove)); - - memset(joy3xmove, 0, sizeof(joy3xmove)); - memset(joy3ymove, 0, sizeof(joy3ymove)); - - memset(joy4xmove, 0, sizeof(joy4xmove)); - memset(joy4ymove, 0, sizeof(joy4ymove)); - // reset those just in case the game missed the keyup event memset(dpadscrollstate, false, sizeof(dpadscrollstate)); } diff --git a/src/g_input.h b/src/g_input.h index d801d1020..970560a35 100644 --- a/src/g_input.h +++ b/src/g_input.h @@ -41,10 +41,12 @@ typedef enum KEY_DBLJOY1 = KEY_DBLMOUSE1 + MOUSEBUTTONS, KEY_DBLHAT1 = KEY_DBLJOY1 + JOYBUTTONS, - KEY_2JOY1 = KEY_DBLHAT1 + MOUSEBUTTONS, + KEY_2MOUSE1 = KEY_DBLHAT1 + JOYHATS*4, + KEY_2JOY1 = KEY_2MOUSE1 + MOUSEBUTTONS, KEY_2HAT1 = KEY_2JOY1 + JOYBUTTONS, - KEY_DBL2JOY1 = KEY_2HAT1 + MOUSEBUTTONS, + KEY_DBL2MOUSE1 = KEY_2HAT1 + JOYHATS*4, + KEY_DBL2JOY1 = KEY_DBL2MOUSE1 + MOUSEBUTTONS, KEY_DBL2HAT1 = KEY_DBL2JOY1 + JOYBUTTONS, KEY_3JOY1 = KEY_DBL2HAT1 + JOYHATS*4, @@ -61,8 +63,10 @@ typedef enum KEY_MOUSEWHEELUP = KEY_DBL4HAT1 + JOYHATS*4, KEY_MOUSEWHEELDOWN = KEY_MOUSEWHEELUP + 1, + KEY_2MOUSEWHEELUP = KEY_MOUSEWHEELDOWN + 1, + KEY_2MOUSEWHEELDOWN = KEY_2MOUSEWHEELUP + 1, - NUMINPUTS = KEY_MOUSEWHEELDOWN + 1, + NUMINPUTS = KEY_2MOUSEWHEELDOWN + 1, // FIXME: all the mouse 2 stuff should be removed, but it screws up mappings somehow } key_input_e; typedef enum @@ -113,8 +117,7 @@ extern consvar_t cv_gamepadled[MAXSPLITSCREENPLAYERS]; extern INT32 mousex, mousey; extern INT32 mlooky; //mousey with mlookSensitivity -extern INT32 joyxmove[JOYAXISSET], joyymove[JOYAXISSET], joy2xmove[JOYAXISSET], joy2ymove[JOYAXISSET], - joy3xmove[JOYAXISSET], joy3ymove[JOYAXISSET], joy4xmove[JOYAXISSET], joy4ymove[JOYAXISSET]; +extern INT32 joyxmove[MAXSPLITSCREENPLAYERS][JOYAXISSET], joyymove[MAXSPLITSCREENPLAYERS][JOYAXISSET]; // current state of the keys: true if pushed extern UINT8 gamekeydown[NUMINPUTS]; From d94c10014f129da926e234d56bd41ecb2bfb1d77 Mon Sep 17 00:00:00 2001 From: Indev Date: Thu, 24 Jul 2025 21:20:07 +0300 Subject: [PATCH 13/28] Move server search below refresh option --- src/m_menu.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 0000fae90..04f7bc6ff 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1114,10 +1114,10 @@ static menuitem_t MP_PlayerSetupMenu[] = #ifndef NONET static menuitem_t MP_ConnectMenu[] = { - {IT_STRING | IT_KEYHANDLER, NULL, "", M_HandleServerSearch,0}, - {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 16}, - {IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 24}, - {IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 32}, + {IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 0}, + {IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 8}, + {IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 16}, + {IT_STRING | IT_KEYHANDLER, NULL, "", M_HandleServerSearch,25}, {IT_STRING | IT_SPACE, NULL, "", M_Connect, 48}, {IT_STRING | IT_SPACE, NULL, "", M_Connect, 60}, @@ -1133,10 +1133,10 @@ static menuitem_t MP_ConnectMenu[] = enum { - mp_connect_search, mp_connect_sort, mp_connect_page, mp_connect_refresh, + mp_connect_search, FIRSTSERVERLINE }; #endif @@ -9884,15 +9884,16 @@ static void M_DrawConnectMenu(void) M_DrawServerLines(currentMenu->x, serverlistpage); } - V_DrawFill(currentMenu->x, currentMenu->y, MAXSTRINGLENGTH*8+6, 8+6, 239); + INT32 input_y = currentMenu->menuitems[mp_connect_search].alphaKey; + + V_DrawFill(currentMenu->x, currentMenu->y+input_y, MAXSTRINGLENGTH*8+6, 8+6, 239); const INT32 xoff = 3, yoff = 3; - - if (itemOn != 0) - V_DrawString(currentMenu->x+xoff, currentMenu->y+yoff, V_ALLOWLOWERCASE, menuinput.buffer); + if (itemOn != mp_connect_search) + V_DrawString(currentMenu->x+xoff, currentMenu->y+yoff+input_y, V_ALLOWLOWERCASE, menuinput.buffer); else - M_DrawTextInput(currentMenu->x+xoff, currentMenu->y+yoff, &menuinput, 0); + M_DrawTextInput(currentMenu->x+xoff, currentMenu->y+yoff+input_y, &menuinput, 0); localservercount = serverlistcount; From a658883664235b2a29e693629e9dbebfa2478efd Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 24 Jul 2025 20:39:50 +0200 Subject: [PATCH 14/28] fix console taking minutes to open during frameskipping prob not the best way to handle this, but its the simplest the console should always be openable without issues unless during wipes, since in some cases you end up having to kill the game to do anything --- src/d_main.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 3563f5949..71835c2e3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -896,9 +896,25 @@ void D_SRB2Loop(void) rendertimefrac_unpaused = FRACUNIT; } - if ((interp || doDisplay) && !frameskip) + + if (interp || doDisplay) { - ranwipe = D_Display(); + if (!frameskip) + { + ranwipe = D_Display(); + } + else if (frameskip) + { + // always update console and hud + // otherwise it may take minutes to open it + CON_Drawer(); + + if (gamestate == GS_LEVEL) + { + ST_Drawer(); + HU_Drawer(); + } + } } // Only take screenshots after drawing. From 93cbba218aef67ace9eaf26ed8568d718077ebd7 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 24 Jul 2025 22:33:53 +0200 Subject: [PATCH 15/28] add mobj islocal field so we can skip the pushable trigger stuff for local mobjs for synch reasons very sketchy --- src/k_kart.c | 11 ++++++----- src/lua_mobjlib.c | 3 ++- src/p_mobj.c | 2 +- src/p_mobj.h | 1 + 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 5d152ca17..4733f63ae 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3081,14 +3081,12 @@ static void K_SpawnDriftSparks(player_t *player) if (leveltime % 2 == 1) return; - if (cv_airsparks.value) - goto skipground; + const boolean onground = P_IsObjectOnGround(player->mo); - if (!P_IsObjectOnGround(player->mo)) + // kinda sketchy + if (!cv_airsparks.value && onground) return; -skipground: // idk im sleepy - if (!player->kartstuff[k_drift] || player->kartstuff[k_driftcharge] < K_GetKartDriftSparkValue(player)) return; @@ -3105,6 +3103,8 @@ skipground: // idk im sleepy newy = player->mo->y + P_ReturnThrustY(player->mo, thrustangle, smolscale); spark = P_SpawnMobj(newx, newy, player->mo->z, MT_DRIFTSPARK); + spark->islocal = cv_airsparks.value && !onground; + P_SetTarget(&spark->target, player->mo); spark->angle = travelangle-(ANGLE_45/5)*player->kartstuff[k_drift]; @@ -5361,6 +5361,7 @@ FUNCINLINE static ATTRINLINE void K_SpawnNormalSpeedLines(player_t *player, bool fast->momx = 3*player->mo->momx/4; fast->momy = 3*player->mo->momy/4; fast->momz = 3*player->mo->momz/4; + fast->islocal = !synched; P_SetTarget(&fast->target, player->mo); // easier lua access K_MatchGenericExtraFlags(fast, player->mo); diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c index 4103bce99..ea936d773 100644 --- a/src/lua_mobjlib.c +++ b/src/lua_mobjlib.c @@ -150,7 +150,8 @@ static const udata_field_t mobj_fields[] = { FIELD(mobj_t, cvmem, udatalib_getter_int32, udatalib_setter_int32), FIELD(mobj_t, standingslope, udatalib_getter_slope, mobj_standingslope_noset), FIELD(mobj_t, colorized, udatalib_getter_boolean, udatalib_setter_boolean), - FIELD(mobj_t, mirrored, udatalib_getter_boolean, udatalib_setter_boolean), + FIELD(mobj_t, mirrored, udatalib_getter_boolean, udatalib_setter_boolean), + FIELD(mobj_t, islocal, udatalib_getter_boolean, udatalib_setter_boolean), { NULL, 0, NULL, NULL }, }; #undef FIELD diff --git a/src/p_mobj.c b/src/p_mobj.c index 09649d530..8907ba41a 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6089,7 +6089,7 @@ void P_MobjThinker(mobj_t *mobj) const sector_t *sec1 = mobj->subsector ? mobj->subsector->sector : NULL; // 970 allows ANY mobj to trigger a linedef exec - if (UNLIKELY(sec1 && GETSECSPECIAL(sec1->special, 2) == 8)) + if (UNLIKELY(!mobj->islocal && sec1 && GETSECSPECIAL(sec1->special, 2) == 8)) // BEWARE: islocal does not exist in vanilla { sector_t *sec2; sec2 = P_ThingOnSpecial3DFloor(mobj); diff --git a/src/p_mobj.h b/src/p_mobj.h index cd4033157..0967b1dd5 100644 --- a/src/p_mobj.h +++ b/src/p_mobj.h @@ -414,6 +414,7 @@ typedef struct mobj_s boolean init_salty; // WARNING: New fields must be added separately to savegame and Lua. + boolean islocal; // BEWARE: islocal does not exist in vanilla, strictly to be used for locally loaded addons to not cause desynchs with the mobj linedef trigger check. DO NOT USE THIS IN ACTUAL ADDONS YOU INTEND TO USE ON YOUR SERVER } mobj_t; // From a4810bd6c847a82e824a7c6edbac0ce272cbd04b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustaf=20Alh=C3=A4ll?= Date: Thu, 24 Jul 2025 23:30:09 +0200 Subject: [PATCH 16/28] Fix custom addon directory being ignored when downloading addons --- src/d_netfil.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/d_netfil.c b/src/d_netfil.c index d45570a0e..650433e44 100644 --- a/src/d_netfil.c +++ b/src/d_netfil.c @@ -1185,6 +1185,18 @@ filestatus_t findfile(char *filename, const UINT8 *wantedmd5sum, boolean complet badmd5 = true; // if not found at all, just move on without doing anything + if (cv_addons_option.value == 3 && *cv_addons_folder.string != '\0') + { + // next, check any custom directory if specified + homecheck = filesearch(filename, cv_addons_folder.string, wantedmd5sum, completepath, 10); + + if (homecheck == FS_FOUND) // we found the file, so return that we have :) + return FS_FOUND; + else if (homecheck == FS_MD5SUMBAD) // file has a bad md5; move on and look for a file with the right md5 + badmd5 = true; + // if not found at all, just move on without doing anything + } + // finally check "." directory homecheck = filesearch(filename, ".", wantedmd5sum, completepath, 10); From f97941f86e30751a222545c18a1a9cbe6bc4de6d Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 24 Jul 2025 23:47:23 +0200 Subject: [PATCH 17/28] update link in addon menu to "mb.srb2.org/addons" :chonkbuncle: --- src/m_menu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 04f7bc6ff..debb3c7b5 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6072,8 +6072,8 @@ static void M_AddonsOptions(INT32 choice) M_SetupNextMenu(&OP_AddonsOptionsDef); } -#define LOCATIONSTRING1 "Visit \x83SRB2.ORG/MODS\x80 to get & make addons!" -#define LOCATIONSTRING2 "Visit \x88SRB2.ORG/MODS\x80 to get & make addons!" +#define LOCATIONSTRING1 "Visit \x83mb.srb2.org/addons\x80 to get & make addons!" +#define LOCATIONSTRING2 "Visit \x88mb.srb2.org/addons\x80 to get & make addons!" static void M_AddonsInternal(void) { From 9261d9c5b2d96f612d4c1181dab4a185d286a041 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:12:29 +0200 Subject: [PATCH 18/28] D_CleanFile can be static --- src/d_main.c | 4 +++- src/d_main.h | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 71835c2e3..1140362b3 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -152,6 +152,8 @@ boolean dedicated = false; boolean loaded_config = false; // true once config.cfg loaded AND executed +static void D_CleanFile(char **filearray); + // // D_PostEvent // Called by the I/O functions when input is detected @@ -1231,7 +1233,7 @@ void D_AddPostloadFiles(void) postautoloaded = true; } -void D_CleanFile(char **filearray) +static void D_CleanFile(char **filearray) { size_t pnumwadfiles; for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) diff --git a/src/d_main.h b/src/d_main.h index 1e2de572d..69bbe3026 100644 --- a/src/d_main.h +++ b/src/d_main.h @@ -85,8 +85,6 @@ void D_PostEvent(const event_t *ev); void D_ProcessEvents(void); -void D_CleanFile(char **filearray); - const char *D_Home(void); // From 3e8b3e868b5956bf7c7dd6d156347d0aa57b4553 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:13:19 +0200 Subject: [PATCH 19/28] simplify this --- src/hu_stuff.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 07ebdd26f..59aba1874 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -310,7 +310,7 @@ void HU_LoadGraphics(void) lt_font[0] = (patch_t *)W_CachePatchName("LTFNT039", PU_HUDGFX); /// \note fake start hack // Number support - lt_font[9] = (patch_t *)W_CachePatchName("LTFNT048", PU_HUDGFX); + lt_font[9] = (patch_t *)W_CachePatchName("LTFNT048", PU_HUDGFX); lt_font[10] = (patch_t *)W_CachePatchName("LTFNT049", PU_HUDGFX); lt_font[11] = (patch_t *)W_CachePatchName("LTFNT050", PU_HUDGFX); lt_font[12] = (patch_t *)W_CachePatchName("LTFNT051", PU_HUDGFX); @@ -747,7 +747,7 @@ static void Command_CSay_f(void) return; } - if(!server && !IsPlayerAdmin(consoleplayer)) + if (!server && !IsPlayerAdmin(consoleplayer)) { CONS_Alert(CONS_NOTICE, M_GetText("Only servers and admins can use csay.\n")); return; @@ -2881,13 +2881,11 @@ void HU_DoCEcho(const char *msg) *p = '\n'; CONS_Printf("%s\n", temp); + return; } + else if (cv_cechotoggle.value) + cechotimer = cechoduration; - I_OutputMsg("%s\n", msg); // print to log - - if (!cv_cechotoggle.value) - return; - - cechotimer = cechoduration; + I_OutputMsg("%s\n", msg); // ALWAYS print to log } From 306fec6f9eb29ddf66d7350e2ef84261719dc546 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:14:04 +0200 Subject: [PATCH 20/28] get rid of code dupe for fpscapping stuff --- src/r_fps.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/src/r_fps.c b/src/r_fps.c index 0c3a58737..f5d02dda1 100644 --- a/src/r_fps.c +++ b/src/r_fps.c @@ -42,13 +42,13 @@ static CV_PossibleValue_t fpscap_cons_t[] = { {0, NULL} }; -consvar_t cv_fpscap = {"fpscap", "Match refresh rate", CV_SAVE, fpscap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fpscap = {"fpscap", "Match refresh rate", CV_SAVE, fpscap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_fpscapbg = {"fpscapbackground", "Match refresh rate", CV_SAVE, fpscap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_precipinterp = {"precipinterpolation", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; ps_metric_t ps_interp_frac = {0}; -ps_metric_t ps_interp_lag = {0}; +ps_metric_t ps_interp_lag = {0}; static boolean R_UseBackgroundFramerateCap(void) { @@ -67,21 +67,21 @@ static boolean R_UseBackgroundFramerateCap(void) return false; } -static UINT32 R_GetBackgroundFramerateCap(void) +static UINT32 R_GetFrameCap(INT32 val) { - if (cv_fpscapbg.value == 0) + if (val == 0) { // 0: Match refresh rate return I_GetRefreshRate(); } - if (cv_fpscapbg.value < 0) + if (val < 0) { // -1: Unlimited return 0; } - return cv_fpscapbg.value; + return val; } UINT32 R_GetFramerateCap(void) @@ -95,22 +95,10 @@ UINT32 R_GetFramerateCap(void) if (R_UseBackgroundFramerateCap()) { - return R_GetBackgroundFramerateCap(); + return R_GetFrameCap(cv_fpscapbg.value); } - if (cv_fpscap.value == 0) - { - // 0: Match refresh rate - return I_GetRefreshRate(); - } - - if (cv_fpscap.value < 0) - { - // -1: Unlimited - return 0; - } - - return cv_fpscap.value; + return R_GetFrameCap(cv_fpscap.value); } boolean R_UsingFrameInterpolation(void) From 9859e43be775ac2479a61991fc11213bcb1b34d1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:15:27 +0200 Subject: [PATCH 21/28] get rid of some redundancy R_Frame stuff R_SetupCommonFrame already checks the actual sector for us, so we dont need to do this before --- src/r_main.cpp | 66 ++++++++++++++++++++++++++------------------------ src/r_main.h | 4 +-- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index cef57ad2e..155711a36 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1133,7 +1133,6 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh { if (skyboxmo[1]) { - angle_t ang; fixed_t x = 0, y = 0; if (mh->skybox_scalex > 0) @@ -1165,8 +1164,8 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh newview->y -= x; break; default: - ang = viewmobj->angle>>ANGLETOFINESHIFT; - newview->x += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang)); + angle_t ang = viewmobj->angle>>ANGLETOFINESHIFT; + newview->x += FixedMul(x,FINECOSINE(ang)) - FixedMul(y, FINESINE(ang)); newview->y += FixedMul(x, FINESINE(ang)) + FixedMul(y,FINECOSINE(ang)); break; } @@ -1192,14 +1191,14 @@ static void R_SetupSkyScale(player_t *player, camera_t *thiscam, mapheader_t *mh } } -void R_SkyboxFrame(int s) +void R_SkyboxFrame(UINT8 pnum) { - player_t *player = &players[displayplayers[s]]; - camera_t *thiscam = &camera[s]; - subsector_t *subsector = NULL; + player_t *player = &players[displayplayers[pnum]]; + camera_t *thiscam = &camera[pnum]; + sector_t *viewsec = NULL; mapheader_t *mh = mapheaderinfo[gamemap-1]; - R_SetViewContext(static_cast(VIEWCONTEXT_SKY1 + s)); + R_SetViewContext(static_cast(VIEWCONTEXT_SKY1 + pnum)); // cut-away view stuff newview->sky = true; @@ -1215,35 +1214,38 @@ void R_SkyboxFrame(int s) R_SetupAimingFrame(player, thiscam); - newview->angle += viewmobj->angle; + if (!P_MobjWasRemoved(viewmobj)) + { + newview->angle += viewmobj->angle; - newview->x = viewmobj->x; - newview->y = viewmobj->y; - newview->z = (viewmobj->spawnpoint) ? (((fixed_t)viewmobj->spawnpoint->angle)<x = viewmobj->x; + newview->y = viewmobj->y; + newview->z = (viewmobj->spawnpoint) ? (((fixed_t)viewmobj->spawnpoint->angle) << FRACBITS) : 0; + + if (viewmobj->subsector) + viewsec = viewmobj->subsector->sector; + } if (mh) { R_SetupSkyScale(player, thiscam, mh); } - if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && viewmobj->subsector->sector) - subsector = viewmobj->subsector; - - R_SetupCommonFrame(player, subsector->sector); + R_SetupCommonFrame(player, viewsec); } -void R_SetupFrame(int s, boolean skybox) +void R_SetupFrame(UINT8 pnum, boolean skybox) { - player_t *player = &players[displayplayers[s]]; - camera_t *thiscam = &camera[s]; - boolean chasecam = (cv_chasecam[s].value); - sector_t * sector = NULL; + player_t *player = &players[displayplayers[pnum]]; + camera_t *thiscam = &camera[pnum]; + boolean chasecam = (cv_chasecam[pnum].value); + sector_t *viewsec = NULL; - R_SetViewContext(static_cast(VIEWCONTEXT_PLAYER1 + s)); + R_SetViewContext(static_cast(VIEWCONTEXT_PLAYER1 + pnum)); if (thiscam->reset) { - R_ResetViewInterpolation(s); + R_ResetViewInterpolation(pnum); thiscam->reset = false; } @@ -1278,10 +1280,10 @@ void R_SetupFrame(int s, boolean skybox) newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; - if (viewmobj->subsector && viewmobj->subsector->sector) - sector = viewmobj->subsector->sector; + if (viewmobj->subsector) + viewsec = viewmobj->subsector->sector; - R_SetupCommonFrame(player, sector); + R_SetupCommonFrame(player, viewsec); } else if (thiscam && chasecam) // use outside cam view { @@ -1292,10 +1294,10 @@ void R_SetupFrame(int s, boolean skybox) newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); - if (thiscam->subsector && thiscam->subsector->sector) - sector = thiscam->subsector->sector; + if (thiscam->subsector) + viewsec = thiscam->subsector->sector; - R_SetupCommonFrame(player, sector); + R_SetupCommonFrame(player, viewsec); } else if (player->mo) // use the player's eyes view { @@ -1306,10 +1308,10 @@ void R_SetupFrame(int s, boolean skybox) newview->y = viewmobj->y; newview->z = player->viewz; - if (viewmobj->subsector && viewmobj->subsector->sector) - sector = viewmobj->subsector->sector; + if (viewmobj->subsector) + viewsec = viewmobj->subsector->sector; - R_SetupCommonFrame(player, sector); + R_SetupCommonFrame(player, viewsec); } } diff --git a/src/r_main.h b/src/r_main.h index 295e6e34d..82a0205d3 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -215,8 +215,8 @@ void R_SetViewSize(void); void R_ExecuteSetViewSize(void); fixed_t R_GetPlayerFov(player_t *player); -void R_SkyboxFrame(int s); -void R_SetupFrame(int s, boolean skybox); +void R_SkyboxFrame(UINT8 pnum); +void R_SetupFrame(UINT8 pnum, boolean skybox); // Called by G_Drawer. void R_RenderPlayerView(player_t *player); From d91fbf5d367f1fc377a17040c5276c051fc57119 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:16:31 +0200 Subject: [PATCH 22/28] move assignments after early returns ST_drawLevelTitle --- src/st_stuff.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 16a45ea59..d429cf719 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -419,27 +419,28 @@ static void ST_drawDebugInfo(void) static void ST_drawLevelTitle(void) { - char *lvlttl = mapheaderinfo[gamemap-1]->lvlttl; - char *subttl = mapheaderinfo[gamemap-1]->subttl; - char *zonttl = mapheaderinfo[gamemap-1]->zonttl; // SRB2kart - char *actnum = mapheaderinfo[gamemap-1]->actnum; - INT32 lvlttlxpos; - INT32 ttlnumxpos; - INT32 zonexpos; - INT32 dupcalc = (vid.width/vid.dupx); - UINT8 gtc = G_GetGametypeColor(gametype); + char *lvlttl, *subttl, *zonttl, *actnum; + INT32 lvlttlxpos, ttlnumxpos, zonexpos; + INT32 dupcalc; + UINT8 gtc; INT32 sub = 0; - INT32 bary = (splitscreen) - ? BASEVIDHEIGHT/2 - : 163; + INT32 bary; INT32 lvlw; - if (!cv_stagetitle.value) + if (!cv_stagetitle.value || (timeinmap > 113)) return; - if (timeinmap > 113) + if (*mapheaderinfo[gamemap-1]->lvlttl == '\0') return; + lvlttl = mapheaderinfo[gamemap-1]->lvlttl; + subttl = mapheaderinfo[gamemap-1]->subttl; + zonttl = mapheaderinfo[gamemap-1]->zonttl; // SRB2kart + actnum = mapheaderinfo[gamemap-1]->actnum; + dupcalc = (vid.width/vid.dupx); + gtc = G_GetGametypeColor(gametype); + bary = (splitscreen) ? BASEVIDHEIGHT/2 : 163; + lvlw = V_LevelNameWidth(lvlttl); if (actnum[0]) @@ -603,7 +604,7 @@ static void ST_overlayDrawer(void) } // draw level title Tails - if (*mapheaderinfo[gamemap-1]->lvlttl != '\0' && !(hu_showscores && (netgame || multiplayer) && !mapreset) && LUA_HudEnabled(hud_stagetitle) && !forceshowhud) + if (!(hu_showscores && (netgame || multiplayer) && !mapreset) && LUA_HudEnabled(hud_stagetitle) && !forceshowhud) ST_drawLevelTitle(); if (!hu_showscores && netgame && !mapreset) From cb2e017bcf3d78efaf8d09b9f179ae315ac9926e Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 26 Jul 2025 16:16:51 +0200 Subject: [PATCH 23/28] seenames stuff is always unlikely --- src/st_stuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index d429cf719..0ca8c562c 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -741,7 +741,7 @@ void ST_Drawer(void) UINT8 i; #ifdef SEENAMES - if (cv_seenames.value && cv_allowseenames.value && displayplayers[0] == consoleplayer && seenplayer && seenplayer->mo && !mapreset) + if (UNLIKELY(cv_seenames.value && cv_allowseenames.value && displayplayers[0] == consoleplayer && seenplayer && seenplayer->mo && !mapreset)) { if (cv_seenames.value == 1) V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2 + 15, V_HUDTRANSHALF, player_names[seenplayer-players]); From d9c7a40d4a6af003bbe3912e8389e92e4c2e13bb Mon Sep 17 00:00:00 2001 From: chromaticpipe <127907268+chromaticpipe@users.noreply.github.com> Date: Sat, 26 Jul 2025 11:58:55 -0500 Subject: [PATCH 24/28] Borderless window toggle --- src/sdl/i_video.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index f4a2c288c..e357d98e8 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -134,9 +134,12 @@ static INT32 desktopwidth = 0, desktopheight = 0; static void I_CheckDesktopRes(void); +static void VID_SetBorderless(void); + // synchronize page flipping with screen refresh consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; +static consvar_t cv_borderless = {"borderless", "Off", CV_SAVE|CV_CALL, CV_OnOff, VID_SetBorderless, 0, NULL, NULL, 0, 0, NULL}; static void mousegrabOnChange(void); consvar_t cv_alwaysgrabmouse = {"alwaysgrabmouse", "Off", CV_SAVE|CV_CALL, CV_OnOff, mousegrabOnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -1353,6 +1356,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { wasfullscreen = SDL_TRUE; SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + VID_SetBorderless(); } else // windowed mode { @@ -1877,6 +1881,7 @@ void I_StartupGraphics(void) CV_RegisterVar (&cv_vidwait); CV_RegisterVar (&cv_stretch); CV_RegisterVar (&cv_alwaysgrabmouse); + CV_RegisterVar (&cv_borderless); disable_mouse = M_CheckParm("-nomouse"); disable_fullscreen = M_CheckParm("-win") ? 1 : 0; @@ -2157,4 +2162,10 @@ static void Impl_SetVsync(void) #endif } +static void VID_SetBorderless(void) +{ + SDL_bool borderless = (cv_borderless.value) ? SDL_FALSE : SDL_TRUE; + SDL_SetWindowBordered(window, borderless); +} + #endif From fae50c0e19c539517860af8d6aa6f81118df6814 Mon Sep 17 00:00:00 2001 From: chromaticpipe <127907268+chromaticpipe@users.noreply.github.com> Date: Sat, 26 Jul 2025 15:18:03 -0500 Subject: [PATCH 25/28] Make it a part of fullscreen cvar --- src/dedicated/i_video.c | 5 +++++ src/i_video.h | 2 ++ src/screen.c | 6 +++++- src/sdl/i_video.c | 12 ++++-------- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/dedicated/i_video.c b/src/dedicated/i_video.c index 6c0b6644a..8f8781e9e 100644 --- a/src/dedicated/i_video.c +++ b/src/dedicated/i_video.c @@ -152,3 +152,8 @@ boolean I_UseNativeKeyboard(void) { return false; } + +void I_SetBorderlessWindow(void) +{ + +} diff --git a/src/i_video.h b/src/i_video.h index 68042a654..88d295ed9 100644 --- a/src/i_video.h +++ b/src/i_video.h @@ -145,6 +145,8 @@ boolean I_UseNativeKeyboard(void); boolean I_CheckNativeRes(void); +void I_SetBorderlessWindow(void); + #ifdef USE_FBO_OGL void RefreshOGLSDLSurface(void); diff --git a/src/screen.c b/src/screen.c index eb6c2bc82..a8a3ca78b 100644 --- a/src/screen.c +++ b/src/screen.c @@ -66,7 +66,9 @@ static void Highreshudscale_OnChange(void) static void SCR_ChangeFullscreen (void); -consvar_t cv_fullscreen = {"fullscreen", "Yes", CV_SAVE|CV_CALL, CV_YesNo, SCR_ChangeFullscreen, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t fullscreen_cons_t[] = {{0, "No"}, {1, "Yes"}, {2, "Borderless Window"}, {0, NULL}}; + +consvar_t cv_fullscreen = {"fullscreen", "Yes", CV_SAVE|CV_CALL, fullscreen_cons_t, SCR_ChangeFullscreen, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t accuratefps_cons_t[] = {{0, "Inaccurate"}, {1, "Accurate"}, {0, NULL}}; consvar_t cv_accuratefps = {"fpssampling", "1", CV_SAVE, accuratefps_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -325,6 +327,8 @@ void SCR_SetDefaultMode(void) void SCR_ChangeFullscreen(void) { #ifdef DIRECTFULLSCREEN + I_SetBorderlessWindow(); // Running this here so we can have borderless window at startup + // allow_fullscreen is set by VID_PrepareModeList // it is used to prevent switching to fullscreen during startup if (!allow_fullscreen) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index e357d98e8..fa55e62f1 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -134,12 +134,9 @@ static INT32 desktopwidth = 0, desktopheight = 0; static void I_CheckDesktopRes(void); -static void VID_SetBorderless(void); - // synchronize page flipping with screen refresh consvar_t cv_vidwait = {"vid_wait", "Off", CV_SAVE|CV_CALL|CV_NOINIT, CV_OnOff, Impl_SetVsync, 0, NULL, NULL, 0, 0, NULL}; static consvar_t cv_stretch = {"stretch", "Off", CV_SAVE|CV_NOSHOWHELP, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; -static consvar_t cv_borderless = {"borderless", "Off", CV_SAVE|CV_CALL, CV_OnOff, VID_SetBorderless, 0, NULL, NULL, 0, 0, NULL}; static void mousegrabOnChange(void); consvar_t cv_alwaysgrabmouse = {"alwaysgrabmouse", "Off", CV_SAVE|CV_CALL, CV_OnOff, mousegrabOnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -153,7 +150,7 @@ UINT8 graphics_started = 0; // Is used in console.c and screen.c // To disable fullscreen at startup; is set in VID_PrepareModeList boolean allow_fullscreen = false; static SDL_bool disable_fullscreen = SDL_FALSE; -#define USE_FULLSCREEN (disable_fullscreen||!allow_fullscreen)?0:cv_fullscreen.value +#define USE_FULLSCREEN (disable_fullscreen||!allow_fullscreen)? 0: (cv_fullscreen.value == 1) static SDL_bool disable_mouse = SDL_FALSE; #define USE_MOUSEINPUT (!disable_mouse && cv_usemouse.value && havefocus) #define MOUSE_MENU false //(!disable_mouse && cv_usemouse.value && menuactive && !USE_FULLSCREEN) @@ -1356,7 +1353,7 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) { wasfullscreen = SDL_TRUE; SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); - VID_SetBorderless(); + I_SetBorderlessWindow(); } else // windowed mode { @@ -1881,7 +1878,6 @@ void I_StartupGraphics(void) CV_RegisterVar (&cv_vidwait); CV_RegisterVar (&cv_stretch); CV_RegisterVar (&cv_alwaysgrabmouse); - CV_RegisterVar (&cv_borderless); disable_mouse = M_CheckParm("-nomouse"); disable_fullscreen = M_CheckParm("-win") ? 1 : 0; @@ -2162,9 +2158,9 @@ static void Impl_SetVsync(void) #endif } -static void VID_SetBorderless(void) +void I_SetBorderlessWindow(void) { - SDL_bool borderless = (cv_borderless.value) ? SDL_FALSE : SDL_TRUE; + SDL_bool borderless = (cv_fullscreen.value == 2) ? SDL_FALSE : SDL_TRUE; SDL_SetWindowBordered(window, borderless); } From 6ef1f73d4dbfa2b81f7c8dcecb53909b231ddd24 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 27 Jul 2025 13:54:27 +0300 Subject: [PATCH 26/28] Init displayplayers to {0} --- src/g_game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/g_game.c b/src/g_game.c index 83be4ecf4..76b076bba 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -109,7 +109,7 @@ boolean addedtogame; player_t players[MAXPLAYERS]; INT32 consoleplayer; // player taking events and displaying -INT32 displayplayers[MAXSPLITSCREENPLAYERS]; // view being displayed +INT32 displayplayers[MAXSPLITSCREENPLAYERS] = {0}; // view being displayed tic_t gametic; tic_t levelstarttic; // gametic at level start From 3f599d5a281dc6a3e26f49b76536fd50a033fbe1 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 27 Jul 2025 14:03:35 +0300 Subject: [PATCH 27/28] Fix smol typo :3 --- src/k_kart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/k_kart.c b/src/k_kart.c index 4733f63ae..f9b7f6afb 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3084,7 +3084,7 @@ static void K_SpawnDriftSparks(player_t *player) const boolean onground = P_IsObjectOnGround(player->mo); // kinda sketchy - if (!cv_airsparks.value && onground) + if (!cv_airsparks.value && !onground) return; if (!player->kartstuff[k_drift] || player->kartstuff[k_driftcharge] < K_GetKartDriftSparkValue(player)) From 0f087d13bba436cf0c29959de1a4b56a99de6cb2 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 27 Jul 2025 14:18:30 +0200 Subject: [PATCH 28/28] dont do this in dedi dont need to, its pointless and prob causes more issues than anything --- src/d_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 1140362b3..4dc4b6896 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -898,14 +898,13 @@ void D_SRB2Loop(void) rendertimefrac_unpaused = FRACUNIT; } - if (interp || doDisplay) { if (!frameskip) { ranwipe = D_Display(); } - else if (frameskip) + else if (!dedicated) { // always update console and hud // otherwise it may take minutes to open it