Decal rendering improvements (#6704)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Decals;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Client.Decals
|
||||
{
|
||||
public sealed class DecalSystem : SharedDecalSystem
|
||||
{
|
||||
[Dependency] private readonly IOverlayManager _overlayManager = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transforms = default!;
|
||||
[Dependency] private readonly SpriteSystem _sprites = default!;
|
||||
|
||||
private DecalOverlay _overlay = default!;
|
||||
public Dictionary<GridId, SortedDictionary<int, SortedDictionary<uint, Decal>>> DecalRenderIndex = new();
|
||||
@@ -19,7 +20,7 @@ namespace Content.Client.Decals
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
_overlay = new DecalOverlay(this, MapManager, PrototypeManager);
|
||||
_overlay = new DecalOverlay(this, _transforms, _sprites, EntityManager, MapManager, PrototypeManager);
|
||||
_overlayManager.AddOverlay(_overlay);
|
||||
|
||||
SubscribeNetworkEvent<DecalChunkUpdateEvent>(OnChunkUpdate);
|
||||
@@ -79,9 +80,10 @@ namespace Content.Client.Decals
|
||||
{
|
||||
foreach (var (gridId, gridChunks) in ev.Data)
|
||||
{
|
||||
var chunkCollection = ChunkCollection(gridId);
|
||||
|
||||
foreach (var (indices, newChunkData) in gridChunks)
|
||||
{
|
||||
var chunkCollection = ChunkCollection(gridId);
|
||||
if (chunkCollection.TryGetValue(indices, out var chunk))
|
||||
{
|
||||
var removedUids = new HashSet<uint>(chunk.Keys);
|
||||
@@ -91,12 +93,14 @@ namespace Content.Client.Decals
|
||||
RemoveDecalFromRenderIndex(gridId, removedUid);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var (uid, decal) in newChunkData)
|
||||
{
|
||||
if(!DecalRenderIndex[gridId].ContainsKey(decal.ZIndex))
|
||||
if (!DecalRenderIndex[gridId].ContainsKey(decal.ZIndex))
|
||||
DecalRenderIndex[gridId][decal.ZIndex] = new();
|
||||
|
||||
if (DecalZIndexIndex.TryGetValue(gridId, out var values) && values.TryGetValue(uid, out var zIndex))
|
||||
if (DecalZIndexIndex.TryGetValue(gridId, out var values) &&
|
||||
values.TryGetValue(uid, out var zIndex))
|
||||
{
|
||||
DecalRenderIndex[gridId][zIndex].Remove(uid);
|
||||
}
|
||||
@@ -106,8 +110,24 @@ namespace Content.Client.Decals
|
||||
|
||||
ChunkIndex[gridId][uid] = indices;
|
||||
}
|
||||
|
||||
chunkCollection[indices] = newChunkData;
|
||||
}
|
||||
|
||||
// Now we'll cull old chunks out of range as the server will send them to us anyway.
|
||||
var toRemove = new RemQueue<Vector2i>();
|
||||
|
||||
foreach (var (index, _) in chunkCollection)
|
||||
{
|
||||
if (gridChunks.ContainsKey(index)) continue;
|
||||
|
||||
toRemove.Add(index);
|
||||
}
|
||||
|
||||
foreach (var index in toRemove)
|
||||
{
|
||||
chunkCollection.Remove(index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user