Implicit gas tile & decal states (#15146)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using Content.Shared.Atmos.Components;
|
||||
using Content.Shared.Atmos.Prototypes;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
@@ -8,6 +10,7 @@ namespace Content.Shared.Atmos.EntitySystems
|
||||
{
|
||||
public const byte ChunkSize = 8;
|
||||
protected float AccumulatedFrameTime;
|
||||
protected bool PvsEnabled;
|
||||
|
||||
[Dependency] protected readonly IPrototypeManager ProtoMan = default!;
|
||||
|
||||
@@ -19,6 +22,7 @@ namespace Content.Shared.Atmos.EntitySystems
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<GasTileOverlayComponent, ComponentGetState>(OnGetState);
|
||||
|
||||
List<int> visibleGases = new();
|
||||
|
||||
@@ -32,6 +36,28 @@ namespace Content.Shared.Atmos.EntitySystems
|
||||
VisibleGasId = visibleGases.ToArray();
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, GasTileOverlayComponent component, ref ComponentGetState args)
|
||||
{
|
||||
if (PvsEnabled && !args.ReplayState)
|
||||
return;
|
||||
|
||||
// Should this be a full component state or a delta-state?
|
||||
if (args.FromTick <= component.CreationTick || args.FromTick <= component.ForceTick)
|
||||
{
|
||||
args.State = new GasTileOverlayState(component.Chunks);
|
||||
return;
|
||||
}
|
||||
|
||||
var data = new Dictionary<Vector2i, GasOverlayChunk>();
|
||||
foreach (var (index, chunk) in component.Chunks)
|
||||
{
|
||||
if (chunk.LastUpdate >= args.FromTick)
|
||||
data[index] = chunk;
|
||||
}
|
||||
|
||||
args.State = new GasTileOverlayState(data) { AllChunks = new(component.Chunks.Keys) };
|
||||
}
|
||||
|
||||
public static Vector2i GetGasChunkIndices(Vector2i indices)
|
||||
{
|
||||
return new((int) MathF.Floor((float) indices.X / ChunkSize), (int) MathF.Floor((float) indices.Y / ChunkSize));
|
||||
|
||||
Reference in New Issue
Block a user