Decal fix (#21761)
- Don't send stale chunks for deleted grid as client just errors it anyway. - Store some allocations in fields.
This commit is contained in:
@@ -15,6 +15,9 @@ namespace Content.Client.Decals
|
|||||||
|
|
||||||
private DecalOverlay _overlay = default!;
|
private DecalOverlay _overlay = default!;
|
||||||
|
|
||||||
|
private HashSet<uint> _removedUids = new();
|
||||||
|
private readonly List<Vector2i> _removedChunks = new();
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
@@ -65,13 +68,14 @@ namespace Content.Client.Decals
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// is this a delta or full state?
|
// is this a delta or full state?
|
||||||
var removedChunks = new List<Vector2i>();
|
_removedChunks.Clear();
|
||||||
|
|
||||||
if (!state.FullState)
|
if (!state.FullState)
|
||||||
{
|
{
|
||||||
foreach (var key in gridComp.ChunkCollection.ChunkCollection.Keys)
|
foreach (var key in gridComp.ChunkCollection.ChunkCollection.Keys)
|
||||||
{
|
{
|
||||||
if (!state.AllChunks!.Contains(key))
|
if (!state.AllChunks!.Contains(key))
|
||||||
removedChunks.Add(key);
|
_removedChunks.Add(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -79,12 +83,12 @@ namespace Content.Client.Decals
|
|||||||
foreach (var key in gridComp.ChunkCollection.ChunkCollection.Keys)
|
foreach (var key in gridComp.ChunkCollection.ChunkCollection.Keys)
|
||||||
{
|
{
|
||||||
if (!state.Chunks.ContainsKey(key))
|
if (!state.Chunks.ContainsKey(key))
|
||||||
removedChunks.Add(key);
|
_removedChunks.Add(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (removedChunks.Count > 0)
|
if (_removedChunks.Count > 0)
|
||||||
RemoveChunks(gridUid, gridComp, removedChunks);
|
RemoveChunks(gridUid, gridComp, _removedChunks);
|
||||||
|
|
||||||
if (state.Chunks.Count > 0)
|
if (state.Chunks.Count > 0)
|
||||||
UpdateChunks(gridUid, gridComp, state.Chunks);
|
UpdateChunks(gridUid, gridComp, state.Chunks);
|
||||||
@@ -137,9 +141,10 @@ namespace Content.Client.Decals
|
|||||||
{
|
{
|
||||||
if (chunkCollection.TryGetValue(indices, out var chunk))
|
if (chunkCollection.TryGetValue(indices, out var chunk))
|
||||||
{
|
{
|
||||||
var removedUids = new HashSet<uint>(chunk.Decals.Keys);
|
_removedUids.Clear();
|
||||||
removedUids.ExceptWith(newChunkData.Decals.Keys);
|
_removedUids.UnionWith(chunk.Decals.Keys);
|
||||||
foreach (var removedUid in removedUids)
|
_removedUids.ExceptWith(newChunkData.Decals.Keys);
|
||||||
|
foreach (var removedUid in _removedUids)
|
||||||
{
|
{
|
||||||
OnDecalRemoved(gridId, removedUid, gridComp, indices, chunk);
|
OnDecalRemoved(gridId, removedUid, gridComp, indices, chunk);
|
||||||
gridComp.DecalIndex.Remove(removedUid);
|
gridComp.DecalIndex.Remove(removedUid);
|
||||||
@@ -166,7 +171,8 @@ namespace Content.Client.Decals
|
|||||||
|
|
||||||
foreach (var index in chunks)
|
foreach (var index in chunks)
|
||||||
{
|
{
|
||||||
if (!chunkCollection.TryGetValue(index, out var chunk)) continue;
|
if (!chunkCollection.TryGetValue(index, out var chunk))
|
||||||
|
continue;
|
||||||
|
|
||||||
foreach (var decalId in chunk.Decals.Keys)
|
foreach (var decalId in chunk.Decals.Keys)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -454,9 +454,7 @@ namespace Content.Server.Decals
|
|||||||
previouslySent.Remove(netGrid);
|
previouslySent.Remove(netGrid);
|
||||||
|
|
||||||
// Was the grid deleted?
|
// Was the grid deleted?
|
||||||
if (!TryGetEntity(netGrid, out var gridId) || !MapManager.IsGrid(gridId.Value))
|
if (TryGetEntity(netGrid, out var gridId) && !MapManager.IsGrid(gridId.Value))
|
||||||
staleChunks[netGrid] = oldIndices;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// If grid was deleted then don't worry about telling the client to delete the chunk.
|
// If grid was deleted then don't worry about telling the client to delete the chunk.
|
||||||
oldIndices.Clear();
|
oldIndices.Clear();
|
||||||
|
|||||||
Reference in New Issue
Block a user