diff --git a/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs b/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs index a4220a0271..b15ae04525 100644 --- a/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs +++ b/Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs @@ -53,8 +53,6 @@ namespace Content.Server.Atmos.EntitySystems private int _thresholds; - private bool _pvsEnabled; - public override void Initialize() { base.Initialize(); @@ -64,7 +62,6 @@ namespace Content.Server.Atmos.EntitySystems _confMan.OnValueChanged(CVars.NetPVS, OnPvsToggle, true); SubscribeLocalEvent(Reset); - SubscribeLocalEvent(OnGetState); SubscribeLocalEvent(OnStartup); } @@ -86,10 +83,10 @@ namespace Content.Server.Atmos.EntitySystems private void OnPvsToggle(bool value) { - if (value == _pvsEnabled) + if (value == PvsEnabled) return; - _pvsEnabled = value; + PvsEnabled = value; if (value) return; @@ -254,7 +251,7 @@ namespace Content.Server.Atmos.EntitySystems // First, update per-chunk visual data for any invalidated tiles. UpdateOverlayData(curTick); - if (!_pvsEnabled) + if (!PvsEnabled) return; // Now we'll go through each player, then through each chunk in range of that player checking if the player is still in range @@ -355,27 +352,5 @@ namespace Content.Server.Atmos.EntitySystems data.Clear(); } } - - 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(); - 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) }; - } } } diff --git a/Content.Server/Decals/DecalSystem.cs b/Content.Server/Decals/DecalSystem.cs index 69b73f640e..f9a143a290 100644 --- a/Content.Server/Decals/DecalSystem.cs +++ b/Content.Server/Decals/DecalSystem.cs @@ -41,7 +41,6 @@ namespace Content.Server.Decals private ObjectPool>> _chunkViewerPool = new DefaultObjectPool>>( new DefaultPooledObjectPolicy>>(), 64); - private bool _pvsEnabled; public override void Initialize() { @@ -49,7 +48,6 @@ namespace Content.Server.Decals _playerManager.PlayerStatusChanged += OnPlayerStatusChanged; SubscribeLocalEvent(OnTileChanged); - SubscribeLocalEvent(OnGetState); SubscribeNetworkEvent(OnDecalPlacementRequest); SubscribeNetworkEvent(OnDecalRemovalRequest); @@ -60,10 +58,10 @@ namespace Content.Server.Decals private void OnPvsToggle(bool value) { - if (value == _pvsEnabled) + if (value == PvsEnabled) return; - _pvsEnabled = value; + PvsEnabled = value; if (value) return; @@ -80,28 +78,6 @@ namespace Content.Server.Decals } } - private void OnGetState(EntityUid uid, DecalGridComponent 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 DecalGridState(component.ChunkCollection.ChunkCollection); - return; - } - - var data = new Dictionary(); - foreach (var (index, chunk) in component.ChunkCollection.ChunkCollection) - { - if (chunk.LastModified >= args.FromTick) - data[index] = chunk; - } - - args.State = new DecalGridState(data) { AllChunks = new(component.ChunkCollection.ChunkCollection.Keys) }; - } - private void OnGridSplit(ref PostGridSplitEvent ev) { if (!TryComp(ev.OldGrid, out DecalGridComponent? oldComp)) @@ -408,13 +384,13 @@ namespace Content.Server.Decals Dirty(decals); } - if (!_pvsEnabled) + if (!PvsEnabled) { _dirtyChunks.Clear(); return; } - if (_pvsEnabled) + if (PvsEnabled) { var players = _playerManager.ServerSessions.Where(x => x.Status == SessionStatus.InGame).ToArray(); var opts = new ParallelOptions { MaxDegreeOfParallelism = _parMan.ParallelProcessCount }; diff --git a/Content.Shared/Atmos/EntitySystems/SharedGasTileOverlaySystem.cs b/Content.Shared/Atmos/EntitySystems/SharedGasTileOverlaySystem.cs index b4674f1059..b4722fb53f 100644 --- a/Content.Shared/Atmos/EntitySystems/SharedGasTileOverlaySystem.cs +++ b/Content.Shared/Atmos/EntitySystems/SharedGasTileOverlaySystem.cs @@ -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(OnGetState); List 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(); + 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)); diff --git a/Content.Shared/Decals/SharedDecalSystem.cs b/Content.Shared/Decals/SharedDecalSystem.cs index 29f628c7ae..d1fcccaec6 100644 --- a/Content.Shared/Decals/SharedDecalSystem.cs +++ b/Content.Shared/Decals/SharedDecalSystem.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using Robust.Shared.GameStates; using Robust.Shared.Map; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; @@ -11,6 +12,8 @@ namespace Content.Shared.Decals [Dependency] protected readonly IPrototypeManager PrototypeManager = default!; [Dependency] protected readonly IMapManager MapManager = default!; + protected bool PvsEnabled; + // Note that this constant is effectively baked into all map files, because of how they save the grid decal component. // So if this ever needs changing, the maps need converting. public const int ChunkSize = 32; @@ -22,13 +25,36 @@ namespace Content.Shared.Decals SubscribeLocalEvent(OnGridInitialize); SubscribeLocalEvent(OnCompStartup); + SubscribeLocalEvent(OnGetState); + } + + private void OnGetState(EntityUid uid, DecalGridComponent 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 DecalGridState(component.ChunkCollection.ChunkCollection); + return; + } + + var data = new Dictionary(); + foreach (var (index, chunk) in component.ChunkCollection.ChunkCollection) + { + if (chunk.LastModified >= args.FromTick) + data[index] = chunk; + } + + args.State = new DecalGridState(data) { AllChunks = new(component.ChunkCollection.ChunkCollection.Keys) }; } private void OnGridInitialize(GridInitializeEvent msg) { EnsureComp(msg.EntityUid); } - + private void OnCompStartup(EntityUid uid, DecalGridComponent component, ComponentStartup args) { foreach (var (indices, decals) in component.ChunkCollection.ChunkCollection)