allocate tiltlighting buffer in R_AllocViewMemory again

just removes the ugly stuff in the span drawers
needs to be tested a little, but should be fine
This commit is contained in:
Alug committed 2025-06-23 20:08:04 +02:00
1 parent a5a78425e7
commit dbe32317b2
2 files changed
+26 -32

No files matched your search

+26 -1
View File
@@ -34,6 +34,10 @@
#include "hardware/hw_main.h"
#endif
#ifdef HAVE_THREADS
#include "core/thread_pool.h"
#endif
// ==========================================================================
// COMMON DATA FOR 8bpp AND 16bpp
// ==========================================================================
@@ -77,7 +81,19 @@ floatv3_t *ds_su, *ds_sv, *ds_sz;
float focallengthf;
// For, uh, tilted lighting, duh.
//static INT32 *tiltlighting;
#ifdef HAVE_THREADS
#ifdef _WIN32
#include <windows.h>
#define local_for_thread static __thread
#else
#include <threads.h>
#define local_for_thread thread_local static
#endif
#else
#define local_for_thread static
#endif
local_for_thread INT32 *tiltlighting;
// --------------------------------------------
// c drawer routines
@@ -470,6 +486,15 @@ static void R_AllocViewMemory(void)
xtoviewangle = static_cast<angle_t*>(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL));
auto init_tiltlighting = [] {
tiltlighting = static_cast<INT32*>(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe
};
init_tiltlighting();
#ifdef HAVE_THREADS
srb2::g_main_threadpool->for_each(std::move(init_tiltlighting));
#endif
R_AllocSegMemory();
R_AllocClipSegMemory();
R_AllocPlaneMemory();
-31
View File
@@ -13,18 +13,6 @@
/// \brief span drawer functions
/// \note no includes because this is included as part of r_draw.cpp
#ifdef HAVE_THREADS
#ifdef _WIN32
#include <windows.h>
#define local_for_thread static __thread
#else
#include <threads.h>
#define local_for_thread thread_local static
#endif
#else
#define local_for_thread static
#endif
// ==========================================================================
// SPANS
// ==========================================================================
@@ -210,15 +198,6 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds)
float endz, endu, endv;
UINT32 stepu, stepv;
UINT32 bit;
local_for_thread INT32 *tiltlighting = NULL;
local_for_thread INT32 oldviewwidth = 0;
// dont realloc every frame pls thx
if (tiltlighting == NULL || oldviewwidth != viewwidth)
{
tiltlighting = static_cast<INT32*>(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth));
oldviewwidth = viewwidth;
}
INT32 x1 = ds->x1;
const INT32 nflatxshift = ds->nflatxshift;
@@ -411,16 +390,6 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds)
float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx);
UINT8 *dest;
local_for_thread INT32 *tiltlighting = NULL;
local_for_thread INT32 oldviewwidth = 0;
// dont realloc every frame pls thx
if (tiltlighting == NULL || oldviewwidth != viewwidth)
{
tiltlighting = static_cast<INT32*>(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth));
oldviewwidth = viewwidth;
}
dest = R_Address(ds->x1, ds->y);
const INT32 stride = vid.width;