From 65df25b1a40a4927ab03801150baffb10f61b3fa Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 12 Mar 2016 21:23:32 +0000 Subject: [PATCH] Remove lazy loading of binary map data. --- OpenRA.Game/Graphics/TerrainRenderer.cs | 14 +- OpenRA.Game/Graphics/Viewport.cs | 3 +- OpenRA.Game/Map/Map.cs | 209 ++++++++---------- OpenRA.Game/Map/ProjectedCellRegion.cs | 4 +- .../ImportTiberianDawnLegacyMapCommand.cs | 4 +- .../EditorBrushes/EditorActorBrush.cs | 2 +- .../EditorBrushes/EditorCopyPasteBrush.cs | 6 +- .../EditorBrushes/EditorDefaultBrush.cs | 2 +- .../EditorBrushes/EditorResourceBrush.cs | 6 +- .../EditorBrushes/EditorTileBrush.cs | 8 +- OpenRA.Mods.Common/Effects/Missile.cs | 2 +- .../Traits/Buildings/BuildingUtils.cs | 2 +- .../Traits/Infantry/TerrainModifiesDamage.cs | 1 - .../Traits/Upgrades/DeployToUpgrade.cs | 3 +- .../Traits/World/BridgeLayer.cs | 8 +- .../Traits/World/EditorResourceLayer.cs | 8 +- .../Traits/World/ResourceLayer.cs | 4 +- .../Traits/World/TerrainGeometryOverlay.cs | 6 +- OpenRA.Mods.Common/Widgets/RadarWidget.cs | 6 +- .../UtilityCommands/D2kMapImporter.cs | 6 +- .../ImportRedAlertLegacyMapCommand.cs | 4 +- .../UtilityCommands/ImportTSMapCommand.cs | 16 +- 22 files changed, 141 insertions(+), 183 deletions(-) diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index eed581c7e8..4d82791cf7 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -20,15 +20,11 @@ namespace OpenRA.Graphics readonly Map map; readonly Dictionary spriteLayers = new Dictionary(); readonly Theater theater; - readonly CellLayer mapTiles; - readonly CellLayer mapHeight; public TerrainRenderer(World world, WorldRenderer wr) { map = world.Map; theater = wr.Theater; - mapTiles = map.MapTiles.Value; - mapHeight = map.MapHeight.Value; foreach (var template in map.Rules.TileSet.Templates) { @@ -40,13 +36,13 @@ namespace OpenRA.Graphics foreach (var cell in map.AllCells) UpdateCell(cell); - mapTiles.CellEntryChanged += UpdateCell; - mapHeight.CellEntryChanged += UpdateCell; + map.Tiles.CellEntryChanged += UpdateCell; + map.Height.CellEntryChanged += UpdateCell; } public void UpdateCell(CPos cell) { - var tile = mapTiles[cell]; + var tile = map.Tiles[cell]; var palette = TileSet.TerrainPaletteInternalName; if (map.Rules.TileSet.Templates.ContainsKey(tile.Type)) palette = map.Rules.TileSet.Templates[tile.Type].Palette ?? palette; @@ -67,8 +63,8 @@ namespace OpenRA.Graphics public void Dispose() { - mapTiles.CellEntryChanged -= UpdateCell; - mapHeight.CellEntryChanged -= UpdateCell; + map.Tiles.CellEntryChanged -= UpdateCell; + map.Height.CellEntryChanged -= UpdateCell; foreach (var kv in spriteLayers.Values) kv.Dispose(); diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 9e53dba07b..1408bc32cd 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -161,8 +161,7 @@ namespace OpenRA.Graphics var ramp = 0; if (map.Contains(uv)) { - var tile = map.MapTiles.Value[uv]; - var ti = tileSet.GetTileInfo(tile); + var ti = tileSet.GetTileInfo(map.Tiles[uv]); if (ti != null) ramp = ti.RampType; } diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 9fbcdef740..f9331c3e30 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -146,9 +146,9 @@ namespace OpenRA public int2 MapSize; - [FieldLoader.Ignore] public Lazy> MapTiles; - [FieldLoader.Ignore] public Lazy> MapResources; - [FieldLoader.Ignore] public Lazy> MapHeight; + [FieldLoader.Ignore] public CellLayer Tiles; + [FieldLoader.Ignore] public CellLayer Resources; + [FieldLoader.Ignore] public CellLayer Height; [FieldLoader.Ignore] public CellLayer CustomTerrain; [FieldLoader.Ignore] CellLayer cachedTerrainIndexes; @@ -192,25 +192,16 @@ namespace OpenRA // Will be dropped on save if nothing is added to it RuleDefinitions = new MiniYaml(""); - MapResources = Exts.Lazy(() => new CellLayer(Grid.Type, size)); - - MapTiles = Exts.Lazy(() => + Tiles = new CellLayer(Grid.Type, size); + Resources = new CellLayer(Grid.Type, size); + Height = new CellLayer(Grid.Type, size); + if (Grid.MaximumTerrainHeight > 0) { - var ret = new CellLayer(Grid.Type, size); - ret.Clear(tileRef); - if (Grid.MaximumTerrainHeight > 0) - ret.CellEntryChanged += UpdateProjection; - return ret; - }); + Height.CellEntryChanged += UpdateProjection; + Tiles.CellEntryChanged += UpdateProjection; + } - MapHeight = Exts.Lazy(() => - { - var ret = new CellLayer(Grid.Type, size); - ret.Clear(0); - if (Grid.MaximumTerrainHeight > 0) - ret.CellEntryChanged += UpdateProjection; - return ret; - }); + Tiles.Clear(tileRef); SpawnPoints = Exts.Lazy(() => new CPos[0]); @@ -256,12 +247,64 @@ namespace OpenRA PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players"); ActorDefinitions = MiniYaml.NodesOrEmpty(yaml, "Actors"); - MapTiles = Exts.Lazy(LoadMapTiles); - MapResources = Exts.Lazy(LoadResourceTiles); - MapHeight = Exts.Lazy(LoadMapHeight); - Grid = modData.Manifest.Get(); + var size = new Size(MapSize.X, MapSize.Y); + Tiles = new CellLayer(Grid.Type, size); + Resources = new CellLayer(Grid.Type, size); + Height = new CellLayer(Grid.Type, size); + + using (var s = Package.GetStream("map.bin")) + { + var header = new BinaryDataHeader(s, MapSize); + if (header.TilesOffset > 0) + { + s.Position = header.TilesOffset; + for (var i = 0; i < MapSize.X; i++) + { + for (var j = 0; j < MapSize.Y; j++) + { + var tile = s.ReadUInt16(); + var index = s.ReadUInt8(); + + // TODO: Remember to remove this when rewriting tile variants / PickAny + if (index == byte.MaxValue) + index = (byte)(i % 4 + (j % 4) * 4); + + Tiles[new MPos(i, j)] = new TerrainTile(tile, index); + } + } + } + + if (header.ResourcesOffset > 0) + { + s.Position = header.ResourcesOffset; + for (var i = 0; i < MapSize.X; i++) + { + for (var j = 0; j < MapSize.Y; j++) + { + var type = s.ReadUInt8(); + var density = s.ReadUInt8(); + Resources[new MPos(i, j)] = new ResourceTile(type, density); + } + } + } + + if (header.HeightsOffset > 0) + { + s.Position = header.HeightsOffset; + for (var i = 0; i < MapSize.X; i++) + for (var j = 0; j < MapSize.Y; j++) + Height[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight); + } + } + + if (Grid.MaximumTerrainHeight > 0) + { + Tiles.CellEntryChanged += UpdateProjection; + Height.CellEntryChanged += UpdateProjection; + } + PostInit(); Uid = ComputeUID(Package); @@ -361,7 +404,7 @@ namespace OpenRA PPos[] ProjectCellInner(MPos uv) { - var mapHeight = MapHeight.Value; + var mapHeight = Height; if (!mapHeight.Contains(uv)) return NoProjectedCells; @@ -372,7 +415,7 @@ namespace OpenRA // Odd-height ramps get bumped up a level to the next even height layer if ((height & 1) == 1) { - var ti = Rules.TileSet.GetTileInfo(MapTiles.Value[uv]); + var ti = Rules.TileSet.GetTileInfo(Tiles[uv]); if (ti != null && ti.RampType != 0) height += 1; } @@ -469,84 +512,6 @@ namespace OpenRA Uid = ComputeUID(toPackage); } - public CellLayer LoadMapTiles() - { - var tiles = new CellLayer(this); - using (var s = Package.GetStream("map.bin")) - { - var header = new BinaryDataHeader(s, MapSize); - if (header.TilesOffset > 0) - { - s.Position = header.TilesOffset; - for (var i = 0; i < MapSize.X; i++) - { - for (var j = 0; j < MapSize.Y; j++) - { - var tile = s.ReadUInt16(); - var index = s.ReadUInt8(); - - // TODO: Remember to remove this when rewriting tile variants / PickAny - if (index == byte.MaxValue) - index = (byte)(i % 4 + (j % 4) * 4); - - tiles[new MPos(i, j)] = new TerrainTile(tile, index); - } - } - } - } - - if (Grid.MaximumTerrainHeight > 0) - tiles.CellEntryChanged += UpdateProjection; - - return tiles; - } - - public CellLayer LoadMapHeight() - { - var tiles = new CellLayer(this); - using (var s = Package.GetStream("map.bin")) - { - var header = new BinaryDataHeader(s, MapSize); - if (header.HeightsOffset > 0) - { - s.Position = header.HeightsOffset; - for (var i = 0; i < MapSize.X; i++) - for (var j = 0; j < MapSize.Y; j++) - tiles[new MPos(i, j)] = s.ReadUInt8().Clamp((byte)0, Grid.MaximumTerrainHeight); - } - } - - if (Grid.MaximumTerrainHeight > 0) - tiles.CellEntryChanged += UpdateProjection; - - return tiles; - } - - public CellLayer LoadResourceTiles() - { - var resources = new CellLayer(this); - - using (var s = Package.GetStream("map.bin")) - { - var header = new BinaryDataHeader(s, MapSize); - if (header.ResourcesOffset > 0) - { - s.Position = header.ResourcesOffset; - for (var i = 0; i < MapSize.X; i++) - { - for (var j = 0; j < MapSize.Y; j++) - { - var type = s.ReadUInt8(); - var density = s.ReadUInt8(); - resources[new MPos(i, j)] = new ResourceTile(type, density); - } - } - } - } - - return resources; - } - public byte[] SaveBinaryData() { var dataStream = new MemoryStream(); @@ -575,7 +540,7 @@ namespace OpenRA { for (var j = 0; j < MapSize.Y; j++) { - var tile = MapTiles.Value[new MPos(i, j)]; + var tile = Tiles[new MPos(i, j)]; writer.Write(tile.Type); writer.Write(tile.Index); } @@ -586,7 +551,7 @@ namespace OpenRA if (heightsOffset != 0) for (var i = 0; i < MapSize.X; i++) for (var j = 0; j < MapSize.Y; j++) - writer.Write(MapHeight.Value[new MPos(i, j)]); + writer.Write(Height[new MPos(i, j)]); // Resource data if (resourcesOffset != 0) @@ -595,7 +560,7 @@ namespace OpenRA { for (var j = 0; j < MapSize.Y; j++) { - var tile = MapResources.Value[new MPos(i, j)]; + var tile = Resources[new MPos(i, j)]; writer.Write(tile.Type); writer.Write(tile.Index); } @@ -642,7 +607,7 @@ namespace OpenRA for (var x = 0; x < width; x++) { var uv = new MPos(x + Bounds.Left, y + Bounds.Top); - var resourceType = MapResources.Value[uv].Type; + var resourceType = Resources[uv].Type; if (resourceType != 0) { // Cell contains resources @@ -655,7 +620,7 @@ namespace OpenRA else { // Cell contains terrain - var type = tileset.GetTileInfo(MapTiles.Value[uv]); + var type = tileset.GetTileInfo(Tiles[uv]); leftColor = type != null ? type.LeftColor : Color.Black; rightColor = type != null ? type.RightColor : Color.Black; } @@ -737,7 +702,7 @@ namespace OpenRA // (b) Therefore: // - ax + by adds (a - b) * 512 + 512 to u // - ax + by adds (a + b) * 512 + 512 to v - var z = MapHeight.Value.Contains(cell) ? 512 * MapHeight.Value[cell] : 0; + var z = Height.Contains(cell) ? 512 * Height[cell] : 0; return new WPos(512 * (cell.X - cell.Y + 1), 512 * (cell.X + cell.Y + 1), z); } @@ -816,14 +781,14 @@ namespace OpenRA public void Resize(int width, int height) { - var oldMapTiles = MapTiles.Value; - var oldMapResources = MapResources.Value; - var oldMapHeight = MapHeight.Value; + var oldMapTiles = Tiles; + var oldMapResources = Resources; + var oldMapHeight = Height; var newSize = new Size(width, height); - MapTiles = Exts.Lazy(() => CellLayer.Resize(oldMapTiles, newSize, oldMapTiles[MPos.Zero])); - MapResources = Exts.Lazy(() => CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero])); - MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero])); + Tiles = CellLayer.Resize(oldMapTiles, newSize, oldMapTiles[MPos.Zero]); + Resources = CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero]); + Height = CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]); MapSize = new int2(newSize); var tl = new MPos(0, 0); @@ -865,8 +830,8 @@ namespace OpenRA { for (var i = Bounds.Left; i < Bounds.Right; i++) { - var type = MapTiles.Value[new MPos(i, j)].Type; - var index = MapTiles.Value[new MPos(i, j)].Index; + var type = Tiles[new MPos(i, j)].Type; + var index = Tiles[new MPos(i, j)].Index; if (!tileset.Templates.ContainsKey(type)) { Console.WriteLine("Unknown Tile ID {0}".F(type)); @@ -878,7 +843,7 @@ namespace OpenRA continue; index = (byte)r.Next(0, template.TilesCount); - MapTiles.Value[new MPos(i, j)] = new TerrainTile(type, index); + Tiles[new MPos(i, j)] = new TerrainTile(type, index); } } } @@ -896,7 +861,7 @@ namespace OpenRA // Invalidate the entry for a cell if anything could cause the terrain index to change. Action invalidateTerrainIndex = c => cachedTerrainIndexes[c] = InvalidCachedTerrainIndex; CustomTerrain.CellEntryChanged += invalidateTerrainIndex; - MapTiles.Value.CellEntryChanged += invalidateTerrainIndex; + Tiles.CellEntryChanged += invalidateTerrainIndex; } var uv = cell.ToMPos(this); @@ -907,7 +872,7 @@ namespace OpenRA { var custom = CustomTerrain[uv]; terrainIndex = cachedTerrainIndexes[uv] = - custom != byte.MaxValue ? custom : Rules.TileSet.GetTerrainIndex(MapTiles.Value[uv]); + custom != byte.MaxValue ? custom : Rules.TileSet.GetTerrainIndex(Tiles[uv]); } return (byte)terrainIndex; @@ -1157,7 +1122,7 @@ namespace OpenRA Func valid = Contains; if (allowOutsideBounds) - valid = MapTiles.Value.Contains; + valid = Tiles.Contains; for (var i = minRange; i <= maxRange; i++) { diff --git a/OpenRA.Game/Map/ProjectedCellRegion.cs b/OpenRA.Game/Map/ProjectedCellRegion.cs index ef7122c334..85dcfa5eaa 100644 --- a/OpenRA.Game/Map/ProjectedCellRegion.cs +++ b/OpenRA.Game/Map/ProjectedCellRegion.cs @@ -44,8 +44,8 @@ namespace OpenRA var maxHeight = map.Grid.MaximumTerrainHeight; var heightOffset = map.Grid.Type == MapGridType.RectangularIsometric ? maxHeight : maxHeight / 2; - // Use the MapHeight data array to clamp the bottom coordinate so it doesn't overflow the map - mapBottomRight = map.MapHeight.Value.Clamp(new MPos(bottomRight.U, bottomRight.V + heightOffset)); + // Use the map Height data array to clamp the bottom coordinate so it doesn't overflow the map + mapBottomRight = map.Height.Clamp(new MPos(bottomRight.U, bottomRight.V + heightOffset)); } public bool Contains(PPos puv) diff --git a/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs b/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs index 7efafefb3f..f7280b7aed 100644 --- a/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs +++ b/OpenRA.Mods.Cnc/ImportTiberianDawnLegacyMapCommand.cs @@ -66,7 +66,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands { var type = ms.ReadUInt8(); var index = ms.ReadUInt8(); - Map.MapTiles.Value[new CPos(i, j)] = new TerrainTile(type, index); + Map.Tiles[new CPos(i, j)] = new TerrainTile(type, index); } } } @@ -96,7 +96,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands if (overlayResourceMapping.ContainsKey(type)) res = overlayResourceMapping[type]; - Map.MapResources.Value[cell] = new ResourceTile(res.First, res.Second); + Map.Resources[cell] = new ResourceTile(res.First, res.Second); if (overlayActors.Contains(type)) { var ar = new ActorReference(type) diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs index 7b25f53a8a..b39d223255 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorActorBrush.cs @@ -95,7 +95,7 @@ namespace OpenRA.Mods.Common.Widgets if (mi.Button == MouseButton.Left && mi.Event == MouseInputEvent.Down) { // Check the actor is inside the map - if (!footprint.All(c => world.Map.MapTiles.Value.Contains(cell + locationOffset + c))) + if (!footprint.All(c => world.Map.Tiles.Contains(cell + locationOffset + c))) return true; var newActorReference = new ActorReference(Actor.Name); diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorCopyPasteBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorCopyPasteBrush.cs index 1fbd8ac5ee..9799015b4f 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorCopyPasteBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorCopyPasteBrush.cs @@ -94,9 +94,9 @@ namespace OpenRA.Mods.Common.Widgets void Copy(CellRegion source, CVec offset) { var gridType = worldRenderer.World.Map.Grid.Type; - var mapTiles = worldRenderer.World.Map.MapTiles.Value; - var mapHeight = worldRenderer.World.Map.MapHeight.Value; - var mapResources = worldRenderer.World.Map.MapResources.Value; + var mapTiles = worldRenderer.World.Map.Tiles; + var mapHeight = worldRenderer.World.Map.Height; + var mapResources = worldRenderer.World.Map.Resources; var dest = new CellRegion(gridType, source.TopLeft + offset, source.BottomRight + offset); diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs index 430ede9af9..017bf9fa90 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorDefaultBrush.cs @@ -71,7 +71,7 @@ namespace OpenRA.Mods.Common.Widgets var underCursor = editorLayer.PreviewsAt(worldPixel).MinByOrDefault(CalculateActorSelectionPriority); - var mapResources = world.Map.MapResources.Value; + var mapResources = world.Map.Resources; ResourceType type; if (underCursor != null) editorWidget.SetTooltip(underCursor.Tooltip); diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs index 99300343fc..ab47677569 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorResourceBrush.cs @@ -69,7 +69,7 @@ namespace OpenRA.Mods.Common.Widgets { var type = (byte)ResourceType.ResourceType; var index = (byte)ResourceType.MaxDensity; - world.Map.MapResources.Value[cell] = new ResourceTile(type, index); + world.Map.Resources[cell] = new ResourceTile(type, index); } return true; @@ -77,11 +77,11 @@ namespace OpenRA.Mods.Common.Widgets public bool AllowResourceAt(CPos cell) { - var mapResources = world.Map.MapResources.Value; + var mapResources = world.Map.Resources; if (!mapResources.Contains(cell)) return false; - var tile = world.Map.MapTiles.Value[cell]; + var tile = world.Map.Tiles[cell]; var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); if (tileInfo == null) return false; diff --git a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs index 28577bf154..7eeeb568ef 100644 --- a/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs +++ b/OpenRA.Mods.Common/EditorBrushes/EditorTileBrush.cs @@ -97,8 +97,8 @@ namespace OpenRA.Mods.Common.Widgets void PaintCell(CPos cell, bool isMoving) { var map = world.Map; - var mapTiles = map.MapTiles.Value; - var mapHeight = map.MapHeight.Value; + var mapTiles = map.Tiles; + var mapHeight = map.Height; var tileset = map.Rules.TileSet; var template = tileset.Templates[Template]; @@ -129,7 +129,7 @@ namespace OpenRA.Mods.Common.Widgets void FloodFillWithBrush(CPos cell, bool isMoving) { var map = world.Map; - var mapTiles = map.MapTiles.Value; + var mapTiles = map.Tiles; var replace = mapTiles[cell]; if (replace.Type == Template) @@ -203,7 +203,7 @@ namespace OpenRA.Mods.Common.Widgets bool PlacementOverlapsSameTemplate(TerrainTemplateInfo template, CPos cell) { var map = world.Map; - var mapTiles = map.MapTiles.Value; + var mapTiles = map.Tiles; var i = 0; for (var y = 0; y < template.Size.Y; y++) { diff --git a/OpenRA.Mods.Common/Effects/Missile.cs b/OpenRA.Mods.Common/Effects/Missile.cs index f1131f00ad..10b153ca83 100644 --- a/OpenRA.Mods.Common/Effects/Missile.cs +++ b/OpenRA.Mods.Common/Effects/Missile.cs @@ -447,7 +447,7 @@ namespace OpenRA.Mods.Common.Effects if (!world.Map.Contains(world.Map.CellContaining(posProbe))) break; - var ht = world.Map.MapHeight.Value[world.Map.CellContaining(posProbe)] * 512; + var ht = world.Map.Height[world.Map.CellContaining(posProbe)] * 512; curDist += stepSize; if (ht > predClfHgt) diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs index 6ffbc634d2..91a7da0d0b 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs @@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits if (!bi.AllowInvalidPlacement && world.ActorMap.GetActorsAt(cell).Any(a => a != toIgnore)) return false; - var tile = world.Map.MapTiles.Value[cell]; + var tile = world.Map.Tiles[cell]; var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); // TODO: This is bandaiding over bogus tilesets. diff --git a/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs b/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs index 536dc64739..c72d9ef575 100644 --- a/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs +++ b/OpenRA.Mods.Common/Traits/Infantry/TerrainModifiesDamage.cs @@ -49,7 +49,6 @@ namespace OpenRA.Mods.Common.Traits var world = self.World; var map = world.Map; - var tiles = map.MapTiles.Value; var pos = map.CellContaining(self.CenterPosition); var terrainType = map.GetTerrainInfo(pos).Type; diff --git a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs index 700b9cc31d..44917304b2 100644 --- a/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs +++ b/OpenRA.Mods.Common/Traits/Upgrades/DeployToUpgrade.cs @@ -158,7 +158,6 @@ namespace OpenRA.Mods.Common.Traits if (!checkTerrainType) return true; - var tiles = self.World.Map.MapTiles.Value; var terrainType = self.World.Map.GetTerrainInfo(self.Location).Type; return info.AllowedTerrainTypes.Contains(terrainType); @@ -172,7 +171,7 @@ namespace OpenRA.Mods.Common.Traits var ramp = 0; if (self.World.Map.Contains(self.Location)) { - var tile = self.World.Map.MapTiles.Value[self.Location]; + var tile = self.World.Map.Tiles[self.Location]; var ti = self.World.Map.Rules.TileSet.GetTileInfo(tile); if (ti != null) ramp = ti.RampType; diff --git a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs index 805f11a1f2..dfcac3caaf 100644 --- a/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/BridgeLayer.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits } // Take all templates to overlay from the map - foreach (var cell in w.Map.AllCells.Where(cell => bridgeTypes.ContainsKey(w.Map.MapTiles.Value[cell].Type))) + foreach (var cell in w.Map.AllCells.Where(cell => bridgeTypes.ContainsKey(w.Map.Tiles[cell].Type))) ConvertBridgeToActor(w, cell); // Link adjacent (long)-bridges so that artwork is updated correctly @@ -65,8 +65,8 @@ namespace OpenRA.Mods.Common.Traits return; // Correlate the tile "image" aka subtile with its position to find the template origin - var tile = w.Map.MapTiles.Value[cell].Type; - var index = w.Map.MapTiles.Value[cell].Index; + var tile = w.Map.Tiles[cell].Type; + var index = w.Map.Tiles[cell].Index; var template = w.Map.Rules.TileSet.Templates[tile]; var ni = cell.X - index % template.Size.X; var nj = cell.Y - index / template.Size.X; @@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits }).Trait(); var subTiles = new Dictionary(); - var mapTiles = w.Map.MapTiles.Value; + var mapTiles = w.Map.Tiles; // For each subtile in the template for (byte ind = 0; ind < template.Size.X * template.Size.Y; ind++) diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index 12f0c71e45..5107483834 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits Resources = self.TraitsImplementing() .ToDictionary(r => r.Info.ResourceType, r => r); - Map.MapResources.Value.CellEntryChanged += UpdateCell; + Map.Resources.CellEntryChanged += UpdateCell; } public void WorldLoaded(World w, WorldRenderer wr) @@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Traits public void UpdateCell(CPos cell) { var uv = cell.ToMPos(Map); - var tile = Map.MapResources.Value[uv]; + var tile = Map.Resources[uv]; var t = Tiles[cell]; if (t.Density > 0) @@ -127,7 +127,7 @@ namespace OpenRA.Mods.Common.Traits // Set density based on the number of neighboring resources var adjacent = 0; var type = Tiles[c].Type; - var resources = Map.MapResources.Value; + var resources = Map.Resources; for (var u = -1; u < 2; u++) { for (var v = -1; v < 2; v++) @@ -205,7 +205,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var kv in spriteLayers.Values) kv.Dispose(); - Map.MapResources.Value.CellEntryChanged -= UpdateCell; + Map.Resources.CellEntryChanged -= UpdateCell; disposed = true; } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 6eefc23035..97ecdb6040 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -111,7 +111,7 @@ namespace OpenRA.Mods.Common.Traits foreach (var cell in w.Map.AllCells) { ResourceType t; - if (!resources.TryGetValue(w.Map.MapResources.Value[cell].Type, out t)) + if (!resources.TryGetValue(w.Map.Resources[cell].Type, out t)) continue; if (!AllowResourceAt(t, cell)) @@ -193,7 +193,7 @@ namespace OpenRA.Mods.Common.Traits if (!rt.Info.AllowOnRamps) { - var tile = world.Map.MapTiles.Value[cell]; + var tile = world.Map.Tiles[cell]; var tileInfo = world.Map.Rules.TileSet.GetTileInfo(tile); if (tileInfo != null && tileInfo.RampType > 0) return false; diff --git a/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs b/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs index 03c6cdfe92..9fc11cf4ab 100644 --- a/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs +++ b/OpenRA.Mods.Common/Traits/World/TerrainGeometryOverlay.cs @@ -57,11 +57,11 @@ namespace OpenRA.Mods.Common.Traits foreach (var uv in wr.Viewport.AllVisibleCells.CandidateMapCoords) { - if (!map.MapHeight.Value.Contains(uv)) + if (!map.Height.Contains(uv)) continue; - var height = (int)map.MapHeight.Value[uv]; - var tile = map.MapTiles.Value[uv]; + var height = (int)map.Height[uv]; + var tile = map.Tiles[uv]; var ti = tileSet.GetTileInfo(tile); var ramp = ti != null ? ti.RampType : 0; diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index 7d7b028431..010a13ca2c 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Widgets foreach (var cell in world.Map.AllCells) UpdateTerrainCell(cell); - world.Map.MapTiles.Value.CellEntryChanged += UpdateTerrainCell; + world.Map.Tiles.CellEntryChanged += UpdateTerrainCell; world.Map.CustomTerrain.CellEntryChanged += UpdateTerrainCell; } @@ -140,7 +140,7 @@ namespace OpenRA.Mods.Common.Widgets int leftColor, rightColor; if (custom == byte.MaxValue) { - var type = world.Map.Rules.TileSet.GetTileInfo(world.Map.MapTiles.Value[uv]); + var type = world.Map.Rules.TileSet.GetTileInfo(world.Map.Tiles[uv]); leftColor = type != null ? type.LeftColor.ToArgb() : Color.Black.ToArgb(); rightColor = type != null ? type.RightColor.ToArgb() : Color.Black.ToArgb(); } @@ -444,7 +444,7 @@ namespace OpenRA.Mods.Common.Widgets public override void Removed() { base.Removed(); - world.Map.MapTiles.Value.CellEntryChanged -= UpdateTerrainCell; + world.Map.Tiles.CellEntryChanged -= UpdateTerrainCell; world.Map.CustomTerrain.CellEntryChanged -= UpdateTerrainCell; Dispose(); } diff --git a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs index 3656ad15fd..5fe559a2ef 100644 --- a/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs +++ b/OpenRA.Mods.D2k/UtilityCommands/D2kMapImporter.cs @@ -336,13 +336,13 @@ namespace OpenRA.Mods.D2k.UtilityCommands var locationOnMap = GetCurrentTilePositionOnMap(); - map.MapTiles.Value[locationOnMap] = tile; + map.Tiles[locationOnMap] = tile; // Spice if (tileSpecialInfo == 1) - map.MapResources.Value[locationOnMap] = new ResourceTile(1, 1); + map.Resources[locationOnMap] = new ResourceTile(1, 1); if (tileSpecialInfo == 2) - map.MapResources.Value[locationOnMap] = new ResourceTile(1, 2); + map.Resources[locationOnMap] = new ResourceTile(1, 2); // Actors if (ActorDataByActorCode.ContainsKey(tileSpecialInfo)) diff --git a/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs b/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs index ed3b5840a2..cd4db44f71 100644 --- a/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs +++ b/OpenRA.Mods.RA/ImportRedAlertLegacyMapCommand.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.UtilityCommands for (var j = 0; j < MapSize; j++) for (var i = 0; i < MapSize; i++) - Map.MapTiles.Value[new CPos(i, j)] = new TerrainTile(types[i, j], ms.ReadUInt8()); + Map.Tiles[new CPos(i, j)] = new TerrainTile(types[i, j], ms.ReadUInt8()); } static string[] overlayActors = new string[] @@ -104,7 +104,7 @@ namespace OpenRA.Mods.RA.UtilityCommands res = overlayResourceMapping[redAlertOverlayNames[o]]; var cell = new CPos(i, j); - Map.MapResources.Value[cell] = new ResourceTile(res.First, res.Second); + Map.Resources[cell] = new ResourceTile(res.First, res.Second); if (o != 255 && overlayActors.Contains(redAlertOverlayNames[o])) { diff --git a/OpenRA.Mods.TS/UtilityCommands/ImportTSMapCommand.cs b/OpenRA.Mods.TS/UtilityCommands/ImportTSMapCommand.cs index c8f2c1f53b..7ce541f66a 100644 --- a/OpenRA.Mods.TS/UtilityCommands/ImportTSMapCommand.cs +++ b/OpenRA.Mods.TS/UtilityCommands/ImportTSMapCommand.cs @@ -232,9 +232,9 @@ namespace OpenRA.Mods.TS.UtilityCommands map.Title = basic.GetValue("Name", Path.GetFileNameWithoutExtension(filename)); map.Author = "Westwood Studios"; map.Bounds = new Rectangle(iniBounds[0], iniBounds[1], iniBounds[2], 2 * iniBounds[3] + 2 * iniBounds[1]); - map.MapResources = Exts.Lazy(() => new CellLayer(map.Grid.Type, size)); - map.MapTiles = Exts.Lazy(() => new CellLayer(map.Grid.Type, size)); - map.MapHeight = Exts.Lazy(() => new CellLayer(map.Grid.Type, size)); + map.Resources = new CellLayer(map.Grid.Type, size); + map.Tiles = new CellLayer(map.Grid.Type, size); + map.Height = new CellLayer(map.Grid.Type, size); map.RequiresMod = modData.Manifest.Mod.Id; @@ -268,13 +268,13 @@ namespace OpenRA.Mods.TS.UtilityCommands var mapCell = new MPos(dx / 2, dy); var cell = mapCell.ToCPos(map); - if (map.MapTiles.Value.Contains(cell)) + if (map.Tiles.Contains(cell)) { if (!tileset.Templates.ContainsKey(tilenum)) tilenum = subtile = 0; - map.MapTiles.Value[cell] = new TerrainTile(tilenum, subtile); - map.MapHeight.Value[cell] = z; + map.Tiles[cell] = new TerrainTile(tilenum, subtile); + map.Height[cell] = z; } } } @@ -303,7 +303,7 @@ namespace OpenRA.Mods.TS.UtilityCommands var rx = (ushort)((dx + dy) / 2 + 1); var ry = (ushort)(dy - rx + fullSize.X + 1); - if (!map.MapResources.Value.Contains(uv)) + if (!map.Resources.Contains(uv)) continue; var idx = rx + 512 * ry; @@ -331,7 +331,7 @@ namespace OpenRA.Mods.TS.UtilityCommands if (resourceType != 0) { - map.MapResources.Value[uv] = new ResourceTile(resourceType, overlayDataPack[idx]); + map.Resources[uv] = new ResourceTile(resourceType, overlayDataPack[idx]); continue; }