Cache ProjectedCellBounds during load time

This commit is contained in:
abcdefg30
2020-05-22 13:47:35 +02:00
committed by teinarss
parent 173aae1f81
commit 889e2152a4
5 changed files with 12 additions and 11 deletions

View File

@@ -233,7 +233,7 @@ namespace OpenRA
public CellLayer<byte> Ramp { get; private set; } public CellLayer<byte> Ramp { get; private set; }
public CellLayer<byte> CustomTerrain { get; private set; } public CellLayer<byte> CustomTerrain { get; private set; }
public ProjectedCellRegion ProjectedCellBounds { get; private set; } public PPos[] ProjectedCells { get; private set; }
public CellRegion AllCells { get; private set; } public CellRegion AllCells { get; private set; }
public List<CPos> AllEdgeCells { get; private set; } public List<CPos> AllEdgeCells { get; private set; }
@@ -822,6 +822,7 @@ namespace OpenRA
foreach (var puv in projectedCells) foreach (var puv in projectedCells)
if (!Contains(puv)) if (!Contains(puv))
return false; return false;
return true; return true;
} }
@@ -1017,7 +1018,8 @@ namespace OpenRA
ProjectedBottomRight = new WPos(br.U * 1024 - 1, (br.V + 1) * 1024 - 1, 0); ProjectedBottomRight = new WPos(br.U * 1024 - 1, (br.V + 1) * 1024 - 1, 0);
} }
ProjectedCellBounds = new ProjectedCellRegion(this, tl, br); // PERF: This enumeration isn't going to change during the game
ProjectedCells = new ProjectedCellRegion(this, tl, br).ToArray();
} }
public void FixOpenAreas() public void FixOpenAreas()

View File

@@ -162,7 +162,7 @@ namespace OpenRA.Traits
if (OnShroudChanged == null) if (OnShroudChanged == null)
return; return;
foreach (var puv in map.ProjectedCellBounds) foreach (var puv in map.ProjectedCells)
{ {
if (!touched[puv]) if (!touched[puv])
continue; continue;
@@ -298,7 +298,7 @@ namespace OpenRA.Traits
if (map.Bounds != s.map.Bounds) if (map.Bounds != s.map.Bounds)
throw new ArgumentException("The map bounds of these shrouds do not match.", "s"); throw new ArgumentException("The map bounds of these shrouds do not match.", "s");
foreach (var puv in map.ProjectedCellBounds) foreach (var puv in map.ProjectedCells)
{ {
if (!explored[puv] && s.explored[puv]) if (!explored[puv] && s.explored[puv])
{ {
@@ -310,7 +310,7 @@ namespace OpenRA.Traits
public void ExploreAll() public void ExploreAll()
{ {
foreach (var puv in map.ProjectedCellBounds) foreach (var puv in map.ProjectedCells)
{ {
if (!explored[puv]) if (!explored[puv])
{ {
@@ -322,7 +322,7 @@ namespace OpenRA.Traits
public void ResetExploration() public void ResetExploration()
{ {
foreach (var puv in map.ProjectedCellBounds) foreach (var puv in map.ProjectedCells)
{ {
touched[puv] = true; touched[puv] = true;
explored[puv] = (visibleCount[puv] + passiveVisibleCount[puv]) > 0; explored[puv] = (visibleCount[puv] + passiveVisibleCount[puv]) > 0;

View File

@@ -49,8 +49,7 @@ namespace OpenRA.Mods.Common.Traits
protected PPos[] ProjectedCells(Actor self) protected PPos[] ProjectedCells(Actor self)
{ {
var map = self.World.Map; return self.World.Map.ProjectedCells;
return map.ProjectedCellBounds.ToArray();
} }
void INotifyActorDisposing.Disposing(Actor self) void INotifyActorDisposing.Disposing(Actor self)

View File

@@ -271,7 +271,7 @@ namespace OpenRA.Mods.Common.Traits
UpdateShroud(new ProjectedCellRegion(map, tl, br)); UpdateShroud(new ProjectedCellRegion(map, tl, br));
} }
void UpdateShroud(ProjectedCellRegion region) void UpdateShroud(IEnumerable<PPos> region)
{ {
foreach (var puv in region) foreach (var puv in region)
{ {
@@ -299,7 +299,7 @@ namespace OpenRA.Mods.Common.Traits
void IRenderShroud.RenderShroud(WorldRenderer wr) void IRenderShroud.RenderShroud(WorldRenderer wr)
{ {
UpdateShroud(map.ProjectedCellBounds); UpdateShroud(map.ProjectedCells);
fogLayer.Draw(wr.Viewport); fogLayer.Draw(wr.Viewport);
shroudLayer.Draw(wr.Viewport); shroudLayer.Draw(wr.Viewport);
} }

View File

@@ -134,7 +134,7 @@ namespace OpenRA.Mods.Common.Widgets
if (newShroud != null) if (newShroud != null)
{ {
newShroud.OnShroudChanged += UpdateShroudCell; newShroud.OnShroudChanged += UpdateShroudCell;
foreach (var puv in world.Map.ProjectedCellBounds) foreach (var puv in world.Map.ProjectedCells)
UpdateShroudCell(puv); UpdateShroudCell(puv);
} }