From 0b448b500dfa6ee6a45181904a1ee56095085dd5 Mon Sep 17 00:00:00 2001 From: Visne Date: Sun, 16 Aug 2020 14:54:52 +0200 Subject: [PATCH] Merge MathHelper and FloatMath Requires space-wizards/RobustToolbox#1234 --- Content.Client/Chat/SpeechBubble.cs | 6 +++--- .../GameObjects/Components/Disposal/DisposalUnitWindow.cs | 4 ++-- .../GameObjects/Components/HandheldLightComponent.cs | 2 +- .../GameObjects/Components/MagicMirrorBoundUserInterface.cs | 2 +- .../GameObjects/Components/Mobs/CameraRecoilComponent.cs | 2 +- .../Components/Mobs/ClientStatusEffectsComponent.cs | 2 +- .../GameObjects/Components/Power/ApcBoundUserInterface.cs | 4 ++-- .../GameObjects/Components/Weapons/FlashableComponent.cs | 2 +- Content.Client/UserInterface/CooldownGraphic.cs | 2 +- Content.Client/UserInterface/ItemSlotManager.cs | 2 +- Content.Server/AI/Utility/Considerations/Consideration.cs | 6 +++--- Content.Server/Atmos/HighPressureMovementController.cs | 4 ++-- Content.Server/Atmos/TileAtmosphere.cs | 4 ++-- .../GameObjects/Components/Power/BatteryComponent.cs | 2 +- .../Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs | 2 +- .../EntitySystems/AI/Steering/AiSteeringSystem.cs | 2 +- Content.Server/GameTicking/GamePresets/PresetSuspicion.cs | 4 ++-- Content.Server/Preferences/PreferencesDatabase.cs | 2 +- 18 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Content.Client/Chat/SpeechBubble.cs b/Content.Client/Chat/SpeechBubble.cs index 715715d9a1..bffe42c721 100644 --- a/Content.Client/Chat/SpeechBubble.cs +++ b/Content.Client/Chat/SpeechBubble.cs @@ -106,13 +106,13 @@ namespace Content.Client.Chat } // Lerp to our new vertical offset if it's been modified. - if (FloatMath.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1)) + if (MathHelper.CloseTo(_verticalOffsetAchieved - VerticalOffset, 0, 0.1)) { _verticalOffsetAchieved = VerticalOffset; } else { - _verticalOffsetAchieved = FloatMath.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds); + _verticalOffsetAchieved = MathHelper.Lerp(_verticalOffsetAchieved, VerticalOffset, 10 * args.DeltaSeconds); } var worldPos = _senderEntity.Transform.WorldPosition; @@ -122,7 +122,7 @@ namespace Content.Client.Chat var screenPos = lowerCenter - (Width / 2, ContentHeight + _verticalOffsetAchieved); LayoutContainer.SetPosition(this, screenPos); - var height = FloatMath.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight); + var height = MathHelper.Clamp(lowerCenter.Y - screenPos.Y, 0, ContentHeight); LayoutContainer.SetSize(this, (Size.X, height)); } diff --git a/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs b/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs index 62e6bd1a24..98bf7af37c 100644 --- a/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs +++ b/Content.Client/GameObjects/Components/Disposal/DisposalUnitWindow.cs @@ -113,12 +113,12 @@ namespace Content.Client.GameObjects.Components.Disposal if (normalized <= leftSideSize) { normalized /= leftSideSize; // Adjust range to 0.0 to 1.0 - finalHue = FloatMath.Lerp(leftHue, middleHue, normalized); + finalHue = MathHelper.Lerp(leftHue, middleHue, normalized); } else { normalized = (normalized - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0. - finalHue = FloatMath.Lerp(middleHue, rightHue, normalized); + finalHue = MathHelper.Lerp(middleHue, rightHue, normalized); } // Check if null first to avoid repeatedly creating this. diff --git a/Content.Client/GameObjects/Components/HandheldLightComponent.cs b/Content.Client/GameObjects/Components/HandheldLightComponent.cs index d6f4a75aaa..2b2d43b1a7 100644 --- a/Content.Client/GameObjects/Components/HandheldLightComponent.cs +++ b/Content.Client/GameObjects/Components/HandheldLightComponent.cs @@ -78,7 +78,7 @@ namespace Content.Client.GameObjects.Components int level; - if (FloatMath.CloseTo(charge, 0)) + if (MathHelper.CloseTo(charge, 0)) { level = 0; } diff --git a/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs b/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs index aea3434e61..440b9f1d2d 100644 --- a/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/MagicMirrorBoundUserInterface.cs @@ -243,7 +243,7 @@ namespace Content.Client.GameObjects.Components if (int.TryParse(ev.Text, out var result)) { - result = FloatMath.Clamp(result, 0, byte.MaxValue); + result = MathHelper.Clamp(result, 0, byte.MaxValue); _ignoreEvents = true; _colorValue = (byte) result; diff --git a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs index 68288ff66a..7cda73f26b 100644 --- a/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/CameraRecoilComponent.cs @@ -87,7 +87,7 @@ namespace Content.Client.GameObjects.Components.Mobs // Continually restore camera to 0. var normalized = _currentKick.Normalized; _lastKickTime += frameTime; - var restoreRate = FloatMath.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp)); + var restoreRate = MathHelper.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp)); var restore = normalized * restoreRate * frameTime; var (x, y) = _currentKick - restore; if (Math.Sign(x) != Math.Sign(_currentKick.X)) diff --git a/Content.Client/GameObjects/Components/Mobs/ClientStatusEffectsComponent.cs b/Content.Client/GameObjects/Components/Mobs/ClientStatusEffectsComponent.cs index 926e6a5c46..8c9344d5fd 100644 --- a/Content.Client/GameObjects/Components/Mobs/ClientStatusEffectsComponent.cs +++ b/Content.Client/GameObjects/Components/Mobs/ClientStatusEffectsComponent.cs @@ -152,7 +152,7 @@ namespace Content.Client.GameObjects.Components.Mobs var progress = (_gameTiming.CurTime - start).TotalSeconds / length; var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5); - cooldownGraphic.Progress = FloatMath.Clamp((float)ratio, -1, 1); + cooldownGraphic.Progress = MathHelper.Clamp((float)ratio, -1, 1); cooldownGraphic.Visible = ratio > -1f; } } diff --git a/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs b/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs index 616997820e..108b85fe55 100644 --- a/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs +++ b/Content.Client/GameObjects/Components/Power/ApcBoundUserInterface.cs @@ -86,12 +86,12 @@ namespace Content.Client.GameObjects.Components.Power if (normalizedCharge <= leftSideSize) { normalizedCharge /= leftSideSize; // Adjust range to 0.0 to 1.0 - finalHue = FloatMath.Lerp(leftHue, middleHue, normalizedCharge); + finalHue = MathHelper.Lerp(leftHue, middleHue, normalizedCharge); } else { normalizedCharge = (normalizedCharge - leftSideSize) / rightSideSize; // Adjust range to 0.0 to 1.0. - finalHue = FloatMath.Lerp(middleHue, rightHue, normalizedCharge); + finalHue = MathHelper.Lerp(middleHue, rightHue, normalizedCharge); } // Check if null first to avoid repeatedly creating this. diff --git a/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs b/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs index 18047a8f85..5e8573034a 100644 --- a/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs +++ b/Content.Client/GameObjects/Components/Weapons/FlashableComponent.cs @@ -141,7 +141,7 @@ namespace Content.Client.GameObjects.Components.Weapons const float xOffset = 0.0f; // Overkill but easy to adjust if you want to mess around with the design - var result = (float) FloatMath.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0); + var result = (float) MathHelper.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0); DebugTools.Assert(!float.IsNaN(result)); return result; } diff --git a/Content.Client/UserInterface/CooldownGraphic.cs b/Content.Client/UserInterface/CooldownGraphic.cs index 777ec9e1d9..a092cf425b 100644 --- a/Content.Client/UserInterface/CooldownGraphic.cs +++ b/Content.Client/UserInterface/CooldownGraphic.cs @@ -41,7 +41,7 @@ namespace Content.Client.UserInterface } else { - var alpha = FloatMath.Clamp(0.5f * lerp, 0f, 0.5f); + var alpha = MathHelper.Clamp(0.5f * lerp, 0f, 0.5f); color = new Color(1f, 1f, 1f, alpha); } diff --git a/Content.Client/UserInterface/ItemSlotManager.cs b/Content.Client/UserInterface/ItemSlotManager.cs index d7d4c1e78d..2ac6588f73 100644 --- a/Content.Client/UserInterface/ItemSlotManager.cs +++ b/Content.Client/UserInterface/ItemSlotManager.cs @@ -107,7 +107,7 @@ namespace Content.Client.UserInterface var progress = (_gameTiming.CurTime - start).TotalSeconds / length; var ratio = (progress <= 1 ? (1 - progress) : (_gameTiming.CurTime - end).TotalSeconds * -5); - cooldownDisplay.Progress = FloatMath.Clamp((float)ratio, -1, 1); + cooldownDisplay.Progress = MathHelper.Clamp((float)ratio, -1, 1); if (ratio > -1f) { diff --git a/Content.Server/AI/Utility/Considerations/Consideration.cs b/Content.Server/AI/Utility/Considerations/Consideration.cs index 20afc4dec1..6fc9966607 100644 --- a/Content.Server/AI/Utility/Considerations/Consideration.cs +++ b/Content.Server/AI/Utility/Considerations/Consideration.cs @@ -17,7 +17,7 @@ namespace Content.Server.AI.Utility.Considerations var modificationFactor = 1.0f - 1.0f / considerationsCount; var makeUpValue = (1.0f - score) * modificationFactor; var adjustedScore = score + makeUpValue * score; - return FloatMath.Clamp(adjustedScore, 0.0f, 1.0f); + return MathHelper.Clamp(adjustedScore, 0.0f, 1.0f); } [Pure] @@ -59,7 +59,7 @@ namespace Content.Server.AI.Utility.Considerations [Pure] private static float LogisticCurve(float x, float slope, float exponent, float yOffset, float xOffset) { - return FloatMath.Clamp( + return MathHelper.Clamp( exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * x + xOffset))) + yOffset, 0.0f, 1.0f); } @@ -77,7 +77,7 @@ namespace Content.Server.AI.Utility.Considerations [Pure] private static float QuadraticCurve(float x, float slope, float exponent, float yOffset, float xOffset) { - return FloatMath.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f); + return MathHelper.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f); } public Func QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset) diff --git a/Content.Server/Atmos/HighPressureMovementController.cs b/Content.Server/Atmos/HighPressureMovementController.cs index 2e27f513ad..bd9f6b3e38 100644 --- a/Content.Server/Atmos/HighPressureMovementController.cs +++ b/Content.Server/Atmos/HighPressureMovementController.cs @@ -53,14 +53,14 @@ namespace Content.Server.Atmos { if (throwTarget != GridCoordinates.InvalidGrid) { - var moveForce = maxForce * FloatMath.Clamp(moveProb, 0, 100) / 150f; + var moveForce = maxForce * MathHelper.Clamp(moveProb, 0, 100) / 150f; var pos = ((throwTarget.Position - transform.GridPosition.Position).Normalized + direction.ToVec()).Normalized; LinearVelocity = pos * moveForce; } else { - var moveForce = MathF.Min(maxForce * FloatMath.Clamp(moveProb, 0, 100) / 2500f, 20f); + var moveForce = MathF.Min(maxForce * MathHelper.Clamp(moveProb, 0, 100) / 2500f, 20f); LinearVelocity = direction.ToVec() * moveForce; } diff --git a/Content.Server/Atmos/TileAtmosphere.cs b/Content.Server/Atmos/TileAtmosphere.cs index 8e634a1c7d..9cf67015ac 100644 --- a/Content.Server/Atmos/TileAtmosphere.cs +++ b/Content.Server/Atmos/TileAtmosphere.cs @@ -171,7 +171,7 @@ namespace Content.Server.Atmos { if(_soundCooldown == 0) EntitySystem.Get().PlayAtCoords("/Audio/Effects/space_wind.ogg", - GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(FloatMath.Clamp(PressureDifference / 10, 10, 100))); + GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(MathHelper.Clamp(PressureDifference / 10, 10, 100))); } @@ -1021,7 +1021,7 @@ namespace Content.Server.Atmos private void HandleDecompressionFloorRip(float sum) { - var chance = FloatMath.Clamp(sum / 500, 0.005f, 0.5f); + var chance = MathHelper.Clamp(sum / 500, 0.005f, 0.5f); if (sum > 20 && _robustRandom.Prob(chance)) _gridAtmosphereComponent.PryTile(GridIndices); } diff --git a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs index 77ce70f0d4..de481e77ec 100644 --- a/Content.Server/GameObjects/Components/Power/BatteryComponent.cs +++ b/Content.Server/GameObjects/Components/Power/BatteryComponent.cs @@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.Components.Power private void SetCurrentCharge(float newChargeAmount) { - _currentCharge = FloatMath.Clamp(newChargeAmount, 0, MaxCharge); + _currentCharge = MathHelper.Clamp(newChargeAmount, 0, MaxCharge); UpdateStorageState(); OnChargeChanged(); } diff --git a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs index 4b0553fe2b..61cecee6c2 100644 --- a/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs +++ b/Content.Server/GameObjects/Components/Weapon/Ranged/Barrels/ServerRangedBarrelComponent.cs @@ -178,7 +178,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels { var currentTime = _gameTiming.CurTime; var timeSinceLastFire = (currentTime - _lastFire).TotalSeconds; - var newTheta = FloatMath.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta); + var newTheta = MathHelper.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta); _currentAngle = new Angle(newTheta); var random = (_robustRandom.NextDouble() - 0.5) * 2; diff --git a/Content.Server/GameObjects/EntitySystems/AI/Steering/AiSteeringSystem.cs b/Content.Server/GameObjects/EntitySystems/AI/Steering/AiSteeringSystem.cs index a9a7899300..2d955dbe82 100644 --- a/Content.Server/GameObjects/EntitySystems/AI/Steering/AiSteeringSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AI/Steering/AiSteeringSystem.cs @@ -647,7 +647,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering var additionalVector = (centerGrid.Position - entityGridCoords.Position); var distance = additionalVector.Length; // If we're too far no point, if we're close then cap it at the normalized vector - distance = FloatMath.Clamp(2.5f - distance, 0.0f, 1.0f); + distance = MathHelper.Clamp(2.5f - distance, 0.0f, 1.0f); additionalVector = new Angle(90 * distance).RotateVec(additionalVector); avoidanceVector += additionalVector; // if we do need to avoid that means we'll have to lookahead for the next tile diff --git a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs index bd2f43a13d..093135da42 100644 --- a/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs +++ b/Content.Server/GameTicking/GamePresets/PresetSuspicion.cs @@ -56,8 +56,8 @@ namespace Content.Server.GameTicking.GamePresets } } - var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor, - MinTraitors, readyPlayers.Count); + var numTraitors = MathHelper.Clamp(readyPlayers.Count % PlayersPerTraitor, + MinTraitors, readyPlayers.Count); for (var i = 0; i < numTraitors; i++) { diff --git a/Content.Server/Preferences/PreferencesDatabase.cs b/Content.Server/Preferences/PreferencesDatabase.cs index 8f13a1324e..e4a0b4176f 100644 --- a/Content.Server/Preferences/PreferencesDatabase.cs +++ b/Content.Server/Preferences/PreferencesDatabase.cs @@ -60,7 +60,7 @@ namespace Content.Server.Preferences await _prefsSemaphore.WaitAsync(); try { - index = FloatMath.Clamp(index, 0, _maxCharacterSlots - 1); + index = MathHelper.Clamp(index, 0, _maxCharacterSlots - 1); await _prefsDb.SaveSelectedCharacterIndex(username, index); } finally