Optimise decal allocs (#7550)

I saw it at the time but didn't think it'd be as big of a deal as it is.
This commit is contained in:
metalgearsloth
2022-04-14 17:10:32 +10:00
committed by GitHub
parent ba75934512
commit 859ba303fc

View File

@@ -19,6 +19,8 @@ namespace Content.Client.Decals
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowEntities;
private readonly Dictionary<string, Texture> _cachedTextures = new(64);
public DecalOverlay(
DecalSystem decals,
SharedTransformSystem transforms,
@@ -37,10 +39,8 @@ namespace Content.Client.Decals
protected override void Draw(in OverlayDrawArgs args)
{
// Shouldn't need to clear cached textures unless the prototypes get reloaded.
var handle = args.WorldHandle;
Dictionary<string, Texture> cachedTextures = new();
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
foreach (var (gridId, zIndexDictionary) in _decals.DecalRenderIndex)
@@ -54,11 +54,11 @@ namespace Content.Client.Decals
{
foreach (var (_, decal) in decals)
{
if (!cachedTextures.TryGetValue(decal.Id, out var texture))
if (!_cachedTextures.TryGetValue(decal.Id, out var texture))
{
var sprite = GetDecalSprite(decal.Id);
texture = _sprites.Frame0(sprite);
cachedTextures[decal.Id] = texture;
_cachedTextures[decal.Id] = texture;
}
if (decal.Angle.Equals(Angle.Zero))