Decal rendering improvements (#6704)
Co-authored-by: metalgearsloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.Decals;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
@@ -11,15 +10,27 @@ namespace Content.Client.Decals
|
||||
{
|
||||
public sealed class DecalOverlay : Overlay
|
||||
{
|
||||
private readonly DecalSystem _system;
|
||||
private readonly DecalSystem _decals;
|
||||
private readonly SharedTransformSystem _transform;
|
||||
private readonly SpriteSystem _sprites;
|
||||
private readonly IEntityManager _entManager;
|
||||
private readonly IMapManager _mapManager;
|
||||
private readonly IPrototypeManager _prototypeManager;
|
||||
|
||||
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities;
|
||||
|
||||
public DecalOverlay(DecalSystem system, IMapManager mapManager, IPrototypeManager prototypeManager)
|
||||
public DecalOverlay(
|
||||
DecalSystem decals,
|
||||
SharedTransformSystem transforms,
|
||||
SpriteSystem sprites,
|
||||
IEntityManager entManager,
|
||||
IMapManager mapManager,
|
||||
IPrototypeManager prototypeManager)
|
||||
{
|
||||
_system = system;
|
||||
_decals = decals;
|
||||
_transform = transforms;
|
||||
_sprites = sprites;
|
||||
_entManager = entManager;
|
||||
_mapManager = mapManager;
|
||||
_prototypeManager = prototypeManager;
|
||||
}
|
||||
@@ -40,16 +51,25 @@ namespace Content.Client.Decals
|
||||
return spriteSpecifier;
|
||||
}
|
||||
|
||||
foreach (var (gridId, zIndexDictionary) in _system.DecalRenderIndex)
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var (gridId, zIndexDictionary) in _decals.DecalRenderIndex)
|
||||
{
|
||||
var grid = _mapManager.GetGrid(gridId);
|
||||
handle.SetTransform(grid.WorldMatrix);
|
||||
var gridUid = _mapManager.GetGridEuid(gridId);
|
||||
var xform = xformQuery.GetComponent(gridUid);
|
||||
|
||||
handle.SetTransform(_transform.GetWorldMatrix(xform));
|
||||
|
||||
foreach (var (_, decals) in zIndexDictionary)
|
||||
{
|
||||
foreach (var (_, decal) in decals)
|
||||
{
|
||||
var spriteSpecifier = GetSpriteSpecifier(decal.Id);
|
||||
handle.DrawTexture(spriteSpecifier.Frame0(), decal.Coordinates, decal.Angle, decal.Color);
|
||||
|
||||
if (decal.Angle.Equals(Angle.Zero))
|
||||
handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Color);
|
||||
else
|
||||
handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Angle, decal.Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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