From f5fdf917bd76506fcaed6a05cb4f73982833580b Mon Sep 17 00:00:00 2001 From: Eidolon Date: Sat, 11 Jul 2026 13:48:56 -0500 Subject: [PATCH 01/22] Support >4GB sys mem in memfree for linux, win32, macOS sys mem counts Also includes memory counts for the extended allocation functionality --- src/android/i_system.c | 10 +++---- src/core/memory.cpp | 3 +++ src/core/memory.h | 4 +++ src/dedicated/i_system.c | 56 +++++++++++++++++++++++++++++++++------- src/sdl/i_system.cpp | 54 +++++++++++++++++++++++++++++++------- src/z_zone.cpp | 10 +++++++ src/z_zone.h | 1 + 7 files changed, 113 insertions(+), 25 deletions(-) diff --git a/src/android/i_system.c b/src/android/i_system.c index ef10df5b5..c0f7cc11c 100644 --- a/src/android/i_system.c +++ b/src/android/i_system.c @@ -34,8 +34,8 @@ size_t I_GetFreeMem(size_t *total) /* return si.freeram; */ char buf[1024]; char *memTag; - UINT32 freeKBytes; - UINT32 totalKBytes; + size_t freeKBytes; + size_t totalKBytes; INT32 n; INT32 meminfo_fd = -1; @@ -46,7 +46,7 @@ size_t I_GetFreeMem(size_t *total) if (n < 0) { // Error - *total = 0L; + *total = 0; return 0; } @@ -54,7 +54,7 @@ size_t I_GetFreeMem(size_t *total) if (NULL == (memTag = strstr(buf, MEMTOTAL))) { // Error - *total = 0L; + *total = 0; return 0; } @@ -64,7 +64,7 @@ size_t I_GetFreeMem(size_t *total) if (NULL == (memTag = strstr(buf, MEMFREE))) { // Error - *total = 0L; + *total = 0; return 0; } diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 9e591e78c..81ba79d5d 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -114,6 +114,7 @@ void* PoolAllocator::allocate() FreeBlock* ret = head_; head_ = head_->next; + allocated_blocks_++; return ret; } @@ -125,6 +126,7 @@ void PoolAllocator::deallocate(void* p) FreeBlock* block = reinterpret_cast(p); block->next = head_; head_ = block; + allocated_blocks_--; } void PoolAllocator::release() @@ -144,6 +146,7 @@ void PoolAllocator::release() first_chunk_ = nullptr; head_ = nullptr; + allocated_blocks_ = 0; } static LinearMemory g_frame_memory {4 * 1024 * 1024}; diff --git a/src/core/memory.h b/src/core/memory.h index 77e7206b5..4aec917d7 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -37,6 +37,7 @@ class PoolAllocator final FreeBlock* head_; size_t block_size_; size_t blocks_; + size_t allocated_blocks_; int32_t tag_; ChunkFooter* allocate_chunk(); @@ -47,6 +48,7 @@ public: , head_(nullptr) , block_size_(block_size) , blocks_(blocks) + , allocated_blocks_(0) , tag_(tag) {} PoolAllocator(const PoolAllocator&) = delete; @@ -59,6 +61,8 @@ public: void* allocate(); void deallocate(void* p); constexpr size_t block_size() const noexcept { return block_size_; }; + constexpr size_t allocated_blocks() const noexcept { return allocated_blocks_; }; + constexpr size_t allocated_bytes() const noexcept { return allocated_blocks_ * block_size_; }; void release(); }; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index fb3cc2731..fc38ffdef 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -68,6 +68,12 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #include #if defined (__linux__) #include +#elif defined(__APPLE__) +#include +#include +#include +#include +#include #else #include #include @@ -2009,13 +2015,13 @@ size_t I_GetFreeMem(size_t *total) *total = 32 << 20; return 32 << 20; #elif defined (_WIN32) - MEMORYSTATUS info; + MEMORYSTATUSEX info; - info.dwLength = sizeof (MEMORYSTATUS); - GlobalMemoryStatus( &info ); + info.dwLength = sizeof (MEMORYSTATUSEX); + GlobalMemoryStatusEx( &info ); if (total) - *total = (size_t)info.dwTotalPhys; - return (size_t)info.dwAvailPhys; + *total = (size_t)info.ullTotalPhys; + return (size_t)info.ullAvailPhys; #elif defined (__OS2__) UINT32 pr_arena; @@ -2048,7 +2054,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } @@ -2057,12 +2063,12 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } memTag += sizeof (MEMTOTAL); - totalKBytes = (size_t)atoi(memTag); + totalKBytes = strtoul(memTag, NULL, 10); if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) { @@ -2076,7 +2082,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } freeKBytes = MemAvailable; @@ -2084,16 +2090,46 @@ size_t I_GetFreeMem(size_t *total) else { memTag += sizeof (MEMAVAILABLE); - freeKBytes = atoi(memTag); + freeKBytes = strtoul(memTag, NULL, 10); } if (total) *total = totalKBytes << 10; return freeKBytes << 10; +#elif defined(__APPLE__) + /* macOS */ + mach_port_t host = mach_host_self(); + kern_return_t kr; + mach_msg_type_number_t count; + vm_size_t v_page_size; + struct vm_statistics64 vm_stats; + uint64_t total_mem, free_mem; + size_t size; + + size = sizeof(total_mem); + if (sysctlbyname("hw.memsize", &total_mem, &size, NULL, 0) < 0) + total_mem = 0; + + kr = host_page_size(host, &v_page_size); + if (kr != KERN_SUCCESS) + v_page_size = 4096; + + count = HOST_VM_INFO64_COUNT; + kr = host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count); + if (kr == KERN_SUCCESS) + free_mem = (uint64_t)(vm_stats.free_count + vm_stats.inactive_count) * v_page_size; + else + free_mem = 0; + + if (total) + *total = (size_t)total_mem; + return (size_t)free_mem; #else // Guess 48 MB. if (total) + { *total = 48<<20; + } return 48<<20; #endif } diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 4e9de24c2..fb4f0dcd5 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -83,6 +83,12 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #if defined (__unix__) || defined(__APPLE__) || (defined (UNIXCOMMON) && !defined (__HAIKU__)) #if defined (__linux__) #include +#elif defined(__APPLE__) +#include +#include +#include +#include +#include #else #include #include @@ -2635,13 +2641,13 @@ size_t I_GetFreeMem(size_t *total) *total = 32 << 20; return 32 << 20; #elif defined (_WIN32) - MEMORYSTATUS info; + MEMORYSTATUSEX info; - info.dwLength = sizeof (MEMORYSTATUS); - GlobalMemoryStatus( &info ); + info.dwLength = sizeof (MEMORYSTATUSEX); + GlobalMemoryStatusEx( &info ); if (total) - *total = (size_t)info.dwTotalPhys; - return (size_t)info.dwAvailPhys; + *total = (size_t)info.ullTotalPhys; + return (size_t)info.ullAvailPhys; #elif defined (__OS2__) UINT32 pr_arena; @@ -2674,7 +2680,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } @@ -2683,12 +2689,12 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } memTag += sizeof (MEMTOTAL); - totalKBytes = (size_t)atoi(memTag); + totalKBytes = strtoul(memTag, NULL, 10); if ((memTag = strstr(buf, MEMAVAILABLE)) == NULL) { @@ -2702,7 +2708,7 @@ size_t I_GetFreeMem(size_t *total) { // Error if (total) - *total = 0L; + *total = 0; return 0; } freeKBytes = MemAvailable; @@ -2710,12 +2716,40 @@ size_t I_GetFreeMem(size_t *total) else { memTag += sizeof (MEMAVAILABLE); - freeKBytes = atoi(memTag); + freeKBytes = strtoul(memTag, NULL, 10); } if (total) *total = totalKBytes << 10; return freeKBytes << 10; +#elif defined(__APPLE__) + /* macOS */ + mach_port_t host = mach_host_self(); + kern_return_t kr; + mach_msg_type_number_t count; + vm_size_t v_page_size; + struct vm_statistics64 vm_stats; + uint64_t total_mem, free_mem; + size_t size; + + size = sizeof(total_mem); + if (sysctlbyname("hw.memsize", &total_mem, &size, NULL, 0) < 0) + total_mem = 0; + + kr = host_page_size(host, &v_page_size); + if (kr != KERN_SUCCESS) + v_page_size = 4096; + + count = HOST_VM_INFO64_COUNT; + kr = host_statistics64(host, HOST_VM_INFO64, (host_info64_t)&vm_stats, &count); + if (kr == KERN_SUCCESS) + free_mem = (uint64_t)(vm_stats.free_count + vm_stats.inactive_count) * v_page_size; + else + free_mem = 0; + + if (total) + *total = (size_t)total_mem; + return (size_t)free_mem; #else // Guess 48 MB. if (total) diff --git a/src/z_zone.cpp b/src/z_zone.cpp index f25f99e43..f688dd831 100644 --- a/src/z_zone.cpp +++ b/src/z_zone.cpp @@ -114,6 +114,7 @@ void Z_Init(void) head.next = head.prev = &head; memfree = I_GetFreeMem(&total)>>20; + CONS_Printf("System memory: %sMB - Free: %sMB\n", sizeu1(total>>20), sizeu2(memfree)); // Note: This allocates memory. Watch out. @@ -745,6 +746,7 @@ static void Command_Memfree_f(void) CONS_Printf(M_GetText("HUD graphics : %7s KB\n"), sizeu1(Z_TagUsage(PU_HUDGFX)>>10)); CONS_Printf(M_GetText("Locked cache : %7s KB\n"), sizeu1(Z_TagUsage(PU_CACHE)>>10)); CONS_Printf(M_GetText("Level : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVEL)>>10)); + CONS_Printf(M_GetText("Level (pooled) : %7s KB\n"), sizeu1(Z_LevelPoolUsage()>>10)); CONS_Printf(M_GetText("Special thinker : %7s KB\n"), sizeu1(Z_TagUsage(PU_LEVSPEC)>>10)); CONS_Printf(M_GetText("All purgable : %7s KB\n"), sizeu1(Z_TagsUsage(PU_PURGELEVEL, INT32_MAX)>>10)); @@ -804,6 +806,14 @@ char *Z_StrDup(const char *s) return strcpy((char*)ZZ_Alloc(strlen(s) + 1), s); } +size_t Z_LevelPoolUsage(void) +{ + return g_level_large_pool.allocated_bytes() + + g_level_med_pool.allocated_bytes() + + g_level_small_pool.allocated_bytes() + + g_level_tiny_pool.allocated_bytes(); +} + void* Z_LevelPoolMalloc(size_t size) { void* p = nullptr; diff --git a/src/z_zone.h b/src/z_zone.h index 38f00c48c..847e47291 100644 --- a/src/z_zone.h +++ b/src/z_zone.h @@ -167,6 +167,7 @@ char *Z_StrDup(const char *in); // // Specialty allocation functions // +size_t Z_LevelPoolUsage(void); void *Z_LevelPoolMalloc(size_t size); void *Z_LevelPoolCalloc(size_t size); void Z_LevelPoolFree(void *p, size_t size); From 8a62f4e9783ad6dcdcc7e66201b43f22fbfb7632 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jul 2026 07:40:13 +0200 Subject: [PATCH 02/22] software: move hom removal to R_RenderPlayerView gl also has it there so why not --- src/d_main.c | 14 -------------- src/r_main.cpp | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 2150b1e72..ed0e0199e 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -275,20 +275,6 @@ static void D_Renderview(void) R_ApplyLevelInterpolators(R_GetTimeFrac(RTF_LEVEL)); - if (rendermode == render_soft && cv_homremoval.value) - { - if (cv_homremoval.value == 1) - { - // Clear the software screen buffer to remove HOM - memset(vid.screens[0], 31, vid.width * vid.height); - } - else if (cv_homremoval.value == 2) - { - //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. - memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); - } - } - for (i = 0; i <= splitscreen; i++) { if (!P_MobjWasRemoved(players[displayplayers[i]].mo) || players[displayplayers[i]].playerstate == PST_DEAD) diff --git a/src/r_main.cpp b/src/r_main.cpp index d2b6eed65..d6fe70c2d 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1389,6 +1389,21 @@ void R_RenderPlayerView(player_t *player) maskcount_t* masks = static_cast(malloc(sizeof(maskcount_t))); const boolean skybox = (skyboxmo[0] && cv_skybox.value); + // Only do it if it's the first screen being rendered + if (cv_homremoval.value && viewssnum == 0) + { + if (cv_homremoval.value == 1) + { + // Clear the software screen buffer to remove HOM + memset(vid.screens[0], 31, vid.width * vid.height); + } + else if (cv_homremoval.value == 2) + { + //'development' HOM removal -- makes it blindingly obvious if HOM is spotted. + memset(vid.screens[0], 32+(timeinmap&15), vid.width * vid.height); + } + } + // load previous saved value of skyVisible for the player skyVisible = skyVisiblePerPlayer[viewssnum]; @@ -1455,10 +1470,12 @@ void R_RenderPlayerView(player_t *player) NetUpdate(); R_SetColumnContext(COLUMNCONTEXT_FLUSH); + ps_numbspcalls.value.i = ps_numpolyobjects.value.i = ps_numdrawnodes.value.i = 0; PS_START_TIMING(ps_bsptime); R_RenderViewpoint(&masks[nummasks - 1], true); PS_STOP_TIMING(ps_bsptime); + PS_START_TIMING(ps_sw_spritecliptime); R_ClipSprites(drawsegs, NULL); PS_STOP_TIMING(ps_sw_spritecliptime); @@ -1466,8 +1483,8 @@ void R_RenderPlayerView(player_t *player) ps_numsprites.value.i = numvisiblesprites; - PS_START_TIMING(ps_sw_portaltime); // Portal rendering. Hijacks the BSP traversal. + PS_START_TIMING(ps_sw_portaltime); if (portal_base) { portal_t *portal; @@ -1517,6 +1534,7 @@ void R_RenderPlayerView(player_t *player) PS_START_TIMING(ps_sw_maskedtime); R_DrawMasked(masks, nummasks); PS_STOP_TIMING(ps_sw_maskedtime); + free(masks); // Check for new console commands. From 7048eeacc3834b5d5262e472530a526523748132 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jul 2026 07:41:01 +0200 Subject: [PATCH 03/22] Portal_AddSkybox can be static its unused anyways also adds plane bounds check which was missing --- src/r_portal.c | 5 ++++- src/r_portal.h | 1 - 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/r_portal.c b/src/r_portal.c index d84a99be4..00baad528 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -272,7 +272,7 @@ static boolean TrimVisplaneBounds(const visplane_t* plane, INT16* start, INT16* * Applies the necessary offsets and rotation to give * a depth illusion to the skybox. */ -void Portal_AddSkybox(const visplane_t* plane) +static void Portal_AddSkybox(const visplane_t* plane) { INT16 start, end; mapheader_t *mh; @@ -337,6 +337,9 @@ void Portal_AddSkyboxPortals(void) { for (pl = visplanes[i]; pl; pl = pl->next) { + if (pl->minx >= pl->maxx) + continue; + if (pl->picnum == skyflatnum) { Portal_AddSkybox(pl); diff --git a/src/r_portal.h b/src/r_portal.h index 223dd83be..4c4583903 100644 --- a/src/r_portal.h +++ b/src/r_portal.h @@ -58,7 +58,6 @@ void Portal_Add2Lines (const INT32 line1, const INT32 line2, const INT32 x1, con void Portal_ClipApply (const portal_t* portal); -void Portal_AddSkybox(const visplane_t* plane); void Portal_AddSkyboxPortals(void); #ifdef __cplusplus From 7971f768850ea8612ccfac8e5d4fa62554789853 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jul 2026 07:42:38 +0200 Subject: [PATCH 04/22] software: cleanup sky hacks still horrid, but atleast this wont give me braindamage each time i have to look at it this also read stale data from the previous frames and was just insanely messy this still sucks ass but oh well --- src/r_segs.cpp | 128 +++++++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 57 deletions(-) diff --git a/src/r_segs.cpp b/src/r_segs.cpp index 8460d4679..8a2693c84 100644 --- a/src/r_segs.cpp +++ b/src/r_segs.cpp @@ -713,16 +713,11 @@ void R_RenderThickSideRange(drawseg_t *drawseg, INT32 x1, INT32 x2, ffloor_t *pf rw_scalestep = drawseg->scalestep; spryscale = drawseg->scale1 + (x1 - drawseg->x1)*rw_scalestep; -#define CLAMPMAX INT32_MAX -#define CLAMPMIN (-INT32_MAX) // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out. auto overflow_clamp = [&](INT64 overflow_test) { - return (overflow_test > (INT64)CLAMPMAX) ? CLAMPMAX : - (overflow_test > (INT64)CLAMPMIN) ? (fixed_t)overflow_test : - CLAMPMIN; + // This is not INT32_MIN on purpose! INT32_MIN makes the drawers freak out. + return (fixed_t)std::clamp(overflow_test, (-INT32_MAX), INT32_MAX); }; -#undef CLAMPMAX -#undef CLAMPMIN dc->numlights = 0; if (frontsector->numlights) @@ -2604,71 +2599,91 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (linedef->special == HORIZONSPECIAL) // HORIZON LINES { topstep = bottomstep = 0; - topfrac = bottomfrac = (centeryfrac>>4); + topfrac = bottomfrac = (centeryfrac >> 4); topfrac++; // Prevent 1px HOM } else { + topstep = -FixedMul(rw_scalestep, worldtop); + topfrac = (centeryfrac >> 4) - FixedMul(worldtop, rw_scale); + // for anyone that sees this // dont. // this is absolute shit-tier hacks // but i just cant determine this in any sane way // but this checks a shitton of things to make software handle skies better - auto set_topstep_normal = [&] - { - topstep = -FixedMul(rw_scalestep, worldtop); - topfrac = (centeryfrac>>4) - FixedMul(worldtop, rw_scale); - }; - // untextured seg - if (!segtextured && !curline->polyseg) + if (!segtextured && !curline->polyseg) // not for polyobjects..... { - const bool tophigh = (worldhigh <= worldtop && worldhighslope <= worldtopslope); + const boolean nofrontsky = (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum); + const boolean inskybox = (skyboxmo[0] && cv_skybox.value && newview->sky); // dont mess with skyVisible within skybox rendering! - // if we cant see the goddamn skyplane, well there wont be any skybox - // we could kill skyVisible instead, but i want to keep the performance improvements it yields - // so we do this absolute trash - if ((tophigh - && (frontsector->floorpic != skyflatnum && frontsector->ceilingpic != skyflatnum)) // try to guess if its a "window" - && ((!backsector) // single sided - || ((backsector && (worldhigh != worldtop || worldhighslope != worldtopslope)) - && (backsector->floorheight >= frontsector->ceilingheight || backsector->ceilingheight <= frontsector->floorheight)))) // check if there is a "thok" sector behind it - skyVisible = true; - - // this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead - if (tophigh && !backsector && frontsector->ceilingpic == skyflatnum) + // single sided line + if (!backsector) { - // account for slopes to try and get rid of sharp edges from the black void - if (frontsector->f_slope || (backsector && backsector->f_slope)) + // this is an attempt to fix issues with textureless single sided lines drawing nothing where they should just draw sky instead + + // there is a sky flat on the ceiling + // so we can assume this is supposed to draw the sky + if (frontsector->ceilingpic == skyflatnum) { - topstep = -FixedMul(rw_scalestep, worldbottomslope); - topfrac = (centeryfrac>>4) - FixedMul(worldbottomslope, rw_scale); + // just draw sky from top to bottom! + if (frontsector->f_slope) + { + topstep = -FixedMul(rw_scalestep, worldbottomslope); + topfrac = (centeryfrac >> 4) - FixedMul(worldbottomslope, rw_scale); + } + else + { + topstep = -FixedMul(rw_scalestep, worldbottom); + topfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale); + } } - else + else if (nofrontsky && !inskybox) { - topstep = -FixedMul(rw_scalestep, worldbottom); - topfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale); + // completely empty wall without sky flats, just assume skybox is visible then + skyVisible = true; } } - else - set_topstep_normal(); + else if (nofrontsky && !inskybox) // if there was a skyflat, drawplane would already set skyvisible + { + // "thok walls" are double sided + // so we need to check a few things here + // to be rather conservative + // as skyrendering is pretty costly! + + // ideally we´d just dont care and always draw the skytexture + // or skybox at any time, like gl does + // wonder if there would be a fast way to draw atleast just the texture? + + // gotta shift those here for proper comparisons + const INT32 whigh = worldhigh >> 4; + const INT32 whslope = worldhighslope >> 4; + + // check if there is a window to force skybox to draw + if ((whigh <= worldtop && whslope <= worldtopslope) && (backsector->ceilingpic == skyflatnum)) // backsector has a skyflat? + skyVisible = true; + // otherwise check for thokwalls + else if ((whigh != worldtop || whslope != worldtopslope) && // FIXME: i forgor what this was for lol + (backsector->floorheight >= frontsector->ceilingheight || // thok walls usually are set up like that... + frontsector->floorheight >= backsector->ceilingheight)) // floor higher than the other sides ceiling + skyVisible = true; + } } - else - set_topstep_normal(); bottomstep = -FixedMul(rw_scalestep, worldbottom); - bottomfrac = (centeryfrac>>4) - FixedMul(worldbottom, rw_scale); + bottomfrac = (centeryfrac >> 4) - FixedMul(worldbottom, rw_scale); if (frontsector->c_slope) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldtopslope, ds_p->scale2); + fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldtopslope, ds_p->scale2); topstep = (topfracend-topfrac)/(range); } if (frontsector->f_slope) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldbottomslope, ds_p->scale2); + fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldbottomslope, ds_p->scale2); bottomstep = (bottomfracend-bottomfrac)/(range); } } @@ -2706,12 +2721,13 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (leftheight < worldbottom && rightheight < worldbottomslope) continue; - if (leftheight > worldtop && rightheight > worldtopslope && i+1 < dc.numlights && frontsector->lightlist[i+1].height > frontsector->ceilingheight) + if ((leftheight > worldtop) && (rightheight > worldtopslope) && + (i+1 < dc.numlights) && (frontsector->lightlist[i+1].height > frontsector->ceilingheight)) continue; } - rlight->height = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); - rlight->heightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); + rlight->height = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale); + rlight->heightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2); rlight->heightstep = (rlight->heightstep-rlight->height)/(range); rlight->flags = static_cast(light->flags); @@ -2730,10 +2746,9 @@ void R_StoreWallRange(INT32 start, INT32 stop) leftheight >>= 4; rightheight >>= 4; - rlight->botheight = (centeryfrac>>4) - FixedMul(leftheight, rw_scale); - rlight->botheightstep = (centeryfrac>>4) - FixedMul(rightheight, ds_p->scale2); + rlight->botheight = (centeryfrac >> 4) - FixedMul(leftheight, rw_scale); + rlight->botheightstep = (centeryfrac >> 4) - FixedMul(rightheight, ds_p->scale2); rlight->botheightstep = (rlight->botheightstep-rlight->botheight)/(range); - } rlight->lightlevel = *light->lightlevel; @@ -2754,13 +2769,14 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (linedef->special == HORIZONSPECIAL) // Horizon lines extend FOFs in contact with them too. { visffloor[i].f_step = 0; - visffloor[i].f_frac = (centeryfrac>>4); + visffloor[i].f_frac = (centeryfrac >> 4); topfrac++; // Prevent 1px HOM } else { - visffloor[i].f_frac = (centeryfrac>>4) - FixedMul(visffloor[i].f_pos, rw_scale); - visffloor[i].f_step = ((centeryfrac>>4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2) - visffloor[i].f_frac)/(range); + visffloor[i].f_frac = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos, rw_scale); + visffloor[i].f_step = (centeryfrac >> 4) - FixedMul(visffloor[i].f_pos_slope, ds_p->scale2); + visffloor[i].f_step = (visffloor[i].f_step - visffloor[i].f_frac)/(range); } } } @@ -2774,9 +2790,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (toptexture) { - fixed_t topfracend = (centeryfrac>>4) - FixedMul(worldhighslope, ds_p->scale2); - - pixhigh = (centeryfrac>>4) - FixedMul (worldhigh, rw_scale); + fixed_t topfracend = (centeryfrac >> 4) - FixedMul(worldhighslope, ds_p->scale2); + pixhigh = (centeryfrac >> 4) - FixedMul(worldhigh, rw_scale); pixhighstep = (topfracend-pixhigh)/(range); // If the lowest part of a ceiling stretching down covers the entire screen @@ -2786,9 +2801,8 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (bottomtexture) { - fixed_t bottomfracend = (centeryfrac>>4) - FixedMul(worldlowslope, ds_p->scale2); - - pixlow = (centeryfrac>>4) - FixedMul (worldlow, rw_scale); + fixed_t bottomfracend = (centeryfrac >> 4) - FixedMul(worldlowslope, ds_p->scale2); + pixlow = (centeryfrac >> 4) - FixedMul(worldlow, rw_scale); pixlowstep = (bottomfracend-pixlow)/(range); // If the highest part of a floor stretching up covers the entire screen From b27b4bfd7a11b6913b8f9ed81320d0907c7624fa Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jul 2026 07:43:33 +0200 Subject: [PATCH 05/22] software: fix cv_spriteclip scaled sprites should be excluded from the simple viewwindow checks also R_CheckSpriteVisible should be done AFTER portal adjustments --- src/r_things.cpp | 95 +++++++++++++++++++++++++----------------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/src/r_things.cpp b/src/r_things.cpp index ee517c11f..79c280ee5 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -87,6 +87,8 @@ static drawseg_xrange_item_t *drawsegs_xrange; static size_t drawsegs_xrange_size = 0; static INT32 drawsegs_xrange_count = 0; +#define CLIP_UNDEF -2 + // // Sprite rotation 0 is facing the viewer, // rotation 1 is one angle turn CLOCKWISE around the axis. @@ -2221,6 +2223,7 @@ static void R_SortVisSprites(vissprite_t* vsprsortedhead, UINT32 start, UINT32 e best = ds; } } + if (best) { best->next->prev = best->prev; @@ -2629,7 +2632,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port for (x = x1; x <= x2; x++) { - spr->clipbot[x] = spr->cliptop[x] = -2; + spr->clipbot[x] = spr->cliptop[x] = CLIP_UNDEF; } // Scan drawsegs from end to start for obscuring segs. @@ -2658,29 +2661,26 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port ds = curr->user; - if (ds->portalpass != 66) // unused? + if (ds->portalpass > 0 && ds->portalpass <= portalrender) + continue; // is a portal + + if (ds->scale1 > ds->scale2) { - if (ds->portalpass > 0 && ds->portalpass <= portalrender) - continue; // is a portal + lowscale = ds->scale2; + scale = ds->scale1; + } + else + { + lowscale = ds->scale1; + scale = ds->scale2; + } - if (ds->scale1 > ds->scale2) - { - lowscale = ds->scale2; - scale = ds->scale1; - } - else - { - lowscale = ds->scale1; - scale = ds->scale2; - } - - if (scale < spr->sortscale || - (lowscale < spr->sortscale && - !R_PointOnSegSide(spr->gx, spr->gy, ds->curline))) - { - // seg is behind sprite - continue; - } + if (scale < spr->sortscale || + (lowscale < spr->sortscale && + !R_PointOnSegSide(spr->gx, spr->gy, ds->curline))) + { + // seg is behind sprite + continue; } r1 = ds->x1 < x1 ? x1 : ds->x1; @@ -2699,14 +2699,14 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { // bottom sil for (x = r1; x <= r2; x++) - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = ds->sprbottomclip[x]; } else if (silhouette == SIL_TOP) { // top sil for (x = r1; x <= r2; x++) - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = ds->sprtopclip[x]; } else if (silhouette == (SIL_TOP|SIL_BOTTOM)) @@ -2714,9 +2714,9 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port // both for (x = r1; x <= r2; x++) { - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = ds->sprbottomclip[x]; - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = ds->sprtopclip[x]; } } @@ -2735,13 +2735,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (mh <= 0 || (phs != -1 && viewz > sectors[phs].floorheight)) { // clip bottom for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || h < spr->clipbot[x]) spr->clipbot[x] = (INT16)h; } else // clip top { for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || h > spr->cliptop[x]) spr->cliptop[x] = (INT16)h; } } @@ -2753,13 +2753,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (phs != -1 && viewz >= sectors[phs].ceilingheight) { // clip bottom for (x = x1; x <= x2; x++) - if (spr->clipbot[x] == -2 || h < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || h < spr->clipbot[x]) spr->clipbot[x] = (INT16)h; } else // clip top { for (x = x1; x <= x2; x++) - if (spr->cliptop[x] == -2 || h > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || h > spr->cliptop[x]) spr->cliptop[x] = (INT16)h; } } @@ -2769,10 +2769,10 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->cliptop[x] == -2 || spr->szt > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || spr->szt > spr->cliptop[x]) spr->cliptop[x] = spr->szt; - if (spr->clipbot[x] == -2 || spr->sz < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || spr->sz < spr->clipbot[x]) spr->clipbot[x] = spr->sz; } } @@ -2780,7 +2780,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->cliptop[x] == -2 || spr->szt > spr->cliptop[x]) + if (spr->cliptop[x] == CLIP_UNDEF || spr->szt > spr->cliptop[x]) spr->cliptop[x] = spr->szt; } } @@ -2788,7 +2788,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port { for (x = x1; x <= x2; x++) { - if (spr->clipbot[x] == -2 || spr->sz < spr->clipbot[x]) + if (spr->clipbot[x] == CLIP_UNDEF || spr->sz < spr->clipbot[x]) spr->clipbot[x] = spr->sz; } } @@ -2798,21 +2798,13 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port // check for unclipped columns for (x = x1; x <= x2; x++) { - if (spr->clipbot[x] == -2) + if (spr->clipbot[x] == CLIP_UNDEF) spr->clipbot[x] = (INT16)viewheight; - if (spr->cliptop[x] == -2) + if (spr->cliptop[x] == CLIP_UNDEF) spr->cliptop[x] = -1; } - // Check if it'll be visible - // Not done for floorsprites. - if (cv_spriteclip.value) - { - if (!R_CheckSpriteVisible(spr, x1, x2)) - spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); - } - if (portal) { INT32 start_index = std::max(portal->start, x1); @@ -2823,6 +2815,7 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port spr->clipbot[x] = -1; spr->cliptop[x] = -1; } + for (x = start_index; x <= end_index; x++) { if (spr->clipbot[x] > portal->floorclip[x - portal->start]) @@ -2830,12 +2823,21 @@ static void R_ClipVisSprite(vissprite_t *spr, INT32 x1, INT32 x2, portal_t* port if (spr->cliptop[x] < portal->ceilingclip[x - portal->start]) spr->cliptop[x] = portal->ceilingclip[x - portal->start]; } + for (x = end_index + 1; x <= x2; x++) { spr->clipbot[x] = -1; spr->cliptop[x] = -1; } } + + // Check if it'll be visible + // Not done for floorsprites. + if (cv_spriteclip.value) + { + if (!R_CheckSpriteVisible(spr, x1, x2)) + spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); + } } void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) @@ -2908,8 +2910,9 @@ void R_ClipSprites(drawseg_t* dsstart, portal_t* portal) { vissprite_t *spr = R_GetVisSprite(clippedvissprites); - if (cv_spriteclip.value - && (spr->szt > vid.height || spr->sz < 0)) + if (cv_spriteclip.value && + (spr->szt > vid.height || spr->sz < 0) && + !spr->scalestep) { spr->cut = static_cast(spr->cut | SC_NOTVISIBLE); continue; From ba0b414062c67e3d4955499b6208286bf754c3c2 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jul 2026 20:31:20 +0200 Subject: [PATCH 06/22] fix paletterender toggle calling setpalette during startup --- src/st_stuff.c | 4 +++- src/v_video.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 57a7c6e29..c8bdd5d51 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -14,6 +14,7 @@ /// Does palette indicators as well (red pain/berserk, bright pickup) #include "doomdef.h" +#include "d_main.h" #include "g_game.h" #include "g_input.h" #include "k_director.h" @@ -172,7 +173,8 @@ INT32 st_palette = 0; void ST_ResetPaletteStuff(void) { st_palette = 0; - V_SetPalette(0); + if (loaded_config) + V_SetPalette(0); } static void ST_doPaletteStuff(void) diff --git a/src/v_video.c b/src/v_video.c index fc84a0cdc..109eac171 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -676,6 +676,7 @@ static void CV_palette_OnChange(void) { if (!loaded_config) return; + // reload palette // recalculate Color Cube V_ReloadPalette(); From 587f24ae859f157f10a3225dbb3b609c6338ddad Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 13 Jul 2026 23:56:47 +0300 Subject: [PATCH 07/22] Add empty I_OpenURL into dedicated server build --- src/dedicated/i_system.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index fc38ffdef..d4a1397b9 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1419,6 +1419,11 @@ static void I_Fork(void) } #endif/*NEWSIGNALHANDLER*/ +int I_OpenURL(const char *url) +{ + return -1; +} + INT32 I_StartupSystem(void) { I_StartupConsole(); From 53fbbecbcdc6cafaeff13aee3db9821ee58df48f Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Jul 2026 01:32:51 +0200 Subject: [PATCH 08/22] fix incrementing garbage in Portal_AddSkyboxPortals --- src/r_portal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_portal.c b/src/r_portal.c index 00baad528..f403c17c7 100644 --- a/src/r_portal.c +++ b/src/r_portal.c @@ -333,7 +333,7 @@ void Portal_AddSkyboxPortals(void) INT32 i; UINT16 count = 0; - for (i = 0; i < MAXVISPLANES; i++, pl++) + for (i = 0; i < MAXVISPLANES; i++) { for (pl = visplanes[i]; pl; pl = pl->next) { From d0f02f15308e1a5ebfc7a25d281f00be6f889a77 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Jul 2026 09:40:20 +0200 Subject: [PATCH 09/22] remove pointless skybox check here if skybox then newview->sky will be false there which R_DrawSkyPlanes will check for --- src/r_main.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/r_main.cpp b/src/r_main.cpp index d6fe70c2d..ad8f1aa0a 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -1525,8 +1525,7 @@ void R_RenderPlayerView(player_t *player) R_SetColumnContext(COLUMNCONTEXT_DIRECT); PS_START_TIMING(ps_sw_planetime); - if (!skybox) - R_DrawSkyPlanes(); + R_DrawSkyPlanes(); R_DrawPlanes(); PS_STOP_TIMING(ps_sw_planetime); // draw mid texture and sprite From 28c4061a26f067c6a70b13c4acddc1856bd45740 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Jul 2026 09:39:14 +0200 Subject: [PATCH 10/22] remove viewsky which doesent exist lol --- src/r_state.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/r_state.h b/src/r_state.h index 0431525e7..5e226103b 100644 --- a/src/r_state.h +++ b/src/r_state.h @@ -90,7 +90,7 @@ extern side_t *sides; extern fixed_t viewx, viewy, viewz; extern angle_t viewangle, aimingangle, viewroll; extern UINT8 viewssnum; // splitscreen view number -extern boolean viewsky, skyVisible; +extern boolean skyVisible; extern boolean skyVisiblePerPlayer[MAXSPLITSCREENPLAYERS]; // saved values of skyVisible of each splitscreen player extern sector_t *viewsector; extern player_t *viewplayer; From ee9c9e283945e4cd461c2f06da337688e6dd890b Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 14 Jul 2026 11:28:40 +0200 Subject: [PATCH 11/22] hack: fix paletterender stuff not applying to screenshots/gifs when using downsampling fbo this sucks but the final screen texture with the palette render postprocess step will not be in the downsample fbo so we have to redraw it there with the postprocess step...... this is still better than drawing another screen texture when using paletterender which costs perf --- src/hardware/r_opengl/r_opengl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index aff722773..0c04beb09 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -1465,6 +1465,19 @@ void GL_ReadScreenTexture(int tex, UINT8 *restrict dest, INT32 scale) if (tex != HWD_SCREENTEXTURE_GENERIC2) GL_DrawScreenTexture(tex, NULL, 0); +#ifdef USE_FBO_OGL + // FIXME: this is incredibly stupid + // but the final screen texture will NOT be drawn in the downsample fbo + if (tex == HWD_SCREENTEXTURE_GENERIC2 && + UseScreenFBO() && HWR_ShouldUsePaletteRendering()) + { + GL_SetShader(HWR_GetShaderFromTarget(SHADER_PALETTE_POSTPROCESS)); + GL_EnableShader(); + GL_DrawScreenTexture(HWD_SCREENTEXTURE_GENERIC2, NULL, 0); + GL_UnSetShader(); + } +#endif + image = malloc(screen_width*screen_height*3); pglPixelStorei(GL_PACK_ALIGNMENT, 1); pglReadPixels(0, 0, screen_width, screen_height, GL_RGB, GL_UNSIGNED_BYTE, image); From 7ee93d889eb41f16dc4c7670ca1b8c1332cb8fdb Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 16 Jul 2026 20:16:33 +0200 Subject: [PATCH 12/22] remove this from polyvertex_t was used for optimization but not used anymore --- src/hardware/hw_defs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 6a8649099..ed4bff5a2 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -96,7 +96,6 @@ typedef struct typedef struct { float x, y, z; - fixed_t x2, y2, z2; } polyvertex_t; // a convex 'plane' polygon, clockwise order From a1127068df439077a6ad3cc8a86db78008d29503 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 17 Jul 2026 22:42:24 +0200 Subject: [PATCH 13/22] fix wireframe potentially not disabling on toggle netupdate sucks ass --- src/hardware/hw_main.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index fbd9702ce..562be50bb 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -3483,6 +3483,8 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) fixed_t v1x, v1y, v2x, v2y; INT32 shader = SHADER_NONE; + const boolean billboarding = (cv_glspritebillboarding.value && !cv_glshearing.value && !papersprite); + gpatch = spr->gpatch; // cache the patch in the graphics card memory @@ -3680,7 +3682,7 @@ static void HWR_SplitSprite(gl_vissprite_t *spr, const boolean papersprite) wallVerts[1].y = endbot; // The x and y only need to be adjusted in the case that it's not a papersprite - if (cv_glspritebillboarding.value && !cv_glshearing.value && !papersprite) + if (billboarding) { // Get the x and z of the vertices so billboarding draws correctly realheight = realbot - realtop; @@ -5451,6 +5453,8 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool { gl_portallist_t portallist; + const boolean wireframe = HWR_IsWireframeMode(); + player_t *viewplayer = &players[displayplayers[viewssnum]]; const float fpov = FixedToFloat(R_GetPlayerFov(viewplayer)); @@ -5511,7 +5515,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool } } - if (HWR_IsWireframeMode()) + if (wireframe) GL_SetSpecialState(HWD_SET_WIREFRAME, 1); // FIXME: perfstats does not account for portal rendering! @@ -5597,7 +5601,7 @@ static void HWR_RenderViewpoint(gl_portal_t *rootportal, int stencil_level, bool HWR_RenderDrawNodes(); - if (HWR_IsWireframeMode()) + if (wireframe) GL_SetSpecialState(HWD_SET_WIREFRAME, 0); HWR_FreePortalList(portallist); // always call this just in case From 6892c212d1483b1fb5a151480d0b571f6585315d Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 19 Jul 2026 03:31:09 +0300 Subject: [PATCH 14/22] Comment out stairjank particles for now, since spawning mobjs during P_TryMove may mess up some global variables --- src/p_map.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index ce43c2235..646e88708 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2613,7 +2613,9 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (cv_stairjanksfx.value) S_StartSoundAtVolume(thing, (thing->player->stairjank >= 8 ? sfx_s23b : sfx_s268), 192); // dont blast this at full volume lul - //if (!thing->player->stairjank) + // Can't spawn things during P_TryMove, because global variables :) + // TODO - move this elsewhere later, should probably be safe in K_KartPlayerThink or something + /*if (!thing->player->stairjank) { // 90 degrees to direction you're facing fixed_t dirx = -FINESINE(thing->angle>>ANGLETOFINESHIFT); @@ -2639,7 +2641,7 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) P_SetTarget(&spark->target, thing); //P_SetTarget(&spark->owner, thing); //spark->renderflags |= RF_REDUCEVFX; - } + }*/ thing->player->stairjank = 9; //thing->player->stairjank = 17; From 267a7584471d948e0ea3d7bac3a45f129b25ff75 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 Jul 2026 02:36:08 +0200 Subject: [PATCH 15/22] fix up dedi i_system --- src/dedicated/i_system.c | 53 +++++++++++++++++++++++----------------- src/sdl/i_system.cpp | 16 ++++++------ 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index d4a1397b9..b6d50a712 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -162,8 +162,7 @@ const char *wadSearchPaths[] = { /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.srb" -#define WADKEYWORD2 "srb2.wad" +#define WADKEYWORD "srb2.srb" /** \brief holds wad path */ static char returnWadPath[256]; @@ -526,16 +525,23 @@ void I_OutputMsg(const char *fmt, ...) { size_t len; char *txt; - va_list argptr; + va_list argptr; - va_start(argptr,fmt); + if (!fmt) + return; + + va_start(argptr, fmt); len = vsnprintf(NULL, 0, fmt, argptr); va_end(argptr); if (len == 0) return; - txt = malloc(len+1); - va_start(argptr,fmt); + txt = (char*)(malloc(len+1)); + + if (!txt) + I_Error("I_OutputMsg: Out of memory!\n"); + + va_start(argptr, fmt); vsprintf(txt, fmt, argptr); va_end(argptr); @@ -1421,6 +1427,7 @@ static void I_Fork(void) int I_OpenURL(const char *url) { + (void)url; return -1; } @@ -1813,20 +1820,12 @@ const char *I_ClipboardPaste(void) */ static boolean isWadPathOk(const char *path) { - char *wad3path = malloc(256); + char *wad3path = (char*)(malloc(256)); if (!wad3path) return false; - sprintf(wad3path, pandf, path, WADKEYWORD1); - - if (FIL_ReadFileOK(wad3path)) - { - free(wad3path); - return true; - } - - sprintf(wad3path, pandf, path, WADKEYWORD2); + sprintf(wad3path, pandf, path, WADKEYWORD); if (FIL_ReadFileOK(wad3path)) { @@ -1843,12 +1842,17 @@ static void pathonly(char *s) size_t j; for (j = strlen(s); j != (size_t)-1; j--) + { if ((s[j] == '\\') || (s[j] == ':') || (s[j] == '/')) { - if (s[j] == ':') s[j+1] = 0; - else s[j] = 0; + if (s[j] == ':') + s[j+1] = 0; + else + s[j] = 0; + return; } + } } /** \brief search for srb2.srb in the given path @@ -1864,7 +1868,7 @@ static const char *searchWad(const char *searchDir) static char tempsw[256] = ""; filestatus_t fstemp; - strcpy(tempsw, WADKEYWORD1); + strcpy(tempsw, WADKEYWORD); fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { @@ -1985,17 +1989,22 @@ const char *I_LocateWad(void) static long get_entry(const char* name, const char* buf) { long val; - char* hit = strstr(buf, name); - if (hit == NULL) { + const char* hit = strstr(buf, name); + + if (hit == NULL) + { return -1; } errno = 0; val = strtol(hit + strlen(name), NULL, 10); - if (errno != 0) { + + if (errno != 0) + { CONS_Alert(CONS_ERROR, M_GetText("get_entry: strtol() failed: %s\n"), strerror(errno)); return -1; } + return val; } #endif diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index fb4f0dcd5..dd3508efd 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -178,8 +178,7 @@ const char *wadSearchPaths[] = { /** \brief WAD file to look for */ -#define WADKEYWORD1 "srb2.srb" -#define WADKEYWORD2 "srb2.wad" +#define WADKEYWORD "srb2.srb" /** \brief holds wad path */ static char returnWadPath[256]; @@ -561,12 +560,12 @@ void I_OutputMsg(const char *fmt, ...) { size_t len; char *txt; - va_list argptr; + va_list argptr; if (!fmt) return; - va_start(argptr,fmt); + va_start(argptr, fmt); len = vsnprintf(NULL, 0, fmt, argptr); va_end(argptr); if (len == 0) @@ -577,7 +576,7 @@ void I_OutputMsg(const char *fmt, ...) if (!txt) I_Error("I_OutputMsg: Out of memory!\n"); - va_start(argptr,fmt); + va_start(argptr, fmt); vsprintf(txt, fmt, argptr); va_end(argptr); @@ -2265,7 +2264,6 @@ void I_ShutdownSystem(void) logstream = NULL; } #endif - } void I_GetDiskFreeSpace(INT64 *freespace) @@ -2437,7 +2435,7 @@ static boolean isWadPathOk(const char *path) if (!wad3path) return false; - sprintf(wad3path, pandf, path, WADKEYWORD1); + sprintf(wad3path, pandf, path, WADKEYWORD); if (FIL_ReadFileOK(wad3path)) { @@ -2477,10 +2475,10 @@ static void pathonly(char *s) */ static const char *searchWad(const char *searchDir) { - static char tempsw[255] = ""; + static char tempsw[256] = ""; filestatus_t fstemp; - strcpy(tempsw, WADKEYWORD1); + strcpy(tempsw, WADKEYWORD); fstemp = filesearch(tempsw, searchDir, NULL, true, 20); if (fstemp == FS_FOUND) { From 735c4b67dc6f154c295b8033f7c4aa32d4e424ff Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 Jul 2026 02:35:47 +0200 Subject: [PATCH 16/22] move stairjank particles into K_MoveKartPlayer to where we also rotate the player also means we now use K_AltFlip :p also means the visual toggle now actually does prevent spawning them --- src/k_kart.c | 22 ++++++++++++++++++++++ src/p_map.c | 28 ---------------------------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 0196bb521..e77c0b5ee 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7055,6 +7055,28 @@ void K_MoveKartPlayer(player_t *player, boolean onground) // "Stair jank" visuals akin to RR if (cv_stairjank.value && player->stairjank > 0) { + // only spawn em once + if (player->stairjank > 8) + { + // 90 degrees to direction you're facing + fixed_t dirx = -FINESINE(player->mo->angle>>ANGLETOFINESHIFT); + fixed_t diry = FINECOSINE(player->mo->angle>>ANGLETOFINESHIFT); + fixed_t offset = player->mo->radius; + + dirx = K_AltFlip(-dirx, 4); + diry = K_AltFlip(-diry, 4); + + mobj_t * spark = P_SpawnMobj(player->mo->x + FixedMul(dirx, offset), player->mo->y + FixedMul(diry, offset), player->mo->z, MT_DRIFTDUST); + spark->momx = FixedMul(dirx, FRACUNIT) + (6 + ((int)leveltime % 5))*(player->mo->momx)/10; + spark->momy = FixedMul(diry, FRACUNIT) + (6 + ((int)leveltime % 5))*(player->mo->momy)/10; + spark->momz = 5*FRACUNIT; + spark->scale = mapobjectscale/5; + spark->destscale = mapobjectscale/2; + spark->islocal = true; + spark->color = SKINCOLOR_WHITE; + P_SetTarget(&spark->target, player->mo); + } + player->mo->temprollangle += K_StairJankFlip(ANGLE_11hh / 2 / (17 / player->stairjank)); // TODO: make strength adjustable? } diff --git a/src/p_map.c b/src/p_map.c index 646e88708..5436e144c 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2614,34 +2614,6 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) S_StartSoundAtVolume(thing, (thing->player->stairjank >= 8 ? sfx_s23b : sfx_s268), 192); // dont blast this at full volume lul // Can't spawn things during P_TryMove, because global variables :) - // TODO - move this elsewhere later, should probably be safe in K_KartPlayerThink or something - /*if (!thing->player->stairjank) - { - // 90 degrees to direction you're facing - fixed_t dirx = -FINESINE(thing->angle>>ANGLETOFINESHIFT); - fixed_t diry = FINECOSINE(thing->angle>>ANGLETOFINESHIFT); - fixed_t offset = thing->radius; - - if (leveltime % 8 < 4) - { - dirx = -dirx; - diry = -diry; - } - - mobj_t * spark = P_SpawnMobj(thing->x + FixedMul(dirx, offset), thing->y + FixedMul(diry, offset), thing->z, MT_DRIFTDUST); - spark->momx = FixedMul(dirx, FRACUNIT) + (6 + ((int)leveltime % 5))*(thing->momx)/10; - spark->momy = FixedMul(diry, FRACUNIT) + (6 + ((int)leveltime % 5))*(thing->momy)/10; - spark->momz = 5*FRACUNIT; - spark->scale = mapobjectscale/5; - spark->destscale = mapobjectscale/2; - spark->islocal = true; - //spark->fuse = 9; - spark->color = SKINCOLOR_WHITE; - //spark->cusval = K_StairJankFlip(ANGLE_90); - P_SetTarget(&spark->target, thing); - //P_SetTarget(&spark->owner, thing); - //spark->renderflags |= RF_REDUCEVFX; - }*/ thing->player->stairjank = 9; //thing->player->stairjank = 17; From f09c61cee98d12171621bc82b345e2b1b92036da Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 Jul 2026 02:42:10 +0200 Subject: [PATCH 17/22] only play stairjank sound if we have its visuals enabled --- src/p_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index 5436e144c..4ebc9a124 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -2610,7 +2610,7 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) // sound does not work out all that well for kart maps // best i can do... - if (cv_stairjanksfx.value) + if (cv_stairjank.value && cv_stairjanksfx.value) S_StartSoundAtVolume(thing, (thing->player->stairjank >= 8 ? sfx_s23b : sfx_s268), 192); // dont blast this at full volume lul // Can't spawn things during P_TryMove, because global variables :) From 0acfc96812fc5736930347ff7e99d28109edce11 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 19 Jul 2026 04:32:29 +0200 Subject: [PATCH 18/22] attempt to fix kick/ban commands causing dedicated servers to self destruct if a player was specified which was not being in game this is what caused dedis to sometimes go to the main menu --- src/d_clisrv.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8efc2a1cd..1401d3bf0 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -110,7 +110,7 @@ SINT8 joinnode = 0; // used for CL_VIEWSERVER boolean player_muted[MAXPLAYERS] = {}; // Server specific vars -UINT8 playernode[MAXPLAYERS] = {}; +UINT8 playernode[MAXPLAYERS] = {UINT8_MAX}; // Minimum timeout for sending the savegame // The actual timeout will be longer depending on the savegame length @@ -3767,6 +3767,10 @@ static void Command_Ban(void) if (pn == -1 || pn == 0) return; + // player does not exist + if (!playeringame[pn]) + return; + WRITEUINT8(p, pn); if (COM_Argc() == 2) @@ -3884,6 +3888,10 @@ static void Command_Kick(void) if (pn == -1 || pn == 0) return; + // player does not exist + if (!playeringame[pn]) + return; + // Special case if we are trying to kick a player who is downloading the game state: // trigger a timeout instead of kicking them, because a kick would only // take effect after they have finished downloading @@ -3933,6 +3941,13 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) pnum = READUINT8(*p); msg = READUINT8(*p); + if (pnum >= MAXPLAYERS) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal kick command received from %s for player %d\n"), player_names[playernum], pnum); + return; + } + + // FIXME: this does not work at all on dedi, servernode == 0 which is prevented from kick/ban command if (pnum == serverplayer && IsPlayerAdmin(playernum)) { CONS_Printf(M_GetText("Server is being shut down remotely. Goodbye!\n")); @@ -3987,6 +4002,16 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) msg = KICK_MSG_CON_FAIL; } + // without this the server will remove itself and thus self destruct on dedicated + if (server && (playernode[pnum] == UINT8_MAX || !nodeingame[playernode[pnum]])) + { + CONS_Alert(CONS_WARNING, M_GetText("Attempting to kick player %d which is not in game received from %s\n"), pnum, player_names[playernum]); + return; + } + + // make sure we dont read garbage anywhere + memset(reason, 0, sizeof(buf)); + if (msg == KICK_MSG_CUSTOM_BAN || msg == KICK_MSG_CUSTOM_KICK) { READSTRINGN(*p, reason, MAX_REASONLENGTH+1); From a132db9e6ea030adcbc2ef8c2e6d469cf4fa16dd Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 19 Jul 2026 23:41:19 +0300 Subject: [PATCH 19/22] Attempt to fix server locking up when trying to kick player that has left already --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 1401d3bf0..0491b2c3f 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4003,7 +4003,7 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) } // without this the server will remove itself and thus self destruct on dedicated - if (server && (playernode[pnum] == UINT8_MAX || !nodeingame[playernode[pnum]])) + if (server && !playeringame[pnum]) { CONS_Alert(CONS_WARNING, M_GetText("Attempting to kick player %d which is not in game received from %s\n"), pnum, player_names[playernum]); return; From 5a966aa317293a2a6af52c7d91d69d243836e755 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 20 Jul 2026 01:54:47 +0300 Subject: [PATCH 20/22] Re-add playernode check --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 0491b2c3f..a19e916cb 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -4003,7 +4003,7 @@ static void Got_KickCmd(const UINT8 **p, INT32 playernum) } // without this the server will remove itself and thus self destruct on dedicated - if (server && !playeringame[pnum]) + if (server && (playernode[pnum] == UINT8_MAX || !playeringame[pnum])) { CONS_Alert(CONS_WARNING, M_GetText("Attempting to kick player %d which is not in game received from %s\n"), pnum, player_names[playernum]); return; From df3a64339c7800a82448e77dee86ad2c8079b23e Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 20 Jul 2026 01:00:57 +0200 Subject: [PATCH 21/22] fix skin search command overflow when using localskins and going over the skinlimit this should use numskins not numallskins there no i dont feel like supporting localskins here the other skin commands also dont care --- src/d_netcmd.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 66e4aad3a..452263b75 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1806,7 +1806,7 @@ INT32 D_LookupPlayer(const char *s) if ((playernum = atoi(s))) { - playernum = max(min(playernum, MAXPLAYERS-1), 0);/* not out of range */ + playernum = max(min(playernum, MAXPLAYERS-1), 0); /* not out of range */ return playernum; } @@ -5691,19 +5691,22 @@ static void Command_SkinSearch(void) size_t i; UINT16 s; UINT16 ic = 0; - //skin_t *skininput = &skins[s]; - for (i = 1; i < COM_Argc(); i++){ - for( s = 0 ; s < numallskins ; s++ ) + + for (i = 1; i < COM_Argc(); i++) + { + for (s = 0; s < numskins; s++) { skin_t *skininput = &skins[s]; - if (strcasestr(skininput->realname,COM_Argv(i))) + + if (strcasestr(skininput->realname, COM_Argv(i))) { ic++; - CONS_Printf("%d. %s%s:\x80 %s\n", ic,HU_SkinColorToConsoleColor(skininput->prefcolor),skininput->realname,skininput->name); + CONS_Printf("%d. %s%s:\x80 %s\n", ic, HU_SkinColorToConsoleColor(skininput->prefcolor), skininput->realname, skininput->name); } } } - CONS_Printf("Total %d skins.\n", ic); + + CONS_Printf("Total %d skins.\n", ic); } /** Sends a color change for the console player, unless that player is moving. From 9692484d2e1a75a5a52b9e1e332e2c8a82b2fabc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 20 Jul 2026 11:29:19 +0200 Subject: [PATCH 22/22] fix issues with sound freeslotting this "works" with a skinlimit of 255 but would cause hard to debug crashes with raised skinlimits and was generally really unsafe and could cause soundnames to not be null terminated aswell as buffer overflows from blind strcpy the sprintf fix is from Indev originally for neptune NOTE: if the skinlimit is ever raised above 1024 then freeslotnames NEEDS to be atleast one byte bigger to not truncuate stuff NOTE2: pretty sure localskins are fucked if any are loaded in servers with 255 skins loaded, but i dont care atm --- src/sounds.c | 23 ++++++++++++----------- src/sounds.h | 2 ++ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/sounds.c b/src/sounds.c index 3769bf65b..e17e79512 100644 --- a/src/sounds.c +++ b/src/sounds.c @@ -972,7 +972,7 @@ sfxinfo_t S_sfx[NUMSFX] = // initialized to NULL }; -char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][7] = {}; +static char freeslotnames[sfx_freeslot0 + NUMSFXFREESLOTS + NUMSKINSFXSLOTS][MAXSOUNDNAME] = {}; // Prepare free sfx slots to add sfx at run time void S_InitRuntimeSounds(void) @@ -985,16 +985,13 @@ void S_InitRuntimeSounds(void) { value = (i+1) - sfx_freeslot0; - if (value < 10) - sprintf(soundname, "fre00%d", value); - else if (value < 100) - sprintf(soundname, "fre0%d", value); - else if (value < 1000) - sprintf(soundname, "fre%d", value); - else - sprintf(soundname, "fr%d", value); + sprintf(soundname, "fr%04x", value); - strcpy(freeslotnames[value-1], soundname); + // this might happen when raising skinlimit + I_Assert(strlen(soundname) < MAXSOUNDNAME); + + strncpy(freeslotnames[value-1], soundname, MAXSOUNDNAME-1); + freeslotnames[value-1][MAXSOUNDNAME-1] = '\0'; S_sfx[i].name = freeslotnames[value-1]; S_sfx[i].singularity = false; @@ -1024,7 +1021,11 @@ sfxenum_t S_AddSoundFx(const char *name, boolean singular, INT32 flags, boolean { if (!S_sfx[i].priority) { - strncpy(freeslotnames[i-sfx_freeslot0], name, 6); + I_Assert(strlen(name) < MAXSOUNDNAME); + + strncpy(freeslotnames[i - sfx_freeslot0], name, MAXSOUNDNAME-1); + freeslotnames[i - sfx_freeslot0][MAXSOUNDNAME-1] = '\0'; + S_sfx[i].singularity = singular; S_sfx[i].priority = 60; S_sfx[i].pitch = flags; diff --git a/src/sounds.h b/src/sounds.h index ea530da05..a8522f1c6 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -59,6 +59,8 @@ typedef enum #define NUMSFXFREESLOTS 1600 // Matches SOC Editor. #define NUMSKINSFXSLOTS (MAXSKINS*NUMSKINSOUNDS) +#define MAXSOUNDNAME 7 + // // SoundFX struct. //