diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index eba6538c36..07c4ebec06 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -18,22 +18,11 @@ using OpenRA.Traits; 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() .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(); @@ -120,7 +112,7 @@ namespace OpenRA.Graphics bitmap.UnlockBits(bitmapData); return bitmap; } - + public static Bitmap AddActors(World world, Bitmap terrain) { var map = world.Map; @@ -151,13 +143,12 @@ namespace OpenRA.Graphics continue; } 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().GetBuildingAt(new int2(mapX, mapY)); - if (b != null) *(c + (y * bitmapData.Stride >> 2) + x) = b.Owner.Color.ToArgb(); } diff --git a/OpenRA.Game/Graphics/Util.cs b/OpenRA.Game/Graphics/Util.cs index 99a8f0a799..4211b97f64 100644 --- a/OpenRA.Game/Graphics/Util.cs +++ b/OpenRA.Game/Graphics/Util.cs @@ -112,10 +112,30 @@ namespace OpenRA.Graphics LerpChannel(t, a.G, b.G), 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; + } } }