@@ -1,6 +1,7 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.Atmos.Components;
|
||||
|
||||
@@ -23,47 +24,55 @@ public sealed partial class GasTileOverlayComponent : Component
|
||||
public GameTick ForceTick { get; set; }
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class GasTileOverlayState(Dictionary<Vector2i, GasOverlayChunk> chunks) : ComponentState
|
||||
{
|
||||
public readonly Dictionary<Vector2i, GasOverlayChunk> Chunks = chunks;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class GasTileOverlayDeltaState(
|
||||
Dictionary<Vector2i, GasOverlayChunk> modifiedChunks,
|
||||
HashSet<Vector2i> allChunks)
|
||||
: ComponentState, IComponentDeltaState<GasTileOverlayState>
|
||||
public sealed class GasTileOverlayState : ComponentState, IComponentDeltaState
|
||||
{
|
||||
public readonly Dictionary<Vector2i, GasOverlayChunk> ModifiedChunks = modifiedChunks;
|
||||
public readonly HashSet<Vector2i> AllChunks = allChunks;
|
||||
public readonly Dictionary<Vector2i, GasOverlayChunk> Chunks;
|
||||
public bool FullState => AllChunks == null;
|
||||
|
||||
public void ApplyToFullState(GasTileOverlayState state)
|
||||
// required to infer deleted/missing chunks for delta states
|
||||
public HashSet<Vector2i>? AllChunks;
|
||||
|
||||
public GasTileOverlayState(Dictionary<Vector2i, GasOverlayChunk> chunks)
|
||||
{
|
||||
Chunks = chunks;
|
||||
}
|
||||
|
||||
public void ApplyToFullState(IComponentState fullState)
|
||||
{
|
||||
DebugTools.Assert(!FullState);
|
||||
var state = (GasTileOverlayState) fullState;
|
||||
DebugTools.Assert(state.FullState);
|
||||
|
||||
foreach (var key in state.Chunks.Keys)
|
||||
{
|
||||
if (!AllChunks.Contains(key))
|
||||
if (!AllChunks!.Contains(key))
|
||||
state.Chunks.Remove(key);
|
||||
}
|
||||
|
||||
foreach (var (chunk, data) in ModifiedChunks)
|
||||
foreach (var (chunk, data) in Chunks)
|
||||
{
|
||||
state.Chunks[chunk] = new(data);
|
||||
}
|
||||
}
|
||||
|
||||
public GasTileOverlayState CreateNewFullState(GasTileOverlayState state)
|
||||
public IComponentState CreateNewFullState(IComponentState fullState)
|
||||
{
|
||||
var chunks = new Dictionary<Vector2i, GasOverlayChunk>(AllChunks.Count);
|
||||
DebugTools.Assert(!FullState);
|
||||
var state = (GasTileOverlayState) fullState;
|
||||
DebugTools.Assert(state.FullState);
|
||||
|
||||
foreach (var (chunk, data) in ModifiedChunks)
|
||||
var chunks = new Dictionary<Vector2i, GasOverlayChunk>(state.Chunks.Count);
|
||||
|
||||
foreach (var (chunk, data) in Chunks)
|
||||
{
|
||||
chunks[chunk] = new(data);
|
||||
}
|
||||
|
||||
foreach (var (chunk, data) in state.Chunks)
|
||||
{
|
||||
if (AllChunks.Contains(chunk))
|
||||
if (AllChunks!.Contains(chunk))
|
||||
chunks.TryAdd(chunk, new(data));
|
||||
}
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace Content.Shared.Atmos.EntitySystems
|
||||
data[index] = chunk;
|
||||
}
|
||||
|
||||
args.State = new GasTileOverlayDeltaState(data, new(component.Chunks.Keys));
|
||||
args.State = new GasTileOverlayState(data) { AllChunks = new(component.Chunks.Keys) };
|
||||
}
|
||||
|
||||
public static Vector2i GetGasChunkIndices(Vector2i indices)
|
||||
|
||||
Reference in New Issue
Block a user