Move TerrainRenderer to a mod-defined trait.
This commit is contained in:
@@ -34,7 +34,7 @@ namespace OpenRA.Graphics
|
|||||||
readonly HashSet<Actor> onScreenActors = new HashSet<Actor>();
|
readonly HashSet<Actor> onScreenActors = new HashSet<Actor>();
|
||||||
readonly HardwarePalette palette = new HardwarePalette();
|
readonly HardwarePalette palette = new HardwarePalette();
|
||||||
readonly Dictionary<string, PaletteReference> palettes = new Dictionary<string, PaletteReference>();
|
readonly Dictionary<string, PaletteReference> palettes = new Dictionary<string, PaletteReference>();
|
||||||
readonly TerrainRenderer terrainRenderer;
|
readonly IRenderTerrain terrainRenderer;
|
||||||
readonly Lazy<DebugVisualizations> debugVis;
|
readonly Lazy<DebugVisualizations> debugVis;
|
||||||
readonly Func<string, PaletteReference> createPaletteReference;
|
readonly Func<string, PaletteReference> createPaletteReference;
|
||||||
readonly bool enableDepthBuffer;
|
readonly bool enableDepthBuffer;
|
||||||
@@ -62,7 +62,7 @@ namespace OpenRA.Graphics
|
|||||||
palette.Initialize();
|
palette.Initialize();
|
||||||
|
|
||||||
Theater = new Theater(world.Map.Rules.TileSet);
|
Theater = new Theater(world.Map.Rules.TileSet);
|
||||||
terrainRenderer = new TerrainRenderer(world, this);
|
terrainRenderer = world.WorldActor.TraitOrDefault<IRenderTerrain>();
|
||||||
|
|
||||||
debugVis = Exts.Lazy(() => world.WorldActor.TraitOrDefault<DebugVisualizations>());
|
debugVis = Exts.Lazy(() => world.WorldActor.TraitOrDefault<DebugVisualizations>());
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,9 @@ namespace OpenRA.Graphics
|
|||||||
if (enableDepthBuffer)
|
if (enableDepthBuffer)
|
||||||
Game.Renderer.Context.EnableDepthBuffer();
|
Game.Renderer.Context.EnableDepthBuffer();
|
||||||
|
|
||||||
terrainRenderer.Draw(this, Viewport);
|
if (terrainRenderer != null)
|
||||||
|
terrainRenderer.RenderTerrain(this, Viewport);
|
||||||
|
|
||||||
Game.Renderer.Flush();
|
Game.Renderer.Flush();
|
||||||
|
|
||||||
for (var i = 0; i < renderables.Count; i++)
|
for (var i = 0; i < renderables.Count; i++)
|
||||||
@@ -330,7 +332,6 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
palette.Dispose();
|
palette.Dispose();
|
||||||
Theater.Dispose();
|
Theater.Dispose();
|
||||||
terrainRenderer.Dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,6 @@
|
|||||||
<Compile Include="Graphics\SpriteFont.cs" />
|
<Compile Include="Graphics\SpriteFont.cs" />
|
||||||
<Compile Include="Graphics\SpriteLoader.cs" />
|
<Compile Include="Graphics\SpriteLoader.cs" />
|
||||||
<Compile Include="Graphics\SpriteRenderer.cs" />
|
<Compile Include="Graphics\SpriteRenderer.cs" />
|
||||||
<Compile Include="Graphics\TerrainRenderer.cs" />
|
|
||||||
<Compile Include="Graphics\Util.cs" />
|
<Compile Include="Graphics\Util.cs" />
|
||||||
<Compile Include="Graphics\Viewport.cs" />
|
<Compile Include="Graphics\Viewport.cs" />
|
||||||
<Compile Include="Graphics\WorldRenderer.cs" />
|
<Compile Include="Graphics\WorldRenderer.cs" />
|
||||||
|
|||||||
@@ -374,12 +374,16 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
|
public interface INotifyBecomingIdle { void OnBecomingIdle(Actor self); }
|
||||||
|
|
||||||
[RequireExplicitImplementation]
|
[RequireExplicitImplementation]
|
||||||
public interface INotifyIdle { void TickIdle(Actor self); }
|
public interface INotifyIdle { void TickIdle(Actor self); }
|
||||||
|
|
||||||
public interface IRenderAboveWorld { void RenderAboveWorld(Actor self, WorldRenderer wr); }
|
public interface IRenderAboveWorld { void RenderAboveWorld(Actor self, WorldRenderer wr); }
|
||||||
public interface IRenderShroud { void RenderShroud(Shroud shroud, WorldRenderer wr); }
|
public interface IRenderShroud { void RenderShroud(Shroud shroud, WorldRenderer wr); }
|
||||||
|
|
||||||
|
[RequireExplicitImplementation]
|
||||||
|
public interface IRenderTerrain { void RenderTerrain(WorldRenderer wr, Viewport viewport); }
|
||||||
|
|
||||||
public interface IRenderAboveShroud
|
public interface IRenderAboveShroud
|
||||||
{
|
{
|
||||||
IEnumerable<IRenderable> RenderAboveShroud(Actor self, WorldRenderer wr);
|
IEnumerable<IRenderable> RenderAboveShroud(Actor self, WorldRenderer wr);
|
||||||
|
|||||||
@@ -563,6 +563,7 @@
|
|||||||
<Compile Include="Traits\World\PaletteFromGimpOrJascFile.cs" />
|
<Compile Include="Traits\World\PaletteFromGimpOrJascFile.cs" />
|
||||||
<Compile Include="Traits\World\PaletteFromPng.cs" />
|
<Compile Include="Traits\World\PaletteFromPng.cs" />
|
||||||
<Compile Include="Traits\World\PaletteFromRGBA.cs" />
|
<Compile Include="Traits\World\PaletteFromRGBA.cs" />
|
||||||
|
<Compile Include="Traits\World\TerrainRenderer.cs" />
|
||||||
<Compile Include="Traits\World\ValidateOrder.cs" />
|
<Compile Include="Traits\World\ValidateOrder.cs" />
|
||||||
<Compile Include="Pathfinder\CellInfoLayerPool.cs" />
|
<Compile Include="Pathfinder\CellInfoLayerPool.cs" />
|
||||||
<Compile Include="Pathfinder\Constants.cs" />
|
<Compile Include="Pathfinder\Constants.cs" />
|
||||||
|
|||||||
@@ -11,19 +11,32 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
|
|
||||||
namespace OpenRA.Graphics
|
namespace OpenRA.Mods.Common.Traits
|
||||||
{
|
{
|
||||||
sealed class TerrainRenderer : IDisposable
|
public class TerrainRendererInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new TerrainRenderer(init.World); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class TerrainRenderer : IRenderTerrain, IWorldLoaded, INotifyActorDisposing
|
||||||
{
|
{
|
||||||
readonly Map map;
|
readonly Map map;
|
||||||
readonly Dictionary<string, TerrainSpriteLayer> spriteLayers = new Dictionary<string, TerrainSpriteLayer>();
|
readonly Dictionary<string, TerrainSpriteLayer> spriteLayers = new Dictionary<string, TerrainSpriteLayer>();
|
||||||
readonly Theater theater;
|
Theater theater;
|
||||||
|
bool disposed;
|
||||||
|
|
||||||
public TerrainRenderer(World world, WorldRenderer wr)
|
public TerrainRenderer(World world)
|
||||||
{
|
{
|
||||||
map = world.Map;
|
map = world.Map;
|
||||||
|
}
|
||||||
|
|
||||||
|
void IWorldLoaded.WorldLoaded(World world, WorldRenderer wr)
|
||||||
|
{
|
||||||
theater = wr.Theater;
|
theater = wr.Theater;
|
||||||
|
|
||||||
foreach (var template in map.Rules.TileSet.Templates)
|
foreach (var template in map.Rules.TileSet.Templates)
|
||||||
@@ -52,7 +65,7 @@ namespace OpenRA.Graphics
|
|||||||
kv.Value.Update(cell, palette == kv.Key ? sprite : null);
|
kv.Value.Update(cell, palette == kv.Key ? sprite : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw(WorldRenderer wr, Viewport viewport)
|
void IRenderTerrain.RenderTerrain(WorldRenderer wr, Viewport viewport)
|
||||||
{
|
{
|
||||||
foreach (var kv in spriteLayers.Values)
|
foreach (var kv in spriteLayers.Values)
|
||||||
kv.Draw(wr.Viewport);
|
kv.Draw(wr.Viewport);
|
||||||
@@ -61,13 +74,18 @@ namespace OpenRA.Graphics
|
|||||||
r.Render(wr);
|
r.Render(wr);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
void INotifyActorDisposing.Disposing(Actor self)
|
||||||
{
|
{
|
||||||
|
if (disposed)
|
||||||
|
return;
|
||||||
|
|
||||||
map.Tiles.CellEntryChanged -= UpdateCell;
|
map.Tiles.CellEntryChanged -= UpdateCell;
|
||||||
map.Height.CellEntryChanged -= UpdateCell;
|
map.Height.CellEntryChanged -= UpdateCell;
|
||||||
|
|
||||||
foreach (var kv in spriteLayers.Values)
|
foreach (var kv in spriteLayers.Values)
|
||||||
kv.Dispose();
|
kv.Dispose();
|
||||||
|
|
||||||
|
disposed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
VictoryMusic: win1
|
VictoryMusic: win1
|
||||||
DefeatMusic: nod_map1
|
DefeatMusic: nod_map1
|
||||||
DebugVisualizations:
|
DebugVisualizations:
|
||||||
|
TerrainRenderer:
|
||||||
TerrainGeometryOverlay:
|
TerrainGeometryOverlay:
|
||||||
ShroudRenderer:
|
ShroudRenderer:
|
||||||
ShroudVariants: typea, typeb, typec, typed
|
ShroudVariants: typea, typeb, typec, typed
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
DefeatMusic: score
|
DefeatMusic: score
|
||||||
TerrainGeometryOverlay:
|
TerrainGeometryOverlay:
|
||||||
DebugVisualizations:
|
DebugVisualizations:
|
||||||
|
TerrainRenderer:
|
||||||
ShroudRenderer:
|
ShroudRenderer:
|
||||||
ShroudVariants: shrouda, shroudb, shroudc, shroudd
|
ShroudVariants: shrouda, shroudb, shroudc, shroudd
|
||||||
FogVariants: foga, fogb, fogc, fogd
|
FogVariants: foga, fogb, fogc, fogd
|
||||||
|
|||||||
@@ -89,6 +89,7 @@
|
|||||||
Locomotor@IMMOBILE:
|
Locomotor@IMMOBILE:
|
||||||
Name: immobile
|
Name: immobile
|
||||||
TerrainSpeeds:
|
TerrainSpeeds:
|
||||||
|
TerrainRenderer:
|
||||||
ShroudRenderer:
|
ShroudRenderer:
|
||||||
FogVariants: shroud
|
FogVariants: shroud
|
||||||
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
MusicPlaylist:
|
MusicPlaylist:
|
||||||
VictoryMusic: score
|
VictoryMusic: score
|
||||||
DefeatMusic: maps
|
DefeatMusic: maps
|
||||||
|
TerrainRenderer:
|
||||||
ShroudRenderer:
|
ShroudRenderer:
|
||||||
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
Index: 255, 16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 20, 40, 56, 65, 97, 130, 148, 194, 24, 33, 66, 132, 28, 41, 67, 134, 1, 2, 4, 8, 3, 6, 12, 9, 7, 14, 13, 11, 5, 10, 15, 255
|
||||||
UseExtendedIndex: true
|
UseExtendedIndex: true
|
||||||
|
|||||||
Reference in New Issue
Block a user