diff --git a/OpenRA.Game/Cursor.cs b/OpenRA.Game/Cursor.cs index b38fdb6aaf..a67599cd23 100644 --- a/OpenRA.Game/Cursor.cs +++ b/OpenRA.Game/Cursor.cs @@ -20,9 +20,9 @@ namespace OpenRA sequence = CursorProvider.GetCursorSequence(cursor); } - public void Draw(WorldRenderer wr, int frame, float2 pos) + public void Draw(int frame, float2 pos) { - sequence.GetSprite(frame).DrawAt(wr, pos - sequence.Hotspot, sequence.Palette); + sequence.GetSprite(frame).DrawAt(pos - sequence.Hotspot, Game.modData.Palette.GetPaletteIndex(sequence.Palette)); } } } diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 1436dfd7e2..9ef4ea6c8a 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -109,7 +109,7 @@ namespace OpenRA } Tick( orderManager ); - if( orderManager.world != worldRenderer.world ) + if( worldRenderer != null && orderManager.world != worldRenderer.world ) Tick( worldRenderer.world.orderManager ); using (new PerfSample("render")) @@ -244,13 +244,16 @@ namespace OpenRA Console.WriteLine("Loading mods: {0}",string.Join(",",mods)); modData = new ModData( mods ); + modData.Sucks(); + Sound.Initialize(); PerfHistory.items["render"].hasNormalTick = false; PerfHistory.items["batches"].hasNormalTick = false; JoinLocal(); + viewport = new Viewport(new int2(Renderer.Resolution), Rectangle.Empty, Renderer); - StartGame(ChooseShellmap()); + //StartGame(ChooseShellmap()); // TODO: unhardcode this modData.WidgetLoader.LoadWidget( new Dictionary(), Widget.RootWidget, "PERF_BG" ); diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index e38b0fc12b..17f9368ed5 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -17,7 +17,7 @@ using OpenRA.Traits; namespace OpenRA.Graphics { - class HardwarePalette + public class HardwarePalette { public const int MaxPalettes = 64; int allocated = 0; @@ -26,7 +26,7 @@ namespace OpenRA.Graphics Dictionary palettes; Dictionary indices; - public HardwarePalette(Map map) + public HardwarePalette() { palettes = new Dictionary(); indices = new Dictionary(); diff --git a/OpenRA.Game/Graphics/SpriteLoader.cs b/OpenRA.Game/Graphics/SpriteLoader.cs index 27fe912771..570f8daf50 100644 --- a/OpenRA.Game/Graphics/SpriteLoader.cs +++ b/OpenRA.Game/Graphics/SpriteLoader.cs @@ -15,10 +15,10 @@ namespace OpenRA.Graphics { public class SpriteLoader { - public SpriteLoader( TileSet tileset, SheetBuilder sheetBuilder ) + public SpriteLoader( string[] exts, SheetBuilder sheetBuilder ) { - exts = tileset.Extensions; - SheetBuilder = sheetBuilder; + SheetBuilder = sheetBuilder; + this.exts = exts; sprites = new Cache( LoadSprites ); } diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 05a50a4d86..ddb01e0a07 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -84,11 +84,12 @@ namespace OpenRA.Graphics public void DrawRegions( WorldRenderer wr, IInputHandler inputHandler ) { renderer.BeginFrame(scrollPosition); + if (wr != null) + wr.Draw(); - wr.Draw(); Widget.DoDraw(); var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default"; - new Cursor(cursorName).Draw(wr, (int)cursorFrame, Viewport.LastMousePos + Location); + new Cursor(cursorName).Draw((int)cursorFrame, Viewport.LastMousePos + Location); renderer.EndFrame( inputHandler ); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index cbe8b6f776..f222f3c26e 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -33,7 +33,7 @@ namespace OpenRA.Graphics terrainRenderer = new TerrainRenderer(world, this); shroudRenderer = new ShroudRenderer(world); uiOverlay = new UiOverlay(); - palette = new HardwarePalette(world.Map); + this.palette = Game.modData.Palette; foreach( var pal in world.traitDict.ActorsWithTraitMultiple( world ) ) pal.Trait.InitPalette( this ); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 7b87cf9cf7..6bacc85464 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -1,121 +1,133 @@ -#region Copyright & License Information -/* - * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see LICENSE. - */ -#endregion - -using System.Collections.Generic; -using System.IO; -using System.Linq; -using OpenRA.FileFormats; -using OpenRA.Graphics; - -namespace OpenRA -{ - public class ModData - { - public readonly Manifest Manifest; - public readonly ObjectCreator ObjectCreator; - public readonly Dictionary AvailableMaps; - public readonly WidgetLoader WidgetLoader; - public ILoadScreen LoadScreen = null; - public SheetBuilder SheetBuilder; - public CursorSheetBuilder CursorSheetBuilder; - public SpriteLoader SpriteLoader; - - public ModData( params string[] mods ) - { - Manifest = new Manifest( mods ); - ObjectCreator = new ObjectCreator( Manifest ); - LoadScreen = ObjectCreator.CreateObject(Manifest.LoadScreen); - LoadScreen.Init(); - LoadScreen.Display(); - - // all this manipulation of static crap here is nasty and breaks - // horribly when you use ModData in unexpected ways. - - FileSystem.LoadFromManifest( Manifest ); - ChromeProvider.Initialize( Manifest.Chrome ); - SheetBuilder = new SheetBuilder( TextureChannel.Red ); - CursorSheetBuilder = new CursorSheetBuilder( this ); - AvailableMaps = FindMaps( mods ); - WidgetLoader = new WidgetLoader( this ); - } - - public static IEnumerable FindMapsIn(string dir) - { - string[] NoMaps = { }; - - if (!Directory.Exists(dir)) - return NoMaps; - - // todo: look for compressed maps too. - return Directory.GetDirectories(dir) - .Concat(Directory.GetFiles(dir, "*.zip")) - .Concat(Directory.GetFiles(dir, "*.oramap")); - } - - Dictionary FindMaps(string[] mods) - { - var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p))) - .Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Game.SupportDir, p)))); - - Dictionary ret = new Dictionary(); - foreach (var path in paths) - { - var map = new MapStub(path); - if (ret.ContainsKey(map.Uid)) - System.Console.WriteLine("Ignoring duplicate map: {0}", path); - else - ret.Add(map.Uid, map); - } - return ret; - } - - string cachedTileset = null; +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System.Collections.Generic; +using System.IO; +using System.Linq; +using OpenRA.FileFormats; +using OpenRA.Graphics; + +namespace OpenRA +{ + public class ModData + { + public readonly Manifest Manifest; + public readonly ObjectCreator ObjectCreator; + public readonly Dictionary AvailableMaps; + public readonly WidgetLoader WidgetLoader; + public ILoadScreen LoadScreen = null; + public SheetBuilder SheetBuilder; + public CursorSheetBuilder CursorSheetBuilder; + public SpriteLoader SpriteLoader; + public readonly HardwarePalette Palette; + + public ModData( params string[] mods ) + { + Manifest = new Manifest( mods ); + ObjectCreator = new ObjectCreator( Manifest ); + LoadScreen = ObjectCreator.CreateObject(Manifest.LoadScreen); + LoadScreen.Init(); + LoadScreen.Display(); + + AvailableMaps = FindMaps( Manifest.Mods ); + WidgetLoader = new WidgetLoader( this ); + Palette = new HardwarePalette(); + } + + public void Sucks() + { + // all this manipulation of static crap here is nasty and breaks + // horribly when you use ModData in unexpected ways. + + FileSystem.UnmountAll(); + foreach (var dir in Manifest.Folders) FileSystem.Mount(dir); + //foreach (var pkg in Manifest.Packages) FileSystem.Mount(pkg); + + Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false )); + ChromeProvider.Initialize( Manifest.Chrome ); + SheetBuilder = new SheetBuilder( TextureChannel.Red ); + CursorSheetBuilder = new CursorSheetBuilder( this ); + + SpriteLoader = new SpriteLoader(new[]{".shp"}, SheetBuilder); + CursorProvider.Initialize(Manifest.Cursors); + } + + public static IEnumerable FindMapsIn(string dir) + { + string[] NoMaps = { }; + + if (!Directory.Exists(dir)) + return NoMaps; + + return Directory.GetDirectories(dir) + .Concat(Directory.GetFiles(dir, "*.zip")) + .Concat(Directory.GetFiles(dir, "*.oramap")); + } + + Dictionary FindMaps(string[] mods) + { + var paths = mods.SelectMany(p => FindMapsIn("mods{0}{1}{0}maps{0}".F(Path.DirectorySeparatorChar, p))) + .Concat(mods.SelectMany(p => FindMapsIn("{1}maps{0}{2}{0}".F(Path.DirectorySeparatorChar, Game.SupportDir, p)))); + + Dictionary ret = new Dictionary(); + foreach (var path in paths) + { + var map = new MapStub(path); + if (ret.ContainsKey(map.Uid)) + System.Console.WriteLine("Ignoring duplicate map: {0}", path); + else + ret.Add(map.Uid, map); + } + return ret; + } + + string cachedTileset = null; bool previousMapHadSequences = true; - IFolder previousMapMount = null; - - public Map PrepareMap(string uid) - { - LoadScreen.Display(); - - if (!AvailableMaps.ContainsKey(uid)) - throw new InvalidDataException("Invalid map uid: {0}".F(uid)); - - var map = new Map(AvailableMaps[uid].Path); - - // unload the previous map mount if we have one - if (previousMapMount != null) FileSystem.Unmount(previousMapMount); - - // Adds the map its container to the FileSystem - // allowing the map to use custom assets - // Container should have the lowest priority of all (ie int max) - // Store a reference so we can unload it next time - previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); - FileSystem.Mount(previousMapMount); - Rules.LoadRules(Manifest, map); - - if (map.Tileset != cachedTileset - || previousMapHadSequences || map.Sequences.Count > 0) - { - SheetBuilder = new SheetBuilder( TextureChannel.Red ); - SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset], SheetBuilder); - CursorSheetBuilder = new CursorSheetBuilder( this ); - CursorProvider.Initialize(Manifest.Cursors); - SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); - cachedTileset = map.Tileset; - } - - previousMapHadSequences = map.Sequences.Count > 0; - - return map; - } - } - - public interface ILoadScreen { void Display(); void Init(); } -} + IFolder previousMapMount = null; + + public Map PrepareMap(string uid) + { + LoadScreen.Display(); + + if (!AvailableMaps.ContainsKey(uid)) + throw new InvalidDataException("Invalid map uid: {0}".F(uid)); + + var map = new Map(AvailableMaps[uid].Path); + + // unload the previous map mount if we have one + if (previousMapMount != null) FileSystem.Unmount(previousMapMount); + + // Adds the map its container to the FileSystem + // allowing the map to use custom assets + // Container should have the lowest priority of all (ie int max) + // Store a reference so we can unload it next time + previousMapMount = FileSystem.OpenPackage(map.Path, int.MaxValue); + FileSystem.Mount(previousMapMount); + Rules.LoadRules(Manifest, map); + + if (map.Tileset != cachedTileset + || previousMapHadSequences || map.Sequences.Count > 0) + { + SheetBuilder = new SheetBuilder( TextureChannel.Red ); + SpriteLoader = new SpriteLoader( Rules.TileSets[map.Tileset].Extensions, SheetBuilder ); + CursorSheetBuilder = new CursorSheetBuilder( this ); + CursorProvider.Initialize(Manifest.Cursors); + SequenceProvider.Initialize(Manifest.Sequences, map.Sequences); + cachedTileset = map.Tileset; + } + + previousMapHadSequences = map.Sequences.Count > 0; + + return map; + } + } + + public interface ILoadScreen { void Display(); void Init(); } +}