diff --git a/Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs b/Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs index 560705ffb7d..59773559686 100644 --- a/Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs +++ b/Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs @@ -37,8 +37,8 @@ protected override void Draw(in OverlayDrawArgs args) var worldHandle = args.WorldHandle; - var accumulator = Math.Clamp((float) Comp.PulseAccumulator.TotalSeconds, 0f, Comp.PulseTime); - var alpha = Comp.PulseTime <= 0 ? 1f : float.Lerp(1f, 0f, accumulator / Comp.PulseTime); + var accumulator = Math.Clamp(Comp.PulseAccumulator, 0f, Comp.PulseTime); + var alpha = Comp.PulseTime <= 0f ? 1f : float.Lerp(1f, 0f, accumulator / Comp.PulseTime); worldHandle.SetTransform(Matrix3x2.Identity); worldHandle.UseShader(_shader); diff --git a/Content.Client/Overlays/Switchable/NightVisionSystem.cs b/Content.Client/Overlays/Switchable/NightVisionSystem.cs index bb1c9c2a3ef..659ec14413c 100644 --- a/Content.Client/Overlays/Switchable/NightVisionSystem.cs +++ b/Content.Client/Overlays/Switchable/NightVisionSystem.cs @@ -57,15 +57,20 @@ protected override void UpdateInternal(RefreshEquipmentHudEvent 0f && comp.PulseAccumulator < comp.PulseTime) + active = true; + else continue; - - if (nvComp == null) - nvComp = comp; - else if (!nvComp.DrawOverlay && comp.DrawOverlay) - nvComp = comp; - else if (nvComp.DrawOverlay == comp.DrawOverlay && nvComp.PulseTime > 0 && comp.PulseTime <= 0) - nvComp = comp; + if (comp.DrawOverlay) + { + if (nvComp == null) + nvComp = comp; + else if (nvComp.PulseTime > 0f && comp.PulseTime <= 0f) + nvComp = comp; + } + + if (active && nvComp is { PulseTime: <= 0 }) + break; } UpdateNightVision(active); diff --git a/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs b/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs index 725dac730d5..010d1411702 100644 --- a/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs +++ b/Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs @@ -63,8 +63,8 @@ protected override void Draw(in OverlayDrawArgs args) if (!_entity.TryGetComponent(player, out TransformComponent? playerXform)) return; - var accumulator = Math.Clamp((float) Comp.PulseAccumulator.TotalSeconds, 0f, Comp.PulseTime); - var alpha = Comp.PulseTime <= 0 ? 1f : float.Lerp(1f, 0f, accumulator / Comp.PulseTime); + var accumulator = Math.Clamp(Comp.PulseAccumulator, 0f, Comp.PulseTime); + var alpha = Comp.PulseTime <= 0f ? 1f : float.Lerp(1f, 0f, accumulator / Comp.PulseTime); // Thermal vision grants some night vision (clientside light) if (LightRadius > 0) diff --git a/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs b/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs index b4bc9bf54a2..b172389df4b 100644 --- a/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs +++ b/Content.Client/Overlays/Switchable/ThermalVisionSystem.cs @@ -56,14 +56,14 @@ protected override void UpdateInternal(RefreshEquipmentHudEvent= comp.PulseTime)) continue; if (tvComp == null) tvComp = comp; else if (!tvComp.DrawOverlay && comp.DrawOverlay) tvComp = comp; - else if (tvComp.DrawOverlay == comp.DrawOverlay && tvComp.PulseTime > 0 && comp.PulseTime <= 0) + else if (tvComp.DrawOverlay == comp.DrawOverlay && tvComp.PulseTime > 0f && comp.PulseTime <= 0f) tvComp = comp; lightRadius = MathF.Max(lightRadius, comp.LightRadius); diff --git a/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs b/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs index a13e20b60f5..2e107a5e4bb 100644 --- a/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs +++ b/Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs @@ -19,15 +19,14 @@ public abstract partial class SwitchableOverlayComponent : BaseOverlayComponent [DataField] public bool IsEquipment; - + /// + /// If it is greater than 0, overlay isn't toggled but pulsed instead + /// [DataField] - public float PulseTime = 0; - - [ViewVariables(VVAccess.ReadOnly)] - public TimeSpan PulseAccumulator = TimeSpan.Zero; + public float PulseTime; [ViewVariables(VVAccess.ReadOnly)] - public TimeSpan PulseEndTime = TimeSpan.Zero; + public float PulseAccumulator; [DataField] public virtual SoundSpecifier? ActivateSound { get; set; } = diff --git a/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs b/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs index 5e0375869af..665e153ea3e 100644 --- a/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs +++ b/Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs @@ -50,14 +50,14 @@ private void ActiveTick(float frameTime) while (query.MoveNext(out var uid, out var comp)) { - if (comp.PulseTime <= 0) + if (comp.PulseTime <= 0f || comp.PulseAccumulator >= comp.PulseTime) continue; // The accumulator is for visually rendering the pulse strength decaying. - comp.PulseAccumulator += comp.PulseEndTime - _timing.CurTime; + comp.PulseAccumulator += frameTime; // This line is for the actual check that shuts off the pulse when its time is up. - if (_timing.CurTime < comp.PulseEndTime) + if (comp.PulseAccumulator < comp.PulseTime) continue; Toggle(uid, comp, false, false); @@ -103,8 +103,6 @@ private void OnHandleState(EntityUid uid, TComp component, ref ComponentHandleSt return; component.IsActive = state.IsActive; - if (component.PulseTime != 0) - component.PulseEndTime = _timing.CurTime + TimeSpan.FromSeconds(component.PulseTime); RaiseSwitchableOverlayToggledEvent(uid, component.IsEquipment ? Transform(uid).ParentUid : uid, @@ -127,7 +125,7 @@ private void OnShutdown(EntityUid uid, TComp component, ComponentShutdown args) private void OnInit(EntityUid uid, TComp component, ComponentInit args) { - component.PulseAccumulator = TimeSpan.FromSeconds(component.PulseTime); + component.PulseAccumulator = component.PulseTime; } private void OnMapInit(EntityUid uid, TComp component, MapInitEvent args) @@ -153,9 +151,9 @@ private void Toggle(EntityUid uid, TComp component, bool activate, bool playSoun false); } - if (component.PulseTime > 0) + if (component.PulseTime > 0f) { - component.PulseAccumulator = activate ? TimeSpan.Zero : TimeSpan.FromSeconds(component.PulseTime); + component.PulseAccumulator = activate ? 0f : component.PulseTime; return; }