Optimise flashlights (#2468)

Flashlights were calling dirty EVERY TICK so this just means they only call it when absoluetely necessary which saves a lot.

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-11-01 07:56:46 +11:00
committed by GitHub
parent 87cb22838b
commit 2e65b1e5fa
6 changed files with 79 additions and 57 deletions

View File

@@ -1,5 +1,6 @@
using Content.Shared.GameObjects.Components.Power;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Utility;
using Robust.Server.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
@@ -45,10 +46,15 @@ namespace Content.Server.GameObjects.Components.Power
{
if (Owner.TryGetComponent(out AppearanceComponent appearance))
{
appearance.SetData(PowerCellVisuals.ChargeLevel, CurrentCharge / MaxCharge);
appearance.SetData(PowerCellVisuals.ChargeLevel, GetLevel(CurrentCharge / MaxCharge));
}
}
private byte GetLevel(float fraction)
{
return (byte) ContentHelpers.RoundToNearestLevels(fraction, 1, SharedPowerCell.PowerCellVisualsLevels);
}
void IExamine.Examine(FormattedMessage message, bool inDetailsRange)
{
if(inDetailsRange)