encompass-cs/encompass-cs/UberRenderer.cs

42 lines
1.5 KiB
C#
Raw Normal View History

2019-12-17 04:16:46 +00:00
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);
}
}
}