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

@@ -97,7 +97,7 @@ namespace OpenRa.Graphics
return;
var bitmap = new Bitmap(oreLayer);
var bitmapData = bitmap.LockBits(new Rectangle( 0,0,bitmap.Width, bitmap.Height ),
var bitmapData = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
unsafe
@@ -105,26 +105,23 @@ namespace OpenRa.Graphics
var colors = terrainTypeColors[world.Map.Theater.ToLowerInvariant()];
int* c = (int*)bitmapData.Scan0;
for (var y = 0; y < 128; y++)
for (var x = 0; x < 128; x++)
foreach (var a in world.Queries.WithTrait<Unit>())
*(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) =
playerColors[(int)a.Actor.Owner.Palette].ToArgb();
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++)
{
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
{
*(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();
}
foreach (var a in world.Queries.WithTrait<Unit>())
*(c + (a.Actor.Location.Y * bitmapData.Stride >> 2) + a.Actor.Location.X) =
playerColors[(int)a.Actor.Owner.Palette].ToArgb();
unchecked
{
for (var y = 0; y < 128; y++)
for (var x = 0; x < 128; x++)
if (!world.LocalPlayer.Shroud.DisplayOnRadar(x, y))
*(c + (y * bitmapData.Stride >> 2) + x) = shroudColor.ToArgb();
}
}
bitmap.UnlockBits(bitmapData);

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)