Refactor per-player shrouds & fix shellmap shroud.
This commit is contained in:
@@ -139,7 +139,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
foreach (var t in world.ActorsWithTrait<IRadarSignature>())
|
||||
{
|
||||
if (!world.RenderedShroud.IsVisible(t.Actor))
|
||||
if (world.ShroudObscures(t.Actor))
|
||||
continue;
|
||||
|
||||
var color = t.Trait.RadarSignatureColor(t.Actor);
|
||||
@@ -158,7 +158,7 @@ namespace OpenRA.Graphics
|
||||
var map = world.Map;
|
||||
var size = Exts.NextPowerOf2(Math.Max(map.Bounds.Width, map.Bounds.Height));
|
||||
var bitmap = new Bitmap(size, size);
|
||||
if (world.RenderedShroud.Disabled)
|
||||
if (world.RenderPlayer == null)
|
||||
return bitmap;
|
||||
|
||||
var bitmapData = bitmap.LockBits(bitmap.Bounds(),
|
||||
@@ -174,11 +174,10 @@ namespace OpenRA.Graphics
|
||||
for (var x = 0; x < map.Bounds.Width; x++)
|
||||
for (var y = 0; y < map.Bounds.Height; y++)
|
||||
{
|
||||
var mapX = x + map.Bounds.Left;
|
||||
var mapY = y + map.Bounds.Top;
|
||||
if (!world.RenderedShroud.IsExplored(mapX, mapY))
|
||||
var p = new CPos(x + map.Bounds.Left, y + map.Bounds.Top);
|
||||
if (world.ShroudObscures(p))
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = shroud;
|
||||
else if (!world.RenderedShroud.IsVisible(mapX,mapY))
|
||||
else if (world.FogObscures(p))
|
||||
*(c + (y * bitmapData.Stride >> 2) + x) = fog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,21 +15,12 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
public class ShroudRenderer
|
||||
{
|
||||
World world;
|
||||
Traits.Shroud shroud {
|
||||
get {
|
||||
return world.RenderedShroud;
|
||||
}
|
||||
}
|
||||
|
||||
Map map;
|
||||
Sprite[] shadowBits = Game.modData.SpriteLoader.LoadAllSprites("shadow");
|
||||
Sprite[,] sprites, fogSprites;
|
||||
|
||||
Map map;
|
||||
|
||||
public ShroudRenderer(World world)
|
||||
{
|
||||
this.world = world;
|
||||
this.map = world.Map;
|
||||
|
||||
sprites = new Sprite[map.MapSize.X, map.MapSize.Y];
|
||||
@@ -56,58 +47,58 @@ namespace OpenRA.Graphics
|
||||
new byte[] { 46 },
|
||||
};
|
||||
|
||||
Sprite ChooseShroud(int i, int j)
|
||||
Sprite ChooseShroud(Shroud s, int i, int j)
|
||||
{
|
||||
if( !shroud.IsExplored( i, j ) ) return shadowBits[ 0xf ];
|
||||
if (!s.IsExplored(i, j))
|
||||
return shadowBits[0xf];
|
||||
|
||||
// bits are for unexploredness: up, right, down, left
|
||||
var v = 0;
|
||||
// bits are for unexploredness: TL, TR, BR, BL
|
||||
var u = 0;
|
||||
|
||||
if( !shroud.IsExplored( i, j - 1 ) ) { v |= 1; u |= 3; }
|
||||
if( !shroud.IsExplored( i + 1, j ) ) { v |= 2; u |= 6; }
|
||||
if( !shroud.IsExplored( i, j + 1 ) ) { v |= 4; u |= 12; }
|
||||
if( !shroud.IsExplored( i - 1, j ) ) { v |= 8; u |= 9; }
|
||||
if (!s.IsExplored(i, j - 1)) { v |= 1; u |= 3; }
|
||||
if (!s.IsExplored(i + 1, j)) { v |= 2; u |= 6; }
|
||||
if (!s.IsExplored(i, j + 1)) { v |= 4; u |= 12; }
|
||||
if (!s.IsExplored(i - 1, j)) { v |= 8; u |= 9; }
|
||||
|
||||
var uSides = u;
|
||||
if (!s.IsExplored(i - 1, j - 1)) u |= 1;
|
||||
if (!s.IsExplored(i + 1, j - 1)) u |= 2;
|
||||
if (!s.IsExplored(i + 1, j + 1)) u |= 4;
|
||||
if (!s.IsExplored(i - 1, j + 1)) u |= 8;
|
||||
|
||||
if( !shroud.IsExplored( i - 1, j - 1 ) ) u |= 1;
|
||||
if( !shroud.IsExplored( i + 1, j - 1 ) ) u |= 2;
|
||||
if( !shroud.IsExplored( i + 1, j + 1 ) ) u |= 4;
|
||||
if( !shroud.IsExplored( i - 1, j + 1 ) ) u |= 8;
|
||||
|
||||
return shadowBits[ SpecialShroudTiles[ u ^ uSides ][ v ] ];
|
||||
return shadowBits[SpecialShroudTiles[u ^ uSides][v]];
|
||||
}
|
||||
|
||||
Sprite ChooseFog(int i, int j)
|
||||
Sprite ChooseFog(Shroud s, int i, int j)
|
||||
{
|
||||
if (!shroud.IsVisible(i,j)) return shadowBits[0xf];
|
||||
if (!shroud.IsExplored(i, j)) return shadowBits[0xf];
|
||||
if (!s.IsVisible(i, j)) return shadowBits[0xf];
|
||||
if (!s.IsExplored(i, j)) return shadowBits[0xf];
|
||||
|
||||
// bits are for unexploredness: up, right, down, left
|
||||
var v = 0;
|
||||
// bits are for unexploredness: TL, TR, BR, BL
|
||||
var u = 0;
|
||||
|
||||
if (!shroud.IsVisible(i, j - 1)) { v |= 1; u |= 3; }
|
||||
if (!shroud.IsVisible(i + 1, j)) { v |= 2; u |= 6; }
|
||||
if (!shroud.IsVisible(i, j + 1)) { v |= 4; u |= 12; }
|
||||
if (!shroud.IsVisible(i - 1, j)) { v |= 8; u |= 9; }
|
||||
if (!s.IsVisible(i, j - 1)) { v |= 1; u |= 3; }
|
||||
if (!s.IsVisible(i + 1, j)) { v |= 2; u |= 6; }
|
||||
if (!s.IsVisible(i, j + 1)) { v |= 4; u |= 12; }
|
||||
if (!s.IsVisible(i - 1, j)) { v |= 8; u |= 9; }
|
||||
|
||||
var uSides = u;
|
||||
|
||||
if (!shroud.IsVisible(i - 1, j - 1)) u |= 1;
|
||||
if (!shroud.IsVisible(i + 1, j - 1)) u |= 2;
|
||||
if (!shroud.IsVisible(i + 1, j + 1)) u |= 4;
|
||||
if (!shroud.IsVisible(i - 1, j + 1)) u |= 8;
|
||||
if (!s.IsVisible(i - 1, j - 1)) u |= 1;
|
||||
if (!s.IsVisible(i + 1, j - 1)) u |= 2;
|
||||
if (!s.IsVisible(i + 1, j + 1)) u |= 4;
|
||||
if (!s.IsVisible(i - 1, j + 1)) u |= 8;
|
||||
|
||||
return shadowBits[SpecialShroudTiles[u ^ uSides][v]];
|
||||
}
|
||||
|
||||
bool initializePalettes = true;
|
||||
PaletteReference fogPalette, shroudPalette;
|
||||
internal void Draw(WorldRenderer wr)
|
||||
internal void Draw(WorldRenderer wr, Player renderPlayer)
|
||||
{
|
||||
if (initializePalettes)
|
||||
{
|
||||
@@ -116,18 +107,42 @@ namespace OpenRA.Graphics
|
||||
initializePalettes = false;
|
||||
}
|
||||
|
||||
if (shroud != null && shroud.dirty)
|
||||
if (renderPlayer == null)
|
||||
{
|
||||
shroud.dirty = false;
|
||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||
sprites[i, j] = ChooseShroud(i, j);
|
||||
// Players with no shroud see the whole map so we only need to set the edges
|
||||
var b = map.Bounds;
|
||||
for (int i = b.Left; i < b.Right; i++)
|
||||
for (int j = b.Top; j < b.Bottom; j++)
|
||||
{
|
||||
var v = 0;
|
||||
var u = 0;
|
||||
|
||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||
fogSprites[i, j] = ChooseFog(i, j);
|
||||
if (j == b.Top) { v |= 1; u |= 3; }
|
||||
if (i == b.Right - 1) { v |= 2; u |= 6; }
|
||||
if (j == b.Bottom - 1) { v |= 4; u |= 12; }
|
||||
if (i == b.Left) { v |= 8; u |= 9; }
|
||||
|
||||
var uSides = u;
|
||||
if (i == b.Left && j == b.Top) u |= 1;
|
||||
if (i == b.Right - 1 && j == b.Top) u |= 2;
|
||||
if (i == b.Right - 1 && j == b.Bottom - 1) u |= 4;
|
||||
if (i == b.Left && j == b.Bottom - 1) u |= 8;
|
||||
|
||||
sprites[i, j] = fogSprites[i, j] = shadowBits[SpecialShroudTiles[u ^ uSides][v]];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderPlayer.Shroud.dirty = false;
|
||||
|
||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||
sprites[i, j] = ChooseShroud(renderPlayer.Shroud, i, j);
|
||||
|
||||
for (int i = map.Bounds.Left; i < map.Bounds.Right; i++)
|
||||
for (int j = map.Bounds.Top; j < map.Bounds.Bottom; j++)
|
||||
fogSprites[i, j] = ChooseFog(renderPlayer.Shroud, i, j);
|
||||
}
|
||||
var clipRect = Game.viewport.WorldBounds(wr.world);
|
||||
DrawShroud(wr, clipRect, sprites, shroudPalette);
|
||||
if (wr.world.WorldActor.HasTrait<Fog>())
|
||||
|
||||
@@ -72,9 +72,9 @@ namespace OpenRA.Graphics
|
||||
if (firstRow < 0) firstRow = 0;
|
||||
if (lastRow > map.Bounds.Height) lastRow = map.Bounds.Height;
|
||||
|
||||
if (world.RenderedPlayer != null && !world.RenderedShroud.Disabled && world.RenderedShroud.Bounds.HasValue)
|
||||
if (world.VisibleBounds.HasValue)
|
||||
{
|
||||
var r = world.RenderedShroud.Bounds.Value;
|
||||
var r = world.VisibleBounds.Value;
|
||||
if (firstRow < r.Top - map.Bounds.Top)
|
||||
firstRow = r.Top - map.Bounds.Top;
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace OpenRA.Graphics
|
||||
cachedScroll = scrollPosition;
|
||||
}
|
||||
|
||||
var b = world.RenderedShroud.Bounds;
|
||||
var b = world.VisibleBounds;
|
||||
return (b.HasValue) ? Rectangle.Intersect(cachedRect, b.Value) : cachedRect;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ namespace OpenRA.Graphics
|
||||
if (world.OrderGenerator != null)
|
||||
world.OrderGenerator.RenderAfterWorld(this, world);
|
||||
|
||||
shroudRenderer.Draw( this );
|
||||
shroudRenderer.Draw(this, world.RenderPlayer);
|
||||
Game.Renderer.DisableScissor();
|
||||
|
||||
foreach (var g in world.Selection.Actors.Where(a => !a.Destroyed)
|
||||
|
||||
Reference in New Issue
Block a user