]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Implicit gas tile & decal states (#15146)
authorLeon Friedrich <60421075+ElectroJr@users.noreply.github.com>
Wed, 5 Apr 2023 23:43:12 +0000 (11:43 +1200)
committerGitHub <noreply@github.com>
Wed, 5 Apr 2023 23:43:12 +0000 (17:43 -0600)
Content.Server/Atmos/EntitySystems/GasTileOverlaySystem.cs
Content.Server/Decals/DecalSystem.cs
Content.Shared/Atmos/EntitySystems/SharedGasTileOverlaySystem.cs
Content.Shared/Decals/SharedDecalSystem.cs

index a4220a0271244e7ff31a3f1ab9c15a2abe909d21..b15ae04525236854eff56119f2be70d85299410b 100644 (file)
@@ -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<RoundRestartCleanupEvent>(Reset);
-            SubscribeLocalEvent<GasTileOverlayComponent, ComponentGetState>(OnGetState);
             SubscribeLocalEvent<GasTileOverlayComponent, ComponentStartup>(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<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) };
-        }
     }
 }
index 69b73f640e9f090e4fe3ad1bc7fcab1242550ba7..f9a143a290d7e20a377219fcf4a32df5cc0bb715 100644 (file)
@@ -41,7 +41,6 @@ namespace Content.Server.Decals
         private ObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>> _chunkViewerPool =
             new DefaultObjectPool<Dictionary<EntityUid, HashSet<Vector2i>>>(
                 new DefaultPooledObjectPolicy<Dictionary<EntityUid, HashSet<Vector2i>>>(), 64);
-        private bool _pvsEnabled;
 
         public override void Initialize()
         {
@@ -49,7 +48,6 @@ namespace Content.Server.Decals
 
             _playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
             SubscribeLocalEvent<TileChangedEvent>(OnTileChanged);
-            SubscribeLocalEvent<DecalGridComponent, ComponentGetState>(OnGetState);
 
             SubscribeNetworkEvent<RequestDecalPlacementEvent>(OnDecalPlacementRequest);
             SubscribeNetworkEvent<RequestDecalRemovalEvent>(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<Vector2i, DecalChunk>();
-            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 };
index b4674f1059f27d181224177aa73b7e89d1c0b768..b4722fb53f34fccffebb6b93775af091c4b29d31 100644 (file)
@@ -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));
index 29f628c7ae0ed9adaa749507341ab37a2bfc2711..d1fcccaec61b1e31bee67402cd8cb863c91da131 100644 (file)
@@ -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<GridInitializeEvent>(OnGridInitialize);
             SubscribeLocalEvent<DecalGridComponent, ComponentStartup>(OnCompStartup);
+            SubscribeLocalEvent<DecalGridComponent, ComponentGetState>(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<Vector2i, DecalChunk>();
+            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<DecalGridComponent>(msg.EntityUid);
         }
-        
+
         private void OnCompStartup(EntityUid uid, DecalGridComponent component, ComponentStartup args)
         {
             foreach (var (indices, decals) in component.ChunkCollection.ChunkCollection)