Add FrozenUnderFog property to BibLayer.
Note: This implements the desired behavior for FrozenUnderFog, so is still inconsistent with its current (broken) behavior.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.FileFormats;
|
using OpenRA.FileFormats;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -21,14 +22,23 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
{
|
{
|
||||||
public readonly string[] BibTypes = { "bib3", "bib2", "bib1" };
|
public readonly string[] BibTypes = { "bib3", "bib2", "bib1" };
|
||||||
public readonly int[] BibWidths = { 2, 3, 4 };
|
public readonly int[] BibWidths = { 2, 3, 4 };
|
||||||
|
public readonly bool FrozenUnderFog = false;
|
||||||
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
|
public object Create(ActorInitializer init) { return new BibLayer(init.self, this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
class BibLayer : IRenderOverlay, IWorldLoaded
|
struct CachedBib
|
||||||
|
{
|
||||||
|
public Dictionary<CPos, TileReference<byte, byte>> Tiles;
|
||||||
|
public IEnumerable<CPos> Footprint;
|
||||||
|
public bool Visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
class BibLayer : IRenderOverlay, IWorldLoaded, ITickRender
|
||||||
{
|
{
|
||||||
World world;
|
World world;
|
||||||
BibLayerInfo info;
|
BibLayerInfo info;
|
||||||
Dictionary<CPos, TileReference<byte, byte>> tiles;
|
Dictionary<Actor, CachedBib> visible;
|
||||||
|
Dictionary<Actor, CachedBib> dirty;
|
||||||
Sprite[][] bibSprites;
|
Sprite[][] bibSprites;
|
||||||
|
|
||||||
public BibLayer(Actor self, BibLayerInfo info)
|
public BibLayer(Actor self, BibLayerInfo info)
|
||||||
@@ -43,7 +53,8 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
public void WorldLoaded(World w)
|
public void WorldLoaded(World w)
|
||||||
{
|
{
|
||||||
world = w;
|
world = w;
|
||||||
tiles = new Dictionary<CPos, TileReference<byte, byte>>();
|
visible = new Dictionary<Actor, CachedBib>();
|
||||||
|
dirty = new Dictionary<Actor, CachedBib>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DoBib(Actor b, bool isAdd)
|
public void DoBib(Actor b, bool isAdd)
|
||||||
@@ -55,40 +66,69 @@ namespace OpenRA.Mods.RA.Buildings
|
|||||||
var size = buildingInfo.Dimensions.X;
|
var size = buildingInfo.Dimensions.X;
|
||||||
var bibOffset = buildingInfo.Dimensions.Y - 1;
|
var bibOffset = buildingInfo.Dimensions.Y - 1;
|
||||||
|
|
||||||
int bib = Array.IndexOf(info.BibWidths, size);
|
var bib = Array.IndexOf(info.BibWidths, size);
|
||||||
if (bib < 0)
|
if (bib < 0)
|
||||||
{
|
{
|
||||||
Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name);
|
Log.Write("debug", "Cannot bib {0}-wide building {1}", size, b.Info.Name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dirty[b] = new CachedBib()
|
||||||
|
{
|
||||||
|
Footprint = FootprintUtils.Tiles(b),
|
||||||
|
Tiles = new Dictionary<CPos, TileReference<byte, byte>>(),
|
||||||
|
Visible = isAdd
|
||||||
|
};
|
||||||
|
|
||||||
for (var i = 0; i < 2 * size; i++)
|
for (var i = 0; i < 2 * size; i++)
|
||||||
{
|
{
|
||||||
var p = b.Location + new CVec(i % size, i / size + bibOffset);
|
var cell = b.Location + new CVec(i % size, i / size + bibOffset);
|
||||||
if (isAdd)
|
var tile = new TileReference<byte, byte>((byte)(bib + 1), (byte) i);
|
||||||
tiles[p] = new TileReference<byte, byte>((byte)(bib + 1), (byte)i);
|
dirty[b].Tiles.Add(cell, tile);
|
||||||
else
|
|
||||||
tiles.Remove(p);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void TickRender(WorldRenderer wr, Actor self)
|
||||||
|
{
|
||||||
|
var remove = new List<Actor>();
|
||||||
|
foreach (var kv in dirty)
|
||||||
|
{
|
||||||
|
if (!info.FrozenUnderFog || kv.Value.Footprint.Any(c => !self.World.FogObscures(c)))
|
||||||
|
{
|
||||||
|
if (kv.Value.Visible)
|
||||||
|
visible[kv.Key] = kv.Value;
|
||||||
|
else
|
||||||
|
visible.Remove(kv.Key);
|
||||||
|
|
||||||
|
remove.Add(kv.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var r in remove)
|
||||||
|
dirty.Remove(r);
|
||||||
|
}
|
||||||
|
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
var pal = wr.Palette("terrain");
|
var pal = wr.Palette("terrain");
|
||||||
var cliprect = Game.viewport.WorldBounds(world);
|
var cliprect = Game.viewport.WorldBounds(world);
|
||||||
|
|
||||||
foreach (var kv in tiles)
|
foreach (var bib in visible.Values)
|
||||||
{
|
{
|
||||||
if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
|
foreach (var kv in bib.Tiles)
|
||||||
continue;
|
{
|
||||||
if (world.ShroudObscures(kv.Key))
|
if (!cliprect.Contains(kv.Key.X, kv.Key.Y))
|
||||||
continue;
|
continue;
|
||||||
|
if (world.ShroudObscures(kv.Key))
|
||||||
|
continue;
|
||||||
|
|
||||||
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal);
|
var tile = bibSprites[kv.Value.type - 1][kv.Value.index];
|
||||||
|
tile.DrawAt(wr.ScreenPxPosition(kv.Key.CenterPosition) - 0.5f * tile.size, pal);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BibInfo : TraitInfo<Bib> { }
|
public class BibInfo : TraitInfo<Bib>, Requires<BuildingInfo> { }
|
||||||
public class Bib { }
|
public class Bib { }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,6 +354,7 @@ World:
|
|||||||
BibLayer:
|
BibLayer:
|
||||||
BibTypes: bib3x, bib2x
|
BibTypes: bib3x, bib2x
|
||||||
BibWidths: 3, 2
|
BibWidths: 3, 2
|
||||||
|
FrozenUnderFog: true
|
||||||
DomainIndex:
|
DomainIndex:
|
||||||
ResourceLayer:
|
ResourceLayer:
|
||||||
ResourceClaimLayer:
|
ResourceClaimLayer:
|
||||||
|
|||||||
Reference in New Issue
Block a user