fix reflection breaking on .net framework
parent
18fd4ceaa6
commit
045b0917ba
|
@ -39,60 +39,52 @@ namespace Encompass
|
|||
{
|
||||
foreach (var type in _componentTypes)
|
||||
{
|
||||
CallGenericMethod(type, "ReadComponent", 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 });
|
||||
CallGenericWrappedMethod(type, "CallAllComponentMethods", null);
|
||||
}
|
||||
|
||||
foreach (var type in _messageTypes)
|
||||
{
|
||||
CallGenericMethod(type, "SendMessageIgnoringTimeDilation", new object[] { Activator.CreateInstance(type), 1 });
|
||||
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, "CallAllMessageMethods", null);
|
||||
|
||||
CallGenericWrappedMethod(type, "ReadMessagesWrapper", null);
|
||||
CallGenericMethod(type, "SomeMessage", null);
|
||||
if (typeof(IHasEntity).IsAssignableFrom(type))
|
||||
{
|
||||
CallGenericMethod(type, "ReadMessagesWithEntity", new object[] { Entity });
|
||||
CallGenericMethod(type, "ReadMessageWithEntity", new object[] { Entity });
|
||||
CallGenericMethod(type, "SomeMessageWithEntity", new object[] { Entity });
|
||||
CallGenericWrappedMethod(type, "CallAllEntityMessageMethods", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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>();
|
||||
}
|
||||
|
||||
protected void ReadMessagesWrapper<TMessage>() where TMessage : struct, IMessage
|
||||
{
|
||||
ReadMessages<TMessage>();
|
||||
}
|
||||
|
||||
protected void ReadEntitiesWrapper<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
ReadEntity<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...
|
||||
private void CallGenericMethod(Type type, string methodName, object[] parameters)
|
||||
protected void CallAllMessageMethods<TMessage>() where TMessage : struct, IMessage
|
||||
{
|
||||
var readComponentMethod = typeof(Engine).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
||||
genericReadComponentMethod.Invoke(this, parameters);
|
||||
// RuntimeHelpers.PrepareMethod(genericReadComponentMethod.MethodHandle);
|
||||
SendMessageIgnoringTimeDilation<TMessage>(default, 0.1);
|
||||
SendMessage<TMessage>(default);
|
||||
SendMessage<TMessage>(default, 0.1);
|
||||
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)
|
||||
|
@ -101,21 +93,5 @@ namespace Encompass
|
|||
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
||||
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)
|
||||
{
|
||||
CallGenericWrappedMethod(type, "ReadEntitiesWrapper", 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);
|
||||
CallGenericWrappedMethod(type, "CallAllComponentMethods", null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void ReadEntitiesWrapper<TComponent>() where TComponent : struct, IComponent
|
||||
protected void CallAllComponentMethods<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
ReadEntity<TComponent>();
|
||||
ReadEntities<TComponent>();
|
||||
}
|
||||
|
||||
protected void ReadComponentsWrapper<TComponent>() where TComponent : struct, IComponent
|
||||
{
|
||||
ReadComponent<TComponent>();
|
||||
ReadComponents<TComponent>();
|
||||
}
|
||||
|
||||
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);
|
||||
GetComponent<TComponent>(_entity);
|
||||
HasComponent<TComponent>(_entity);
|
||||
SomeComponent<TComponent>();
|
||||
}
|
||||
|
||||
private void CallGenericWrappedMethod(Type type, string methodName, object[] parameters)
|
||||
|
|
Loading…
Reference in New Issue