Files
OldThink/Content.Shared/Atmos/GasOverlayChunk.cs

98 lines
2.9 KiB
C#
Raw Normal View History

Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
using Content.Shared.Atmos.EntitySystems;
2022-07-25 14:10:18 +12:00
using Robust.Shared.Serialization;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
2022-07-25 14:10:18 +12:00
using System.Diagnostics.CodeAnalysis;
using static Content.Shared.Atmos.EntitySystems.SharedGasTileOverlaySystem;
Atmos pipe rework (#3833) * Initial * Cleanup a bunch of things * some changes dunno * RequireAnchored * a * stuff * more work * Lots of progress * delete pipe visualizer * a * b * pipenet and pipenode cleanup * Fixes * Adds GasValve * Adds GasMiner * Fix stuff, maybe? * More fixes * Ignored components on the client * Adds thermomachine behavior, change a bunch of stuff * Remove Anchored * some work, but it's shitcode * significantly more ECS * ECS AtmosDevices * Cleanup * fix appearance * when the pipe direction is sus * Gas tanks and canisters * pipe anchoring and stuff * coding is my passion * Unsafe pipes take longer to unanchor * turns out we're no longer using eris canisters * Gas canister inserted tank appearance, improvements * Work on a bunch of appearances * Scrubber appearance * Reorganize AtmosphereSystem.Piping into a bunch of different systems * Appearance for vent/scrubber/pump turns off when leaving atmosphere * ThermoMachine appearance * Cleanup gas tanks * Remove passive gate unused imports * remove old canister UI functionality * PipeNode environment air, make everything use AssumeAir instead of merging manually * a * Reorganize atmos to follow new structure * ????? * Canister UI, restructure client * Restructure shared * Fix build tho * listen, at least the canister UI works entirely... * fix build : ) * Atmos device prototypes have names and descriptions * gas canister ui slider doesn't jitter * trinary prototypes * sprite for miners * ignore components * fix YAML * Fix port system doing useless thing * Fix build * fix thinking moment * fix build again because * canister direction * pipenode is a word * GasTank Air will throw on invalid states * fix build.... * Unhardcode volume pump thresholds * Volume pump and filter take time into account * Rename Join/Leave atmosphere events to AtmosDeviceEnabled/Disabled Event * Gas tank node volume is set by initial mixtuer * I love node container
2021-06-19 13:25:05 +02:00
namespace Content.Shared.Atmos
{
2022-07-25 14:10:18 +12:00
[Serializable, NetSerializable]
[Access(typeof(SharedGasTileOverlaySystem))]
public sealed class GasOverlayChunk
{
/// <summary>
2022-07-25 14:10:18 +12:00
/// The index of this chunk
/// </summary>
2022-07-25 14:10:18 +12:00
public readonly Vector2i Index;
public readonly Vector2i Origin;
2022-07-25 14:10:18 +12:00
public GasOverlayData?[][] TileData = new GasOverlayData?[ChunkSize][];
2022-07-25 14:10:18 +12:00
[NonSerialized]
public GameTick LastUpdate;
2022-07-25 14:10:18 +12:00
public GasOverlayChunk(Vector2i index)
{
2022-07-25 14:10:18 +12:00
Index = index;
Origin = Index * ChunkSize;
2022-07-25 14:10:18 +12:00
// For whatever reason, net serialize does not like multi_D arrays. So Jagged it is.
for (var i = 0; i < ChunkSize; i++)
{
TileData[i] = new GasOverlayData?[ChunkSize];
}
}
2022-07-25 14:10:18 +12:00
public GasOverlayData? GetData(Vector2i gridIndices)
{
2022-07-25 14:10:18 +12:00
DebugTools.Assert(InBounds(gridIndices));
return TileData[gridIndices.X - Origin.X][gridIndices.Y - Origin.Y];
}
2022-07-25 14:10:18 +12:00
public GasOverlayData? SetData(Vector2i gridIndices, GasOverlayData? data)
{
2022-07-25 14:10:18 +12:00
DebugTools.Assert(InBounds(gridIndices));
return TileData[gridIndices.X - Origin.X][gridIndices.Y - Origin.Y] = data;
}
2022-07-25 14:10:18 +12:00
private bool InBounds(Vector2i gridIndices)
{
2022-07-25 14:10:18 +12:00
return gridIndices.X >= Origin.X &&
gridIndices.Y >= Origin.Y &&
gridIndices.X < Origin.X + ChunkSize &&
gridIndices.Y < Origin.Y + ChunkSize;
}
2022-07-25 14:10:18 +12:00
}
public struct GasChunkEnumerator
{
private GasOverlayChunk _chunk;
public int X = 0;
public int Y = -1;
private GasOverlayData?[] _column;
2022-07-25 14:10:18 +12:00
public GasChunkEnumerator(GasOverlayChunk chunk)
{
2022-07-25 14:10:18 +12:00
_chunk = chunk;
_column = _chunk.TileData[0];
}
2022-07-25 14:10:18 +12:00
public bool MoveNext([NotNullWhen(true)] out GasOverlayData? gas)
{
2022-07-25 14:10:18 +12:00
while (X < ChunkSize)
{
2022-07-25 14:10:18 +12:00
// We want to increment Y before returning, but we also want it to match the current Y coordinate for
// the returned gas, so using a slightly different logic for the Y loop.
while (Y < ChunkSize - 1)
{
2022-07-25 14:10:18 +12:00
Y++;
gas = _column[Y];
if (gas != null)
return true;
}
2022-07-25 14:10:18 +12:00
X++;
if (X < ChunkSize)
_column = _chunk.TileData[X];
Y = -1;
}
2022-07-25 14:10:18 +12:00
gas = null;
return false;
}
}
}