uber renderer

pull/5/head
evan 2019-12-16 20:16:46 -08:00
parent d8a5cd6493
commit 84876ebc87
3 changed files with 56 additions and 1 deletions

View File

@ -41,6 +41,8 @@ namespace Encompass
CallGenericMethod(type, "ReadComponentIncludingEntity", null);
CallGenericMethod(type, "ReadComponents", null);
CallGenericMethod(type, "ReadComponentsIncludingEntity", null);
CallGenericMethod(type, "ReadEntity", null);
CallGenericMethod(type, "ReadEntities", null);
CallGenericMethod(type, "GetComponent", new Type[] { typeof(Entity) }, new object[] { _entity });
CallGenericMethod(type, "HasComponent", new Type[] { typeof(Entity) }, new object[] { _entity });
CallGenericMethod(type, "SomeComponent", null);

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Encompass
{
class UberRenderer : Renderer
{
private Entity _entity;
private IEnumerable<Type> _componentTypes;
public UberRenderer(Entity entity, IEnumerable<Type> componentTypes)
{
_entity = entity;
_componentTypes = componentTypes;
}
public void Render()
{
foreach (var type in _componentTypes)
{
CallGenericMethod(type, "ReadEntities", null);
CallGenericMethod(type, "ReadEntity", null);
CallGenericMethod(type, "ReadComponent", null);
CallGenericMethod(type, "ReadComponentIncludingEntity", null);
CallGenericMethod(type, "ReadComponents", null);
CallGenericMethod(type, "ReadComponentsIncludingEntity", null);
CallGenericMethod(type, "GetComponent", new object[] { _entity });
CallGenericMethod(type, "HasComponent", new object[] { _entity });
CallGenericMethod(type, "SomeComponent", null);
}
}
private void CallGenericMethod(Type type, string methodName, object[] parameters)
{
var readComponentMethod = typeof(Renderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
genericReadComponentMethod.Invoke(this, parameters);
}
}
}

View File

@ -399,7 +399,9 @@ namespace Encompass
var dummyRenderManager = new RenderManager(dummyDrawLayerManager);
var prepEngineOrder = new List<Engine>();
var uberEngine = new UberEngine(dummyEntityManager.CreateEntity(), componentTypes, messageTypes);
var entity = dummyEntityManager.CreateEntity();
var uberEngine = new UberEngine(entity, componentTypes, messageTypes);
uberEngine.AssignEntityManager(dummyEntityManager);
uberEngine.AssignComponentManager(dummyComponentManager);
@ -407,6 +409,10 @@ namespace Encompass
uberEngine.AssignComponentUpdateManager(dummyComponentUpdateManager);
uberEngine.AssignTimeManager(dummyTimeManager);
var uberRenderer = new UberRenderer(entity, componentTypes);
uberRenderer.AssignComponentManager(dummyComponentManager);
uberRenderer.AssignEntityManager(dummyEntityManager);
foreach (var type in componentTypes)
{
var componentManagerRegisterMethod = typeof(ComponentManager).GetMethod("RegisterComponentType");
@ -451,6 +457,12 @@ namespace Encompass
dummyComponentUpdateManager.Clear();
dummyWorld.Update(1);
uberEngine.Write();
dummyComponentManager.WriteComponents();
dummyComponentUpdateManager.Clear();
uberRenderer.Render();
}
}
}