2019-12-17 04:16:46 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace Encompass
|
|
|
|
|
{
|
|
|
|
|
class UberRenderer : Renderer
|
|
|
|
|
{
|
2020-03-20 07:09:57 +00:00
|
|
|
|
private readonly IEnumerable<Type> _componentTypes;
|
2019-12-24 02:45:49 +00:00
|
|
|
|
private Entity _entity;
|
2019-12-17 04:16:46 +00:00
|
|
|
|
|
2019-12-24 02:45:49 +00:00
|
|
|
|
public UberRenderer(IEnumerable<Type> componentTypes)
|
2019-12-17 04:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
_componentTypes = componentTypes;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-24 02:45:49 +00:00
|
|
|
|
public void SetEntity(Entity entity)
|
|
|
|
|
{
|
|
|
|
|
_entity = entity;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-23 02:10:28 +00:00
|
|
|
|
// can't reflect invoke on Span returns...
|
2021-03-24 00:37:47 +00:00
|
|
|
|
public override void Render(double dt, double alpha)
|
2019-12-17 04:16:46 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var type in _componentTypes)
|
|
|
|
|
{
|
2020-03-25 21:19:40 +00:00
|
|
|
|
CallGenericWrappedMethod(type, "CallAllComponentMethods", null);
|
2019-12-17 04:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 08:25:25 +00:00
|
|
|
|
protected void CallAllComponentMethods<TComponent>() where TComponent : struct
|
2020-03-25 05:19:24 +00:00
|
|
|
|
{
|
2020-03-25 21:19:40 +00:00
|
|
|
|
ReadEntity<TComponent>();
|
2020-03-25 05:19:24 +00:00
|
|
|
|
ReadEntities<TComponent>();
|
2020-03-25 21:19:40 +00:00
|
|
|
|
ReadComponent<TComponent>();
|
2020-03-25 05:19:24 +00:00
|
|
|
|
ReadComponents<TComponent>();
|
2020-03-25 21:19:40 +00:00
|
|
|
|
GetComponent<TComponent>(_entity);
|
|
|
|
|
HasComponent<TComponent>(_entity);
|
|
|
|
|
SomeComponent<TComponent>();
|
2019-12-17 04:16:46 +00:00
|
|
|
|
}
|
2020-03-25 05:19:24 +00:00
|
|
|
|
|
|
|
|
|
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
|
|
|
|
{
|
|
|
|
|
var readComponentMethod = typeof(UberRenderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
|
|
|
|
genericReadComponentMethod.Invoke(this, parameters);
|
|
|
|
|
}
|
2019-12-17 04:16:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|