Shift the nasty bits of map loading into ModData

This commit is contained in:
Paul Chote
2010-08-21 20:23:14 +12:00
parent 4e2d76f6ed
commit 9db92ed8ba
2 changed files with 24 additions and 19 deletions

View File

@@ -50,28 +50,13 @@ namespace OpenRA
public static Session LobbyInfo = new Session(); public static Session LobbyInfo = new Session();
static bool mapChangePending; static bool mapChangePending;
static void LoadMap(string mapName) static void LoadMap(string uid)
{ {
Timer.Time("----LoadMap"); var map = modData.PrepareMap(uid);
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);
viewport = new Viewport(clientSize, map.TopLeft, map.BottomRight, Renderer); 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. world = null; // trying to access the old world will NRE, rather than silently doing it wrong.
Timer.Time("viewport: {0}"); 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); world = new World(modData.Manifest, map);
Timer.Time("world: {0}"); Timer.Time("world: {0}");

View File

@@ -5,6 +5,7 @@ using System.Text;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using System.IO; using System.IO;
using OpenRA.Support;
namespace OpenRA namespace OpenRA
{ {
@@ -30,7 +31,7 @@ namespace OpenRA
} }
// TODO: Do this nicer // TODO: Do this nicer
static Dictionary<string, MapStub> FindMaps(string[] mods) Dictionary<string, MapStub> FindMaps(string[] mods)
{ {
var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/")) var paths = new[] { "maps/" }.Concat(mods.Select(m => "mods/" + m + "/maps/"))
.Where(p => Directory.Exists(p)) .Where(p => Directory.Exists(p))
@@ -38,5 +39,24 @@ namespace OpenRA
return paths.Select(p => new MapStub(new Folder(p))).ToDictionary(m => m.Uid); 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;
}
} }
} }