Freeze smudges under fog.
This commit is contained in:
@@ -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,25 +59,40 @@ 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
|
||||||
var tile = tiles[loc];
|
{
|
||||||
|
|
||||||
// Existing smudge; make it deeper
|
// Existing smudge; make it deeper
|
||||||
|
var tile = dirty.ContainsKey(loc) ? dirty[loc] : tiles[loc];
|
||||||
var depth = Info.Depths[tile.type - 1];
|
var depth = Info.Depths[tile.type - 1];
|
||||||
if (tile.index < depth - 1)
|
if (tile.index < depth - 1)
|
||||||
{
|
|
||||||
tile.index++;
|
tile.index++;
|
||||||
tiles[loc] = tile; // struct semantics.
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var r in remove)
|
||||||
|
dirty.Remove(r);
|
||||||
|
}
|
||||||
|
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
{
|
{
|
||||||
var cliprect = Game.viewport.WorldBounds(world);
|
var cliprect = Game.viewport.WorldBounds(world);
|
||||||
|
|||||||
Reference in New Issue
Block a user