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;
|
2020-08-29 06:05:44 -05:00
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.AME
|
2020-08-29 06:05:44 -05:00
|
|
|
|
{
|
|
|
|
|
|
[UsedImplicitly]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class AntimatterEngineSystem : EntitySystem
|
2020-08-29 06:05:44 -05:00
|
|
|
|
{
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-29 06:05:44 -05:00
|
|
|
|
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?
|
2020-08-29 06:05:44 -05:00
|
|
|
|
_accumulatedFrameTime += frameTime;
|
2022-03-29 03:58:51 +11:00
|
|
|
|
if (_accumulatedFrameTime >= UpdateCooldown)
|
2020-08-29 06:05:44 -05:00
|
|
|
|
{
|
2021-10-18 14:58:34 +02:00
|
|
|
|
foreach (var comp in EntityManager.EntityQuery<AMEControllerComponent>())
|
2020-08-29 06:05:44 -05:00
|
|
|
|
{
|
|
|
|
|
|
comp.OnUpdate(frameTime);
|
|
|
|
|
|
}
|
2022-03-29 03:58:51 +11:00
|
|
|
|
_accumulatedFrameTime -= UpdateCooldown;
|
2020-08-29 06:05:44 -05:00
|
|
|
|
}
|
2022-03-29 03:58:51 +11:00
|
|
|
|
}
|
2020-08-29 06:05:44 -05:00
|
|
|
|
|
2022-03-29 03:58:51 +11:00
|
|
|
|
private static void OnAMEPowerChange(EntityUid uid, AMEControllerComponent component, PowerChangedEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
component.UpdateUserInterface();
|
2020-08-29 06:05:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|