63 lines
2.2 KiB
C#
63 lines
2.2 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Encompass
|
|
{
|
|
internal class RenderManager
|
|
{
|
|
private readonly EntityManager entityManager;
|
|
private readonly ComponentManager componentManager;
|
|
private readonly DrawLayerManager drawLayerManager;
|
|
|
|
private readonly Dictionary<Type, Action<Guid, IComponent>> drawComponentTypeToOrderedRenderer = new Dictionary<Type, Action<Guid, IComponent>>();
|
|
|
|
public RenderManager(
|
|
EntityManager entityManager,
|
|
ComponentManager componentManager,
|
|
DrawLayerManager drawLayerManager
|
|
)
|
|
{
|
|
this.entityManager = entityManager;
|
|
this.componentManager = componentManager;
|
|
this.drawLayerManager = drawLayerManager;
|
|
}
|
|
|
|
public void RegisterOrderedRenderer<TComponent>(Action<Guid, IComponent> renderAction) where TComponent : struct, IComponent
|
|
{
|
|
drawComponentTypeToOrderedRenderer.Add(typeof(TComponent), renderAction);
|
|
}
|
|
|
|
public void RegisterGeneralRendererWithLayer(GeneralRenderer renderer, int layer)
|
|
{
|
|
drawLayerManager.RegisterGeneralRendererWithLayer(renderer, layer);
|
|
}
|
|
|
|
public void Draw()
|
|
{
|
|
foreach (var layer in drawLayerManager.LayerOrder)
|
|
{
|
|
var componentIDSet = drawLayerManager.ComponentIDsByLayer(layer);
|
|
var generalRendererSet = drawLayerManager.GeneralRenderersByLayer(layer);
|
|
|
|
foreach (var componentID in componentIDSet)
|
|
{
|
|
var component = componentManager.GetComponentByID(componentID);
|
|
var componentType = componentManager.GetComponentTypeByID(componentID);
|
|
|
|
if (drawComponentTypeToOrderedRenderer.ContainsKey(componentType))
|
|
{
|
|
var internalRenderAction = drawComponentTypeToOrderedRenderer[componentType];
|
|
internalRenderAction(componentID, component);
|
|
}
|
|
}
|
|
|
|
foreach (var generalRenderer in generalRendererSet)
|
|
{
|
|
generalRenderer.Render();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|