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