More refactoring and a TODO on custom terrain perf
This commit is contained in:
@@ -19,21 +19,10 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
class Minimap
|
||||
{
|
||||
static int NextPowerOf2(int v)
|
||||
{
|
||||
--v;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
++v;
|
||||
return v;
|
||||
}
|
||||
|
||||
public static Bitmap RenderTerrainBitmap(Map map)
|
||||
{
|
||||
var tileset = Rules.TileSets[map.Tileset];
|
||||
var size = NextPowerOf2(Math.Max(map.Width, map.Height));
|
||||
var size = Util.NextPowerOf2(Math.Max(map.Width, map.Height));
|
||||
Bitmap terrain = new Bitmap(size, size);
|
||||
|
||||
var bitmapData = terrain.LockBits(new Rectangle(0, 0, terrain.Width, terrain.Height),
|
||||
@@ -108,9 +97,12 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var mapX = x + map.TopLeft.X;
|
||||
var mapY = y + map.TopLeft.Y;
|
||||
|
||||
// This is extremely slow (~7ms). TODO: cache this information and only update when it changes
|
||||
var customTerrain = world.WorldActor.traits.WithInterface<ITerrainTypeModifier>()
|
||||
.Select( t => t.GetTerrainType(new int2(mapX, mapY)) )
|
||||
.FirstOrDefault( t => t != null );
|
||||
|
||||
if (customTerrain == null) continue;
|
||||
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = world.TileSet.Terrain[customTerrain].Color.ToArgb();
|
||||
@@ -152,12 +144,11 @@ namespace OpenRA.Graphics
|
||||
}
|
||||
if (!world.LocalPlayer.Shroud.IsVisible(mapX,mapY))
|
||||
{
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = Util.Lerp(fogOpacity, Color.FromArgb(*(c + (y * bitmapData.Stride >> 2) + x)), Color.Black).ToArgb();
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = Util.LerpARGBColor(fogOpacity, *(c + (y * bitmapData.Stride >> 2) + x), shroud);
|
||||
continue;
|
||||
}
|
||||
|
||||
var b = world.WorldActor.traits.Get<BuildingInfluence>().GetBuildingAt(new int2(mapX, mapY));
|
||||
|
||||
if (b != null)
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = b.Owner.Color.ToArgb();
|
||||
}
|
||||
|
||||
@@ -113,9 +113,29 @@ namespace OpenRA.Graphics
|
||||
LerpChannel(t, a.B, b.B));
|
||||
}
|
||||
|
||||
public static int LerpARGBColor(float t, int c1, int c2)
|
||||
{
|
||||
int a = LerpChannel(t, (c1 >> 24) & 255, (c2 >> 24) & 255);
|
||||
int r = LerpChannel(t, (c1 >> 16) & 255, (c2 >> 16) & 255);
|
||||
int g = LerpChannel(t, (c1 >> 8) & 255, (c2 >> 8) & 255);
|
||||
int b = LerpChannel(t, c1 & 255, c2 & 255);
|
||||
return (a << 24) | (r << 16) | (g << 8) | b;
|
||||
}
|
||||
|
||||
public static int LerpChannel(float t, int a, int b)
|
||||
{
|
||||
return (int)((1 - t) * a + t * b);
|
||||
}
|
||||
|
||||
public static int NextPowerOf2(int v)
|
||||
{
|
||||
--v;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
++v;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user