Skip to content

Commit

Permalink
Some more small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Jul 1, 2024
1 parent c8e0572 commit 35eb6f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Content.Server/Psionics/Abilities/DispelPowerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ private void OnPowerUsed(DispelPowerActionEvent args)
{
args.Handled = true;
_psionics.LogPowerUsed(args.Performer, "dispel", psionic, 1, 1, true);
_glimmerSystem.DeltaGlimmerInput(-_random.NextFloat(2 * psionic.Dampening - psionic.Amplification, 4 * psionic.Dampening - psionic.Amplification));

// Redundant check here as well for a small performance optimization
// Dispel has its own niche equations for glimmer.
if (_glimmerSystem.GetGlimmerEnabled())
_glimmerSystem.DeltaGlimmerOutput(-_random.NextFloat(2 * psionic.Dampening - psionic.Amplification, 4 * psionic.Dampening - psionic.Amplification));
}
}

Expand Down
8 changes: 8 additions & 0 deletions Content.Shared/Psionics/Glimmer/GlimmerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public float GetGlimmerEquilibriumRatio()
return 0.01f;
else return GlimmerOutput / GlimmerEquilibrium;
}

/// <summary>
/// Returns the GlimmerEnabled CVar, useful for niche early exits in systems that otherwise don't have any calls to CVars.
/// </summary>
public bool GetGlimmerEnabled()
{
return _enabled;
}
}

[Serializable, NetSerializable]
Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Psionics/SharedPsionicAbilitiesSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public void LogPowerUsed(EntityUid uid, string power, PsionicComponent? psionic
var ev = new PsionicPowerUsedEvent(uid, power);
RaiseLocalEvent(uid, ev, false);

if (!overrideGlimmer)
//Redundant check for the GlimmerEnabled CVar because I want to skip this math too if its turned off.
if (_glimmerSystem.GetGlimmerEnabled() && !overrideGlimmer)
{
if (psionic == null)
_glimmerSystem.DeltaGlimmerInput(_robustRandom.NextFloat(minGlimmer, maxGlimmer));
Expand Down

0 comments on commit 35eb6f6

Please sign in to comment.