diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 833e64ec2..e399fab0e 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -34,10 +34,6 @@ #include "hardware/hw_main.h" #endif -#ifdef HAVE_THREADS -#include "core/thread_pool.h" -#endif - // ========================================================================== // COMMON DATA FOR 8bpp AND 16bpp // ========================================================================== @@ -81,19 +77,7 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -#ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static -#endif - -local_for_thread INT32 *tiltlighting; +//static INT32 *tiltlighting; // -------------------------------------------- // c drawer routines @@ -486,15 +470,6 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); - auto init_tiltlighting = [] { - tiltlighting = static_cast(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(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index 192ffc1b4..a8ed71008 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -13,6 +13,18 @@ /// \brief span drawer functions /// \note no includes because this is included as part of r_draw.cpp +#ifdef HAVE_THREADS +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static +#endif + // ========================================================================== // SPANS // ========================================================================== @@ -211,6 +223,15 @@ 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(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); + oldviewwidth = viewwidth; + } INT32 x1 = ds->x1; const INT32 nflatxshift = ds->nflatxshift; @@ -403,6 +424,16 @@ 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 * restrict 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(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); + oldviewwidth = viewwidth; + } + dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width;