Optimize allocations in MetabolismComponent and TileAtmosphere
This commit is contained in:
@@ -574,7 +574,7 @@ namespace Content.Server.Atmos
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void FinalizeEq()
|
private void FinalizeEq()
|
||||||
{
|
{
|
||||||
var transferDirections = new float[Atmospherics.Directions];
|
Span<float> transferDirections = stackalloc float[Atmospherics.Directions];
|
||||||
var hasTransferDirs = false;
|
var hasTransferDirs = false;
|
||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
@@ -609,7 +609,7 @@ namespace Content.Server.Atmos
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
private void FinalizeEqNeighbors(in float[] transferDirs)
|
private void FinalizeEqNeighbors(ReadOnlySpan<float> transferDirs)
|
||||||
{
|
{
|
||||||
for (var i = 0; i < Atmospherics.Directions; i++)
|
for (var i = 0; i < Atmospherics.Directions; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -145,20 +145,20 @@ namespace Content.Server.GameObjects.Components.Metabolism
|
|||||||
|
|
||||||
private float SuffocatingPercentage()
|
private float SuffocatingPercentage()
|
||||||
{
|
{
|
||||||
var percentages = new float[Atmospherics.TotalNumberOfGases];
|
var total = 0f;
|
||||||
|
|
||||||
foreach (var (gas, deficit) in DeficitGases)
|
foreach (var (gas, deficit) in DeficitGases)
|
||||||
{
|
{
|
||||||
if (!NeedsGases.TryGetValue(gas, out var needed))
|
var lack = 1f;
|
||||||
|
if (NeedsGases.TryGetValue(gas, out var needed))
|
||||||
{
|
{
|
||||||
percentages[(int) gas] = 1;
|
lack = deficit / needed;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
percentages[(int) gas] = deficit / needed;
|
total += lack / Atmospherics.TotalNumberOfGases;
|
||||||
}
|
}
|
||||||
|
|
||||||
return percentages.Average();
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
private float GasProducedMultiplier(Gas gas, float usedAverage)
|
private float GasProducedMultiplier(Gas gas, float usedAverage)
|
||||||
|
|||||||
Reference in New Issue
Block a user