AddEntityRenderer and AddGeneralRenderer take initialized renderers

pull/5/head
Evan Hemsley 2019-06-24 16:49:26 -07:00
parent 29179e0ad6
commit 148d629e51
5 changed files with 10 additions and 12 deletions

View File

@ -97,9 +97,8 @@ namespace Encompass
return engine; return engine;
} }
public TRenderer AddEntityRenderer<TRenderer>() where TRenderer : Renderer, new() public TRenderer AddEntityRenderer<TRenderer>(TRenderer renderer) where TRenderer : Renderer
{ {
var renderer = new TRenderer();
renderer.AssignEntityManager(entityManager); renderer.AssignEntityManager(entityManager);
renderer.AssignComponentManager(componentManager); renderer.AssignComponentManager(componentManager);
@ -112,9 +111,8 @@ namespace Encompass
return renderer; return renderer;
} }
public TRenderer AddGeneralRenderer<TRenderer>(int layer) where TRenderer : GeneralRenderer, new() public TRenderer AddGeneralRenderer<TRenderer>(TRenderer renderer, int layer) where TRenderer : GeneralRenderer
{ {
var renderer = new TRenderer();
renderer.AssignEntityManager(entityManager); renderer.AssignEntityManager(entityManager);
renderer.AssignComponentManager(componentManager); renderer.AssignComponentManager(componentManager);

View File

@ -1,6 +1,6 @@
using System; using System;
namespace Encompass namespace Encompass.Exceptions
{ {
public class ComponentTypeMismatchException : Exception public class ComponentTypeMismatchException : Exception
{ {

View File

@ -25,7 +25,7 @@ namespace Tests
public void CheckAndTrackEntities() public void CheckAndTrackEntities()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer<TestRenderer>(); var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
AComponent aComponent; AComponent aComponent;
BComponent bComponent; BComponent bComponent;
@ -68,7 +68,7 @@ namespace Tests
public void InactiveDrawComponent() public void InactiveDrawComponent()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer<TestRenderer>(); var renderer = worldBuilder.AddEntityRenderer(new TestRenderer());
AComponent aComponent; AComponent aComponent;
BComponent bComponent; BComponent bComponent;
@ -110,7 +110,7 @@ namespace Tests
public void RenderMethodCalledOnWorldDraw() public void RenderMethodCalledOnWorldDraw()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
var renderer = worldBuilder.AddEntityRenderer<CalledRenderer>(); var renderer = worldBuilder.AddEntityRenderer(new CalledRenderer());
AComponent aComponent; AComponent aComponent;
CComponent cComponent; CComponent cComponent;

View File

@ -27,7 +27,7 @@ namespace Tests
public void SingletonComponent() public void SingletonComponent()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer<TestRenderer>(1); worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
AComponent aComponent; AComponent aComponent;
@ -46,7 +46,7 @@ namespace Tests
public void MultipleComponents() public void MultipleComponents()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddGeneralRenderer<TestRenderer>(1); worldBuilder.AddGeneralRenderer(new TestRenderer(), 1);
AComponent aComponent; AComponent aComponent;
AComponent aComponentTwo; AComponent aComponentTwo;

View File

@ -37,8 +37,8 @@ namespace Tests
public void DrawOrder() public void DrawOrder()
{ {
var worldBuilder = new WorldBuilder(); var worldBuilder = new WorldBuilder();
worldBuilder.AddEntityRenderer<TestEntityRenderer>(); worldBuilder.AddEntityRenderer(new TestEntityRenderer());
var testGeneralRenderer = worldBuilder.AddGeneralRenderer<TestGeneralRenderer>(7); var testGeneralRenderer = worldBuilder.AddGeneralRenderer(new TestGeneralRenderer(), 7);
TestComponent testComponent; TestComponent testComponent;
TestDrawComponent testDrawComponent = default(TestDrawComponent); TestDrawComponent testDrawComponent = default(TestDrawComponent);