From fceb8a479d13c9cede4c80c34fd68da3f4e22376 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 2 Mar 2025 14:00:40 +0000 Subject: [PATCH] Allow maps to be loaded directly, bypassing the MapCache. --- OpenRA.Game/Game.cs | 26 ++++++++++++++++++++++---- OpenRA.Game/ModData.cs | 9 +-------- OpenRA.Game/World.cs | 5 ++--- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 67350f50a4..fca786f774 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -181,7 +181,16 @@ namespace OpenRA public static event Action BeforeGameStart = () => { }; public static event Action AfterGameStart = () => { }; - internal static void StartGame(string mapUID, WorldType type) + internal static void StartGame(string uid, WorldType type) + { + var preview = ModData.MapCache[uid]; + if (preview.Status != MapStatus.Available) + throw new InvalidDataException($"Invalid map uid: {uid}"); + + StartGame(preview.ToMap(), type); + } + + internal static void StartGame(Map map, WorldType type) { // Dispose of the old world before creating a new one. worldRenderer?.Dispose(); @@ -190,7 +199,10 @@ namespace OpenRA BeforeGameStart(); using (new PerfTimer("NewWorld")) - OrderManager.World = new World(mapUID, ModData, OrderManager, type); + { + ModData.PrepareMap(map); + OrderManager.World = new World(map, ModData, OrderManager, type); + } OrderManager.World.GameOver += FinishBenchmark; @@ -507,10 +519,16 @@ namespace OpenRA ModData.LoadScreen.StartGame(args); } - public static void LoadEditor(string mapUid) + public static void LoadEditor(string uid) { JoinLocal(); - StartGame(mapUid, WorldType.Editor); + StartGame(uid, WorldType.Editor); + } + + public static void LoadEditor(Map map) + { + JoinLocal(); + StartGame(map, WorldType.Editor); } public static void LoadShellMap() diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 13b2f23aba..32a7ffc15f 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -12,7 +12,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.IO; using System.Linq; using OpenRA.FileSystem; using OpenRA.Graphics; @@ -141,15 +140,11 @@ namespace OpenRA public IEnumerable Languages { get; } - public Map PrepareMap(string uid) + public void PrepareMap(Map map) { LoadScreen?.Display(); - if (MapCache[uid].Status != MapStatus.Available) - throw new InvalidDataException($"Invalid map uid: {uid}"); - // Reinitialize all our assets - var map = MapCache[uid].ToMap(); InitializeLoaders(map); map.Sequences.LoadSprites(); @@ -157,8 +152,6 @@ namespace OpenRA using (new Support.PerfTimer("Map.Music")) foreach (var entry in map.Rules.Music) entry.Value.Load(map); - - return map; } public List[] GetRulesYaml() diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index c026b80be8..e343452055 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -188,13 +188,12 @@ namespace OpenRA bool wasLoadingGameSave; - internal World(string mapUID, ModData modData, OrderManager orderManager, WorldType type) + internal World(Map map, ModData modData, OrderManager orderManager, WorldType type) { this.modData = modData; Type = type; OrderManager = orderManager; - using (new PerfTimer("PrepareMap")) - Map = modData.PrepareMap(mapUID); + Map = map; if (string.IsNullOrEmpty(modData.Manifest.DefaultOrderGenerator)) throw new InvalidDataException("mod.yaml must define a DefaultOrderGenerator");