Skip to content

Commit

Permalink
Fix CyberEyes (#1723)
Browse files Browse the repository at this point in the history
# Description

Last changes to CyberEyes broke nightvision, so this reverts those
changes.

# Changelog

:cl:
- fix: Fixed night vision not working correctly.
  • Loading branch information
VMSolidus authored Feb 6, 2025
1 parent c908efb commit 3d24fed
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 28 deletions.
4 changes: 2 additions & 2 deletions Content.Client/Overlays/Switchable/BaseSwitchableOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 13 additions & 8 deletions Content.Client/Overlays/Switchable/NightVisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ protected override void UpdateInternal(RefreshEquipmentHudEvent<NightVisionCompo
NightVisionComponent? nvComp = null;
foreach (var comp in args.Components)
{
if (!comp.IsActive && (comp.PulseTime <= 0 || _timing.CurTime < comp.PulseEndTime))
if (comp.IsActive || comp.PulseTime > 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);
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Overlays/Switchable/ThermalVisionOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Overlays/Switchable/ThermalVisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ protected override void UpdateInternal(RefreshEquipmentHudEvent<ThermalVisionCom
var lightRadius = 0f;
foreach (var comp in args.Components)
{
if (!comp.IsActive && (comp.PulseTime <= 0 || _timing.CurTime < comp.PulseEndTime))
if (!comp.IsActive && (comp.PulseTime <= 0f || comp.PulseAccumulator >= 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);
Expand Down
11 changes: 5 additions & 6 deletions Content.Shared/Overlays/Switchable/SwitchableOverlayComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ public abstract partial class SwitchableOverlayComponent : BaseOverlayComponent
[DataField]
public bool IsEquipment;


/// <summary>
/// If it is greater than 0, overlay isn't toggled but pulsed instead
/// </summary>
[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; } =
Expand Down
14 changes: 6 additions & 8 deletions Content.Shared/Overlays/Switchable/SwitchableOverlaySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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;
}

Expand Down

0 comments on commit 3d24fed

Please sign in to comment.