From bdca58f2ed088a35f107f7c0d167a21338ffdef5 Mon Sep 17 00:00:00 2001 From: mirrorcult Date: Mon, 4 Apr 2022 22:56:07 -0700 Subject: [PATCH] Optimize status effects (#7429) --- Content.Shared/StatusEffect/StatusEffectsComponent.cs | 3 +++ Content.Shared/StatusEffect/StatusEffectsSystem.cs | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Content.Shared/StatusEffect/StatusEffectsComponent.cs b/Content.Shared/StatusEffect/StatusEffectsComponent.cs index 8dd3ef7813..c95e57f85d 100644 --- a/Content.Shared/StatusEffect/StatusEffectsComponent.cs +++ b/Content.Shared/StatusEffect/StatusEffectsComponent.cs @@ -24,6 +24,9 @@ namespace Content.Shared.StatusEffect public List AllowedEffects = default!; } + [RegisterComponent] + public sealed class ActiveStatusEffectsComponent : Component {} + /// /// Holds information about an active status effect. /// diff --git a/Content.Shared/StatusEffect/StatusEffectsSystem.cs b/Content.Shared/StatusEffect/StatusEffectsSystem.cs index 469f04eb9f..40019a8926 100644 --- a/Content.Shared/StatusEffect/StatusEffectsSystem.cs +++ b/Content.Shared/StatusEffect/StatusEffectsSystem.cs @@ -32,9 +32,8 @@ namespace Content.Shared.StatusEffect base.Update(frameTime); var curTime = _gameTiming.CurTime; - foreach (var status in EntityManager.EntityQuery(false)) + foreach (var (_, status) in EntityManager.EntityQuery()) { - 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(uid); } if (proto.Alert != null) @@ -271,6 +271,10 @@ namespace Content.Shared.StatusEffect } status.ActiveEffects.Remove(key); + if (status.ActiveEffects.Count == 0) + { + RemComp(uid); + } Dirty(status); // event?