51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class RenderManager
|
|
{
|
|
private readonly DrawLayerManager drawLayerManager;
|
|
|
|
private readonly Dictionary<Type, Action<Entity, IComponent>> drawComponentTypeToOrderedRenderer = new Dictionary<Type, Action<Entity, IComponent>>(256);
|
|
|
|
public RenderManager(DrawLayerManager drawLayerManager)
|
|
{
|
|
this.drawLayerManager = drawLayerManager;
|
|
}
|
|
|
|
public void RegisterOrderedRenderer<TComponent>(Action<Entity, IComponent> renderAction) where TComponent : struct, IComponent
|
|
{
|
|
drawComponentTypeToOrderedRenderer.Add(typeof(TComponent), renderAction);
|
|
drawLayerManager.RegisterOrderedDrawable<TComponent>();
|
|
}
|
|
|
|
public void RegisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer)
|
|
{
|
|
drawLayerManager.RegisterGeneralRendererWithLayer(renderer, layer);
|
|
}
|
|
|
|
public void Draw()
|
|
{
|
|
foreach (var layer in drawLayerManager.LayerOrder)
|
|
{
|
|
var generalRendererSet = drawLayerManager.GeneralRenderersByLayer(layer);
|
|
|
|
foreach (var (entity, componentType, component) in drawLayerManager.AllInLayer(layer))
|
|
{
|
|
if (drawComponentTypeToOrderedRenderer.ContainsKey(componentType))
|
|
{
|
|
var internalRenderAction = drawComponentTypeToOrderedRenderer[componentType];
|
|
internalRenderAction(entity, component);
|
|
}
|
|
}
|
|
|
|
foreach (var generalRenderer in generalRendererSet)
|
|
{
|
|
generalRenderer.Render();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|