From 9db92ed8baed6e0ae5e9adfcefa9860b77e7ab91 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Aug 2010 20:23:14 +1200 Subject: [PATCH] Shift the nasty bits of map loading into ModData --- OpenRA.Game/Game.cs | 21 +++------------------ OpenRA.Game/ModData.cs | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index d23d191cfb..1b05cd8591 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -50,28 +50,13 @@ namespace OpenRA public static Session LobbyInfo = new Session(); static bool mapChangePending; - static void LoadMap(string mapName) + static void LoadMap(string uid) { - Timer.Time("----LoadMap"); - modData = new ModData( LobbyInfo.GlobalSettings.Mods ); - Timer.Time("manifest: {0}"); - - if (!modData.AvailableMaps.ContainsKey(mapName)) - throw new InvalidDataException("Cannot find map with Uid {0}".F(mapName)); - - var map = new Map(modData.AvailableMaps[mapName].Package); - + var map = modData.PrepareMap(uid); + viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, Renderer); world = null; // trying to access the old world will NRE, rather than silently doing it wrong. Timer.Time("viewport: {0}"); - - Rules.LoadRules(modData.Manifest,map); - Timer.Time( "load rules: {0}" ); - - SpriteSheetBuilder.Initialize( Rules.TileSets[map.Tileset] ); - SequenceProvider.Initialize(modData.Manifest.Sequences); - Timer.Time("SeqProv: {0}"); - world = new World(modData.Manifest, map); Timer.Time("world: {0}"); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index b9be026b11..781ef9cd1d 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -5,6 +5,7 @@ using System.Text; using OpenRA.FileFormats; using OpenRA.Graphics; using System.IO; +using OpenRA.Support; namespace OpenRA { @@ -30,7 +31,7 @@ namespace OpenRA } // TODO: Do this nicer - static Dictionary FindMaps(string[] mods) + Dictionary FindMaps(string[] mods) { var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/")) .Where(p => Directory.Exists(p)) @@ -38,5 +39,24 @@ namespace OpenRA return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid); } + + public Map PrepareMap(string uid) + { + Timer.Time("----PrepareMap"); + var map = new Map(AvailableMaps[uid].Package); + Timer.Time( "Map: {0}" ); + + if (!AvailableMaps.ContainsKey(uid)) + throw new InvalidDataException("Invalid map uid: {0}".F(uid)); + + Rules.LoadRules(Manifest, map); + Timer.Time( "Rules: {0}" ); + + SpriteSheetBuilder.Initialize( Rules.TileSets[map.Tileset] ); + SequenceProvider.Initialize(Manifest.Sequences); + Timer.Time("SSB, SeqProv: {0}"); + + return map; + } } }