Files
tbd-station-14/Content.Shared/GameObjects/EntitySystems/Atmos/SharedGasTileOverlaySystem.cs
Visne 9b94d5c195 Added nullable to most Content.Shared files (#3238)
* Add nullable to some Content.Shared files.

* Use [NotNullWhen(true)]

* Undo adding now redundant !'s

* Forgot one

* Add a ton more nullable

* You can guess

* Fix some issues

* It actually compiles now

* Auto stash before merge of "null2" and "origin/master"

* I lied

* enable annotations -> enable

* Revert ActionBlockerSystem.cs to original

* Fix ActionBlockerSystem.cs

* More nullable

* Undo some added exclamation marks

* Fix issues

* Update Content.Shared/Maps/ContentTileDefinition.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Resolve some issues

* Remove unused method

* Fix more issues

* Fix more issues

* Fix more issues

* Fix more issues

* Fix issue, rollback SharedGhostComponent.cs

* Update submodule

* Fix issue, invert some if-statements to reduce nesting

* Revert RobustToolbox

* FIx things broken by merge

* Some fixes

- Replaced with string.Empty
- Remove some exclamation marks
- Revert file

* Some fixes

* Trivial #nullable enable

* Fix null ables

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
2021-02-27 14:12:09 +11:00

117 lines
3.6 KiB
C#

#nullable enable
using System;
using System.Collections.Generic;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.EntitySystems.Atmos
{
public abstract class SharedGasTileOverlaySystem : EntitySystem
{
public const byte ChunkSize = 8;
protected float AccumulatedFrameTime;
public static Vector2i GetGasChunkIndices(Vector2i indices)
{
return new((int) Math.Floor((float) indices.X / ChunkSize) * ChunkSize, (int) MathF.Floor((float) indices.Y / ChunkSize) * ChunkSize);
}
[Serializable, NetSerializable]
public readonly struct GasData : IEquatable<GasData>
{
public readonly byte Index;
public readonly byte Opacity;
public GasData(byte gasId, byte opacity)
{
Index = gasId;
Opacity = opacity;
}
public override int GetHashCode()
{
return HashCode.Combine(Index, Opacity);
}
public bool Equals(GasData other)
{
return other.Index == Index && other.Opacity == Opacity;
}
}
[Serializable, NetSerializable]
public readonly struct GasOverlayData : IEquatable<GasOverlayData>
{
public readonly byte FireState;
public readonly float FireTemperature;
public readonly GasData[] Gas;
public readonly int HashCode;
public GasOverlayData(byte fireState, float fireTemperature, GasData[] gas)
{
FireState = fireState;
FireTemperature = fireTemperature;
Gas = gas ?? Array.Empty<GasData>();
Array.Sort(Gas, (a, b) => a.Index.CompareTo(b.Index));
var hash = new HashCode();
hash.Add(FireState);
hash.Add(FireTemperature);
foreach (var gasData in Gas)
{
hash.Add(gasData);
}
HashCode = hash.ToHashCode();
}
public override int GetHashCode()
{
return HashCode;
}
public bool Equals(GasOverlayData other)
{
if (HashCode != other.HashCode) return false;
if (Gas.Length != other.Gas.Length) return false;
if (FireState != other.FireState) return false;
if (MathHelper.CloseTo(FireTemperature, FireTemperature)) return false;
if (Gas.GetHashCode() != other.Gas.GetHashCode()) return false;
for (var i = 0; i < Gas.Length; i++)
{
var gas = Gas[i];
var otherGas = other.Gas[i];
if (!gas.Equals(otherGas))
return false;
}
return true;
}
}
/// <summary>
/// Invalid tiles for the gas overlay.
/// No point re-sending every tile if only a subset might have been updated.
/// </summary>
[Serializable, NetSerializable]
public sealed class GasOverlayMessage : EntitySystemMessage
{
public GridId GridId { get; }
public List<(Vector2i, GasOverlayData)> OverlayData { get; }
public GasOverlayMessage(GridId gridIndices, List<(Vector2i,GasOverlayData)> overlayData)
{
GridId = gridIndices;
OverlayData = overlayData;
}
}
}
}