diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index e735281ce8..68455d1e2f 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -368,22 +368,7 @@ namespace OpenRA Settings.Game.Platform = p; try { - var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + p + ".dll"); - -#if NET5_0_OR_GREATER - var loader = new AssemblyLoader(rendererPath); - var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); - -#else - // NOTE: This is currently the only use of System.Reflection in this file, so would give an unused using error if we import it above - var assembly = System.Reflection.Assembly.LoadFile(rendererPath); - var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); -#endif - - if (platformType == null) - throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation."); - - var platform = (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null); + var platform = CreatePlatform(p); Renderer = new Renderer(platform, Settings.Graphics); Sound = new Sound(platform, Settings.Sound); @@ -440,6 +425,26 @@ namespace OpenRA InitializeMod(modID, args); } + public static IPlatform CreatePlatform(string platformName) + { + var rendererPath = Path.Combine(Platform.BinDir, "OpenRA.Platforms." + platformName + ".dll"); + +#if NET5_0_OR_GREATER + var loader = new AssemblyLoader(rendererPath); + var platformType = loader.LoadDefaultAssembly().GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); + +#else + // NOTE: This is currently the only use of System.Reflection in this file, so would give an unused using error if we import it above + var assembly = System.Reflection.Assembly.LoadFile(rendererPath); + var platformType = assembly.GetTypes().SingleOrDefault(t => typeof(IPlatform).IsAssignableFrom(t)); +#endif + + if (platformType == null) + throw new InvalidOperationException("Platform dll must include exactly one IPlatform implementation."); + + return (IPlatform)platformType.GetConstructor(Type.EmptyTypes).Invoke(null); + } + public static void InitializeMod(string mod, Arguments args) { // Clear static state if we have switched mods diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index a48ef63e8a..59f9051ae7 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -27,7 +27,7 @@ namespace OpenRA.Graphics float deviceScale; - public SpriteFont(string name, byte[] data, int size, int ascender, float scale, SheetBuilder builder) + public SpriteFont(IPlatform platform, string name, byte[] data, int size, int ascender, float scale, SheetBuilder builder) { if (builder.Type != SheetType.BGRA) throw new ArgumentException("The sheet builder must create BGRA sheets.", nameof(builder)); @@ -36,7 +36,7 @@ namespace OpenRA.Graphics this.size = size; this.builder = builder; - font = Game.Renderer.CreateFont(data); + font = platform.CreateFont(data); glyphs = new Cache(CreateGlyph); contrastGlyphs = new Cache<(char, int), Sprite>(CreateContrastGlyph); dilationElements = new Cache(CreateCircularWeightMap); diff --git a/OpenRA.Game/Renderer.cs b/OpenRA.Game/Renderer.cs index f5edf8180f..0e864e5311 100644 --- a/OpenRA.Game/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -134,8 +134,9 @@ namespace OpenRA fontSheetBuilder?.Dispose(); fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512); Fonts = modData.Manifest.Get().FontList.ToDictionary(x => x.Key, - x => new SpriteFont(x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(), - x.Value.Size, x.Value.Ascender, Window.EffectiveWindowScale, fontSheetBuilder)); + x => new SpriteFont( + platform, x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(), + x.Value.Size, x.Value.Ascender, Window.EffectiveWindowScale, fontSheetBuilder)); } Window.OnWindowScaleChanged += (oldNative, oldEffective, newNative, newEffective) => @@ -563,11 +564,6 @@ namespace OpenRA public string GLVersion => Context.GLVersion; - public IFont CreateFont(byte[] data) - { - return platform.CreateFont(data); - } - public int DisplayCount => Window.DisplayCount; public int CurrentDisplay => Window.CurrentDisplay;