Content changes for SetTiles change (#37229)
* Content changes for SetTiles change * Retest with new engine changes * Derp * Update for new engine PR changes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -22,19 +22,21 @@ public sealed class AutomaticAtmosSystem : EntitySystem
|
||||
}
|
||||
|
||||
private void OnTileChanged(ref TileChangedEvent ev)
|
||||
{
|
||||
foreach (var change in ev.Changes)
|
||||
{
|
||||
// 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);
|
||||
var oldSpace = change.OldTile.IsSpace(_tileDefinitionManager);
|
||||
var newSpace = change.NewTile.IsSpace(_tileDefinitionManager);
|
||||
|
||||
if (!(oldSpace && !newSpace ||
|
||||
!oldSpace && newSpace) ||
|
||||
_atmosphereSystem.HasAtmosphere(ev.Entity))
|
||||
return;
|
||||
continue;
|
||||
|
||||
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
|
||||
return;
|
||||
@@ -48,4 +50,5 @@ public sealed class AutomaticAtmosSystem : EntitySystem
|
||||
// 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.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,21 +160,23 @@ namespace Content.Server.Decals
|
||||
|
||||
private void OnTileChanged(ref TileChangedEvent args)
|
||||
{
|
||||
if (!args.NewTile.IsSpace(_tileDefMan))
|
||||
foreach (var change in args.Changes)
|
||||
{
|
||||
if (!change.NewTile.IsSpace(_tileDefMan))
|
||||
return;
|
||||
|
||||
if (!TryComp(args.Entity, out DecalGridComponent? grid))
|
||||
return;
|
||||
|
||||
var indices = GetChunkIndices(args.NewTile.GridIndices);
|
||||
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)
|
||||
if (new Vector2((int)Math.Floor(decal.Coordinates.X), (int)Math.Floor(decal.Coordinates.Y)) ==
|
||||
change.GridIndices)
|
||||
{
|
||||
toDelete.Add(uid);
|
||||
}
|
||||
@@ -193,6 +195,7 @@ namespace Content.Server.Decals
|
||||
if (chunk.Decals.Count == 0)
|
||||
grid.ChunkCollection.ChunkCollection.Remove(indices);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||
{
|
||||
|
||||
@@ -232,35 +232,35 @@ public sealed partial class ExplosionSystem
|
||||
/// When a tile is updated, we might need to update the grid edge maps.
|
||||
/// </summary>
|
||||
private void OnTileChanged(ref TileChangedEvent ev)
|
||||
{
|
||||
foreach (var change in ev.Changes)
|
||||
{
|
||||
// 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)
|
||||
if (!change.NewTile.IsEmpty && !change.OldTile.IsEmpty)
|
||||
return;
|
||||
|
||||
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
||||
return;
|
||||
|
||||
var tileRef = ev.NewTile;
|
||||
|
||||
if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
|
||||
if (!_gridEdges.TryGetValue(ev.Entity, out var edges))
|
||||
{
|
||||
edges = new();
|
||||
_gridEdges[tileRef.GridUid] = edges;
|
||||
_gridEdges[ev.Entity] = edges;
|
||||
}
|
||||
|
||||
if (tileRef.Tile.IsEmpty)
|
||||
if (change.NewTile.IsEmpty)
|
||||
{
|
||||
// if the tile is empty, it cannot itself be an edge tile.
|
||||
edges.Remove(tileRef.GridIndices);
|
||||
edges.Remove(change.GridIndices);
|
||||
|
||||
// add any valid neighbours to the list of edge-tiles
|
||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
||||
{
|
||||
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
|
||||
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
|
||||
|
||||
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
|
||||
{
|
||||
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
|
||||
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
|
||||
edges[neighbourIndex] = edges.GetValueOrDefault(neighbourIndex) | oppositeDirection;
|
||||
}
|
||||
}
|
||||
@@ -272,11 +272,11 @@ public sealed partial class ExplosionSystem
|
||||
// be edge tiles.
|
||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
||||
{
|
||||
var neighbourIndex = tileRef.GridIndices + NeighbourVectors[i];
|
||||
var neighbourIndex = change.GridIndices + NeighbourVectors[i];
|
||||
|
||||
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
|
||||
{
|
||||
var oppositeDirection = (NeighborFlag) (1 << ((i + 4) % 8));
|
||||
var oppositeDirection = (NeighborFlag)(1 << ((i + 4) % 8));
|
||||
neighborSpaceDir &= ~oppositeDirection;
|
||||
if (neighborSpaceDir == NeighborFlag.Invalid)
|
||||
{
|
||||
@@ -290,8 +290,9 @@ public sealed partial class ExplosionSystem
|
||||
}
|
||||
|
||||
// finally check if the new tile is itself an edge tile
|
||||
if (IsEdge(grid, tileRef.GridIndices, out var spaceDir))
|
||||
edges.Add(tileRef.GridIndices, spaceDir);
|
||||
if (IsEdge(grid, change.GridIndices, out var spaceDir))
|
||||
edges.Add(change.GridIndices, spaceDir);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -50,10 +50,13 @@ public sealed partial class PathfindingSystem
|
||||
|
||||
private void OnTileChange(ref TileChangedEvent ev)
|
||||
{
|
||||
if (ev.OldTile.IsEmpty == ev.NewTile.Tile.IsEmpty)
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -101,10 +101,12 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
|
||||
|
||||
private void OnTileChanged(ref TileChangedEvent ev)
|
||||
{
|
||||
if (!ev.EmptyChanged || !_navQuery.TryComp(ev.NewTile.GridUid, out var navMap))
|
||||
foreach (var change in ev.Changes)
|
||||
{
|
||||
if (!change.EmptyChanged || !_navQuery.TryComp(ev.Entity, out var navMap))
|
||||
return;
|
||||
|
||||
var tile = ev.NewTile.GridIndices;
|
||||
var tile = change.GridIndices;
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
||||
|
||||
var chunk = EnsureChunk(navMap, chunkOrigin);
|
||||
@@ -113,10 +115,10 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
|
||||
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
|
||||
ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
|
||||
|
||||
if (ev.NewTile.IsSpace(_tileDefManager))
|
||||
if (change.NewTile.IsSpace(_tileDefManager))
|
||||
{
|
||||
tileData = 0;
|
||||
if (PruneEmpty((ev.NewTile.GridUid, navMap), chunk))
|
||||
if (PruneEmpty((ev.Entity, navMap), chunk))
|
||||
return;
|
||||
}
|
||||
else
|
||||
@@ -124,7 +126,8 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
|
||||
tileData = FloorMask;
|
||||
}
|
||||
|
||||
DirtyChunk((ev.NewTile.GridUid, navMap), chunk);
|
||||
DirtyChunk((ev.Entity, navMap), chunk);
|
||||
}
|
||||
}
|
||||
|
||||
private void DirtyChunk(Entity<NavMapComponent> entity, NavMapChunk chunk)
|
||||
|
||||
@@ -93,12 +93,14 @@ public sealed class ThrusterSystem : EntitySystem
|
||||
}
|
||||
|
||||
private void OnShuttleTileChange(EntityUid uid, ShuttleComponent component, ref TileChangedEvent args)
|
||||
{
|
||||
foreach (var change in args.Changes)
|
||||
{
|
||||
// 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))
|
||||
if (change.NewTile.IsSpace(_tileDefManager) || !change.OldTile.IsSpace(_tileDefManager))
|
||||
return;
|
||||
|
||||
var tilePos = args.NewTile.GridIndices;
|
||||
var tilePos = change.GridIndices;
|
||||
var grid = Comp<MapGridComponent>(uid);
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
||||
@@ -131,6 +133,8 @@ public sealed class ThrusterSystem : EntitySystem
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (args.Handled || !args.Complex)
|
||||
|
||||
@@ -26,7 +26,9 @@ public sealed class RequiresTileSystem : EntitySystem
|
||||
if (!TryComp<MapGridComponent>(ev.Entity, out var grid))
|
||||
return;
|
||||
|
||||
var anchored = _maps.GetAnchoredEntitiesEnumerator(ev.Entity, grid, ev.NewTile.GridIndices);
|
||||
foreach (var change in ev.Changes)
|
||||
{
|
||||
var anchored = _maps.GetAnchoredEntitiesEnumerator(ev.Entity, grid, change.GridIndices);
|
||||
if (anchored.Equals(AnchoredEntitiesEnumerator.Empty))
|
||||
return;
|
||||
|
||||
@@ -38,4 +40,5 @@ public sealed class RequiresTileSystem : EntitySystem
|
||||
QueueDel(ent.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,13 +122,16 @@ namespace Content.Shared.SubFloor
|
||||
|
||||
private void OnTileChanged(ref TileChangedEvent args)
|
||||
{
|
||||
if (args.OldTile.IsEmpty)
|
||||
foreach (var change in args.Changes)
|
||||
{
|
||||
if (change.OldTile.IsEmpty)
|
||||
return; // Nothing is anchored here anyways.
|
||||
|
||||
if (args.NewTile.Tile.IsEmpty)
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user