Merge pull request #10942 from pchote/remove-map-lazyness

Remove map lazyness.
This commit is contained in:
Matthias Mailänder
2016-03-21 20:23:47 +01:00
28 changed files with 195 additions and 256 deletions

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

View File

@@ -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++)
{

View File

@@ -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)

View File

@@ -10,6 +10,7 @@
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
@@ -46,14 +47,18 @@ namespace OpenRA.Mods.Common.Lint
if (worldActor.HasTraitInfo<MPStartLocationsInfo>())
{
var multiPlayers = players.Count(p => p.Value.Playable);
var spawns = map.ActorDefinitions.Where(a => a.Value.Value == "mpspawn");
var spawnCount = spawns.Count();
var playerCount = players.Count(p => p.Value.Playable);
var spawns = new List<CPos>();
foreach (var kv in map.ActorDefinitions.Where(d => d.Value.Value == "mpspawn"))
{
var s = new ActorReference(kv.Value.Value, kv.Value.ToDictionary());
spawns.Add(s.InitDict.Get<LocationInit>().Value(null));
}
if (multiPlayers > spawnCount)
emitError("The map allows {0} possible players, but defines only {1} spawn points".F(multiPlayers, spawnCount));
if (playerCount > spawns.Count)
emitError("The map allows {0} possible players, but defines only {1} spawn points".F(playerCount, spawns.Count));
if (map.SpawnPoints.Value.Distinct().Count() != spawnCount)
if (spawns.Distinct().Count() != spawns.Count)
emitError("Duplicate spawn point locations detected.");
}

View File

@@ -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.

View File

@@ -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;

View File

@@ -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;

View File

@@ -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<Bridge>();
var subTiles = new Dictionary<CPos, byte>();
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++)

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
Resources = self.TraitsImplementing<ResourceType>()
.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;
}

View File

@@ -38,7 +38,10 @@ namespace OpenRA.Mods.Common.Traits
public void WorldLoaded(World world, WorldRenderer wr)
{
var spawns = world.Map.SpawnPoints.Value;
var spawns = world.Actors.Where(a => a.Info.Name == "mpspawn")
.Select(a => a.Location)
.ToArray();
var taken = world.LobbyInfo.Clients.Where(c => c.SpawnPoint != 0 && c.Slot != null)
.Select(c => spawns[c.SpawnPoint - 1]).ToList();
var available = spawns.Except(taken).ToList();

View File

@@ -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;

View File

@@ -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;

View File

@@ -87,7 +87,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
foreach (var testMap in maps)
{
Console.WriteLine("Testing map: {0}".F(testMap.Title));
testMap.PreloadRules();
// Run all rule checks on the map if it defines custom rules.
if (testMap.RuleDefinitions != null || testMap.VoiceDefinitions != null || testMap.WeaponDefinitions != null)

View File

@@ -35,6 +35,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
public Map Map;
public List<string> Players = new List<string>();
public MapPlayers MapPlayers;
int spawnCount;
public bool ValidateArguments(string[] args)
{
@@ -81,12 +82,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
LoadSmudges(file, "SMUDGE");
var waypoints = file.GetSection("Waypoints");
LoadWaypoints(Map, waypoints, MapSize);
LoadWaypoints(waypoints);
// Create default player definitions only if there are no players to import
MapPlayers = new MapPlayers(Map.Rules, (Players.Count == 0) ? Map.SpawnPoints.Value.Length : 0);
MapPlayers = new MapPlayers(Map.Rules, Players.Count == 0 ? spawnCount : 0);
foreach (var p in Players)
LoadPlayer(file, p);
Map.PlayerDefinitions = MapPlayers.ToMiniYaml();
}
@@ -235,13 +237,13 @@ namespace OpenRA.Mods.Common.UtilityCommands
return new int2(offset % mapSize, offset / mapSize);
}
static void LoadWaypoints(Map map, IniSection waypointSection, int mapSize)
void LoadWaypoints(IniSection waypointSection)
{
var actorCount = map.ActorDefinitions.Count;
var actorCount = Map.ActorDefinitions.Count;
var wps = waypointSection
.Where(kv => Exts.ParseIntegerInvariant(kv.Value) > 0)
.Select(kv => Pair.New(Exts.ParseIntegerInvariant(kv.Key),
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), mapSize)));
LocationFromMapOffset(Exts.ParseIntegerInvariant(kv.Value), MapSize)));
// Add waypoint actors
foreach (var kv in wps)
@@ -254,7 +256,8 @@ namespace OpenRA.Mods.Common.UtilityCommands
new OwnerInit("Neutral")
};
map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
Map.ActorDefinitions.Add(new MiniYamlNode("Actor" + actorCount++, ar.Save()));
spawnCount++;
}
else
{
@@ -264,7 +267,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
new OwnerInit("Neutral")
};
map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
Map.ActorDefinitions.Add(new MiniYamlNode("waypoint" + kv.First, ar.Save()));
}
}
}

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var br = new PPos(width, height + maxTerrainHeight);
map.SetBounds(tl, br);
map.PlayerDefinitions = new MapPlayers(map.Rules, map.SpawnPoints.Value.Length).ToMiniYaml();
map.PlayerDefinitions = new MapPlayers(map.Rules, 0).ToMiniYaml();
map.FixOpenAreas();
Action<string> afterSave = uid =>

View File

@@ -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();
}