Freeze resources under fog.
This commit is contained in:
@@ -18,12 +18,14 @@ namespace OpenRA.Traits
|
|||||||
{
|
{
|
||||||
public class ResourceLayerInfo : TraitInfo<ResourceLayer> { }
|
public class ResourceLayerInfo : TraitInfo<ResourceLayer> { }
|
||||||
|
|
||||||
public class ResourceLayer : IRenderOverlay, IWorldLoaded
|
public class ResourceLayer : IRenderOverlay, IWorldLoaded, ITickRender
|
||||||
{
|
{
|
||||||
World world;
|
World world;
|
||||||
|
|
||||||
ResourceType[] resourceTypes;
|
ResourceType[] resourceTypes;
|
||||||
CellContents[,] content;
|
CellContents[,] content;
|
||||||
|
CellContents[,] render;
|
||||||
|
List<CPos> dirty;
|
||||||
bool hasSetupPalettes;
|
bool hasSetupPalettes;
|
||||||
|
|
||||||
public void Render(WorldRenderer wr)
|
public void Render(WorldRenderer wr)
|
||||||
@@ -37,23 +39,30 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
var clip = Game.viewport.WorldBounds(world);
|
var clip = Game.viewport.WorldBounds(world);
|
||||||
for (var x = clip.Left; x < clip.Right; x++)
|
for (var x = clip.Left; x < clip.Right; x++)
|
||||||
|
{
|
||||||
for (var y = clip.Top; y < clip.Bottom; y++)
|
for (var y = clip.Top; y < clip.Bottom; y++)
|
||||||
{
|
{
|
||||||
if (world.ShroudObscures(new CPos(x, y)))
|
var pos = new CPos(x, y);
|
||||||
|
if (world.ShroudObscures(pos))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var c = content[x, y];
|
var c = render[x, y];
|
||||||
if (c.Image != null)
|
if (c.Image != null)
|
||||||
c.Image[c.Density].DrawAt(
|
{
|
||||||
new CPos(x, y).ToPPos().ToFloat2(),
|
var tile = c.Image[c.Density];
|
||||||
c.Type.info.PaletteRef);
|
var px = wr.ScreenPxPosition(pos.CenterPosition) - 0.5f * tile.size;
|
||||||
|
tile.DrawAt(px, c.Type.info.PaletteRef);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WorldLoaded(World w)
|
public void WorldLoaded(World w)
|
||||||
{
|
{
|
||||||
this.world = w;
|
this.world = w;
|
||||||
content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
|
content = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
|
||||||
|
render = new CellContents[w.Map.MapSize.X, w.Map.MapSize.Y];
|
||||||
|
dirty = new List<CPos>();
|
||||||
|
|
||||||
resourceTypes = w.WorldActor.TraitsImplementing<ResourceType>().ToArray();
|
resourceTypes = w.WorldActor.TraitsImplementing<ResourceType>().ToArray();
|
||||||
foreach (var rt in resourceTypes)
|
foreach (var rt in resourceTypes)
|
||||||
@@ -73,17 +82,37 @@ namespace OpenRA.Traits
|
|||||||
if (!AllowResourceAt(type, new CPos(x, y)))
|
if (!AllowResourceAt(type, new CPos(x, y)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
content[x, y].Type = type;
|
render[x, y].Type = content[x, y].Type = type;
|
||||||
content[x, y].Image = ChooseContent(type);
|
render[x, y].Image = content[x, y].Image = ChooseContent(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var x = map.Bounds.Left; x < map.Bounds.Right; x++)
|
for (var x = map.Bounds.Left; x < map.Bounds.Right; x++)
|
||||||
|
{
|
||||||
for (var y = map.Bounds.Top; y < map.Bounds.Bottom; y++)
|
for (var y = map.Bounds.Top; y < map.Bounds.Bottom; y++)
|
||||||
|
{
|
||||||
if (content[x, y].Type != null)
|
if (content[x, y].Type != null)
|
||||||
{
|
{
|
||||||
content[x, y].Density = GetIdealDensity(x, y);
|
render[x, y].Density = content[x, y].Density = GetIdealDensity(x, y);
|
||||||
w.Map.CustomTerrain[x, y] = content[x, y].Type.info.TerrainType;
|
w.Map.CustomTerrain[x, y] = content[x, y].Type.info.TerrainType;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void TickRender(WorldRenderer wr, Actor self)
|
||||||
|
{
|
||||||
|
var remove = new List<CPos>();
|
||||||
|
foreach (var c in dirty)
|
||||||
|
{
|
||||||
|
if (!self.World.FogObscures(c))
|
||||||
|
{
|
||||||
|
render[c.X, c.Y] = content[c.X, c.Y];
|
||||||
|
remove.Add(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var r in remove)
|
||||||
|
dirty.Remove(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AllowResourceAt(ResourceType rt, CPos a)
|
public bool AllowResourceAt(ResourceType rt, CPos a)
|
||||||
@@ -138,6 +167,10 @@ namespace OpenRA.Traits
|
|||||||
content[i, j].Density + n);
|
content[i, j].Density + n);
|
||||||
|
|
||||||
world.Map.CustomTerrain[i, j] = t.info.TerrainType;
|
world.Map.CustomTerrain[i, j] = t.info.TerrainType;
|
||||||
|
|
||||||
|
var cell = new CPos(i, j);
|
||||||
|
if (!dirty.Contains(cell))
|
||||||
|
dirty.Add(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsFull(int i, int j)
|
public bool IsFull(int i, int j)
|
||||||
@@ -158,6 +191,9 @@ namespace OpenRA.Traits
|
|||||||
world.Map.CustomTerrain[p.X, p.Y] = null;
|
world.Map.CustomTerrain[p.X, p.Y] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!dirty.Contains(p))
|
||||||
|
dirty.Add(p);
|
||||||
|
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,6 +207,9 @@ namespace OpenRA.Traits
|
|||||||
content[p.X, p.Y].Image = null;
|
content[p.X, p.Y].Image = null;
|
||||||
content[p.X, p.Y].Density = 0;
|
content[p.X, p.Y].Density = 0;
|
||||||
world.Map.CustomTerrain[p.X, p.Y] = null;
|
world.Map.CustomTerrain[p.X, p.Y] = null;
|
||||||
|
|
||||||
|
if (!dirty.Contains(p))
|
||||||
|
dirty.Add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceType GetResource(CPos p) { return content[p.X, p.Y].Type; }
|
public ResourceType GetResource(CPos p) { return content[p.X, p.Y].Type; }
|
||||||
|
|||||||
Reference in New Issue
Block a user