Files
crystall-punk-14/Content.Shared/Atmos/GasOverlayChunk.cs

92 lines
2.6 KiB
C#
Raw Permalink 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 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;
public GasOverlayData[] TileData = new GasOverlayData[ChunkSize * 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;
}
public GasOverlayChunk(GasOverlayChunk data)
{
Index = data.Index;
Origin = data.Origin;
// This does not clone the opacity array. However, this chunk cloning is only used by the client,
// which never modifies that directly. So this should be fine.
Array.Copy(data.TileData, TileData, data.TileData.Length);
}
/// <summary>
/// Resolve a data index into <see cref="TileData"/> for the given grid index.
/// </summary>
public int GetDataIndex(Vector2i gridIndices)
{
2022-07-25 14:10:18 +12:00
DebugTools.Assert(InBounds(gridIndices));
return (gridIndices.X - Origin.X) + (gridIndices.Y - Origin.Y) * ChunkSize;
}
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 readonly GasOverlayData[] _tileData;
private int _index = -1;
public int X = ChunkSize - 1;
public int Y = -1;
2022-07-25 14:10:18 +12:00
public GasChunkEnumerator(GasOverlayChunk chunk)
{
_tileData = chunk.TileData;
}
public bool MoveNext(out GasOverlayData gas)
{
while (++_index < _tileData.Length)
{
X += 1;
if (X >= ChunkSize)
{
X = 0;
Y += 1;
}
gas = _tileData[_index];
if (!gas.Equals(default))
return true;
2022-07-25 14:10:18 +12:00
}
gas = default;
2022-07-25 14:10:18 +12:00
return false;
}
}
}