Skip to content

Commit

Permalink
Update GlimmerSystem.cs (#1694)
Browse files Browse the repository at this point in the history
# Description

These weren't sanitized because I woefully assumed that nothing could
actually escape the bounds of an asymptote equation. Lo' and behold
floating point precision rounding errors can.


![image](https://github.com/user-attachments/assets/cda09b59-f81e-47ca-a4b6-27e12fb8aa94)

# Changelog

:cl:
- fix: Fixed an issue where Glimmer can reach infinite values under
certain conditions.
  • Loading branch information
VMSolidus authored Jan 31, 2025
1 parent 65362e5 commit 641b99d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Content.Shared/Psionics/Glimmer/GlimmerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Robust.Shared.Configuration;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Prometheus;

namespace Content.Shared.Psionics.Glimmer;

Expand All @@ -13,6 +14,15 @@ public sealed class GlimmerSystem : EntitySystem
{
[Dependency] private readonly IConfigurationManager _cfg = default!;

private static readonly Gauge GlimmerInputCount = Metrics.CreateGauge(
"glimmer_input",
"Amount of Input Glimmer");

private static readonly Gauge GlimmerOutputCount = Metrics.CreateGauge(
"glimmer_output",
"Amount of Output Glimmer");


private float _glimmerInput = 0;

/// <summary>
Expand Down Expand Up @@ -73,7 +83,10 @@ public override void Initialize()
private void Reset(RoundRestartCleanupEvent args)
{
GlimmerInput = 0;
GlimmerInputCount.Set(GlimmerInput);

GlimmerOutput = 0;
GlimmerOutputCount.Set(GlimmerOutput);
}

/// <summary>
Expand Down Expand Up @@ -118,7 +131,10 @@ public void DeltaGlimmerInput(float delta)
if (_enabled && delta != 0)
{
GlimmerInput += delta;
GlimmerOutput = 2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerInput)) - 1000;
GlimmerInputCount.Set(GlimmerInput);

GlimmerOutput = Math.Clamp(2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerInput)) - 1000, 0, 999.999999f);
GlimmerOutputCount.Set(GlimmerOutput);
}
}

Expand All @@ -132,7 +148,10 @@ public void DeltaGlimmerOutput(float delta)
if (_enabled && delta != 0)
{
GlimmerOutput += delta;
GlimmerInput = 2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerOutput)) - 1000;
GlimmerOutputCount.Set(GlimmerOutput);

GlimmerInput = Math.Max(2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerOutput)) - 1000, 0);
GlimmerInputCount.Set(GlimmerInput);
}
}

Expand All @@ -146,7 +165,10 @@ public void SetGlimmerOutput(float set)
if (_enabled && set != 0)
{
GlimmerOutput = Math.Clamp(set, 0, 999.999f);
GlimmerOutputCount.Set(GlimmerOutput);

GlimmerInput = 2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerOutput)) - 1000;
GlimmerInputCount.Set(GlimmerInput);
}
}

Expand All @@ -160,7 +182,10 @@ public void SetGlimmerInput(float set)
if (_enabled && set >= 0)
{
GlimmerInput = set;
GlimmerInputCount.Set(GlimmerInput);

GlimmerOutput = 2000 / (1 + MathF.Pow(MathF.E, -.0022f * GlimmerOutput)) - 1000;
GlimmerOutputCount.Set(GlimmerOutput);
}
}

Expand Down

0 comments on commit 641b99d

Please sign in to comment.