Refactor per-player shrouds & fix shellmap shroud.
This commit is contained in:
@@ -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>())
|
||||
|
||||
Reference in New Issue
Block a user