Skip to content

Commit

Permalink
Switch frame time tracking to using timespans
Browse files Browse the repository at this point in the history
  • Loading branch information
Quanteey committed Feb 9, 2025
1 parent 29d99ec commit e95d79d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public sealed partial class CrewMonitoringConsoleComponent : Component
/// <summary>
/// Accumulated time for tracking alert cooldown
/// </summary>
public float AccumulatedFrameTime = 0f;
public TimeSpan AccumulatedTime = TimeSpan.Zero;

/// <summary>
/// Time between alerts
/// </summary>
[DataField]
public float AlertCooldown = 15f;
public TimeSpan AlertCooldown = TimeSpan.FromSeconds(15);

/// <summary>
/// Alert sound that is played when a crew member goes into critical / dies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ private void OnPacketReceived(EntityUid uid, CrewMonitoringConsoleComponent comp

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

// We are doing this outside the cooldown check to avoid "alert queues"
Expand Down Expand Up @@ -126,7 +126,7 @@ public override void Update(float frameTime)
var query = EntityQueryEnumerator<CrewMonitoringConsoleComponent>();
while (query.MoveNext(out var uid, out var cmp))
{
cmp.AccumulatedFrameTime += frameTime;
cmp.AccumulatedTime += TimeSpan.FromSeconds(frameTime);
}
}
// DeltaV - end of alert system code
Expand Down

0 comments on commit e95d79d

Please sign in to comment.