From d0077b4ff2c5cc777f3d113d3380933d04e5ba3d Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Fri, 25 Mar 2022 13:18:15 +1100 Subject: [PATCH] Reduce decal allocs take 3 (#7243) --- Content.Client/Decals/DecalOverlay.cs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Content.Client/Decals/DecalOverlay.cs b/Content.Client/Decals/DecalOverlay.cs index a107c0bd7f..5834232516 100644 --- a/Content.Client/Decals/DecalOverlay.cs +++ b/Content.Client/Decals/DecalOverlay.cs @@ -39,17 +39,7 @@ namespace Content.Client.Decals { var handle = args.WorldHandle; - Dictionary cachedTextures = new(); - - SpriteSpecifier GetSpriteSpecifier(string id) - { - if (cachedTextures.TryGetValue(id, out var spriteSpecifier)) - return spriteSpecifier; - - spriteSpecifier = _prototypeManager.Index(id).Sprite; - cachedTextures.Add(id, spriteSpecifier); - return spriteSpecifier; - } + Dictionary cachedTextures = new(); var xformQuery = _entManager.GetEntityQuery(); @@ -58,18 +48,23 @@ namespace Content.Client.Decals var gridUid = _mapManager.GetGridEuid(gridId); var xform = xformQuery.GetComponent(gridUid); - handle.SetTransform(_transform.GetWorldMatrix(xform)); + handle.SetTransform(_transform.GetWorldMatrix(xform, xformQuery)); foreach (var (_, decals) in zIndexDictionary) { foreach (var (_, decal) in decals) { - var spriteSpecifier = GetSpriteSpecifier(decal.Id); + if (!cachedTextures.TryGetValue(decal.Id, out var texture)) + { + var sprite = _prototypeManager.Index(decal.Id).Sprite; + texture = _sprites.Frame0(sprite); + cachedTextures[decal.Id] = texture; + } if (decal.Angle.Equals(Angle.Zero)) - handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Color); + handle.DrawTexture(texture, decal.Coordinates, decal.Color); else - handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Angle, decal.Color); + handle.DrawTexture(texture, decal.Coordinates, decal.Angle, decal.Color); } } }