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> drawComponentTypeToOrderedRenderer = new Dictionary>(); public RenderManager( EntityManager entityManager, ComponentManager componentManager, DrawLayerManager drawLayerManager ) { this.entityManager = entityManager; this.componentManager = componentManager; this.drawLayerManager = drawLayerManager; } public void RegisterOrderedRenderer(Action 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(); } } } } }