From 20d382f51a680db6d8033220d4abe67df4567ecf Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Tue, 24 Mar 2020 22:19:24 -0700 Subject: [PATCH] JIT Renderer methods --- encompass-cs/UberRenderer.cs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/encompass-cs/UberRenderer.cs b/encompass-cs/UberRenderer.cs index f9cac44..9d96e2c 100644 --- a/encompass-cs/UberRenderer.cs +++ b/encompass-cs/UberRenderer.cs @@ -24,9 +24,9 @@ namespace Encompass { foreach (var type in _componentTypes) { - // CallGenericMethod(type, "ReadEntities", null); + CallGenericWrappedMethod(type, "ReadEntitiesWrapper", null); CallGenericMethod(type, "ReadEntity", null); - // CallGenericMethod(type, "ReadComponents", null); + CallGenericWrappedMethod(type, "ReadComponentsWrapper", null); CallGenericMethod(type, "ReadComponent", null); CallGenericMethod(type, "GetComponent", new object[] { _entity }); CallGenericMethod(type, "HasComponent", new object[] { _entity }); @@ -34,11 +34,28 @@ namespace Encompass } } + protected void ReadEntitiesWrapper() where TComponent : struct, IComponent + { + ReadEntities(); + } + + protected void ReadComponentsWrapper() where TComponent : struct, IComponent + { + ReadComponents(); + } + 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); } + + 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); + } } }