Freeze smudges under fog.

This commit is contained in:
Paul Chote
2013-07-24 19:47:57 +12:00
parent ac7b93d39d
commit bfaf5446cb

View File

@@ -29,10 +29,11 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new SmudgeLayer(this); } public object Create(ActorInitializer init) { return new SmudgeLayer(this); }
} }
public class SmudgeLayer : IRenderOverlay, IWorldLoaded public class SmudgeLayer : IRenderOverlay, IWorldLoaded, ITickRender
{ {
public SmudgeLayerInfo Info; public SmudgeLayerInfo Info;
Dictionary<CPos, TileReference<byte, byte>> tiles; Dictionary<CPos, TileReference<byte, byte>> tiles;
Dictionary<CPos, TileReference<byte, byte>> dirty;
Sprite[][] smudgeSprites; Sprite[][] smudgeSprites;
World world; World world;
@@ -46,6 +47,7 @@ namespace OpenRA.Mods.RA
{ {
world = w; world = w;
tiles = new Dictionary<CPos, TileReference<byte, byte>>(); tiles = new Dictionary<CPos, TileReference<byte, byte>>();
dirty = new Dictionary<CPos, TileReference<byte, byte>>();
// Add map smudges // Add map smudges
foreach (var s in w.Map.Smudges.Value.Where(s => Info.Types.Contains(s.Type))) foreach (var s in w.Map.Smudges.Value.Where(s => Info.Types.Contains(s.Type)))
@@ -57,23 +59,38 @@ namespace OpenRA.Mods.RA
if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage) if (Game.CosmeticRandom.Next(0, 100) <= Info.SmokePercentage)
world.AddFrameEndTask(w => w.Add(new Smoke(w, loc.CenterPosition, Info.SmokeType))); world.AddFrameEndTask(w => w.Add(new Smoke(w, loc.CenterPosition, Info.SmokeType)));
// No smudge; create a new one if (!dirty.ContainsKey(loc) && !tiles.ContainsKey(loc))
if (!tiles.ContainsKey(loc))
{ {
byte st = (byte)(1 + world.SharedRandom.Next(Info.Types.Length - 1)); // No smudge; create a new one
tiles.Add(loc, new TileReference<byte, byte>(st, (byte)0)); var st = (byte)(1 + world.SharedRandom.Next(Info.Types.Length - 1));
return; dirty[loc] = new TileReference<byte, byte>(st, (byte)0);
}
else
{
// Existing smudge; make it deeper
var tile = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc];
var depth = Info.Depths[tile.type - 1];
if (tile.index < depth - 1)
tile.index++;
dirty[loc] = tile;
}
}
public void TickRender(WorldRenderer wr, Actor self)
{
var remove = new List<CPos>();
foreach (var kv in dirty)
{
if (!self.World.FogObscures(kv.Key))
{
tiles[kv.Key] = kv.Value;
remove.Add(kv.Key);
}
} }
var tile = tiles[loc]; foreach (var r in remove)
dirty.Remove(r);
// Existing smudge; make it deeper
var depth = Info.Depths[tile.type - 1];
if (tile.index < depth - 1)
{
tile.index++;
tiles[loc] = tile; // struct semantics.
}
} }
public void Render(WorldRenderer wr) public void Render(WorldRenderer wr)