From df6159f12b50081bd13f12e44e616fb7a5be32e9 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Wed, 14 May 2014 23:56:00 +0300 Subject: [PATCH] Do not use the map's rules when rendering the minimap in the map chooser Using the mod's rules is *a lot* faster because we don't have to load each map's rules. --- OpenRA.Editor/Form1.cs | 4 ++-- OpenRA.Editor/MapSelect.cs | 2 +- OpenRA.Game/Graphics/Minimap.cs | 11 ++++++++--- OpenRA.Game/Map/MapCache.cs | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/OpenRA.Editor/Form1.cs b/OpenRA.Editor/Form1.cs index f93a637719..d557ce85e9 100644 --- a/OpenRA.Editor/Form1.cs +++ b/OpenRA.Editor/Form1.cs @@ -70,7 +70,7 @@ namespace OpenRA.Editor { MakeDirty(); var tileSet = Program.Rules.TileSets[surface1.Map.Tileset]; - miniMapBox.Image = Minimap.AddStaticResources(tileSet, surface1.Map, Minimap.TerrainBitmap(tileSet, surface1.Map, true)); + miniMapBox.Image = Minimap.RenderMapPreview(tileSet, surface1.Map, true); cashToolStripStatusLabel.Text = CalculateTotalResource().ToString(); } @@ -288,7 +288,7 @@ namespace OpenRA.Editor p.ResumeLayout(); } - miniMapBox.Image = Minimap.AddStaticResources(tileset, surface1.Map, Minimap.TerrainBitmap(tileset, surface1.Map, true)); + miniMapBox.Image = Minimap.RenderMapPreview(tileset, surface1.Map, true); propertiesToolStripMenuItem.Enabled = true; toolStripMenuItemProperties.Enabled = true; diff --git a/OpenRA.Editor/MapSelect.cs b/OpenRA.Editor/MapSelect.cs index 5739d433b7..5d9388474f 100644 --- a/OpenRA.Editor/MapSelect.cs +++ b/OpenRA.Editor/MapSelect.cs @@ -76,7 +76,7 @@ namespace OpenRA.Editor try { var tileset = Program.Rules.TileSets[map.Tileset]; - MiniMapBox.Image = Minimap.AddStaticResources(tileset, map, Minimap.TerrainBitmap(tileset, map, true)); + MiniMapBox.Image = Minimap.RenderMapPreview(tileset, map, true); } catch (Exception ed) { diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 8105a073c6..dad6b63348 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -55,7 +55,7 @@ namespace OpenRA.Graphics // Add the static resources defined in the map; if the map lives // in a world use AddCustomTerrain instead - public static Bitmap AddStaticResources(TileSet tileset, Map map, Bitmap terrainBitmap) + static Bitmap AddStaticResources(TileSet tileset, Map map, Ruleset resourceRules, Bitmap terrainBitmap) { Bitmap terrain = new Bitmap(terrainBitmap); @@ -74,7 +74,7 @@ namespace OpenRA.Graphics if (map.MapResources.Value[mapX, mapY].Type == 0) continue; - var res = map.Rules.Actors["world"].Traits.WithInterface() + var res = resourceRules.Actors["world"].Traits.WithInterface() .Where(t => t.ResourceType == map.MapResources.Value[mapX, mapY].Type) .Select(t => t.TerrainType).FirstOrDefault(); if (res == null) @@ -179,9 +179,14 @@ namespace OpenRA.Graphics } public static Bitmap RenderMapPreview(TileSet tileset, Map map, bool actualSize) + { + return RenderMapPreview(tileset, map, map.Rules, actualSize); + } + + public static Bitmap RenderMapPreview(TileSet tileset, Map map, Ruleset resourceRules, bool actualSize) { Bitmap terrain = TerrainBitmap(tileset, map, actualSize); - return AddStaticResources(tileset, map, terrain); + return AddStaticResources(tileset, map, resourceRules, terrain); } } } diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 0af6d30509..449bc6996c 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -149,7 +149,7 @@ namespace OpenRA // the next render cycle. // (d) Any partially written bytes from the next minimap is in an // unallocated area, and will be committed in the next cycle. - var bitmap = p.CustomPreview ?? Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, true); + var bitmap = p.CustomPreview ?? Minimap.RenderMapPreview(modData.DefaultRules.TileSets[p.Map.Tileset], p.Map, modData.DefaultRules, true); p.Minimap = sheetBuilder.Add(bitmap); lock (syncRoot)