Distinguish between all map cells and cells inside map bounds.
This commit is contained in:
@@ -180,9 +180,9 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var colors = (int*)bitmapData.Scan0;
|
||||
var stride = bitmapData.Stride / 4;
|
||||
var shroudObscured = world.ShroudObscuresTest(map.Cells);
|
||||
var fogObscured = world.FogObscuresTest(map.Cells);
|
||||
foreach (var uv in map.Cells.MapCoords)
|
||||
var shroudObscured = world.ShroudObscuresTest(map.CellsInsideBounds);
|
||||
var fogObscured = world.FogObscuresTest(map.CellsInsideBounds);
|
||||
foreach (var uv in map.CellsInsideBounds.MapCoords)
|
||||
{
|
||||
var bitmapXy = new int2(uv.U - b.Left, uv.V - b.Top);
|
||||
if (shroudObscured(uv))
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace OpenRA.Graphics
|
||||
mapTiles = world.Map.MapTiles.Value;
|
||||
|
||||
terrain = new TerrainSpriteLayer(world, wr, theater.Sheet, BlendMode.Alpha, wr.Palette("terrain"));
|
||||
foreach (var cell in world.Map.Cells)
|
||||
foreach (var cell in world.Map.AllCells)
|
||||
UpdateCell(cell);
|
||||
|
||||
world.Map.MapTiles.Value.CellEntryChanged += UpdateCell;
|
||||
|
||||
@@ -239,7 +239,8 @@ namespace OpenRA
|
||||
public SequenceProvider SequenceProvider { get { return Rules.Sequences[Tileset]; } }
|
||||
|
||||
public WVec[][] CellCorners { get; private set; }
|
||||
[FieldLoader.Ignore] public CellRegion Cells;
|
||||
[FieldLoader.Ignore] public CellRegion CellsInsideBounds;
|
||||
[FieldLoader.Ignore] public CellRegion AllCells;
|
||||
|
||||
public static Map FromTileset(TileSet tileset)
|
||||
{
|
||||
@@ -392,12 +393,16 @@ namespace OpenRA
|
||||
|
||||
cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);
|
||||
|
||||
var tl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this);
|
||||
var br = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this);
|
||||
Cells = new CellRegion(TileShape, tl, br);
|
||||
var tl = new MPos(0, 0).ToCPos(this);
|
||||
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);
|
||||
AllCells = new CellRegion(TileShape, tl, br);
|
||||
|
||||
var btl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this);
|
||||
var bbr = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this);
|
||||
CellsInsideBounds = new CellRegion(TileShape, btl, bbr);
|
||||
|
||||
CustomTerrain = new CellLayer<byte>(this);
|
||||
foreach (var uv in Cells.MapCoords)
|
||||
foreach (var uv in AllCells.MapCoords)
|
||||
CustomTerrain[uv] = byte.MaxValue;
|
||||
|
||||
var leftDelta = TileShape == TileShape.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0);
|
||||
@@ -689,6 +694,10 @@ namespace OpenRA
|
||||
MapResources = Exts.Lazy(() => CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero]));
|
||||
MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero]));
|
||||
MapSize = new int2(newSize);
|
||||
|
||||
var tl = new MPos(0, 0).ToCPos(this);
|
||||
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);
|
||||
AllCells = new CellRegion(TileShape, tl, br);
|
||||
}
|
||||
|
||||
public void ResizeCordon(int left, int top, int right, int bottom)
|
||||
@@ -697,7 +706,7 @@ namespace OpenRA
|
||||
|
||||
var tl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this);
|
||||
var br = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this);
|
||||
Cells = new CellRegion(TileShape, tl, br);
|
||||
CellsInsideBounds = new CellRegion(TileShape, tl, br);
|
||||
}
|
||||
|
||||
string ComputeHash()
|
||||
@@ -797,8 +806,8 @@ namespace OpenRA
|
||||
|
||||
public WRange DistanceToEdge(WPos pos, WVec dir)
|
||||
{
|
||||
var tl = CenterOfCell(Cells.TopLeft) - new WVec(512, 512, 0);
|
||||
var br = CenterOfCell(Cells.BottomRight) + new WVec(511, 511, 0);
|
||||
var tl = CenterOfCell(CellsInsideBounds.TopLeft) - new WVec(512, 512, 0);
|
||||
var br = CenterOfCell(CellsInsideBounds.BottomRight) + new WVec(511, 511, 0);
|
||||
var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X;
|
||||
var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y;
|
||||
return new WRange(Math.Min(x, y) * dir.Length);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace OpenRA.Traits
|
||||
throw new ArgumentException("The map bounds of these shrouds do not match.", "s");
|
||||
|
||||
var changed = new List<CPos>();
|
||||
foreach (var uv in map.Cells.MapCoords)
|
||||
foreach (var uv in map.CellsInsideBounds.MapCoords)
|
||||
{
|
||||
if (!explored[uv] && s.explored[uv])
|
||||
{
|
||||
@@ -264,7 +264,7 @@ namespace OpenRA.Traits
|
||||
public void ExploreAll(World world)
|
||||
{
|
||||
var changed = new List<CPos>();
|
||||
foreach (var uv in map.Cells.MapCoords)
|
||||
foreach (var uv in map.CellsInsideBounds.MapCoords)
|
||||
{
|
||||
if (!explored[uv])
|
||||
{
|
||||
@@ -279,7 +279,7 @@ namespace OpenRA.Traits
|
||||
public void ResetExploration()
|
||||
{
|
||||
var changed = new List<CPos>();
|
||||
foreach (var uv in map.Cells.MapCoords)
|
||||
foreach (var uv in map.CellsInsideBounds.MapCoords)
|
||||
{
|
||||
var visible = visibleCount[uv] > 0;
|
||||
if (explored[uv] != visible)
|
||||
@@ -318,7 +318,7 @@ namespace OpenRA.Traits
|
||||
public Func<MPos, bool> IsExploredTest(CellRegion region)
|
||||
{
|
||||
// If the region to test extends outside the map we must use the slow test that checks the map boundary every time.
|
||||
if (!map.Cells.Contains(region))
|
||||
if (!map.CellsInsideBounds.Contains(region))
|
||||
return slowExploredTest;
|
||||
|
||||
// If shroud isn't enabled, then we can see everything inside the map.
|
||||
@@ -361,7 +361,7 @@ namespace OpenRA.Traits
|
||||
public Func<MPos, bool> IsVisibleTest(CellRegion region)
|
||||
{
|
||||
// If the region to test extends outside the map we must use the slow test that checks the map boundary every time.
|
||||
if (!map.Cells.Contains(region))
|
||||
if (!map.CellsInsideBounds.Contains(region))
|
||||
return slowVisibleTest;
|
||||
|
||||
// If fog isn't enabled, then we can see everything.
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (w.Type != WorldType.Editor)
|
||||
return;
|
||||
|
||||
foreach (var cell in Map.Cells)
|
||||
foreach (var cell in Map.AllCells)
|
||||
UpdateCell(cell);
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
var resources = w.WorldActor.TraitsImplementing<ResourceType>()
|
||||
.ToDictionary(r => r.Info.ResourceType, r => r);
|
||||
|
||||
foreach (var cell in w.Map.Cells)
|
||||
foreach (var cell in w.Map.AllCells)
|
||||
{
|
||||
ResourceType t;
|
||||
if (!resources.TryGetValue(w.Map.MapResources.Value[cell].Type, out t))
|
||||
@@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
// Set initial density based on the number of neighboring resources
|
||||
foreach (var cell in w.Map.Cells)
|
||||
foreach (var cell in w.Map.AllCells)
|
||||
{
|
||||
var type = content[cell].Type;
|
||||
if (type != null)
|
||||
|
||||
@@ -162,8 +162,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public void WorldLoaded(World w, WorldRenderer wr)
|
||||
{
|
||||
// Initialize tile cache
|
||||
// Adds a 1-cell border around the border to cover any sprites peeking outside the map
|
||||
foreach (var uv in CellRegion.Expand(w.Map.Cells, 1).MapCoords)
|
||||
// This includes the region outside the visible area to cover any sprites peeking outside the map
|
||||
foreach (var uv in w.Map.AllCells.MapCoords)
|
||||
{
|
||||
var screen = wr.ScreenPosition(w.Map.CenterOfCell(uv.ToCPos(map)));
|
||||
var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length);
|
||||
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
wr.PaletteInvalidated += () =>
|
||||
{
|
||||
mapBorderShroudIsCached = false;
|
||||
MarkCellsDirty(CellRegion.Expand(map.Cells, 1));
|
||||
MarkCellsDirty(map.AllCells);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// Cache the whole of the map border shroud ahead of time, since it never changes.
|
||||
Func<MPos, bool> mapContains = map.Contains;
|
||||
foreach (var uv in CellRegion.Expand(map.Cells, 1).MapCoords)
|
||||
foreach (var uv in map.AllCells.MapCoords)
|
||||
{
|
||||
var offset = VertexArrayOffset(uv);
|
||||
var edges = GetEdges(uv, mapContains);
|
||||
@@ -304,7 +304,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
// The map border shroud only affects the map border. If none of the visible cells are on the border, then
|
||||
// we don't need to render anything and can bail early for performance.
|
||||
if (CellRegion.Expand(map.Cells, -1).Contains(visibleRegion))
|
||||
if (CellRegion.Expand(map.CellsInsideBounds, -1).Contains(visibleRegion))
|
||||
return;
|
||||
|
||||
// Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can
|
||||
|
||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
actorSprite = new Sprite(radarSheet, new Rectangle(0, height, width, height), TextureChannel.Alpha);
|
||||
|
||||
// Set initial terrain data
|
||||
foreach (var cell in world.Map.Cells)
|
||||
foreach (var cell in world.Map.CellsInsideBounds)
|
||||
UpdateTerrainCell(cell);
|
||||
|
||||
world.Map.MapTiles.Value.CellEntryChanged += UpdateTerrainCell;
|
||||
@@ -91,6 +91,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
void UpdateTerrainCell(CPos cell)
|
||||
{
|
||||
if (!world.Map.Contains(cell))
|
||||
return;
|
||||
|
||||
var stride = radarSheet.Size.Width;
|
||||
var uv = cell.ToMPos(world.Map);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user