Defer grid state handling TileChangedEvent (#5981)

Rather than doing the old raise-event-per-tile we just raise it at the end.
This commit is contained in:
metalgearsloth
2025-05-29 09:21:45 +10:00
committed by GitHub
parent 8c35c2c380
commit af08e747de

View File

@@ -338,6 +338,8 @@ public abstract partial class SharedMapSystem
chunk.SuppressCollisionRegeneration = true;
DebugTools.Assert(data.TileData.Any(x => !x.IsEmpty));
DebugTools.Assert(data.TileData.Length == component.ChunkSize * component.ChunkSize);
var changedEntry = new ValueList<TileChangedEntry>();
for (ushort x = 0; x < component.ChunkSize; x++)
{
for (ushort y = 0; y < component.ChunkSize; y++)
@@ -346,12 +348,15 @@ public abstract partial class SharedMapSystem
if (!chunk.TrySetTile(x, y, tile, out var oldTile, out _))
continue;
var gridIndices = chunk.ChunkTileToGridTile((x, y));
var newTileRef = new TileRef(uid, gridIndices, tile);
_mapInternal.RaiseOnTileChanged(gridEnt, newTileRef, oldTile, index);
var chunkIndex = new Vector2i(x, y);
var gridIndices = chunk.ChunkTileToGridTile(chunkIndex);
changedEntry.Add(new TileChangedEntry(tile, oldTile, chunk.Indices, gridIndices));
}
}
var ev = new TileChangedEvent(gridEnt, changedEntry.ToArray());
EntityManager.EventBus.RaiseLocalEvent(gridEnt.Owner, ref ev, true);
DebugTools.Assert(chunk.Fixtures.SetEquals(data.Fixtures));
// These should never refer to the same object