some perf improvements

This commit is contained in:
Chris Forbes
2010-01-31 16:51:22 +13:00
parent 13041ea777
commit e2ed45213c
2 changed files with 22 additions and 36 deletions

View File

@@ -21,7 +21,8 @@ namespace OpenRa
public Shroud(Player owner, Map map) { this.owner = owner; this.map = map; }
float gapOpaqueTicks = (int)(Rules.General.GapRegenInterval * 25 * 60);
int gapOpaqueTicks = (int)(Rules.General.GapRegenInterval * 25 * 60);
int gapTicks;
int[,] gapField = new int[128, 128];
bool[,] gapActive = new bool[128, 128];
@@ -33,37 +34,25 @@ namespace OpenRa
public void Tick( World world )
{
if (gapTicks > 0) { --gapTicks; return; }
// Clear active flags
gapActive = new bool[128, 128];
foreach (var a in world.Queries.WithTrait<GeneratesGap>().Where(a => owner != a.Actor.Owner))
{
foreach (var t in a.Trait.GetShroudedTiles())
gapActive[t.X, t.Y] = true;
}
for (int j = 1; j < 127; j++)
for (int i = 1; i < 127; i++)
{
if (gapField[i, j] > 0 && !gapActive[i, j])
{
// Convert gap to shroud
if (gapField[i, j] >= gapOpaqueTicks && explored[i, j])
explored[i, j] = false;
// Clear gap
gapField[i, j] = 0;
dirty = true;
}
// Increase gap tick; rerender if necessary
if (gapActive[i, j] && 0 == gapField[i, j]++)
dirty = true;
gapActive[t.X, t.Y] = true;
explored[t.X, t.Y] = false;
dirty = true;
}
gapTicks = gapOpaqueTicks;
}
public bool IsExplored(int2 xy) { return IsExplored(xy.X, xy.Y); }
public bool IsExplored(int x, int y)
{
if (gapField[ x, y ] >= Rules.General.GapRegenInterval * 25 * 60)
if (gapField[ x, y ] > 0)
return false;
if (hasGPS)