Skip to content

Commit

Permalink
use CannyFastMath in various places even where it might not be any di…
Browse files Browse the repository at this point in the history
…fferent

also update a bunch of packages

clean up redundant YamlDotNet references
  • Loading branch information
Tyler-IN committed Jun 14, 2020
1 parent 916b9a6 commit de274de
Show file tree
Hide file tree
Showing 25 changed files with 71 additions and 66 deletions.
1 change: 1 addition & 0 deletions BuildChecker/BuildChecker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild
<Python Condition="'$(OS)'=='Windows_NT' Or '$(OS)'=='Windows'">py -3</Python>
<ProjectGuid>{C899FCA4-7037-4E49-ABC2-44DE72487110}</ProjectGuid>
<TargetFrameworkMoniker>.NETFramework, Version=v4.7.2</TargetFrameworkMoniker>
<RestorePackages>false</RestorePackages>
</PropertyGroup>
<PropertyGroup>
<OutputType>Library</OutputType>
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</PropertyGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup>
<PackageReference Include="Nett" Version="0.13.0" />
<PackageReference Include="Nett" Version="0.15.0" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-rc0002" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta0009" />
<PackageReference Include="YamlDotNet" Version="8.1.0" />
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\RobustToolbox\Lidgren.Network\Lidgren.Network.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
SolarControlConsoleBoundInterfaceState scc = (SolarControlConsoleBoundInterfaceState) state;
_lastState = scc;
_window.NotARadar.UpdateState(scc);
_window.OutputPower.Text = ((int) Math.Floor(scc.OutputPower)).ToString();
_window.OutputPower.Text = ((int) MathF.Floor(scc.OutputPower)).ToString();
_window.SunAngle.Text = FormatAngle(scc.TowardsSun);
UpdateField(_window.PanelRotation, FormatAngle(scc.Rotation));
UpdateField(_window.PanelVelocity, FormatAngle(scc.AngularVelocity * 60));
Expand Down
19 changes: 11 additions & 8 deletions Content.Client/Parallax/ParallaxGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;
using Color = Robust.Shared.Maths.Color;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Client.Parallax
{
Expand Down Expand Up @@ -78,7 +81,7 @@ private class LayerNoise : Layer
private readonly NoiseGenerator.NoiseType NoiseType = NoiseGenerator.NoiseType.Fbm;
private readonly uint Seed = 1234;
private readonly float Persistence = 0.5f;
private readonly float Lacunarity = (float) (Math.PI * 2 / 3);
private readonly float Lacunarity = (float) (Math.TAU / 3);
private readonly float Frequency = 1;
private readonly uint Octaves = 3;
private readonly float Threshold;
Expand Down Expand Up @@ -179,12 +182,12 @@ public override void Apply(Image<Rgba32> bitmap)
for (var x = 0; x < bitmap.Width; x++)
{
// Do noise calculations.
var noiseVal = Math.Min(1, Math.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));
var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));

// Threshold
noiseVal = Math.Max(0, noiseVal - Threshold);
noiseVal = MathF.Max(0, noiseVal - Threshold);
noiseVal *= threshVal;
noiseVal = (float) Math.Pow(noiseVal, powFactor);
noiseVal = (float) MathF.Pow(noiseVal, powFactor);

// Get colors based on noise values.
var srcColor = Color.InterpolateBetween(OuterColor, InnerColor, noiseVal)
Expand Down Expand Up @@ -215,7 +218,7 @@ private class LayerPoints : Layer
private readonly NoiseGenerator.NoiseType MaskNoiseType = NoiseGenerator.NoiseType.Fbm;
private readonly uint MaskSeed = 1234;
private readonly float MaskPersistence = 0.5f;
private readonly float MaskLacunarity = (float) Math.PI * 2 / 3;
private readonly float MaskLacunarity = (float) (Math.PI * 2 / 3);
private readonly float MaskFrequency = 1;
private readonly uint MaskOctaves = 3;
private readonly float MaskThreshold;
Expand Down Expand Up @@ -406,11 +409,11 @@ private void GenPointsMasked(Image<Rgba32> buffer)
var y = random.Next(0, buffer.Height);

// Grab noise at this point.
var noiseVal = Math.Min(1, Math.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));
var noiseVal = MathF.Min(1, MathF.Max(0, (noise.GetNoiseTiled(x, y) + 1) / 2));
// Threshold
noiseVal = Math.Max(0, noiseVal - MaskThreshold);
noiseVal = MathF.Max(0, noiseVal - MaskThreshold);
noiseVal *= threshVal;
noiseVal = (float) Math.Pow(noiseVal, powFactor);
noiseVal = (float) MathF.Pow(noiseVal, powFactor);

var randomThresh = random.NextFloat();
if (randomThresh > noiseVal)
Expand Down
3 changes: 3 additions & 0 deletions Content.Client/State/LobbyState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
using Robust.Shared.ViewVariables;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Client.State
{
Expand Down
7 changes: 5 additions & 2 deletions Content.Client/UserInterface/CooldownGraphic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Robust.Client.Graphics.Shaders;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Robust.Client.UserInterface.Controls
{
Expand Down Expand Up @@ -33,7 +36,7 @@ protected override void Draw(DrawingHandleScreen handle)
{
Color color;

var lerp = 1f - Math.Abs(Progress); // for future bikeshedding purposes
var lerp = 1f - MathF.Abs(Progress); // for future bikeshedding purposes

if (Progress >= 0f)
{
Expand All @@ -42,7 +45,7 @@ protected override void Draw(DrawingHandleScreen handle)
}
else
{
var alpha = Math.Clamp(0.5f * lerp, 0f, 0.5f);
var alpha = MathF.Clamp(0.5f * lerp, 0f, 0.5f);
color = new Color(1f, 1f, 1f, alpha);
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server.Database/Content.Server.Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
</ItemGroup>

</Project>
5 changes: 4 additions & 1 deletion Content.Server/AI/StaticBarkerProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using Robust.Shared.Interfaces.Timing;
using Robust.Shared.IoC;
using Robust.Shared.Utility;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.AI
{
Expand Down Expand Up @@ -35,7 +38,7 @@ public override void Update(float frameTime)
{
if(_timeMan.CurTime < _nextBark)
return;

var rngState = GenSeed();
_nextBark = _timeMan.CurTime + MinimumDelay + TimeSpan.FromSeconds(Random01(ref rngState) * 10);

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/AI/WanderProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private void EmitProfanity(ref uint rngState)
if(Random01(ref rngState) < 0.5f)
return;

var pick = (int) Math.Round(Random01(ref rngState) * (_normalAssistantConversation.Count - 1));
var pick = (int) MathF.Round(Random01(ref rngState) * (_normalAssistantConversation.Count - 1));
_chatMan.EntitySay(SelfEntity, _normalAssistantConversation[pick]);
}

Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Chemistry/Metabolism/DefaultFood.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DefaultFood : IMetabolizable

void IExposeData.ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1M));
serializer.DataField(ref _metabolismRate, "rate", ReagentUnit.New(1.0));
serializer.DataField(ref _nutritionFactor, "nutrimentFactor", 30.0f);
}

Expand All @@ -36,7 +36,7 @@ ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId,
hunger.UpdateFood(metabolismAmount.Float() * NutritionFactor);

//Return amount of reagent to be removed, remove reagent regardless of HungerComponent presence
return metabolismAmount;
return metabolismAmount;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
using Content.Shared.Interfaces;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Serialization;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.Chemistry.ReactionEffects
{
Expand Down Expand Up @@ -35,9 +38,9 @@ public void ExposeData(ObjectSerializer serializer)
serializer.DataField(ref _maxScale, "maxScale", 1);
}

public void React(IEntity solutionEntity, decimal intensity)
public void React(IEntity solutionEntity, double intensity)
{
float floatIntensity = (float)intensity;
float floatIntensity = (float)intensity;
if (solutionEntity == null)
return;
if(!solutionEntity.TryGetComponent(out SolutionComponent solution))
Expand All @@ -46,18 +49,18 @@ public void React(IEntity solutionEntity, decimal intensity)
//Handle scaling
if (_scaled)
{
floatIntensity = Math.Min(floatIntensity, _maxScale);
floatIntensity = MathF.Min(floatIntensity, _maxScale);
}
else
{
floatIntensity = 1;
}

//Calculate intensities
int finalDevastationRange = (int)Math.Round(_devastationRange * floatIntensity);
int finalHeavyImpactRange = (int)Math.Round(_heavyImpactRange * floatIntensity);
int finalLightImpactRange = (int)Math.Round(_lightImpactRange * floatIntensity);
int finalFlashRange = (int)Math.Round(_flashRange * floatIntensity);
int finalDevastationRange = (int)MathF.Round(_devastationRange * floatIntensity);
int finalHeavyImpactRange = (int)MathF.Round(_heavyImpactRange * floatIntensity);
int finalLightImpactRange = (int)MathF.Round(_lightImpactRange * floatIntensity);
int finalFlashRange = (int)MathF.Round(_flashRange * floatIntensity);
ExplosionHelper.SpawnExplosion(solutionEntity.Transform.GridPosition, finalDevastationRange,
finalHeavyImpactRange, finalLightImpactRange, finalFlashRange);
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Content.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="YamlDotNet" Version="8.1.0" />
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Content.Server.Database\Content.Server.Database.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public ReagentUnit TransferAmount
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5.0M));
serializer.DataField(ref _transferAmount, "transferAmount", ReagentUnit.New(5.0));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private void PerformReaction(ReactionPrototype reaction, ReagentUnit unitReactio
//Trigger reaction effects
foreach (var effect in reaction.Effects)
{
effect.React(Owner, unitReactions.Decimal());
effect.React(Owner, unitReactions.Double());
}

//Play reaction sound client-side
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using Content.Shared.GameObjects.Components.Inventory;
using Robust.Shared.GameObjects;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.GameObjects
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using Timer = Robust.Shared.Timers.Timer;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.GameObjects.Components.Mobs
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.GameObjects.Components.Weapon.Melee
{
Expand Down
5 changes: 4 additions & 1 deletion Content.Server/GameObjects/EntitySystems/PowerSolarSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using Robust.Shared.Maths;
using System;
using System.Linq;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.GameObjects.EntitySystems
{
Expand Down Expand Up @@ -77,7 +80,7 @@ public override void Initialize()
{
EntityQuery = new TypeEntityQuery(typeof(SolarPanelComponent));
// Initialize the sun to something random
TowardsSun = Math.PI * 2 * _robustRandom.NextDouble();
TowardsSun = Math.TAU * _robustRandom.NextDouble();
SunAngularVelocity = Angle.FromDegrees(0.1 + ((_robustRandom.NextDouble() - 0.5) * 0.05));
}

Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Interfaces/Chemistry/IReactionEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace Content.Shared.Interfaces
/// </summary>
public interface IReactionEffect : IExposeData
{
void React(IEntity solutionEntity, decimal intensity);
void React(IEntity solutionEntity, double intensity);
}
}
5 changes: 4 additions & 1 deletion Content.Server/Throw/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using Robust.Shared.Random;
using System;
using Robust.Shared.Interfaces.Physics;
using CannyFastMath;
using Math = CannyFastMath.Math;
using MathF = CannyFastMath.MathF;

namespace Content.Server.Throw
{
Expand Down Expand Up @@ -146,7 +149,7 @@ public static void ThrowTo(IEntity thrownEnt, float throwForceMax, GridCoordinat
var forceNecessary = impulseNecessary * (1f / timing.TickRate);

// Then clamp it to the max force allowed and call Throw().
Throw(thrownEnt, Math.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
Throw(thrownEnt, MathF.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
}
}
}
6 changes: 3 additions & 3 deletions Content.Shared/Chemistry/DefaultMetabolizable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace Content.Shared.Chemistry
class DefaultMetabolizable : IMetabolizable
{
//Rate of metabolism in units / second
private decimal _metabolismRate = 1;
public decimal MetabolismRate => _metabolismRate;
private double _metabolismRate = 1;
public double MetabolismRate => _metabolismRate;

void IExposeData.ExposeData(ObjectSerializer serializer)
{
Expand All @@ -20,7 +20,7 @@ void IExposeData.ExposeData(ObjectSerializer serializer)

ReagentUnit IMetabolizable.Metabolize(IEntity solutionEntity, string reagentId, float tickTime)
{
return ReagentUnit.New(MetabolismRate * (decimal)tickTime);
return ReagentUnit.New(MetabolismRate * tickTime);
}
}
}
18 changes: 1 addition & 17 deletions Content.Shared/Chemistry/ReagentUnit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ public static ReagentUnit New(int value)
return new ReagentUnit(value * (int) Math.Pow(10, Shift));
}

public static ReagentUnit New(decimal value)
{
return new ReagentUnit((int) Math.Round(value * (decimal) Math.Pow(10, Shift), MidpointRounding.AwayFromZero));
}

public static ReagentUnit New(float value)
{
return new ReagentUnit(FromFloat(value));
}

private static int FromFloat(float value)
{
return (int) Math.Round(value * (float) Math.Pow(10, Shift), MidpointRounding.AwayFromZero);
return (int) MathF.Round(value * MathF.Pow(10, Shift), MidpointRounding.AwayFromZero);
}

public static ReagentUnit New(double value)
Expand Down Expand Up @@ -83,12 +78,6 @@ private static float FloatFromString(string value)
return New(aD * b);
}

public static ReagentUnit operator *(ReagentUnit a, decimal b)
{
var aD = (decimal) a.ShiftDown();
return New(aD * b);
}

public static ReagentUnit operator *(ReagentUnit a, double b)
{
var aD = a.ShiftDown();
Expand Down Expand Up @@ -166,11 +155,6 @@ public float Float()
return (float) ShiftDown();
}

public decimal Decimal()
{
return (decimal) ShiftDown();
}

public double Double()
{
return ShiftDown();
Expand Down
Loading

0 comments on commit de274de

Please sign in to comment.