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

@@ -105,25 +105,22 @@ namespace OpenRa.Graphics
var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()]; var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()];
int* c = (int*)bitmapData.Scan0; int* c = (int*)bitmapData.Scan0;
for (var y = 0; y < 128; y++)
for (var x = 0; x < 128; x++)
{
var b = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(new int2(x, y));
if (b != null)
*(c + (y * bitmapData.Stride >> 2) + x) =
(b.Owner != null ? playerColors[(int)b.Owner.Palette] : colors[4]).ToArgb();
}
foreach (var a in world.Queries.WithTrait<Unit>()) foreach (var a in world.Queries.WithTrait<Unit>())
*(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) = *(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) =
playerColors[(int)a.Actor.Owner.Palette].ToArgb(); playerColors[(int)a.Actor.Owner.Palette].ToArgb();
unchecked for (var y = world.Map.YOffset; y < world.Map.YOffset + world.Map.Height; y++)
for (var x = world.Map.XOffset; x < world.Map.XOffset + world.Map.Width; x++)
{ {
for (var y = 0; y < 128; y++)
for (var x = 0; x < 128; x++)
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y)) if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
{
*(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb(); *(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb();
continue;
}
var b = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(new int2(x, y));
if (b != null)
*(c + (y * bitmapData.Stride >> 2) + x) =
(b.Owner != null ? playerColors[(int)b.Owner.Palette] : colors[4]).ToArgb();
} }
} }

View File

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