From e90ef4e88605d5bb300a1439a5d0f1013754caaa Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 9 Jan 2019 00:04:28 +0100 Subject: [PATCH] - moved the impact decal counter into FLevelLocals and do the counting in a less problematic fashion. This was yet another piece of code that lived or died with the assumption that there can only be one level, stored in global variables. # Conflicts: # src/p_saveg.cpp --- src/g_levellocals.h | 1 + src/g_shared/a_decals.cpp | 28 ++++++++++++---------------- src/g_shared/a_sharedglobal.h | 3 +-- src/p_saveg.cpp | 1 + 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/g_levellocals.h b/src/g_levellocals.h index 310e56d1a1..1dbb19b4c9 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -202,6 +202,7 @@ struct FLevelLocals : public FLevelData bool brightfog; bool lightadditivesurfaces; bool notexturefill; + int ImpactDecalCount; FDynamicLight *lights; diff --git a/src/g_shared/a_decals.cpp b/src/g_shared/a_decals.cpp index 7828bd9501..df9746a021 100644 --- a/src/g_shared/a_decals.cpp +++ b/src/g_shared/a_decals.cpp @@ -548,37 +548,39 @@ CUSTOM_CVAR (Int, cl_maxdecals, 1024, CVAR_ARCHIVE) } else { - while (ImpactCount > self) + ForAllLevels([&](FLevelLocals *Level) { - DThinker *thinker = DThinker::FirstThinker (STAT_AUTODECAL); - if (thinker != NULL) + while (Level->ImpactDecalCount > self) { - thinker->Destroy(); + DThinker *thinker = DThinker::FirstThinker(STAT_AUTODECAL); + if (thinker != NULL) + { + thinker->Destroy(); + } } - } + }); } } DImpactDecal::DImpactDecal () : DBaseDecal (STAT_AUTODECAL, 0.) { - ImpactCount++; } DImpactDecal::DImpactDecal (double z) : DBaseDecal (STAT_AUTODECAL, z) { - ImpactCount++; } void DImpactDecal::CheckMax () { - if (ImpactCount >= cl_maxdecals) + if (++level.ImpactDecalCount >= cl_maxdecals) { DThinker *thinker = DThinker::FirstThinker (STAT_AUTODECAL); if (thinker != NULL) { thinker->Destroy(); + level.ImpactDecalCount--; } } } @@ -613,7 +615,6 @@ DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const DVect else lowercolor = color; StaticCreate (tpl_low, pos, wall, ffloor, lowercolor); } - DImpactDecal::CheckMax(); decal = Create(pos.Z); if (decal == NULL) { @@ -624,6 +625,7 @@ DImpactDecal *DImpactDecal::StaticCreate (const FDecalTemplate *tpl, const DVect { return NULL; } + decal->CheckMax(); tpl->ApplyToDecal (decal, wall); if (color != 0) @@ -649,12 +651,12 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl return NULL; } - DImpactDecal::CheckMax(); DImpactDecal *decal = Create(iz); if (decal != NULL) { if (decal->StickToWall (wall, ix, iy, ffloor).isValid()) { + decal->CheckMax(); tpl->ApplyToDecal (decal, wall); decal->AlphaColor = AlphaColor; decal->RenderFlags = (decal->RenderFlags & RF_DECALMASK) | @@ -669,12 +671,6 @@ DBaseDecal *DImpactDecal::CloneSelf (const FDecalTemplate *tpl, double ix, doubl return decal; } -void DImpactDecal::OnDestroy () -{ - ImpactCount--; - Super::OnDestroy(); -} - CCMD (countdecals) { Printf ("%d impact decals\n", ImpactCount); diff --git a/src/g_shared/a_sharedglobal.h b/src/g_shared/a_sharedglobal.h index e221f35525..3d7436548e 100644 --- a/src/g_shared/a_sharedglobal.h +++ b/src/g_shared/a_sharedglobal.h @@ -68,11 +68,10 @@ public: static DImpactDecal *StaticCreate(const FDecalTemplate *tpl, const DVector3 &pos, side_t *wall, F3DFloor * ffloor, PalEntry color = 0); void BeginPlay (); - void OnDestroy() override; protected: DBaseDecal *CloneSelf(const FDecalTemplate *tpl, double x, double y, double z, side_t *wall, F3DFloor * ffloor) const; - static void CheckMax (); + void CheckMax (); private: DImpactDecal(); diff --git a/src/p_saveg.cpp b/src/p_saveg.cpp index db93ef8d84..714b9bb2d3 100644 --- a/src/p_saveg.cpp +++ b/src/p_saveg.cpp @@ -980,6 +980,7 @@ void G_SerializeLevel(FSerializer &arc, bool hubload) ("level.spotstate", level.SpotState) ("level.fragglethinker", level.FraggleScriptThinker) ("level.acsthinker", level.ACSThinker); + ("level.impactdecalcount", level.ImpactDecalCount); // Hub transitions must keep the current total time if (!hubload)