]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix decal draw-order (#22953)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Sat, 30 Dec 2023 16:12:39 +0000 (03:12 +1100)
committerGitHub <noreply@github.com>
Sat, 30 Dec 2023 16:12:39 +0000 (03:12 +1100)
* Fix decal draw-order

Using the new overlayspace ensures they don't draw above grids above them.

* a

Content.Client/Decals/Overlays/DecalOverlay.cs

index 6fcd48264bad608a011d7cc85668dba7cfef87a3..60b24c154b5e9b7f81bfbfad6c069dc58f5e1fbd 100644 (file)
@@ -2,18 +2,17 @@ using Content.Shared.Decals;
 using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
 using Robust.Shared.Enums;
+using Robust.Shared.Map;
 using Robust.Shared.Prototypes;
 
 namespace Content.Client.Decals.Overlays
 {
-    public sealed class DecalOverlay : Overlay
+    public sealed class DecalOverlay : GridOverlay
     {
         private readonly SpriteSystem _sprites;
         private readonly IEntityManager _entManager;
         private readonly IPrototypeManager _prototypeManager;
 
-        public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities;
-
         private readonly Dictionary<string, (Texture Texture, bool SnapCardinals)> _cachedTextures = new(64);
 
         public DecalOverlay(
@@ -28,52 +27,58 @@ namespace Content.Client.Decals.Overlays
 
         protected override void Draw(in OverlayDrawArgs args)
         {
+            if (args.MapId == MapId.Nullspace)
+                return;
+
+            var grid = Grid;
+
+            if (!_entManager.TryGetComponent(grid, out DecalGridComponent? decalGrid) ||
+                !_entManager.TryGetComponent(grid, out TransformComponent? xform))
+            {
+                return;
+            }
+
+            if (xform.MapID != args.MapId)
+                return;
+
             // Shouldn't need to clear cached textures unless the prototypes get reloaded.
             var handle = args.WorldHandle;
             var xformSystem = _entManager.System<TransformSystem>();
             var eyeAngle = args.Viewport.Eye?.Rotation ?? Angle.Zero;
 
-            var gridQuery = _entManager.AllEntityQueryEnumerator<DecalGridComponent, TransformComponent>();
+            var zIndexDictionary = decalGrid.DecalRenderIndex;
 
-            while (gridQuery.MoveNext(out var decalGrid, out var xform))
-            {
-                if (xform.MapID != args.MapId)
-                    continue;
+            if (zIndexDictionary.Count == 0)
+                return;
 
-                var zIndexDictionary = decalGrid.DecalRenderIndex;
+            var (_, worldRot, worldMatrix) = xformSystem.GetWorldPositionRotationMatrix(xform);
 
-                if (zIndexDictionary.Count == 0)
-                    continue;
+            handle.SetTransform(worldMatrix);
 
-                var (_, worldRot, worldMatrix) = xformSystem.GetWorldPositionRotationMatrix(xform);
+            foreach (var decals in zIndexDictionary.Values)
+            {
+                foreach (var decal in decals.Values)
+                {
+                    if (!_cachedTextures.TryGetValue(decal.Id, out var cache) && _prototypeManager.TryIndex<DecalPrototype>(decal.Id, out var decalProto))
+                    {
+                        cache = (_sprites.Frame0(decalProto.Sprite), decalProto.SnapCardinals);
+                        _cachedTextures[decal.Id] = cache;
+                    }
 
-                handle.SetTransform(worldMatrix);
+                    var cardinal = Angle.Zero;
 
-                foreach (var decals in zIndexDictionary.Values)
-                {
-                    foreach (var decal in decals.Values)
+                    if (cache.SnapCardinals)
                     {
-                        if (!_cachedTextures.TryGetValue(decal.Id, out var cache) && _prototypeManager.TryIndex<DecalPrototype>(decal.Id, out var decalProto))
-                        {
-                            cache = (_sprites.Frame0(decalProto.Sprite), decalProto.SnapCardinals);
-                            _cachedTextures[decal.Id] = cache;
-                        }
-
-                        var cardinal = Angle.Zero;
-
-                        if (cache.SnapCardinals)
-                        {
-                            var worldAngle = eyeAngle + worldRot;
-                            cardinal = worldAngle.GetCardinalDir().ToAngle();
-                        }
-
-                        var angle = decal.Angle - cardinal;
-
-                        if (angle.Equals(Angle.Zero))
-                            handle.DrawTexture(cache.Texture, decal.Coordinates, decal.Color);
-                        else
-                            handle.DrawTexture(cache.Texture, decal.Coordinates, angle, decal.Color);
+                        var worldAngle = eyeAngle + worldRot;
+                        cardinal = worldAngle.GetCardinalDir().ToAngle();
                     }
+
+                    var angle = decal.Angle - cardinal;
+
+                    if (angle.Equals(Angle.Zero))
+                        handle.DrawTexture(cache.Texture, decal.Coordinates, decal.Color);
+                    else
+                        handle.DrawTexture(cache.Texture, decal.Coordinates, angle, decal.Color);
                 }
             }