From 2794f8bd5cdaea0c8246b5c49abbe8646304043d Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 23 Jul 2025 15:48:07 +0200 Subject: [PATCH] Revert "omit realloc and use unique_ptr for our tiltlighting buffer" This reverts commit 7e2a9abfda95daa1d424abb15d1d3d166b960458. --- src/r_draw.cpp | 32 ++++++++++++++++++-------------- src/r_draw_span.cpp | 2 -- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index 3525ff785..833e64ec2 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -36,15 +36,6 @@ #ifdef HAVE_THREADS #include "core/thread_pool.h" -#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 // ========================================================================== @@ -90,7 +81,19 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -local_for_thread std::unique_ptr tiltlight; +#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; // -------------------------------------------- // c drawer routines @@ -483,12 +486,13 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); - auto init_tiltlighting = [](INT32 size) { - tiltlight = std::make_unique(size); + auto init_tiltlighting = [] { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe }; - init_tiltlighting(viewwidth); // allocate for main thread + + init_tiltlighting(); #ifdef HAVE_THREADS - srb2::g_main_threadpool->for_each([=] { init_tiltlighting(viewwidth); }); + srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); #endif R_AllocSegMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index ffbb01d62..192ffc1b4 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -217,7 +217,6 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) const INT32 nflatyshift = ds->nflatyshift; const INT32 nflatmask = ds->nflatmask; const INT32 stride = vid.width; - INT32 * restrict tiltlighting = tiltlight.get(); iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); @@ -406,7 +405,6 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width; - INT32 * restrict tiltlighting = tiltlight.get(); // Lighting is simple. It's just linear interpolation from start to end {