From a71a5cc71d26c4e8d83806fb675db74bba182751 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 11 Nov 2017 18:38:53 +0000 Subject: [PATCH] Reduce the size of the sheets created for fonts. - A 512x512 sheet is about half full after precaching and some usage, but uses 16x less memory than the default 2048x2048 sheet. This saving occurs twice as we maintain a managed buffer for this sheet. - Only precache smaller fonts, as the larger fonts are less used and take up more space than is worthwhile. - Only precache in white, as red is largely unused. --- OpenRA.Game/Graphics/SpriteFont.cs | 4 ++-- OpenRA.Game/Renderer.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index ec0e770b3c..0137b0a308 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -49,8 +49,8 @@ namespace OpenRA.Graphics Func characterWidth = character => glyphs[Pair.New(character, Color.White)].Advance; lineWidth = line => line.Sum(characterWidth) / deviceScale; - PrecacheColor(Color.White, name); - PrecacheColor(Color.Red, name); + if (size <= 24) + PrecacheColor(Color.White, name); } public void SetScale(float scale) diff --git a/OpenRA.Game/Renderer.cs b/OpenRA.Game/Renderer.cs index 7e6b084b19..7bc5913376 100644 --- a/OpenRA.Game/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -84,7 +84,7 @@ namespace OpenRA { if (fontSheetBuilder != null) fontSheetBuilder.Dispose(); - fontSheetBuilder = new SheetBuilder(SheetType.BGRA); + fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512); Fonts = modData.Manifest.Fonts.ToDictionary(x => x.Key, x => new SpriteFont(x.Value.First, modData.DefaultFileSystem.Open(x.Value.First).ReadAllBytes(), x.Value.Second, Device.WindowScale, fontSheetBuilder)).AsReadOnly();