- fixed attached dynamic light setup.

This was only run on a state change and missed every external light change.
Any place which wants to flag a light change now only will set a flag and at the end of the thinker loop all flagged actors will be processed.
For performance reasons this was merged with the P_RunEffects iterator loop.
This commit is contained in:
Christoph Oelckers 2019-08-18 13:48:52 +02:00
parent 6e8ee9a684
commit ae57bc71d4
6 changed files with 29 additions and 36 deletions

View file

@ -134,7 +134,6 @@ void P_Ticker (void)
for (auto Level : AllLevels())
{
// todo: set up a sandbox for secondary levels here.
auto it = Level->GetThinkerIterator<AActor>();
AActor *ac;
@ -142,6 +141,7 @@ void P_Ticker (void)
{
ac->ClearInterpolation();
}
P_ThinkParticles(Level); // [RH] make the particles think
for (i = 0; i < MAXPLAYERS; i++)
@ -157,7 +157,22 @@ void P_Ticker (void)
if (!Level->isFrozen())
{
P_UpdateSpecials(Level);
P_RunEffects(Level); // [RH] Run particle effects
}
it = Level->GetThinkerIterator<AActor>();
// Set dynamic lights at the end of the tick, so that this catches all changes being made through the last frame.
while ((ac = it.Next()))
{
if (ac->flags8 & MF8_RECREATELIGHTS)
{
ac->flags8 &= ~MF8_RECREATELIGHTS;
ac->SetDynamicLights();
}
// This was merged from P_RunEffects to eliminate the costly duplicate ThinkerIterator loop.
if ((ac->effects || ac->fountaincolor) && !Level->isFrozen())
{
P_RunEffect(ac, ac->effects);
}
}
// for par times

View file

@ -764,17 +764,11 @@ void AActor::SetDynamicLights()
AttachLight(count++, def);
}
if (LightAssociations.Size() > 0)
for (const auto asso : LightAssociations)
{
unsigned int i;
for (i = 0; i < LightAssociations.Size(); i++)
if (asso->Sprite() == sprite && (asso->Frame() == frame || asso->Frame() == -1))
{
if (LightAssociations[i]->Sprite() == sprite &&
(LightAssociations[i]->Frame()==frame || LightAssociations[i]->Frame()==-1))
{
AttachLight(count++, LightAssociations[i]->Light());
}
AttachLight(count++, asso->Light());
}
}
if (count == 0 && state->Light > 0)
@ -850,6 +844,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;
return 1;
}
return 0;
@ -893,7 +888,7 @@ int AttachLightDirect(AActor *self, int _lightid, int type, int color, int radiu
{
userlight->UnsetSpotPitch();
}
self->flags8 |= MF8_RECREATELIGHTS;
return 1;
}
@ -930,8 +925,10 @@ int RemoveLight(AActor *self, int _lightid)
{
delete self->UserLights[userlight];
self->UserLights.Delete(userlight);
self->flags8 |= MF8_RECREATELIGHTS;
return 1;
}
return 1;
return 0;
}
DEFINE_ACTION_FUNCTION_NATIVE(AActor, A_RemoveLight, RemoveLight)

View file

@ -409,7 +409,8 @@ enum ActorFlag8
MF8_HITOWNER = 0x00000010, // projectile can hit the actor that fired it
MF8_NOFRICTION = 0x00000020, // friction doesn't apply to the actor at all
MF8_NOFRICTIONBOUNCE = 0x00000040, // don't bounce off walls when on icy floors
MF8_RETARGETAFTERSLAM = 0x00000080 // Forces jumping to the idle state after slamming into something
MF8_RETARGETAFTERSLAM = 0x00000080, // Forces jumping to the idle state after slamming into something
MF8_RECREATELIGHTS = 0x00000100, // Internal flag that signifies that the light attachments need to be recreated at the
};
// --- mobj.renderflags ---

View file

@ -299,25 +299,6 @@ void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &v
}
}
//
// P_RunEffects
//
// Run effects on all actors in the world
//
void P_RunEffects (FLevelLocals *Level)
{
AActor *actor;
auto iterator = Level->GetThinkerIterator<AActor>();
while ( (actor = iterator.Next ()) )
{
if (actor->effects || actor->fountaincolor)
{
P_RunEffect (actor, actor->effects);
}
}
}
//
// JitterParticle
//

View file

@ -78,7 +78,6 @@ particle_t *JitterParticle (FLevelLocals *Level, int ttl, double drift);
void P_ThinkParticles (FLevelLocals *Level);
void P_SpawnParticle(FLevelLocals *Level, const DVector3 &pos, const DVector3 &vel, const DVector3 &accel, PalEntry color, double startalpha, int lifetime, double size, double fadestep, double sizestep, int flags = 0);
void P_InitEffects (void);
void P_RunEffects (FLevelLocals *Level);
void P_RunEffect (AActor *actor, int effects);

View file

@ -577,7 +577,7 @@ bool AActor::SetState (FState *newstate, bool nofunction)
newstate = newstate->GetNextState();
} while (tics == 0);
SetDynamicLights();
flags8 |= MF8_RECREATELIGHTS;
return true;
}
@ -4702,9 +4702,9 @@ void AActor::CallBeginPlay()
void AActor::PostBeginPlay ()
{
SetDynamicLights();
PrevAngles = Angles;
flags7 |= MF7_HANDLENODELAY;
flags8 |= MF8_RECREATELIGHTS;
}
void AActor::CallPostBeginPlay()