Skip to content
This repository was archived by the owner on Dec 23, 2025. It is now read-only.

Commit 4dc1c4c

Browse files
authored
Content changes for SetTiles change (space-wizards#37229)
* Content changes for SetTiles change * Retest with new engine changes * Derp * Update for new engine PR changes
1 parent 715165f commit 4dc1c4c

9 files changed

Lines changed: 177 additions & 151 deletions

File tree

Content.Server/Atmos/EntitySystems/AtmosphereSystem.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ public override void Shutdown()
8181

8282
private void OnTileChanged(ref TileChangedEvent ev)
8383
{
84-
InvalidateTile(ev.NewTile.GridUid, ev.NewTile.GridIndices);
84+
foreach (var change in ev.Changes)
85+
{
86+
InvalidateTile(ev.Entity.Owner, change.GridIndices);
87+
}
8588
}
8689

8790
private void OnPrototypesReloaded(PrototypesReloadedEventArgs ev)

Content.Server/Atmos/EntitySystems/AutomaticAtmosSystem.cs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,32 @@ public override void Initialize()
2323

2424
private void OnTileChanged(ref TileChangedEvent ev)
2525
{
26-
// Only if a atmos-holding tile has been added or removed.
27-
// Also, these calls are surprisingly slow.
28-
// TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
29-
// TODO: a simple array lookup, as tile IDs are likely contiguous, and there's at most 2^16 possibilities anyway.
30-
31-
var oldSpace = ev.OldTile.IsSpace(_tileDefinitionManager);
32-
var newSpace = ev.NewTile.IsSpace(_tileDefinitionManager);
33-
34-
if (!(oldSpace && !newSpace ||
35-
!oldSpace && newSpace) ||
36-
_atmosphereSystem.HasAtmosphere(ev.Entity))
37-
return;
38-
39-
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
40-
return;
41-
42-
// We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
43-
if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
26+
foreach (var change in ev.Changes)
4427
{
45-
AddComp<GridAtmosphereComponent>(ev.Entity);
46-
Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
28+
// Only if a atmos-holding tile has been added or removed.
29+
// Also, these calls are surprisingly slow.
30+
// TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
31+
// TODO: a simple array lookup, as tile IDs are likely contiguous, and there's at most 2^16 possibilities anyway.
32+
33+
var oldSpace = change.OldTile.IsSpace(_tileDefinitionManager);
34+
var newSpace = change.NewTile.IsSpace(_tileDefinitionManager);
35+
36+
if (!(oldSpace && !newSpace ||
37+
!oldSpace && newSpace) ||
38+
_atmosphereSystem.HasAtmosphere(ev.Entity))
39+
continue;
40+
41+
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
42+
return;
43+
44+
// We can't actually count how many tiles there are efficiently, so instead estimate with the mass.
45+
if (physics.Mass / ShuttleSystem.TileMassMultiplier >= 7.0f)
46+
{
47+
AddComp<GridAtmosphereComponent>(ev.Entity);
48+
Log.Info($"Giving grid {ev.Entity} GridAtmosphereComponent.");
49+
}
50+
// It's not super important to remove it should the grid become too small again.
51+
// If explosions ever gain the ability to outright shatter grids, do rethink this.
4752
}
48-
// It's not super important to remove it should the grid become too small again.
49-
// If explosions ever gain the ability to outright shatter grids, do rethink this.
5053
}
5154
}

Content.Server/Decals/DecalSystem.cs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -160,38 +160,41 @@ public override void Shutdown()
160160

161161
private void OnTileChanged(ref TileChangedEvent args)
162162
{
163-
if (!args.NewTile.IsSpace(_tileDefMan))
164-
return;
163+
foreach (var change in args.Changes)
164+
{
165+
if (!change.NewTile.IsSpace(_tileDefMan))
166+
return;
165167

166-
if (!TryComp(args.Entity, out DecalGridComponent? grid))
167-
return;
168+
if (!TryComp(args.Entity, out DecalGridComponent? grid))
169+
return;
168170

169-
var indices = GetChunkIndices(args.NewTile.GridIndices);
170-
var toDelete = new HashSet<uint>();
171-
if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
172-
return;
171+
var indices = GetChunkIndices(change.GridIndices);
172+
var toDelete = new HashSet<uint>();
173+
if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
174+
return;
173175

174-
foreach (var (uid, decal) in chunk.Decals)
175-
{
176-
if (new Vector2((int) Math.Floor(decal.Coordinates.X), (int) Math.Floor(decal.Coordinates.Y)) ==
177-
args.NewTile.GridIndices)
176+
foreach (var (uid, decal) in chunk.Decals)
178177
{
179-
toDelete.Add(uid);
178+
if (new Vector2((int)Math.Floor(decal.Coordinates.X), (int)Math.Floor(decal.Coordinates.Y)) ==
179+
change.GridIndices)
180+
{
181+
toDelete.Add(uid);
182+
}
180183
}
181-
}
182184

183-
if (toDelete.Count == 0)
184-
return;
185+
if (toDelete.Count == 0)
186+
return;
185187

186-
foreach (var decalId in toDelete)
187-
{
188-
grid.DecalIndex.Remove(decalId);
189-
chunk.Decals.Remove(decalId);
190-
}
188+
foreach (var decalId in toDelete)
189+
{
190+
grid.DecalIndex.Remove(decalId);
191+
chunk.Decals.Remove(decalId);
192+
}
191193

192-
DirtyChunk(args.Entity, indices, chunk);
193-
if (chunk.Decals.Count == 0)
194-
grid.ChunkCollection.ChunkCollection.Remove(indices);
194+
DirtyChunk(args.Entity, indices, chunk);
195+
if (chunk.Decals.Count == 0)
196+
grid.ChunkCollection.ChunkCollection.Remove(indices);
197+
}
195198
}
196199

197200
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)

Content.Server/Explosion/EntitySystems/ExplosionSystem.GridMap.cs

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -233,65 +233,66 @@ public void GetUnblockedDirections(Dictionary<Vector2i, BlockedSpaceTile> transf
233233
/// </summary>
234234
private void OnTileChanged(ref TileChangedEvent ev)
235235
{
236-
// only need to update the grid-edge map if a tile was added or removed from the grid.
237-
if (!ev.NewTile.Tile.IsEmpty && !ev.OldTile.IsEmpty)
238-
return;
239-
240-
if (!TryComp(ev.Entity, out MapGridComponent? grid))
241-
return;
242-
243-
var tileRef = ev.NewTile;
244-
245-
if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
236+
foreach (var change in ev.Changes)
246237
{
247-
edges = new();
248-
_gridEdges[tileRef.GridUid] = edges;
249-
}
238+
// only need to update the grid-edge map if a tile was added or removed from the grid.
239+
if (!change.NewTile.IsEmpty && !change.OldTile.IsEmpty)
240+
return;
250241

251-
if (tileRef.Tile.IsEmpty)
252-
{
253-
// if the tile is empty, it cannot itself be an edge tile.
254-
edges.Remove(tileRef.GridIndices);
242+
if (!TryComp(ev.Entity, out MapGridComponent? grid))
243+
return;
255244

256-
// add any valid neighbours to the list of edge-tiles
257-
for (var i = 0; i < NeighbourVectors.Length; i++)
245+
if (!_gridEdges.TryGetValue(ev.Entity, out var edges))
246+
{
247+
edges = new();
248+
_gridEdges[ev.Entity] = edges;
249+
}
250+
251+
if (change.NewTile.IsEmpty)
258252
{
259-
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
253+
// if the tile is empty, it cannot itself be an edge tile.
254+
edges.Remove(change.GridIndices);
260255

261-
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
256+
// add any valid neighbours to the list of edge-tiles
257+
for (var i = 0; i < NeighbourVectors.Length; i++)
262258
{
263-
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
264-
edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
265-
}
266-
}
259+
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
267260

268-
return;
269-
}
261+
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
262+
{
263+
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
264+
edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
265+
}
266+
}
270267

271-
// the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
272-
// be edge tiles.
273-
for (var i = 0; i < NeighbourVectors.Length; i++)
274-
{
275-
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
268+
return;
269+
}
276270

277-
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
271+
// the tile is not empty space, but was previously. So update directly adjacent neighbours, which may no longer
272+
// be edge tiles.
273+
for (var i = 0; i < NeighbourVectors.Length; i++)
278274
{
279-
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
280-
neighborSpaceDir &= ~oppositeDirection;
281-
if (neighborSpaceDir == NeighborFlag.Invalid)
275+
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
276+
277+
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
282278
{
283-
// no longer an edge tile
284-
edges.Remove(neighbourIndex);
285-
continue;
286-
}
279+
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
280+
neighborSpaceDir &= ~oppositeDirection;
281+
if (neighborSpaceDir == NeighborFlag.Invalid)
282+
{
283+
// no longer an edge tile
284+
edges.Remove(neighbourIndex);
285+
continue;
286+
}
287287

288-
edges[neighbourIndex] = neighborSpaceDir;
288+
edges[neighbourIndex] = neighborSpaceDir;
289+
}
289290
}
290-
}
291291

292-
// finally check if the new tile is itself an edge tile
293-
if (IsEdge(grid, tileRef.GridIndices, out var spaceDir))
294-
edges.Add(tileRef.GridIndices, spaceDir);
292+
// finally check if the new tile is itself an edge tile
293+
if (IsEdge(grid, change.GridIndices, out var spaceDir))
294+
edges.Add(change.GridIndices, spaceDir);
295+
}
295296
}
296297

297298
/// <summary>

Content.Server/NPC/Pathfinding/PathfindingSystem.Grid.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ private void InitializeGrid()
5050

5151
private void OnTileChange(ref TileChangedEvent ev)
5252
{
53-
if (ev.OldTile.IsEmpty == ev.NewTile.Tile.IsEmpty)
54-
return;
53+
foreach (var change in ev.Changes)
54+
{
55+
if (change.OldTile.IsEmpty == change.NewTile.IsEmpty)
56+
return;
5557

56-
DirtyChunk(ev.Entity, Comp<MapGridComponent>(ev.Entity).GridTileToLocal(ev.NewTile.GridIndices));
58+
DirtyChunk(ev.Entity, _maps.GridTileToLocal(ev.Entity, ev.Entity.Comp, change.GridIndices));
59+
}
5760
}
5861

5962

Content.Server/Pinpointer/NavMapSystem.cs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,33 @@ private NavMapChunk EnsureChunk(NavMapComponent component, Vector2i origin)
101101

102102
private void OnTileChanged(ref TileChangedEvent ev)
103103
{
104-
if (!ev.EmptyChanged || !_navQuery.TryComp(ev.NewTile.GridUid, out var navMap))
105-
return;
104+
foreach (var change in ev.Changes)
105+
{
106+
if (!change.EmptyChanged || !_navQuery.TryComp(ev.Entity, out var navMap))
107+
return;
106108

107-
var tile = ev.NewTile.GridIndices;
108-
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
109+
var tile = change.GridIndices;
110+
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
109111

110-
var chunk = EnsureChunk(navMap, chunkOrigin);
112+
var chunk = EnsureChunk(navMap, chunkOrigin);
111113

112-
// This could be easily replaced in the future to accommodate diagonal tiles
113-
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
114-
ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
114+
// This could be easily replaced in the future to accommodate diagonal tiles
115+
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
116+
ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
115117

116-
if (ev.NewTile.IsSpace(_tileDefManager))
117-
{
118-
tileData = 0;
119-
if (PruneEmpty((ev.NewTile.GridUid, navMap), chunk))
120-
return;
121-
}
122-
else
123-
{
124-
tileData = FloorMask;
125-
}
118+
if (change.NewTile.IsSpace(_tileDefManager))
119+
{
120+
tileData = 0;
121+
if (PruneEmpty((ev.Entity, navMap), chunk))
122+
return;
123+
}
124+
else
125+
{
126+
tileData = FloorMask;
127+
}
126128

127-
DirtyChunk((ev.NewTile.GridUid, navMap), chunk);
129+
DirtyChunk((ev.Entity, navMap), chunk);
130+
}
128131
}
129132

130133
private void DirtyChunk(Entity<NavMapComponent> entity, NavMapChunk chunk)

Content.Server/Shuttles/Systems/ThrusterSystem.cs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,41 +94,45 @@ private void OnIsHotEvent(EntityUid uid, ThrusterComponent component, IsHotEvent
9494

9595
private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args)
9696
{
97-
// If the old tile was space but the new one isn't then disable all adjacent thrusters
98-
if (args.NewTile.IsSpace(_tileDefManager) || !args.OldTile.IsSpace(_tileDefManager))
99-
return;
100-
101-
var tilePos = args.NewTile.GridIndices;
102-
var grid = Comp<MapGridComponent>(uid);
103-
var xformQuery = GetEntityQuery<TransformComponent>();
104-
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
105-
106-
for (var x = -1; x <= 1; x++)
97+
foreach (var change in args.Changes)
10798
{
108-
for (var y = -1; y <= 1; y++)
109-
{
110-
if (x != 0 && y != 0)
111-
continue;
99+
// If the old tile was space but the new one isn't then disable all adjacent thrusters
100+
if (change.NewTile.IsSpace(_tileDefManager) || !change.OldTile.IsSpace(_tileDefManager))
101+
return;
112102

113-
var checkPos = tilePos + new Vector2i(x, y);
114-
var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos);
103+
var tilePos = change.GridIndices;
104+
var grid = Comp<MapGridComponent>(uid);
105+
var xformQuery = GetEntityQuery<TransformComponent>();
106+
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
115107

116-
while (enumerator.MoveNext(out var ent))
108+
for (var x = -1; x <= 1; x++)
109+
{
110+
for (var y = -1; y <= 1; y++)
117111
{
118-
if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
112+
if (x != 0 && y != 0)
119113
continue;
120114

121-
// Work out if the thruster is facing this direction
122-
var xform = xformQuery.GetComponent(ent.Value);
123-
var direction = xform.LocalRotation.ToWorldVec();
115+
var checkPos = tilePos + new Vector2i(x, y);
116+
var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(uid, grid, checkPos);
124117

125-
if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y))
126-
continue;
118+
while (enumerator.MoveNext(out var ent))
119+
{
120+
if (!thrusterQuery.TryGetComponent(ent.Value, out var thruster) || !thruster.RequireSpace)
121+
continue;
127122

128-
DisableThruster(ent.Value, thruster, xform.GridUid);
123+
// Work out if the thruster is facing this direction
124+
var xform = xformQuery.GetComponent(ent.Value);
125+
var direction = xform.LocalRotation.ToWorldVec();
126+
127+
if (new Vector2i((int)direction.X, (int)direction.Y) != new Vector2i(x, y))
128+
continue;
129+
130+
DisableThruster(ent.Value, thruster, xform.GridUid);
131+
}
129132
}
130133
}
131134
}
135+
132136
}
133137

134138
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)

0 commit comments

Comments
 (0)