Skip to content

Commit

Permalink
use timestamps of next alert instead of frame time tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
Quanteey committed Feb 10, 2025
1 parent e7bc9a2 commit 2dbc2f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Content.Shared.Medical.SuitSensor;
using Robust.Shared.Audio; // DeltaV
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; // DeltaV

namespace Content.Server.Medical.CrewMonitoring;

[RegisterComponent]
[RegisterComponent, AutoGenerateComponentPause] // DeltaV - add AutoGenerateComponentPause
[Access(typeof(CrewMonitoringConsoleSystem))]
public sealed partial class CrewMonitoringConsoleComponent : Component
{
Expand Down Expand Up @@ -33,7 +34,8 @@ public sealed partial class CrewMonitoringConsoleComponent : Component
/// <summary>
/// Accumulated time for tracking alert cooldown
/// </summary>
public TimeSpan AccumulatedTime = TimeSpan.Zero;
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan NextAlert;

/// <summary>
/// Time between alerts
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
using System.Linq;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Power.EntitySystems; // DeltaV
using Content.Server.Power.EntitySystems; // DeltaV
using Content.Server.PowerCell;
using Content.Shared.Medical.CrewMonitoring;
using Content.Shared.Medical.SuitSensor;
using Content.Shared.Pinpointer;
using Robust.Server.GameObjects;
using Robust.Shared.Audio; // DeltaV
using Robust.Shared.Audio.Systems; // DeltaV
using Robust.Shared.Audio; // DeltaV
using Robust.Shared.Audio.Systems; // DeltaV
using Robust.Shared.Timing; // DeltaV

namespace Content.Server.Medical.CrewMonitoring;

public sealed class CrewMonitoringConsoleSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _cell = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; // DeltaV
[Dependency] private readonly SharedAudioSystem _audio = default!; // DeltaV
[Dependency] private readonly IGameTiming _timing = default!; // DeltaV

public override void Initialize()
{
Expand Down Expand Up @@ -75,11 +77,11 @@ private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent comp

if (!status.IsAlive || isCritical)
{
if (component.AccumulatedTime >= component.AlertCooldown)
if (_timing.CurTime >= component.NextAlert)
{
var audioParams = AudioParams.Default.WithVolume(-2f).WithMaxDistance(4f);
_audio.PlayPvs(component.AlertSound, uid, audioParams);
component.AccumulatedTime = TimeSpan.Zero;
component.NextAlert = _timing.CurTime + component.AlertCooldown;
}

// We are doing this outside the cooldown check to avoid "alert queues"
Expand Down Expand Up @@ -117,17 +119,4 @@ private void UpdateUserInterface(EntityUid uid, CrewMonitoringConsoleComponent?
var allSensors = component.ConnectedSensors.Values.ToList();
_uiSystem.SetUiState(uid, CrewMonitoringUIKey.Key, new CrewMonitoringState(allSensors));
}

// DeltaV - start alert system code
public override void Update(float frameTime)
{
base.Update(frameTime);

var query = EntityQueryEnumerator<CrewMonitoringConsoleComponent>();
while (query.MoveNext(out var uid, out var cmp))
{
cmp.AccumulatedTime += TimeSpan.FromSeconds(frameTime);
}
}
// DeltaV - end of alert system code
}

0 comments on commit 2dbc2f2

Please sign in to comment.