fix reflection breaking on .net framework
parent
18fd4ceaa6
commit
045b0917ba
|
@ -39,60 +39,52 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
foreach (var type in _componentTypes)
|
foreach (var type in _componentTypes)
|
||||||
{
|
{
|
||||||
CallGenericMethod(type, "ReadComponent", null);
|
CallGenericWrappedMethod(type, "CallAllComponentMethods", null);
|
||||||
CallGenericWrappedMethod(type, "ReadComponentsWrapper", null);
|
|
||||||
CallGenericMethod(type, "ReadEntity", null);
|
|
||||||
CallGenericWrappedMethod(type, "ReadEntitiesWrapper", null);
|
|
||||||
CallGenericMethod(type, "GetComponent", new object[] { Entity });
|
|
||||||
CallGenericMethod(type, "HasComponent", 1, new object[] { Entity });
|
|
||||||
CallGenericMethod(type, "SomeComponent", null);
|
|
||||||
CallGenericMethod(type, "DestroyWith", null);
|
|
||||||
CallGenericMethod(type, "DestroyAllWith", null);
|
|
||||||
CallGenericMethod(type, "RemoveComponent", new object[] { Entity });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var type in _messageTypes)
|
foreach (var type in _messageTypes)
|
||||||
{
|
{
|
||||||
CallGenericMethod(type, "SendMessageIgnoringTimeDilation", new object[] { Activator.CreateInstance(type), 1 });
|
CallGenericWrappedMethod(type, "CallAllMessageMethods", null);
|
||||||
CallGenericMethod(type, "SendMessage", 1, new object[] { Activator.CreateInstance(type) });
|
|
||||||
CallGenericMethod(type, "SendMessage", 2, new object[] { Activator.CreateInstance(type), 1 });
|
|
||||||
CallGenericMethod(type, "ReadMessage", null);
|
|
||||||
|
|
||||||
CallGenericWrappedMethod(type, "ReadMessagesWrapper", null);
|
|
||||||
CallGenericMethod(type, "SomeMessage", null);
|
|
||||||
if (typeof(IHasEntity).IsAssignableFrom(type))
|
if (typeof(IHasEntity).IsAssignableFrom(type))
|
||||||
{
|
{
|
||||||
CallGenericMethod(type, "ReadMessagesWithEntity", new object[] { Entity });
|
CallGenericWrappedMethod(type, "CallAllEntityMessageMethods", null);
|
||||||
CallGenericMethod(type, "ReadMessageWithEntity", new object[] { Entity });
|
|
||||||
CallGenericMethod(type, "SomeMessageWithEntity", new object[] { Entity });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// we can't reflect invoke on Span returns right now... so we have non-return wrapper methods
|
// we can't reflect invoke on byref returns or Span returns right now... so we have non-return wrapper methods
|
||||||
|
|
||||||
protected void ReadComponentsWrapper<TComponent>() where TComponent : struct, IComponent
|
protected void CallAllComponentMethods<TComponent>() where TComponent : struct, IComponent
|
||||||
{
|
{
|
||||||
|
ReadComponent<TComponent>();
|
||||||
ReadComponents<TComponent>();
|
ReadComponents<TComponent>();
|
||||||
}
|
ReadEntity<TComponent>();
|
||||||
|
|
||||||
protected void ReadMessagesWrapper<TMessage>() where TMessage : struct, IMessage
|
|
||||||
{
|
|
||||||
ReadMessages<TMessage>();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void ReadEntitiesWrapper<TComponent>() where TComponent : struct, IComponent
|
|
||||||
{
|
|
||||||
ReadEntities<TComponent>();
|
ReadEntities<TComponent>();
|
||||||
|
GetComponent<TComponent>(Entity);
|
||||||
|
HasComponent<TComponent>(Entity);
|
||||||
|
SomeComponent<TComponent>();
|
||||||
|
DestroyWith<TComponent>();
|
||||||
|
DestroyAllWith<TComponent>();
|
||||||
|
RemoveComponent<TComponent>(Entity);
|
||||||
|
AddComponent<TComponent>(Entity, default);
|
||||||
}
|
}
|
||||||
|
|
||||||
// trying to use PrepareMethod because we can't reflect invoke methods that return a span...
|
protected void CallAllMessageMethods<TMessage>() where TMessage : struct, IMessage
|
||||||
private void CallGenericMethod(Type type, string methodName, object[] parameters)
|
|
||||||
{
|
{
|
||||||
var readComponentMethod = typeof(Engine).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
SendMessageIgnoringTimeDilation<TMessage>(default, 0.1);
|
||||||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
SendMessage<TMessage>(default);
|
||||||
genericReadComponentMethod.Invoke(this, parameters);
|
SendMessage<TMessage>(default, 0.1);
|
||||||
// RuntimeHelpers.PrepareMethod(genericReadComponentMethod.MethodHandle);
|
ReadMessage<TMessage>();
|
||||||
|
ReadMessages<TMessage>();
|
||||||
|
SomeMessage<TMessage>();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void CallAllEntityMessageMethods<TMessage>() where TMessage : struct, IMessage, IHasEntity
|
||||||
|
{
|
||||||
|
ReadMessagesWithEntity<TMessage>(Entity);
|
||||||
|
ReadMessageWithEntity<TMessage>(Entity);
|
||||||
|
SomeMessageWithEntity<TMessage>(Entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
||||||
|
@ -101,21 +93,5 @@ namespace Encompass
|
||||||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
||||||
genericReadComponentMethod.Invoke(this, parameters);
|
genericReadComponentMethod.Invoke(this, parameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CallGenericMethod(Type type, string methodName, Type[] types, object[] parameters)
|
|
||||||
{
|
|
||||||
var readComponentMethod = typeof(Engine).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance, null, types, null);
|
|
||||||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
|
||||||
genericReadComponentMethod.Invoke(this, parameters);
|
|
||||||
// RuntimeHelpers.PrepareMethod(genericReadComponentMethod.MethodHandle);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CallGenericMethod(Type type, string methodName, int argumentNum, object[] parameters)
|
|
||||||
{
|
|
||||||
var method = typeof(Engine).GetRuntimeMethods().Where(m => m.Name == methodName && m.GetParameters().Length == argumentNum).First();
|
|
||||||
var genericMethod = method.MakeGenericMethod(type);
|
|
||||||
genericMethod.Invoke(this, parameters);
|
|
||||||
// RuntimeHelpers.PrepareMethod(genericMethod.MethodHandle);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,31 +24,19 @@ namespace Encompass
|
||||||
{
|
{
|
||||||
foreach (var type in _componentTypes)
|
foreach (var type in _componentTypes)
|
||||||
{
|
{
|
||||||
CallGenericWrappedMethod(type, "ReadEntitiesWrapper", null);
|
CallGenericWrappedMethod(type, "CallAllComponentMethods", null);
|
||||||
CallGenericMethod(type, "ReadEntity", null);
|
|
||||||
CallGenericWrappedMethod(type, "ReadComponentsWrapper", null);
|
|
||||||
CallGenericMethod(type, "ReadComponent", null);
|
|
||||||
CallGenericMethod(type, "GetComponent", new object[] { _entity });
|
|
||||||
CallGenericMethod(type, "HasComponent", new object[] { _entity });
|
|
||||||
CallGenericMethod(type, "SomeComponent", null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void ReadEntitiesWrapper<TComponent>() where TComponent : struct, IComponent
|
protected void CallAllComponentMethods<TComponent>() where TComponent : struct, IComponent
|
||||||
{
|
{
|
||||||
|
ReadEntity<TComponent>();
|
||||||
ReadEntities<TComponent>();
|
ReadEntities<TComponent>();
|
||||||
}
|
ReadComponent<TComponent>();
|
||||||
|
|
||||||
protected void ReadComponentsWrapper<TComponent>() where TComponent : struct, IComponent
|
|
||||||
{
|
|
||||||
ReadComponents<TComponent>();
|
ReadComponents<TComponent>();
|
||||||
}
|
GetComponent<TComponent>(_entity);
|
||||||
|
HasComponent<TComponent>(_entity);
|
||||||
private void CallGenericMethod(Type type, string methodName, object[] parameters)
|
SomeComponent<TComponent>();
|
||||||
{
|
|
||||||
var readComponentMethod = typeof(Renderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
|
||||||
genericReadComponentMethod.Invoke(this, parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
||||||
|
|
Loading…
Reference in New Issue