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)
|
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)
|
private void OnPrototypesReloaded(PrototypesReloadedEventArgs ev)
|
||||||
|
|||||||
@@ -22,19 +22,21 @@ public sealed class AutomaticAtmosSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void OnTileChanged(ref TileChangedEvent ev)
|
private void OnTileChanged(ref TileChangedEvent ev)
|
||||||
|
{
|
||||||
|
foreach (var change in ev.Changes)
|
||||||
{
|
{
|
||||||
// Only if a atmos-holding tile has been added or removed.
|
// Only if a atmos-holding tile has been added or removed.
|
||||||
// Also, these calls are surprisingly slow.
|
// Also, these calls are surprisingly slow.
|
||||||
// TODO: Make tiledefmanager cache the IsSpace property, and turn this lookup-through-two-interfaces into
|
// 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.
|
// 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 oldSpace = change.OldTile.IsSpace(_tileDefinitionManager);
|
||||||
var newSpace = ev.NewTile.IsSpace(_tileDefinitionManager);
|
var newSpace = change.NewTile.IsSpace(_tileDefinitionManager);
|
||||||
|
|
||||||
if (!(oldSpace && !newSpace ||
|
if (!(oldSpace && !newSpace ||
|
||||||
!oldSpace && newSpace) ||
|
!oldSpace && newSpace) ||
|
||||||
_atmosphereSystem.HasAtmosphere(ev.Entity))
|
_atmosphereSystem.HasAtmosphere(ev.Entity))
|
||||||
return;
|
continue;
|
||||||
|
|
||||||
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
|
if (!TryComp<PhysicsComponent>(ev.Entity, out var physics))
|
||||||
return;
|
return;
|
||||||
@@ -49,3 +51,4 @@ public sealed class AutomaticAtmosSystem : EntitySystem
|
|||||||
// If explosions ever gain the ability to outright shatter grids, do rethink this.
|
// If explosions ever gain the ability to outright shatter grids, do rethink this.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -160,13 +160,15 @@ namespace Content.Server.Decals
|
|||||||
|
|
||||||
private void OnTileChanged(ref TileChangedEvent args)
|
private void OnTileChanged(ref TileChangedEvent args)
|
||||||
{
|
{
|
||||||
if (!args.NewTile.IsSpace(_tileDefMan))
|
foreach (var change in args.Changes)
|
||||||
|
{
|
||||||
|
if (!change.NewTile.IsSpace(_tileDefMan))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!TryComp(args.Entity, out DecalGridComponent? grid))
|
if (!TryComp(args.Entity, out DecalGridComponent? grid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var indices = GetChunkIndices(args.NewTile.GridIndices);
|
var indices = GetChunkIndices(change.GridIndices);
|
||||||
var toDelete = new HashSet<uint>();
|
var toDelete = new HashSet<uint>();
|
||||||
if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
|
if (!grid.ChunkCollection.ChunkCollection.TryGetValue(indices, out var chunk))
|
||||||
return;
|
return;
|
||||||
@@ -174,7 +176,7 @@ namespace Content.Server.Decals
|
|||||||
foreach (var (uid, decal) in chunk.Decals)
|
foreach (var (uid, decal) in chunk.Decals)
|
||||||
{
|
{
|
||||||
if (new Vector2((int)Math.Floor(decal.Coordinates.X), (int)Math.Floor(decal.Coordinates.Y)) ==
|
if (new Vector2((int)Math.Floor(decal.Coordinates.X), (int)Math.Floor(decal.Coordinates.Y)) ==
|
||||||
args.NewTile.GridIndices)
|
change.GridIndices)
|
||||||
{
|
{
|
||||||
toDelete.Add(uid);
|
toDelete.Add(uid);
|
||||||
}
|
}
|
||||||
@@ -193,6 +195,7 @@ namespace Content.Server.Decals
|
|||||||
if (chunk.Decals.Count == 0)
|
if (chunk.Decals.Count == 0)
|
||||||
grid.ChunkCollection.ChunkCollection.Remove(indices);
|
grid.ChunkCollection.ChunkCollection.Remove(indices);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -232,31 +232,31 @@ public sealed partial class ExplosionSystem
|
|||||||
/// When a tile is updated, we might need to update the grid edge maps.
|
/// When a tile is updated, we might need to update the grid edge maps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void OnTileChanged(ref TileChangedEvent ev)
|
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.
|
// 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;
|
return;
|
||||||
|
|
||||||
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
if (!TryComp(ev.Entity, out MapGridComponent? grid))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var tileRef = ev.NewTile;
|
if (!_gridEdges.TryGetValue(ev.Entity, out var edges))
|
||||||
|
|
||||||
if (!_gridEdges.TryGetValue(tileRef.GridUid, out var edges))
|
|
||||||
{
|
{
|
||||||
edges = new();
|
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.
|
// 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
|
// add any valid neighbours to the list of edge-tiles
|
||||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
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)
|
if (_mapSystem.TryGetTileRef(ev.Entity, grid, neighbourIndex, out var neighbourTile) && !neighbourTile.Tile.IsEmpty)
|
||||||
{
|
{
|
||||||
@@ -272,7 +272,7 @@ public sealed partial class ExplosionSystem
|
|||||||
// be edge tiles.
|
// be edge tiles.
|
||||||
for (var i = 0; i < NeighbourVectors.Length; i++)
|
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))
|
if (edges.TryGetValue(neighbourIndex, out var neighborSpaceDir))
|
||||||
{
|
{
|
||||||
@@ -290,8 +290,9 @@ public sealed partial class ExplosionSystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
// finally check if the new tile is itself an edge tile
|
// finally check if the new tile is itself an edge tile
|
||||||
if (IsEdge(grid, tileRef.GridIndices, out var spaceDir))
|
if (IsEdge(grid, change.GridIndices, out var spaceDir))
|
||||||
edges.Add(tileRef.GridIndices, spaceDir);
|
edges.Add(change.GridIndices, spaceDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -50,10 +50,13 @@ public sealed partial class PathfindingSystem
|
|||||||
|
|
||||||
private void OnTileChange(ref TileChangedEvent ev)
|
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;
|
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)
|
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;
|
return;
|
||||||
|
|
||||||
var tile = ev.NewTile.GridIndices;
|
var tile = change.GridIndices;
|
||||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
var chunkOrigin = SharedMapSystem.GetChunkIndices(tile, ChunkSize);
|
||||||
|
|
||||||
var chunk = EnsureChunk(navMap, chunkOrigin);
|
var chunk = EnsureChunk(navMap, chunkOrigin);
|
||||||
@@ -113,10 +115,10 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
|
|||||||
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
|
var relative = SharedMapSystem.GetChunkRelative(tile, ChunkSize);
|
||||||
ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
|
ref var tileData = ref chunk.TileData[GetTileIndex(relative)];
|
||||||
|
|
||||||
if (ev.NewTile.IsSpace(_tileDefManager))
|
if (change.NewTile.IsSpace(_tileDefManager))
|
||||||
{
|
{
|
||||||
tileData = 0;
|
tileData = 0;
|
||||||
if (PruneEmpty((ev.NewTile.GridUid, navMap), chunk))
|
if (PruneEmpty((ev.Entity, navMap), chunk))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -124,7 +126,8 @@ public sealed partial class NavMapSystem : SharedNavMapSystem
|
|||||||
tileData = FloorMask;
|
tileData = FloorMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
DirtyChunk((ev.NewTile.GridUid, navMap), chunk);
|
DirtyChunk((ev.Entity, navMap), chunk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DirtyChunk(Entity<NavMapComponent> entity, NavMapChunk 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)
|
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 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;
|
return;
|
||||||
|
|
||||||
var tilePos = args.NewTile.GridIndices;
|
var tilePos = change.GridIndices;
|
||||||
var grid = Comp<MapGridComponent>(uid);
|
var grid = Comp<MapGridComponent>(uid);
|
||||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||||
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
var thrusterQuery = GetEntityQuery<ThrusterComponent>();
|
||||||
@@ -131,6 +133,8 @@ public sealed class ThrusterSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
|
private void OnActivateThruster(EntityUid uid, ThrusterComponent component, ActivateInWorldEvent args)
|
||||||
{
|
{
|
||||||
if (args.Handled || !args.Complex)
|
if (args.Handled || !args.Complex)
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ public sealed class RequiresTileSystem : EntitySystem
|
|||||||
if (!TryComp<MapGridComponent>(ev.Entity, out var grid))
|
if (!TryComp<MapGridComponent>(ev.Entity, out var grid))
|
||||||
return;
|
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))
|
if (anchored.Equals(AnchoredEntitiesEnumerator.Empty))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -39,3 +41,4 @@ public sealed class RequiresTileSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -122,13 +122,16 @@ namespace Content.Shared.SubFloor
|
|||||||
|
|
||||||
private void OnTileChanged(ref TileChangedEvent args)
|
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.
|
return; // Nothing is anchored here anyways.
|
||||||
|
|
||||||
if (args.NewTile.Tile.IsEmpty)
|
if (change.NewTile.IsEmpty)
|
||||||
return; // Anything that was here will be unanchored anyways.
|
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>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user