Increase error tolerance of power debug assert (#12828)

This commit is contained in:
Leon Friedrich
2022-12-09 14:48:53 +13:00
committed by GitHub
parent b49762eae5
commit abaa6c6dd9

View File

@@ -252,7 +252,14 @@ namespace Content.Server.Power.Pow3r
// available supply. IMO this is undesirable, but I can't think of an easy fix ATM.
battery.CurrentStorage -= frameTime * battery.CurrentSupply;
DebugTools.Assert(battery.CurrentStorage >= 0 || MathHelper.CloseTo(battery.CurrentStorage, 0, 1e-5));
#if DEBUG
// Manual "MathHelper.CloseToPercent" using the subtracted value to define the relative error.
if (battery.CurrentStorage < 0)
{
float epsilon = Math.Max(frameTime * battery.CurrentSupply, 1) * 1e-4f;
DebugTools.Assert(battery.CurrentStorage > -epsilon);
}
#endif
battery.CurrentStorage = MathF.Max(0, battery.CurrentStorage);
battery.SupplyRampTarget = battery.MaxEffectiveSupply * relativeTargetBatteryOutput - battery.CurrentReceiving * battery.Efficiency;