Optimise handheld lights (#2927)
* Optimise handheld lights * Woops also these * Might as well do shutdown too * Also these Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Interactable;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
@@ -7,11 +9,41 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
[UsedImplicitly]
|
||||
internal sealed class HandHeldLightSystem : EntitySystem
|
||||
{
|
||||
// TODO: Ideally you'd be able to subscribe to power stuff to get events at certain percentages.. or something?
|
||||
// But for now this will be better anyway.
|
||||
private HashSet<HandheldLightComponent> _activeLights = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ActivateHandheldLightMessage>(HandleActivate);
|
||||
SubscribeLocalEvent<DeactivateHandheldLightMessage>(HandleDeactivate);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
base.Shutdown();
|
||||
_activeLights.Clear();
|
||||
UnsubscribeLocalEvent<ActivateHandheldLightMessage>();
|
||||
UnsubscribeLocalEvent<DeactivateHandheldLightMessage>();
|
||||
}
|
||||
|
||||
private void HandleActivate(ActivateHandheldLightMessage message)
|
||||
{
|
||||
_activeLights.Add(message.Component);
|
||||
}
|
||||
|
||||
private void HandleDeactivate(DeactivateHandheldLightMessage message)
|
||||
{
|
||||
_activeLights.Remove(message.Component);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
foreach (var comp in ComponentManager.EntityQuery<HandheldLightComponent>(false))
|
||||
foreach (var handheld in _activeLights.ToArray())
|
||||
{
|
||||
comp.OnUpdate(frameTime);
|
||||
if (handheld.Deleted || handheld.Paused) continue;
|
||||
handheld.OnUpdate(frameTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user