Don't allocate empty sheets

This commit is contained in:
Gustas
2025-01-20 13:15:16 +02:00
committed by Paul Chote
parent 87cff1f6f1
commit cd9001e7b9
6 changed files with 19 additions and 7 deletions

View File

@@ -128,7 +128,7 @@ namespace OpenRA.Graphics
}
}
sheetBuilder.Current.ReleaseBuffer();
sheetBuilder.Current?.ReleaseBuffer();
hardwareCursorsDoubled = graphicSettings.CursorDouble;
}

View File

@@ -75,8 +75,6 @@ namespace OpenRA.Graphics
{
CurrentChannel = t == SheetType.Indexed ? TextureChannel.Red : TextureChannel.RGBA;
Type = t;
Current = allocateSheet();
sheets.Add(Current);
this.allocateSheet = allocateSheet;
this.margin = margin;
}
@@ -85,6 +83,12 @@ namespace OpenRA.Graphics
public Sprite Add(byte[] src, SpriteFrameType type, Size size, bool premultiplied = false) { return Add(src, type, size, 0, float3.Zero, premultiplied); }
public Sprite Add(byte[] src, SpriteFrameType type, Size size, float zRamp, in float3 spriteOffset, bool premultiplied = false)
{
if (Current == null)
{
Current = allocateSheet();
sheets.Add(Current);
}
// Don't bother allocating empty sprites
if (size.Width == 0 || size.Height == 0)
return new Sprite(Current, Rectangle.Empty, 0, spriteOffset, CurrentChannel, BlendMode.Alpha);
@@ -115,6 +119,12 @@ namespace OpenRA.Graphics
public Sprite Allocate(Size imageSize, float scale = 1f) { return Allocate(imageSize, 0, float3.Zero, scale); }
public Sprite Allocate(Size imageSize, float zRamp, in float3 spriteOffset, float scale = 1f)
{
if (Current == null)
{
Current = allocateSheet();
sheets.Add(Current);
}
if (imageSize.Width + p.X + margin > Current.Size.Width)
{
p = new int2(0, p.Y + rowHeight + margin);

View File

@@ -155,7 +155,7 @@ namespace OpenRA.Graphics
}
foreach (var sb in SheetBuilders.Values)
sb.Current.ReleaseBuffer();
sb.Current?.ReleaseBuffer();
}
public Sprite[] ResolveSprites(int token)

View File

@@ -340,7 +340,9 @@ namespace OpenRA
}
// Release the buffer by forcing changes to be written out to the texture, allowing the buffer to be reclaimed by GC.
Game.RunAfterTick(sheetBuilder.Current.ReleaseBuffer);
if (sheetBuilder.Current != null)
Game.RunAfterTick(sheetBuilder.Current.ReleaseBuffer);
Log.Write("debug", "MapCache.LoadAsyncInternal ended");
}

View File

@@ -228,7 +228,7 @@ namespace OpenRA.Mods.Cnc.Graphics
public void Finish()
{
sheetBuilder.Current.ReleaseBuffer();
sheetBuilder.Current?.ReleaseBuffer();
}
public void Dispose()

View File

@@ -145,7 +145,7 @@ namespace OpenRA.Mods.Common.Terrain
MissingTile = sheetBuilders[missingSheetType].Add(new byte[missingDataLength], missingFrameType, new Size(1, 1));
foreach (var sb in sheetBuilders.Values)
sb.Current.ReleaseBuffer();
sb.Current?.ReleaseBuffer();
}
public bool HasTileSprite(TerrainTile r, int? variant = null)