Remove text caching from CncLoadScreen.

We have repeatedly failed at invalidating these
cached values when things change, so the small perf
win is not worth the hassle.
This commit is contained in:
Paul Chote
2020-03-24 09:43:02 +00:00
committed by reaperrr
parent 9c251e8b6a
commit a5b22e6a36

View File

@@ -25,15 +25,11 @@ namespace OpenRA.Mods.Cnc
Sprite[] border; Sprite[] border;
float2 nodPos, gdiPos, evaPos; float2 nodPos, gdiPos, evaPos;
Rectangle bounds; Rectangle bounds;
string versionText;
SpriteFont loadingFont, versionFont;
string loadingText, versionText;
float2 loadingPos, versionPos;
Sheet lastSheet; Sheet lastSheet;
int lastDensity; int lastDensity;
Size lastResolution; Size lastResolution;
IReadOnlyDictionary<string, SpriteFont> lastFonts;
public override void Init(ModData modData, Dictionary<string, string> info) public override void Init(ModData modData, Dictionary<string, string> info)
{ {
@@ -82,20 +78,6 @@ namespace OpenRA.Mods.Cnc
var barY = bounds.Height - 78; var barY = bounds.Height - 78;
// The fonts dictionary may change when switching between the mod and content installer
if (r.Fonts != lastFonts)
{
lastFonts = r.Fonts;
loadingFont = lastFonts["BigBold"];
loadingText = Info["Text"];
loadingPos = new float2((bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY);
versionFont = lastFonts["Regular"];
var versionSize = versionFont.Measure(versionText);
versionPos = new float2(bounds.Width - 107 - versionSize.X / 2, 115 - versionSize.Y / 2);
}
loadTick = ++loadTick % 8; loadTick = ++loadTick % 8;
r.RgbaSpriteRenderer.DrawSprite(gdiLogo, gdiPos); r.RgbaSpriteRenderer.DrawSprite(gdiLogo, gdiPos);
@@ -104,11 +86,18 @@ namespace OpenRA.Mods.Cnc
WidgetUtils.DrawPanel(bounds, border); WidgetUtils.DrawPanel(bounds, border);
if (loadingFont != null) if (r.Fonts != null)
{
var loadingFont = r.Fonts["BigBold"];
var loadingText = Info["Text"];
var loadingPos = new float2((bounds.Width - loadingFont.Measure(loadingText).X) / 2, barY);
loadingFont.DrawText(loadingText, loadingPos, Color.Gray); loadingFont.DrawText(loadingText, loadingPos, Color.Gray);
if (versionFont != null) var versionFont = r.Fonts["Regular"];
var versionSize = versionFont.Measure(versionText);
var versionPos = new float2(bounds.Width - 107 - versionSize.X / 2, 115 - versionSize.Y / 2);
versionFont.DrawTextWithContrast(versionText, versionPos, Color.White, Color.Black, 2); versionFont.DrawTextWithContrast(versionText, versionPos, Color.White, Color.Black, 2);
}
for (var i = 0; i <= 8; i++) for (var i = 0; i <= 8; i++)
{ {