]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Content changes for SetTiles change (#37229)
authorTayrtahn <tayrtahn@gmail.com>
Thu, 15 May 2025 10:26:47 +0000 (06:26 -0400)
committerGitHub <noreply@github.com>
Thu, 15 May 2025 10:26:47 +0000 (20:26 +1000)
* Content changes for SetTiles change

* Retest with new engine changes

* Derp

* Update for new engine PR changes

Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs
Content.Server/Atmos/EntitySystems/AutomaticAtmosSystem.cs
Content.Server/Decals/DecalSystem.cs
Content.Server/Explosion/EntitySystems/ExplosionSystem.GridMap.cs
Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs
Content.Server/Pinpointer/NavMapSystem.cs
Content.Server/Shuttles/Systems/ThrusterSystem.cs
Content.Server/Tiles/RequiresTileSystem.cs
Content.Shared/SubFloor/SharedSubFloorHideSystem.cs

index 0f5bc1af0423fd7a3b8de7e11b996ee9ba68b169..e9383f3a23a7dedda69cf78ce100c3c27312b705 100644 (file)
@@ -81,7 +81,10 @@ public sealed partial class AtmosphereSystem : SharedAtmosphereSystem
 
     private void OnTileChanged(ref TileChangedEvent ev)
     {
-        InvalidateTile(ev.NewTile.GridUid, ev.NewTile.GridIndices);
+        foreach (var change in ev.Changes)
+        {
+            InvalidateTile(ev.Entity.Owner, change.GridIndices);
+        }
     }
 
     private void OnPrototypesReloaded(PrototypesReloadedEventArgs ev)
index 70e3eef3c443f912fb9b9679d7bcbd8d34418f3b..76775638ee2b93e775f6a85e379685ace77b08e0 100644 (file)
@@ -23,29 +23,32 @@ public sealed class AutomaticAtmosSystem : EntitySystem
 
     private void OnTileChanged(ref TileChangedEvent ev)
     {
-        // Only if a atmos-holding tile has been added or removed.
-        // Also, these calls are surprisingly slow.
-        // TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
-        // TODO: a simple array lookup, as tile IDs are likely contiguous, and there's at most 2^16 possibilities anyway.
-
-        var oldSpace = ev.OldTile.IsSpace(_tileDefinitionManager);
-        var newSpace = ev.NewTile.IsSpace(_tileDefinitionManager);
-
-        if (!(oldSpace && !newSpace ||
-            !oldSpace && newSpace) ||
-            _atmosphereSystem.HasAtmosphere(ev.Entity))
-            return;
-
-        if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
-            return;
-
-        // We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
-        if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
+        foreach (var change in ev.Changes)
         {
-            AddComp<GridAtmosphereComponent>(ev.Entity);
-            Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
+            // Only if a atmos-holding tile has been added or removed.
+            // Also, these calls are surprisingly slow.
+            // TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
+            // TODO: a simple array lookup, as tile IDs are likely contiguous, and there's at most 2^16 possibilities anyway.
+
+            var oldSpace = change.OldTile.IsSpace(_tileDefinitionManager);
+            var newSpace = change.NewTile.IsSpace(_tileDefinitionManager);
+
+            if (!(oldSpace && !newSpace ||
+                !oldSpace && newSpace) ||
+                _atmosphereSystem.HasAtmosphere(ev.Entity))
+                continue;
+
+            if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
+                return;
+
+            // We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
+            if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
+            {
+                AddComp<GridAtmosphereComponent>(ev.Entity);
+                Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
+            }
+            // It's not super important to remove it should the grid become too small again.
+            // If explosions ever gain the ability to outright shatter grids, do rethink this.
         }
-        // It's not super important to remove it should the grid become too small again.
-        // If explosions ever gain the ability to outright shatter grids, do rethink this.
     }
 }
index 2e1ed2c68daf9b25fdd9bbc42afd97095aa86c7a..2af95c7c23c4fe8311d296c53574a0a217da3507 100644 (file)
@@ -160,38 +160,41 @@ namespace Content.Server.Decals
 
         private void OnTileChanged(ref TileChangedEvent args)
         {
-            if (!args.NewTile.IsSpace(_tileDefMan))
-                return;
+            foreach (var change in args.Changes)
+            {
+                if (!change.NewTile.IsSpace(_tileDefMan))
+                    return;
 
-            if (!TryComp(args.Entity, out DecalGridComponent? grid))
-                return;
+                if (!TryComp(args.Entity, out DecalGridComponent? grid))
+                    return;
 
-            var indices = GetChunkIndices(args.NewTile.GridIndices);
-            var toDelete = new HashSet<uint>();
-            if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
-                return;
+                var indices = GetChunkIndices(change.GridIndices);
+                var toDelete = new HashSet<uint>();
+                if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
+                    return;
 
-            foreach (var (uid, decal) in chunk.Decals)
-            {
-                if (new Vector2((int) Math.Floor(decal.Coordinates.X), (int) Math.Floor(decal.Coordinates.Y)) ==
-                    args.NewTile.GridIndices)
+                foreach (var (uid, decal) in chunk.Decals)
                 {
-                    toDelete.Add(uid);
+                    if (new Vector2((int)Math.Floor(decal.Coordinates.X), (int)Math.Floor(decal.Coordinates.Y)) ==
+                        change.GridIndices)
+                    {
+                        toDelete.Add(uid);
+                    }
                 }
-            }
 
-            if (toDelete.Count == 0)
-                return;
+                if (toDelete.Count == 0)
+                    return;
 
-            foreach (var decalId in toDelete)
-            {
-                grid.DecalIndex.Remove(decalId);
-                chunk.Decals.Remove(decalId);
-            }
+                foreach (var decalId in toDelete)
+                {
+                    grid.DecalIndex.Remove(decalId);
+                    chunk.Decals.Remove(decalId);
+                }
 
-            DirtyChunk(args.Entity, indices, chunk);
-            if (chunk.Decals.Count == 0)
-                grid.ChunkCollection.ChunkCollection.Remove(indices);
+                DirtyChunk(args.Entity, indices, chunk);
+                if (chunk.Decals.Count == 0)
+                    grid.ChunkCollection.ChunkCollection.Remove(indices);
+            }
         }
 
         private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
index 3b63750ff6da9cbeae74debfa6478bcf395c85ca..77def3abbab06b4bfa66c0e896f2bf509cfd2b14 100644 (file)
@@ -233,65 +233,66 @@ public sealed partial class ExplosionSystem
     /// </summary>
     private void OnTileChanged(ref TileChangedEvent ev)
     {
-        // only need to update the grid-edge map if a tile was added or removed from the grid.
-        if (!ev.NewTile.Tile.IsEmpty && !ev.OldTile.IsEmpty)
-            return;
-
-        if (!TryComp(ev.Entity, out MapGridComponent? grid))
-            return;
-
-        var tileRef = ev.NewTile;
-
-        if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
+        foreach (var change in ev.Changes)
         {
-            edges = new();
-            _gridEdges[tileRef.GridUid] = edges;
-        }
+            // only need to update the grid-edge map if a tile was added or removed from the grid.
+            if (!change.NewTile.IsEmpty && !change.OldTile.IsEmpty)
+                return;
 
-        if (tileRef.Tile.IsEmpty)
-        {
-            // if the tile is empty, it cannot itself be an edge tile.
-            edges.Remove(tileRef.GridIndices);
+            if (!TryComp(ev.Entity, out MapGridComponent? grid))
+                return;
 
-            // add any valid neighbours to the list of edge-tiles
-            for (var i = 0; i < NeighbourVectors.Length; i++)
+            if (!_gridEdges.TryGetValue(ev.Entity, out var edges))
+            {
+                edges = new();
+                _gridEdges[ev.Entity] = edges;
+            }
+
+            if (change.NewTile.IsEmpty)
             {
-                var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
+                // if the tile is empty, it cannot itself be an edge tile.
+                edges.Remove(change.GridIndices);
 
-                if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
+                // add any valid neighbours to the list of edge-tiles
+                for (var i = 0; i < NeighbourVectors.Length; i++)
                 {
-                    var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
-                    edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
-                }
-            }
+                    var neighbourIndex = change.GridIndices + NeighbourVectors[i];
 
-            return;
-        }
+                    if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
+                    {
+                        var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
+                        edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
+                    }
+                }
 
-        // the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
-        // be edge tiles.
-        for (var i = 0; i < NeighbourVectors.Length; i++)
-        {
-            var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
+                return;
+            }
 
-            if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
+            // the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
+            // be edge tiles.
+            for (var i = 0; i < NeighbourVectors.Length; i++)
             {
-                var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
-                neighborSpaceDir &= ~oppositeDirection;
-                if (neighborSpaceDir == NeighborFlag.Invalid)
+                var neighbourIndex = change.GridIndices + NeighbourVectors[i];
+
+                if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
                 {
-                    // no longer an edge tile
-                    edges.Remove(neighbourIndex);
-                    continue;
-                }
+                    var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
+                    neighborSpaceDir &= ~oppositeDirection;
+                    if (neighborSpaceDir == NeighborFlag.Invalid)
+                    {
+                        // no longer an edge tile
+                        edges.Remove(neighbourIndex);
+                        continue;
+                    }
 
-                edges[neighbourIndex] = neighborSpaceDir;
+                    edges[neighbourIndex] = neighborSpaceDir;
+                }
             }
-        }
 
-        // finally check if the new tile is itself an edge tile
-        if (IsEdge(grid, tileRef.GridIndices, out var spaceDir))
-            edges.Add(tileRef.GridIndices, spaceDir);
+            // finally check if the new tile is itself an edge tile
+            if (IsEdge(grid, change.GridIndices, out var spaceDir))
+                edges.Add(change.GridIndices, spaceDir);
+        }
     }
 
     /// <summary>
index 7105bda0a27776f289434c265d4daab5b8e5486b..3def3feedc563c0fc443145f71f820f4f18073d5 100644 (file)
@@ -50,10 +50,13 @@ public sealed partial class PathfindingSystem
 
     private void OnTileChange(ref TileChangedEvent ev)
     {
-        if (ev.OldTile.IsEmpty == ev.NewTile.Tile.IsEmpty)
-            return;
+        foreach (var change in ev.Changes)
+        {
+            if (change.OldTile.IsEmpty == change.NewTile.IsEmpty)
+                return;
 
-        DirtyChunk(ev.Entity, Comp<MapGridComponent>(ev.Entity).GridTileToLocal(ev.NewTile.GridIndices));
+            DirtyChunk(ev.Entity, _maps.GridTileToLocal(ev.Entity, ev.Entity.Comp, change.GridIndices));
+        }
     }
 
 
index 5ffbbe53ab5b543f83acae838c2e8e99e147239a..ffa048acd605234d19b5584eb74b7b54f5d11175 100644 (file)
@@ -101,30 +101,33 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
 
     private void OnTileChanged(ref TileChangedEvent ev)
     {
-        if (!ev.EmptyChanged || !_navQuery.TryComp(ev.NewTile.GridUid, out var navMap))
-            return;
+        foreach (var change in ev.Changes)
+        {
+            if (!change.EmptyChanged || !_navQuery.TryComp(ev.Entity, out var navMap))
+                return;
 
-        var tile = ev.NewTile.GridIndices;
-        var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
+            var tile = change.GridIndices;
+            var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
 
-        var chunk = EnsureChunk(navMap, chunkOrigin);
+            var chunk = EnsureChunk(navMap, chunkOrigin);
 
-        // This could be easily replaced in the future to accommodate diagonal tiles
-        var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
-        ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
+            // This could be easily replaced in the future to accommodate diagonal tiles
+            var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
+            ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
 
-        if (ev.NewTile.IsSpace(_tileDefManager))
-        {
-            tileData = 0;
-            if (PruneEmpty((ev.NewTile.GridUid, navMap), chunk))
-                return;
-        }
-        else
-        {
-            tileData = FloorMask;
-        }
+            if (change.NewTile.IsSpace(_tileDefManager))
+            {
+                tileData = 0;
+                if (PruneEmpty((ev.Entity, navMap), chunk))
+                    return;
+            }
+            else
+            {
+                tileData = FloorMask;
+            }
 
-        DirtyChunk((ev.NewTile.GridUid, navMap), chunk);
+            DirtyChunk((ev.Entity, navMap), chunk);
+        }
     }
 
     private void DirtyChunk(Entity<NavMapComponent> entity, NavMapChunk chunk)
index 74008a6af7f6da64793ebc11544013b3446d2ad4..294200af9a65806a376af155f3d61e86ed3582fd 100644 (file)
@@ -94,41 +94,45 @@ public sealed class ThrusterSystem : EntitySystem
 
     private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args)
     {
-        // If the old tile was space but the new one isn't then disable all adjacent thrusters
-        if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager))
-            return;
-
-        var tilePos = args.NewTile.GridIndices;
-        var grid = Comp<MapGridComponent>(uid);
-        var xformQuery = GetEntityQuery<TransformComponent>();
-        var thrusterQuery = GetEntityQuery<ThrusterComponent>();
-
-        for (var x = -1; x <= 1; x++)
+        foreach (var change in args.Changes)
         {
-            for (var y = -1; y <= 1; y++)
-            {
-                if (x != 0 && y != 0)
-                    continue;
+            // If the old tile was space but the new one isn't then disable all adjacent thrusters
+            if (change.NewTile.IsSpace(_tileDefManager) || !change.OldTile.IsSpace(_tileDefManager))
+                return;
 
-                var checkPos = tilePos + new Vector2i(x, y);
-                var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos);
+            var tilePos = change.GridIndices;
+            var grid = Comp<MapGridComponent>(uid);
+            var xformQuery = GetEntityQuery<TransformComponent>();
+            var thrusterQuery = GetEntityQuery<ThrusterComponent>();
 
-                while (enumerator.MoveNext(out var ent))
+            for (var x = -1; x <= 1; x++)
+            {
+                for (var y = -1; y <= 1; y++)
                 {
-                    if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
+                    if (x != 0 && y != 0)
                         continue;
 
-                    // Work out if the thruster is facing this direction
-                    var xform = xformQuery.GetComponent(ent.Value);
-                    var direction = xform.LocalRotation.ToWorldVec();
+                    var checkPos = tilePos + new Vector2i(x, y);
+                    var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos);
 
-                    if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y))
-                        continue;
+                    while (enumerator.MoveNext(out var ent))
+                    {
+                        if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
+                            continue;
 
-                    DisableThruster(ent.Value, thruster, xform.GridUid);
+                        // Work out if the thruster is facing this direction
+                        var xform = xformQuery.GetComponent(ent.Value);
+                        var direction = xform.LocalRotation.ToWorldVec();
+
+                        if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y))
+                            continue;
+
+                        DisableThruster(ent.Value, thruster, xform.GridUid);
+                    }
                 }
             }
         }
+
     }
 
     private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
index 571065c82838489dcc8ea3f893cb2a3768694e28..aae07fa660ab2798e986e77613ef9bc44ec5b20d 100644 (file)
@@ -26,16 +26,19 @@ public sealed class RequiresTileSystem : EntitySystem
         if (!TryComp<MapGridComponent>(ev.Entity, out var grid))
             return;
 
-        var anchored = _maps.GetAnchoredEntitiesEnumerator(ev.Entity, grid, ev.NewTile.GridIndices);
-        if (anchored.Equals(AnchoredEntitiesEnumerator.Empty))
-            return;
-
-        while (anchored.MoveNext(out var ent))
+        foreach (var change in ev.Changes)
         {
-            if (!_tilesQuery.HasComponent(ent.Value))
-                continue;
+            var anchored = _maps.GetAnchoredEntitiesEnumerator(ev.Entity, grid, change.GridIndices);
+            if (anchored.Equals(AnchoredEntitiesEnumerator.Empty))
+                return;
+
+            while (anchored.MoveNext(out var ent))
+            {
+                if (!_tilesQuery.HasComponent(ent.Value))
+                    continue;
 
-            QueueDel(ent.Value);
+                QueueDel(ent.Value);
+            }
         }
     }
 }
index 9a7ce0d1df5f79bb92d9598e32782057cb848e6f..65d5e0adb21a2bec90b7c153d117808d20d23ca9 100644 (file)
@@ -122,13 +122,16 @@ namespace Content.Shared.SubFloor
 
         private void OnTileChanged(ref TileChangedEvent args)
         {
-            if (args.OldTile.IsEmpty)
-                return; // Nothing is anchored here anyways.
+            foreach (var change in args.Changes)
+            {
+                if (change.OldTile.IsEmpty)
+                    return; // Nothing is anchored here anyways.
 
-            if (args.NewTile.Tile.IsEmpty)
-                return; // Anything that was here will be unanchored anyways.
+                if (change.NewTile.IsEmpty)
+                    return; // Anything that was here will be unanchored anyways.
 
-            UpdateTile(args.NewTile.GridUid, args.Entity.Comp, args.NewTile.GridIndices);
+                UpdateTile(args.Entity, args.Entity.Comp, change.GridIndices);
+            }
         }
 
         /// <summary>