From 6c12a8de1282e6e3b79244a775d531c68c54503d Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 21 Sep 2021 20:31:10 +0200 Subject: [PATCH] - properly track whether some action in the current frame may have triggered a dynamic light activation. --- src/gamedata/g_mapinfo.h | 1 + src/p_setup.cpp | 3 +++ src/playsim/a_dynlight.cpp | 3 +++ src/playsim/dthinker.cpp | 6 ++++-- src/playsim/p_mobj.cpp | 12 ++++++++++-- wadsrc/static/zscript/constants.zs | 9 +++++++++ 6 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/gamedata/g_mapinfo.h b/src/gamedata/g_mapinfo.h index 9f74728542..4ed13e5baa 100644 --- a/src/gamedata/g_mapinfo.h +++ b/src/gamedata/g_mapinfo.h @@ -260,6 +260,7 @@ enum ELevelFlags : unsigned int LEVEL3_NOSHADOWMAP = 0x00010000, // disables shadowmaps for a given level. LEVEL3_AVOIDMELEE = 0x00020000, // global flag needed for proper MBF support. LEVEL3_NOJUMPDOWN = 0x00040000, // only for MBF21. Inverse of MBF's dog_jumping flag. + LEVEL3_LIGHTCREATED = 0x00080000, // a light had been created in the last frame }; diff --git a/src/p_setup.cpp b/src/p_setup.cpp index b96830a1f6..d05865820c 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -598,6 +598,9 @@ void P_SetupLevel(FLevelLocals *Level, int position, bool newGame) auto it = Level->GetThinkerIterator(); AActor* ac; + + Level->flags3 |= LEVEL3_LIGHTCREATED; + // Initial setup of the dynamic lights. while ((ac = it.Next())) { diff --git a/src/playsim/a_dynlight.cpp b/src/playsim/a_dynlight.cpp index 4750dddfaf..8a5838f1d1 100644 --- a/src/playsim/a_dynlight.cpp +++ b/src/playsim/a_dynlight.cpp @@ -850,6 +850,7 @@ int AttachLightDef(AActor *self, int _lightid, int _lightname) auto userlight = self->UserLights[FindUserLight(self, lightid, true)]; userlight->CopyFrom(*LightDefaults[lightdef]); self->flags8 |= MF8_RECREATELIGHTS; + self->Level->flags3 |= LEVEL3_LIGHTCREATED; return 1; } return 0; @@ -894,6 +895,7 @@ int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radiu userlight->UnsetSpotPitch(); } self->flags8 |= MF8_RECREATELIGHTS; + self->Level->flags3 |= LEVEL3_LIGHTCREATED; return 1; } @@ -931,6 +933,7 @@ int RemoveLight(AActor *self, int _lightid) delete self->UserLights[userlight]; self->UserLights.Delete(userlight); self->flags8 |= MF8_RECREATELIGHTS; + self->Level->flags3 |= LEVEL3_LIGHTCREATED; return 1; } return 0; diff --git a/src/playsim/dthinker.cpp b/src/playsim/dthinker.cpp index 75c75e7895..013ea0829a 100644 --- a/src/playsim/dthinker.cpp +++ b/src/playsim/dthinker.cpp @@ -144,8 +144,9 @@ void FThinkerCollection::RunThinkers(FLevelLocals *Level) } } while (count != 0); - if (Level->HasDynamicLights) + if (Level->lights || (Level->flags3 & LEVEL3_LIGHTCREATED)) { + Level->flags3 &= ~LEVEL3_LIGHTCREATED; recreateLights(); for (auto light = Level->lights; light;) { @@ -174,8 +175,9 @@ void FThinkerCollection::RunThinkers(FLevelLocals *Level) } } while (count != 0); - if (Level->lights && Level->HasDynamicLights) + if (Level->lights || (Level->flags3 & LEVEL3_LIGHTCREATED)) { + Level->flags3 &= ~LEVEL3_LIGHTCREATED; recreateLights(); // Also profile the internal dynamic lights, even though they are not implemented as thinkers. auto &prof = Profiles[NAME_InternalDynamicLight]; diff --git a/src/playsim/p_mobj.cpp b/src/playsim/p_mobj.cpp index cba3950d7b..39ec58a47d 100644 --- a/src/playsim/p_mobj.cpp +++ b/src/playsim/p_mobj.cpp @@ -584,7 +584,11 @@ bool AActor::SetState (FState *newstate, bool nofunction) newstate = newstate->GetNextState(); } while (tics == 0); - flags8 |= MF8_RECREATELIGHTS; + if (GetInfo()->LightAssociations.Size()) + { + flags8 |= MF8_RECREATELIGHTS; + Level->flags3 |= LEVEL3_LIGHTCREATED; + } return true; } @@ -4799,7 +4803,11 @@ void AActor::PostBeginPlay () { PrevAngles = Angles; flags7 |= MF7_HANDLENODELAY; - flags8 |= MF8_RECREATELIGHTS; + if (GetInfo()->LightAssociations.Size()) + { + flags8 |= MF8_RECREATELIGHTS; + Level->flags3 |= LEVEL3_LIGHTCREATED; + } } void AActor::CallPostBeginPlay() diff --git a/wadsrc/static/zscript/constants.zs b/wadsrc/static/zscript/constants.zs index c288f2e450..a3cf305195 100644 --- a/wadsrc/static/zscript/constants.zs +++ b/wadsrc/static/zscript/constants.zs @@ -1333,6 +1333,15 @@ enum ELevelFlags LEVEL3_HIDEAUTHORNAME = 0x00000100, LEVEL3_PROPERMONSTERFALLINGDAMAGE = 0x00000200, // Properly apply falling damage to the monsters LEVEL3_SKYBOXAO = 0x00000400, // Apply SSAO to sector skies + LEVEL3_E1M8SPECIAL = 0x00000800, + LEVEL3_E2M8SPECIAL = 0x00001000, + LEVEL3_E3M8SPECIAL = 0x00002000, + LEVEL3_E4M8SPECIAL = 0x00004000, + LEVEL3_E4M6SPECIAL = 0x00008000, + LEVEL3_NOSHADOWMAP = 0x00010000, // disables shadowmaps for a given level. + LEVEL3_AVOIDMELEE = 0x00020000, // global flag needed for proper MBF support. + LEVEL3_NOJUMPDOWN = 0x00040000, // only for MBF21. Inverse of MBF's dog_jumping flag. + LEVEL3_LIGHTCREATED = 0x00080000, // a light had been created in the last frame }; // [RH] Compatibility flags.