Fix disappearing decals bug (#9608)

This commit is contained in:
Leon Friedrich
2022-07-15 14:33:11 +12:00
committed by GitHub
parent 21fca0f6e3
commit 72599e5282
6 changed files with 204 additions and 90 deletions

View File

@@ -0,0 +1,58 @@
using JetBrains.Annotations;
using Robust.Client.Graphics;
using Robust.Shared.Console;
namespace Content.Client.Commands;
[UsedImplicitly]
public sealed class ZoomCommand : IConsoleCommand
{
[Dependency] private readonly IEyeManager _eyeMan = default!;
public string Command => "zoom";
public string Description => Loc.GetString("zoom-command-description");
public string Help => Loc.GetString("zoom-command-help");
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
Vector2 zoom;
if (args.Length is not (1 or 2))
{
shell.WriteLine(Help);
return;
}
if (!float.TryParse(args[0], out var arg0))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[0])));
return;
}
if (arg0 > 0)
zoom = new(arg0, arg0);
else
{
shell.WriteError(Loc.GetString("zoom-command-error"));
return;
}
if (args.Length == 2)
{
if (!float.TryParse(args[1], out var arg1))
{
shell.WriteError(Loc.GetString("cmd-parse-failure-float", ("arg", args[1])));
return;
}
if (arg1 > 0)
zoom.Y = arg1;
else
{
shell.WriteError(Loc.GetString("zoom-command-error"));
return;
}
}
_eyeMan.CurrentEye.Zoom = zoom;
}
}

View File

@@ -1,6 +1,7 @@
using Content.Shared.Decals;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Utility;
namespace Content.Client.Decals
{
@@ -12,7 +13,7 @@ namespace Content.Client.Decals
private DecalOverlay _overlay = default!;
public Dictionary<EntityUid, SortedDictionary<int, SortedDictionary<uint, Decal>>> DecalRenderIndex = new();
private Dictionary<EntityUid, Dictionary<uint, int>> DecalZIndexIndex = new();
private Dictionary<EntityUid, Dictionary<uint, int>> _decalZIndexIndex = new();
public override void Initialize()
{
@@ -41,13 +42,13 @@ namespace Content.Client.Decals
private void OnGridRemoval(GridRemovalEvent ev)
{
DecalRenderIndex.Remove(ev.EntityUid);
DecalZIndexIndex.Remove(ev.EntityUid);
_decalZIndexIndex.Remove(ev.EntityUid);
}
private void OnGridInitialize(GridInitializeEvent ev)
{
DecalRenderIndex[ev.EntityUid] = new();
DecalZIndexIndex[ev.EntityUid] = new();
_decalZIndexIndex[ev.EntityUid] = new();
}
public override void Shutdown()
@@ -64,25 +65,34 @@ namespace Content.Client.Decals
private void RemoveDecalFromRenderIndex(EntityUid gridId, uint uid)
{
var zIndex = DecalZIndexIndex[gridId][uid];
var zIndex = _decalZIndexIndex[gridId][uid];
DecalRenderIndex[gridId][zIndex].Remove(uid);
if (DecalRenderIndex[gridId][zIndex].Count == 0)
DecalRenderIndex[gridId].Remove(zIndex);
DecalZIndexIndex[gridId].Remove(uid);
_decalZIndexIndex[gridId].Remove(uid);
}
private void OnChunkUpdate(DecalChunkUpdateEvent ev)
{
foreach (var (gridId, gridChunks) in ev.Data)
foreach (var (gridId, updatedGridChunks) in ev.Data)
{
if (gridChunks.Count == 0) continue;
if (updatedGridChunks.Count == 0) continue;
var chunkCollection = ChunkCollection(gridId);
if (!TryComp(gridId, out DecalGridComponent? gridComp))
{
Logger.Error($"Received decal information for an entity without a decal component: {ToPrettyString(gridId)}");
continue;
}
var chunkCollection = gridComp.ChunkCollection.ChunkCollection;
var chunkIndex = ChunkIndex[gridId];
var renderIndex = DecalRenderIndex[gridId];
var zIndexIndex = _decalZIndexIndex[gridId];
// Update any existing data / remove decals we didn't receive data for.
foreach (var (indices, newChunkData) in gridChunks)
foreach (var (indices, newChunkData) in updatedGridChunks)
{
if (chunkCollection.TryGetValue(indices, out var chunk))
{
@@ -90,30 +100,21 @@ namespace Content.Client.Decals
removedUids.ExceptWith(newChunkData.Keys);
foreach (var removedUid in removedUids)
{
RemoveDecalInternal(gridId, removedUid);
RemoveDecalHook(gridId, removedUid);
chunkIndex.Remove(removedUid);
}
}
chunkCollection[indices] = newChunkData;
}
else
{
chunkCollection.Add(indices, newChunkData);
}
chunkCollection[indices] = newChunkData;
foreach (var (uid, decal) in newChunkData)
{
if (!DecalRenderIndex[gridId].ContainsKey(decal.ZIndex))
DecalRenderIndex[gridId][decal.ZIndex] = new();
{
if (zIndexIndex.TryGetValue(uid, out var zIndex))
renderIndex[zIndex].Remove(uid);
if (DecalZIndexIndex.TryGetValue(gridId, out var values) &&
values.TryGetValue(uid, out var zIndex))
{
DecalRenderIndex[gridId][zIndex].Remove(uid);
}
DecalRenderIndex[gridId][decal.ZIndex][uid] = decal;
DecalZIndexIndex[gridId][uid] = decal.ZIndex;
ChunkIndex[gridId][uid] = indices;
renderIndex.GetOrNew(decal.ZIndex)[uid] = decal;
zIndexIndex[uid] = decal.ZIndex;
chunkIndex[uid] = indices;
}
}
}
@@ -123,7 +124,14 @@ namespace Content.Client.Decals
{
if (chunks.Count == 0) continue;
var chunkCollection = ChunkCollection(gridId);
if (!TryComp(gridId, out DecalGridComponent? gridComp))
{
Logger.Error($"Received decal information for an entity without a decal component: {ToPrettyString(gridId)}");
continue;
}
var chunkCollection = gridComp.ChunkCollection.ChunkCollection;
var chunkIndex = ChunkIndex[gridId];
foreach (var index in chunks)
{
@@ -131,7 +139,8 @@ namespace Content.Client.Decals
foreach (var (uid, _) in chunk)
{
RemoveDecalInternal(gridId, uid);
RemoveDecalHook(gridId, uid);
chunkIndex.Remove(uid);
}
chunkCollection.Remove(index);