From 1218ca09ae746d143a04fb3e9f4e2414287593e1 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Thu, 22 Aug 2024 19:21:03 +0100 Subject: [PATCH] Use a smaller sheet in CursorManager. Provide an explicit size of 512, smaller than the default 2048. The cursors for all mods still pack onto this single sheet, so we avoid wasting memory on larger sheets. Sorting the cursors also helps pack them onto the sheets more efficiently. --- OpenRA.Game/Graphics/CursorManager.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Graphics/CursorManager.cs b/OpenRA.Game/Graphics/CursorManager.cs index 03bfbbca11..f311c17d1a 100644 --- a/OpenRA.Game/Graphics/CursorManager.cs +++ b/OpenRA.Game/Graphics/CursorManager.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Linq; using OpenRA.Primitives; namespace OpenRA.Graphics @@ -43,8 +44,11 @@ namespace OpenRA.Graphics hardwareCursorsDisabled = Game.Settings.Graphics.DisableHardwareCursors; graphicSettings = Game.Settings.Graphics; - sheetBuilder = new SheetBuilder(SheetType.BGRA); - foreach (var kv in cursorProvider.Cursors) + sheetBuilder = new SheetBuilder(SheetType.BGRA, 512); + + // Sort the cursors for better packing onto the sheet. + foreach (var kv in cursorProvider.Cursors + .OrderBy(kvp => kvp.Value.Frames.Max(f => f.Size.Height))) { var frames = kv.Value.Frames; var palette = !string.IsNullOrEmpty(kv.Value.Palette) ? cursorProvider.Palettes[kv.Value.Palette] : null;