Remove CannyFastMath.

This commit is contained in:
Pieter-Jan Briers
2020-08-12 21:09:56 +02:00
parent 3ca3b5e684
commit f182ff5613
15 changed files with 64 additions and 81 deletions

View File

@@ -141,7 +141,7 @@ namespace Content.Client.GameObjects.Components.Weapons
const float xOffset = 0.0f; const float xOffset = 0.0f;
// Overkill but easy to adjust if you want to mess around with the design // Overkill but easy to adjust if you want to mess around with the design
var result = (float) Math.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0); var result = (float) FloatMath.Clamp(slope * (float) Math.Pow(ratio - xOffset, exponent) + yOffset, 0.0, 1.0);
DebugTools.Assert(!float.IsNaN(result)); DebugTools.Assert(!float.IsNaN(result));
return result; return result;
} }

View File

@@ -12,9 +12,6 @@ using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Advanced; using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Color = Robust.Shared.Maths.Color; using Color = Robust.Shared.Maths.Color;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Client.Parallax namespace Content.Client.Parallax
{ {
@@ -81,7 +78,7 @@ namespace Content.Client.Parallax
private readonly NoiseGenerator.NoiseType NoiseType = NoiseGenerator.NoiseType.Fbm; private readonly NoiseGenerator.NoiseType NoiseType = NoiseGenerator.NoiseType.Fbm;
private readonly uint Seed = 1234; private readonly uint Seed = 1234;
private readonly float Persistence = 0.5f; private readonly float Persistence = 0.5f;
private readonly float Lacunarity = (float) (Math.TAU / 3); private readonly float Lacunarity = (float) (Math.PI / 3);
private readonly float Frequency = 1; private readonly float Frequency = 1;
private readonly uint Octaves = 3; private readonly uint Octaves = 3;
private readonly float Threshold; private readonly float Threshold;

View File

@@ -20,9 +20,6 @@ using Robust.Shared.Localization;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Client.State namespace Content.Client.State
{ {

View File

@@ -6,9 +6,6 @@ using System;
using Robust.Client.Graphics.Shaders; using Robust.Client.Graphics.Shaders;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Robust.Client.UserInterface.Controls namespace Robust.Client.UserInterface.Controls
{ {
@@ -45,7 +42,7 @@ namespace Robust.Client.UserInterface.Controls
} }
else else
{ {
var alpha = MathF.Clamp(0.5f * lerp, 0f, 0.5f); var alpha = FloatMath.Clamp(0.5f * lerp, 0f, 0.5f);
color = new Color(1f, 1f, 1f, alpha); color = new Color(1f, 1f, 1f, alpha);
} }

View File

@@ -2,6 +2,7 @@ using System;
using Content.Server.AI.WorldState; using Content.Server.AI.WorldState;
using Content.Server.AI.WorldState.States.Utility; using Content.Server.AI.WorldState.States.Utility;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Maths;
namespace Content.Server.AI.Utility.Considerations namespace Content.Server.AI.Utility.Considerations
{ {
@@ -16,7 +17,7 @@ namespace Content.Server.AI.Utility.Considerations
var modificationFactor = 1.0f - 1.0f / considerationsCount; var modificationFactor = 1.0f - 1.0f / considerationsCount;
var makeUpValue = (1.0f - score) * modificationFactor; var makeUpValue = (1.0f - score) * modificationFactor;
var adjustedScore = score + makeUpValue * score; var adjustedScore = score + makeUpValue * score;
return Math.Clamp(adjustedScore, 0.0f, 1.0f); return FloatMath.Clamp(adjustedScore, 0.0f, 1.0f);
} }
[Pure] [Pure]
@@ -58,7 +59,7 @@ namespace Content.Server.AI.Utility.Considerations
[Pure] [Pure]
private static float LogisticCurve(float x, float slope, float exponent, float yOffset, float xOffset) private static float LogisticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
{ {
return Math.Clamp( return FloatMath.Clamp(
exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * x + xOffset))) + yOffset, 0.0f, 1.0f); exponent * (1 / (1 + (float) Math.Pow(Math.Log(1000) * slope, -1 * x + xOffset))) + yOffset, 0.0f, 1.0f);
} }
@@ -76,7 +77,7 @@ namespace Content.Server.AI.Utility.Considerations
[Pure] [Pure]
private static float QuadraticCurve(float x, float slope, float exponent, float yOffset, float xOffset) private static float QuadraticCurve(float x, float slope, float exponent, float yOffset, float xOffset)
{ {
return Math.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f); return FloatMath.Clamp(slope * (float) Math.Pow(x - xOffset, exponent) + yOffset, 0.0f, 1.0f);
} }
public Func<float> QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset) public Func<float> QuadraticCurve(Blackboard context, float slope, float exponent, float yOffset, float xOffset)

View File

@@ -51,13 +51,13 @@ namespace Content.Server.Atmos
if (maxForce > ThrowForce && throwTarget != GridCoordinates.InvalidGrid) if (maxForce > ThrowForce && throwTarget != GridCoordinates.InvalidGrid)
{ {
var moveForce = MathF.Min(maxForce * Math.Clamp(moveProb, 0, 100) / 100f, 50f); var moveForce = MathF.Min(maxForce * FloatMath.Clamp(moveProb, 0, 100) / 100f, 50f);
var pos = throwTarget.Position - transform.GridPosition.Position; var pos = throwTarget.Position - transform.GridPosition.Position;
LinearVelocity = pos * moveForce; LinearVelocity = pos * moveForce;
} }
else else
{ {
var moveForce = MathF.Min(maxForce * Math.Clamp(moveProb, 0, 100) / 100f, 25f); var moveForce = MathF.Min(maxForce * FloatMath.Clamp(moveProb, 0, 100) / 100f, 25f);
LinearVelocity = direction.ToVec() * moveForce; LinearVelocity = direction.ToVec() * moveForce;
} }

View File

@@ -138,7 +138,7 @@ namespace Content.Server.Atmos
{ {
if(_soundCooldown == 0) if(_soundCooldown == 0)
EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg", EntitySystem.Get<AudioSystem>().PlayAtCoords("/Audio/Effects/space_wind.ogg",
GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(Math.Clamp(PressureDifference / 10, 10, 100))); GridIndices.ToGridCoordinates(_mapManager, GridIndex), AudioHelpers.WithVariation(0.125f).WithVolume(FloatMath.Clamp(PressureDifference / 10, 10, 100)));
} }
@@ -810,7 +810,7 @@ namespace Content.Server.Atmos
private void HandleDecompressionFloorRip(float sum) private void HandleDecompressionFloorRip(float sum)
{ {
if (sum > 20 && _robustRandom.Prob(Math.Clamp(sum / 100, 0.005f, 0.5f))) if (sum > 20 && _robustRandom.Prob(FloatMath.Clamp(sum / 100, 0.005f, 0.5f)))
_gridAtmosphereComponent.PryTile(GridIndices); _gridAtmosphereComponent.PryTile(GridIndices);
} }

View File

@@ -4,9 +4,6 @@ using Content.Server.GameObjects.Components.Chemistry;
using Content.Shared.Interfaces; using Content.Shared.Interfaces;
using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Server.Chemistry.ReactionEffects namespace Content.Server.Chemistry.ReactionEffects
{ {

View File

@@ -1,6 +1,6 @@
using Content.Shared.GameObjects.Components.Inventory; using System;
using Content.Shared.GameObjects.Components.Inventory;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Math = CannyFastMath.Math;
namespace Content.Server.GameObjects namespace Content.Server.GameObjects
{ {

View File

@@ -15,10 +15,7 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables; using Robust.Shared.ViewVariables;
using CannyFastMath;
using Content.Shared.Interfaces.GameObjects.Components; using Content.Shared.Interfaces.GameObjects.Components;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Server.GameObjects.Components.Weapon.Melee namespace Content.Server.GameObjects.Components.Weapon.Melee
{ {

View File

@@ -180,7 +180,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
{ {
var currentTime = _gameTiming.CurTime; var currentTime = _gameTiming.CurTime;
var timeSinceLastFire = (currentTime - _lastFire).TotalSeconds; var timeSinceLastFire = (currentTime - _lastFire).TotalSeconds;
var newTheta = Math.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta); var newTheta = FloatMath.Clamp(_currentAngle.Theta + _angleIncrease - _angleDecay * timeSinceLastFire, _minAngle.Theta, _maxAngle.Theta);
_currentAngle = new Angle(newTheta); _currentAngle = new Angle(newTheta);
var random = (_robustRandom.NextDouble() - 0.5) * 2; var random = (_robustRandom.NextDouble() - 0.5) * 2;

View File

@@ -650,7 +650,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
var additionalVector = (centerGrid.Position - entityGridCoords.Position); var additionalVector = (centerGrid.Position - entityGridCoords.Position);
var distance = additionalVector.Length; var distance = additionalVector.Length;
// If we're too far no point, if we're close then cap it at the normalized vector // If we're too far no point, if we're close then cap it at the normalized vector
distance = Math.Clamp(2.5f - distance, 0.0f, 1.0f); distance = FloatMath.Clamp(2.5f - distance, 0.0f, 1.0f);
additionalVector = new Angle(90 * distance).RotateVec(additionalVector); additionalVector = new Angle(90 * distance).RotateVec(additionalVector);
avoidanceVector += additionalVector; avoidanceVector += additionalVector;
// if we do need to avoid that means we'll have to lookahead for the next tile // if we do need to avoid that means we'll have to lookahead for the next tile

View File

@@ -12,9 +12,6 @@ using Robust.Shared.IoC;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using System; using System;
using System.Linq; using System.Linq;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;
namespace Content.Server.Interfaces.GameObjects.Components.Interaction namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{ {
@@ -80,7 +77,7 @@ namespace Content.Server.Interfaces.GameObjects.Components.Interaction
{ {
EntityQuery = new TypeEntityQuery(typeof(SolarPanelComponent)); EntityQuery = new TypeEntityQuery(typeof(SolarPanelComponent));
// Initialize the sun to something random // Initialize the sun to something random
TowardsSun = Math.TAU * _robustRandom.NextDouble(); TowardsSun = MathHelper.TwoPi * _robustRandom.NextDouble();
SunAngularVelocity = Angle.FromDegrees(0.1 + ((_robustRandom.NextDouble() - 0.5) * 0.05)); SunAngularVelocity = Angle.FromDegrees(0.1 + ((_robustRandom.NextDouble() - 0.5) * 0.05));
} }

View File

@@ -16,7 +16,7 @@ using System.Linq;
using Robust.Shared.Log; using Robust.Shared.Log;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Robust.Shared.Maths;
namespace Content.Server.GameTicking.GamePresets namespace Content.Server.GameTicking.GamePresets
@@ -60,7 +60,7 @@ namespace Content.Server.GameTicking.GamePresets
} }
} }
var numTraitors = Math.Clamp(readyPlayers.Count % PlayersPerTraitor, var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor,
MinTraitors, readyPlayers.Count); MinTraitors, readyPlayers.Count);
for (var i = 0; i < numTraitors; i++) for (var i = 0; i < numTraitors; i++)

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components; using System;
using Content.Server.GameObjects.Components;
using Content.Shared.GameObjects.EntitySystems; using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Physics; using Content.Shared.Physics;
using Robust.Shared.GameObjects.Components; using Robust.Shared.GameObjects.Components;
@@ -12,7 +13,6 @@ using Robust.Shared.Maths;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Interfaces.Physics; using Robust.Shared.Interfaces.Physics;
using MathF = CannyFastMath.MathF;
namespace Content.Server.Throw namespace Content.Server.Throw
{ {