using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Timing; namespace Content.Shared.Atmos.Components; [RegisterComponent, NetworkedComponent] public sealed partial class GasTileOverlayComponent : Component { /// /// The tiles that have had their atmos data updated since last tick /// public readonly HashSet InvalidTiles = new(); /// /// Gas data stored in chunks to make PVS / bubbling easier. /// public readonly Dictionary Chunks = new(); /// /// Tick at which PVS was last toggled. Ensures that all players receive a full update when toggling PVS. /// public GameTick ForceTick { get; set; } } [Serializable, NetSerializable] public sealed class GasTileOverlayState(Dictionary chunks) : ComponentState { public readonly Dictionary Chunks = chunks; } [Serializable, NetSerializable] public sealed class GasTileOverlayDeltaState( Dictionary modifiedChunks, HashSet allChunks) : ComponentState, IComponentDeltaState { public readonly Dictionary ModifiedChunks = modifiedChunks; public readonly HashSet AllChunks = allChunks; public void ApplyToFullState(GasTileOverlayState state) { foreach (var key in state.Chunks.Keys) { if (!AllChunks.Contains(key)) state.Chunks.Remove(key); } foreach (var (chunk, data) in ModifiedChunks) { state.Chunks[chunk] = new(data); } } public GasTileOverlayState CreateNewFullState(GasTileOverlayState state) { var chunks = new Dictionary(AllChunks.Count); foreach (var (chunk, data) in ModifiedChunks) { chunks[chunk] = new(data); } foreach (var (chunk, data) in state.Chunks) { if (AllChunks.Contains(chunk)) chunks.TryAdd(chunk, new(data)); } return new GasTileOverlayState(chunks); } }