Optimize status effects (#7429)

This commit is contained in:
mirrorcult
2022-04-04 22:56:07 -07:00
committed by GitHub
parent 53bea6c015
commit bdca58f2ed
2 changed files with 9 additions and 2 deletions

View File

@@ -24,6 +24,9 @@ namespace Content.Shared.StatusEffect
public List<string> AllowedEffects = default!;
}
[RegisterComponent]
public sealed class ActiveStatusEffectsComponent : Component {}
/// <summary>
/// Holds information about an active status effect.
/// </summary>

View File

@@ -32,9 +32,8 @@ namespace Content.Shared.StatusEffect
base.Update(frameTime);
var curTime = _gameTiming.CurTime;
foreach (var status in EntityManager.EntityQuery<StatusEffectsComponent>(false))
foreach (var (_, status) in EntityManager.EntityQuery<ActiveStatusEffectsComponent, StatusEffectsComponent>())
{
if (status.ActiveEffects.Count == 0) continue;
foreach (var state in status.ActiveEffects.ToArray())
{
// if we're past the end point of the effect
@@ -190,6 +189,7 @@ namespace Content.Shared.StatusEffect
else
{
status.ActiveEffects.Add(key, new StatusEffectState(cooldown, refresh, null));
EnsureComp<ActiveStatusEffectsComponent>(uid);
}
if (proto.Alert != null)
@@ -271,6 +271,10 @@ namespace Content.Shared.StatusEffect
}
status.ActiveEffects.Remove(key);
if (status.ActiveEffects.Count == 0)
{
RemComp<ActiveStatusEffectsComponent>(uid);
}
Dirty(status);
// event?