Reduce decal allocs take 3 (#7243)

This commit is contained in:
metalgearsloth
2022-03-25 13:18:15 +11:00
committed by GitHub
parent 021d39be28
commit d0077b4ff2

View File

@@ -39,17 +39,7 @@ namespace Content.Client.Decals
{ {
var handle = args.WorldHandle; var handle = args.WorldHandle;
Dictionary<string, SpriteSpecifier> cachedTextures = new(); Dictionary<string, Texture> cachedTextures = new();
SpriteSpecifier GetSpriteSpecifier(string id)
{
if (cachedTextures.TryGetValue(id, out var spriteSpecifier))
return spriteSpecifier;
spriteSpecifier = _prototypeManager.Index<DecalPrototype>(id).Sprite;
cachedTextures.Add(id, spriteSpecifier);
return spriteSpecifier;
}
var xformQuery = _entManager.GetEntityQuery<TransformComponent>(); var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
@@ -58,18 +48,23 @@ namespace Content.Client.Decals
var gridUid = _mapManager.GetGridEuid(gridId); var gridUid = _mapManager.GetGridEuid(gridId);
var xform = xformQuery.GetComponent(gridUid); var xform = xformQuery.GetComponent(gridUid);
handle.SetTransform(_transform.GetWorldMatrix(xform)); handle.SetTransform(_transform.GetWorldMatrix(xform, xformQuery));
foreach (var (_, decals) in zIndexDictionary) foreach (var (_, decals) in zIndexDictionary)
{ {
foreach (var (_, decal) in decals) foreach (var (_, decal) in decals)
{ {
var spriteSpecifier = GetSpriteSpecifier(decal.Id); if (!cachedTextures.TryGetValue(decal.Id, out var texture))
{
var sprite = _prototypeManager.Index<DecalPrototype>(decal.Id).Sprite;
texture = _sprites.Frame0(sprite);
cachedTextures[decal.Id] = texture;
}
if (decal.Angle.Equals(Angle.Zero)) if (decal.Angle.Equals(Angle.Zero))
handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Color); handle.DrawTexture(texture, decal.Coordinates, decal.Color);
else else
handle.DrawTexture(_sprites.Frame0(spriteSpecifier), decal.Coordinates, decal.Angle, decal.Color); handle.DrawTexture(texture, decal.Coordinates, decal.Angle, decal.Color);
} }
} }
} }