Files
crystall-punk-14/Content.Server/AME/AntimatterEngineSystem.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Server.AME.Components;
2022-03-29 03:58:51 +11:00
using Content.Server.Power.Components;
using JetBrains.Annotations;
2021-06-09 22:19:39 +02:00
namespace Content.Server.AME
{
[UsedImplicitly]
public sealed class AntimatterEngineSystem : EntitySystem
{
private float _accumulatedFrameTime;
2022-03-29 03:58:51 +11:00
private const float UpdateCooldown = 10f;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AMEControllerComponent, PowerChangedEvent>(OnAMEPowerChange);
}
public override void Update(float frameTime)
{
base.Update(frameTime);
2022-03-29 03:58:51 +11:00
// TODO: Won't exactly work with replays I guess?
_accumulatedFrameTime += frameTime;
2022-03-29 03:58:51 +11:00
if (_accumulatedFrameTime >= UpdateCooldown)
{
foreach (var comp in EntityManager.EntityQuery<AMEControllerComponent>())
{
comp.OnUpdate(frameTime);
}
2022-03-29 03:58:51 +11:00
_accumulatedFrameTime -= UpdateCooldown;
}
2022-03-29 03:58:51 +11:00
}
2022-03-29 03:58:51 +11:00
private static void OnAMEPowerChange(EntityUid uid, AMEControllerComponent component, PowerChangedEvent args)
{
component.UpdateUserInterface();
}
}
}