throw if RegisterDrawLayer called after adding renderer #5
|
@ -0,0 +1,13 @@
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Encompass.Exceptions
|
||||||
|
{
|
||||||
|
public class IllegalDrawLayerException : Exception
|
||||||
|
{
|
||||||
|
public IllegalDrawLayerException(
|
||||||
|
string format,
|
||||||
|
params object[] args
|
||||||
|
) : base(string.Format(format, args)) { }
|
||||||
|
}
|
||||||
|
}
|
|
@ -33,15 +33,13 @@ namespace Encompass
|
||||||
private readonly TrackingManager _trackingManager;
|
private readonly TrackingManager _trackingManager;
|
||||||
|
|
||||||
private readonly Dictionary<Type, HashSet<Engine>> _typeToReaders = new Dictionary<Type, HashSet<Engine>>();
|
private readonly Dictionary<Type, HashSet<Engine>> _typeToReaders = new Dictionary<Type, HashSet<Engine>>();
|
||||||
|
|
||||||
private readonly HashSet<Engine> _senders = new HashSet<Engine>();
|
private readonly HashSet<Engine> _senders = new HashSet<Engine>();
|
||||||
|
|
||||||
private readonly HashSet<Type> _componentTypesToPreload = new HashSet<Type>();
|
private readonly HashSet<Type> _componentTypesToPreload = new HashSet<Type>();
|
||||||
|
|
||||||
private readonly HashSet<Type> _messageTypes = new HashSet<Type>();
|
private readonly HashSet<Type> _messageTypes = new HashSet<Type>();
|
||||||
|
|
||||||
private readonly Dictionary<Type, int> _typeToIndex = new Dictionary<Type, int>();
|
private readonly Dictionary<Type, int> _typeToIndex = new Dictionary<Type, int>();
|
||||||
|
|
||||||
|
private bool _rendererRegistered = false;
|
||||||
|
|
||||||
public WorldBuilder(int entityCapacity = 32768)
|
public WorldBuilder(int entityCapacity = 32768)
|
||||||
{
|
{
|
||||||
_entityCapacity = entityCapacity;
|
_entityCapacity = entityCapacity;
|
||||||
|
@ -177,6 +175,10 @@ namespace Encompass
|
||||||
/// <param name="layer">The draw layer to register.</param>
|
/// <param name="layer">The draw layer to register.</param>
|
||||||
public void RegisterDrawLayer(int layer)
|
public void RegisterDrawLayer(int layer)
|
||||||
{
|
{
|
||||||
|
if (_rendererRegistered)
|
||||||
|
{
|
||||||
|
throw new IllegalDrawLayerException("Cannot register a draw layer after a Renderer has been registered.");
|
||||||
|
}
|
||||||
_drawLayerManager.RegisterDrawLayer(layer);
|
_drawLayerManager.RegisterDrawLayer(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +191,7 @@ namespace Encompass
|
||||||
renderer.AssignEntityManager(_entityManager);
|
renderer.AssignEntityManager(_entityManager);
|
||||||
renderer.AssignComponentManager(_componentManager);
|
renderer.AssignComponentManager(_componentManager);
|
||||||
_renderManager.RegisterOrderedRenderer<TComponent>(renderer.InternalRender);
|
_renderManager.RegisterOrderedRenderer<TComponent>(renderer.InternalRender);
|
||||||
|
_rendererRegistered = true;
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,9 +205,8 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
renderer.AssignEntityManager(_entityManager);
|
renderer.AssignEntityManager(_entityManager);
|
||||||
renderer.AssignComponentManager(_componentManager);
|
renderer.AssignComponentManager(_componentManager);
|
||||||
|
|
||||||
_renderManager.RegisterGeneralRendererWithLayer(renderer, layer);
|
_renderManager.RegisterGeneralRendererWithLayer(renderer, layer);
|
||||||
|
_rendererRegistered = true;
|
||||||
return renderer;
|
return renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -558,5 +558,38 @@ namespace Tests
|
||||||
Assert.That(order.IndexOf(engineA), Is.LessThan(order.IndexOf(engineB)));
|
Assert.That(order.IndexOf(engineA), Is.LessThan(order.IndexOf(engineB)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class DrawLayerRegister
|
||||||
|
{
|
||||||
|
struct AComponent : IComponent, IDrawableComponent
|
||||||
|
{
|
||||||
|
public int Layer { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
class ARenderer : OrderedRenderer<AComponent>
|
||||||
|
{
|
||||||
|
|
||||||
|
public override void Render(Entity entity, in AComponent drawComponent) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DrawLayerRegisterAfterOrderedRendererRegisterThrows()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
|
||||||
|
var rendererA = worldBuilder.AddOrderedRenderer(new ARenderer());
|
||||||
|
|
||||||
|
Assert.Throws<IllegalDrawLayerException>(() => worldBuilder.RegisterDrawLayer(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DrawLayerRegisterBeforeOrderedRendererDoesNotThrow()
|
||||||
|
{
|
||||||
|
var worldBuilder = new WorldBuilder();
|
||||||
|
|
||||||
|
Assert.DoesNotThrow(() => worldBuilder.RegisterDrawLayer(1));
|
||||||
|
Assert.DoesNotThrow(() => worldBuilder.AddOrderedRenderer(new ARenderer()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue