Example #1
0
        public void SetUniform(string name, dynamic data)
        {
            Activate();

            Type type = data.GetType();

            if (!uniformLocations.ContainsKey(name))
            {
                uniformLocations.Add(name, GL.GetUniformLocation(programObject, name));
            }

            uniformData[name] = data;

            if (uniformMethods.ContainsKey(type))
            {
                uniformMethods[type](null, new object[] { uniformLocations[name], data });
            }
            else
            {
                foreach (string methodName in uniformSetMethods)
                {
                    Type[]     argTypes   = new Type[] { typeof(int), type };
                    MethodInfo methodInfo = typeof(GL).GetMethod(methodName, argTypes);

                    if (methodInfo != null)
                    {
                        uniformMethods[type] = FastMethodInvoker.GetMethodInvoker(methodInfo);
                        uniformMethods[type](null, new object[] { uniformLocations[name], data });
                        return;
                    }
                }

                throw new Exception("No Uniform method found");
            }
        }
Example #2
0
        public void SetUniformMatrix(string name, bool transpose, dynamic data)
        {
            Activate();

            Type type = data.GetType();

            if (!uniformLocations.ContainsKey(name))
            {
                uniformLocations.Add(name, GL.GetUniformLocation(shaderProgramHandle, name));
            }

            uniformData[name] = data;

            if (uniformMethods.ContainsKey(type))
            {
                uniformMethods[type](null, new object[] { uniformLocations[name], transpose, data });
            }
            else
            {
                foreach (string methodName in uniformSetMethodsMatrix)
                {
                    Type[]     argTypes   = new Type[] { typeof(int), typeof(bool), data.GetType().MakeByRefType() };
                    MethodInfo methodInfo = typeof(GL).GetMethod(methodName, argTypes);

                    if (methodInfo != null)
                    {
                        uniformMethods[type] = FastMethodInvoker.GetMethodInvoker(methodInfo);
                        uniformMethods[type](null, new object[] { uniformLocations[name], transpose, data });
                        return;
                    }
                }

                throw new Exception("No UniformMatrix method found");
            }
        }
Example #3
0
        public void SetFastInvokeHandler(string name, MethodInfo m)
        {
            name = name.ToUpper();

            if (!propertydelegateList.Keys.Contains(name))
            {
                propertydelegateList[name] = FastMethodInvoker.GetMethodInvoker(m);
            }
        }
Example #4
0
        public override void CacheMethod()
        {
            Type type = assembly.GetType(MainClassName);

            mainMethod        = FastMethodInvoker.GetMethodInvoker(type.GetMethod(mainMethodName));
            updateMethod      = FastMethodInvoker.GetMethodInvoker(type.GetMethod(updateMethodName));
            fixedUpdateMethod = FastMethodInvoker.GetMethodInvoker(type.GetMethod(fixedUpdateMethodName));
            lateUpdateMethod  = FastMethodInvoker.GetMethodInvoker(type.GetMethod(lateUpdateMethodName));
            destroyMethod     = FastMethodInvoker.GetMethodInvoker(type.GetMethod(destroyMethodName));
        }
Example #5
0
        public CommandsLoader(FastMethodInvoker fastMethodInvoker, ILogger logger, ICommandArgumentsConverter argumentsConverter)
        {
            _fastMethodInvoker  = fastMethodInvoker;
            _logger             = logger;
            _argumentsConverter = argumentsConverter;

            Instance = this;

            _argumentsConverter.ConverterChanged += ReloadUserParameters;
        }
Example #6
0
        public FastInvoke(Object MyObject, String MyName)
        {
            HostObject = MyObject;
            Type       t2 = MyObject.GetType();
            MethodInfo m2 = t2.GetMethod(MyName);

            MyDelegate        = GetMethodInvoker(m2);
            NumberOfArguments = m2.GetParameters().Length;
            MyMethodInfo      = m2;
            MyParameters      = m2.GetParameters();
        }
        public void GetPossibleMethods_ReturnsCorrectAmountOfMethods()
        {
            var             fastMethodInvoker  = new FastMethodInvoker();
            var             logger             = new ConsoleLogger();
            var             config             = new CommandsConfiguration();
            var             argumentsConverter = new ArgumentsConverter(config);
            ICommandsLoader commandsLoader     = new CommandsLoader(fastMethodInvoker, logger, argumentsConverter);
            var             methodsParser      = new MethodsParser();
            var             args = new string[] { "1", "2" };

            commandsLoader.LoadCommands(Assembly.GetExecutingAssembly());
            var possibleMethods = methodsParser.GetPossibleMethods("TeSt4", args, commandsLoader.GetCommandData("TeSt4") !).ToList();

            Assert.AreEqual(4, possibleMethods.Count);
        }
Example #8
0
 public void CacheMethod()
 {
     if (GameEnvironment.Instance.Platform == GamePlatform.iOS)
     {
         i_updateMethod      = appdomain.LoadedTypes[MainClassName].GetMethod(updateMethodName, 0);
         i_fixedUpdateMethod = appdomain.LoadedTypes[MainClassName].GetMethod(fixedUpdateMethodName, 0);
         i_lateUpdateMethod  = appdomain.LoadedTypes[MainClassName].GetMethod(lateUpdateMethodName, 0);
     }
     else
     {
         Type type = assembly.GetType("HotFixEnter");
         m_mainMethod        = FastMethodInvoker.GetMethodInvoker(type.GetMethod("Main"));
         m_updateMethod      = FastMethodInvoker.GetMethodInvoker(type.GetMethod("Update"));
         m_fixedUpdateMethod = FastMethodInvoker.GetMethodInvoker(type.GetMethod("FixedUpdate"));
         m_lateUpdateMethod  = FastMethodInvoker.GetMethodInvoker(type.GetMethod("LateUpdate"));
         m_DestroyMethod     = FastMethodInvoker.GetMethodInvoker(type.GetMethod("Destroy"));
     }
 }
Example #9
0
        public override void Invoke(string className, string methodName, object instance, params object[] args)
        {
            base.Invoke(className, className, instance, args);

            Dictionary <string, FastMethodInvoker.FastInvokeHandler> temp;

            if (!cache.TryGetValue(className, out temp))
            {
                temp = new Dictionary <string, FastMethodInvoker.FastInvokeHandler>();
                cache.Add(className, temp);
            }

            FastMethodInvoker.FastInvokeHandler method;
            if (!temp.TryGetValue(methodName, out method))
            {
                Type type = assembly.GetType(className);
                method = FastMethodInvoker.GetMethodInvoker(type.GetMethod(methodName));
                temp.Add(methodName, method);
            }

            method.Invoke(instance, args);
        }
            public int Compare(object x, object y)
            {
                if (fastInvoker == null)
                {
                    var propInfo = x.GetType().GetProperty(sortBy);
                    fastInvoker = FastInvoke.GetMethodInvoker(propInfo.GetGetMethod());
                }
                var x1 = fastInvoker.Invoke(x, null) as IComparable;
                var y1 = fastInvoker.Invoke(y, null) as IComparable;

                if (x1 == null || y1 == null)
                {
                    return(0);
                }
                else
                {
                    var result = x1.CompareTo(y1);
                    if (direction == ListSortDirection.Descending)
                    {
                        result = -result;
                    }
                    return(result);
                }
            }
Example #11
0
 public PropertyValueComparer(PropertyInfo property, params string[] keywords)
 {
     this.keywords    = keywords;
     this.fastInvoker = FastInvoke.GetMethodInvoker(property.GetGetMethod());
 }
Example #12
0
        public static FastMethodInvoker GetMethodInvoker(MethodInfo methodInfo)
        {
            DynamicMethod dynamicMethod = new DynamicMethod(string.Empty,
                                                            typeof(object), new Type[] { typeof(object),
                                                                                         typeof(object[]) },
                                                            methodInfo.DeclaringType.Module);
            ILGenerator il = dynamicMethod.GetILGenerator();

            ParameterInfo[] ps         = methodInfo.GetParameters();
            Type[]          paramTypes = new Type[ps.Length];
            for (int i = 0; i < paramTypes.Length; i++)
            {
                if (ps[i].ParameterType.IsByRef)
                {
                    paramTypes[i] = ps[i].ParameterType.GetElementType();
                }
                else
                {
                    paramTypes[i] = ps[i].ParameterType;
                }
            }
            LocalBuilder[] locals = new LocalBuilder[paramTypes.Length];

            for (int i = 0; i < paramTypes.Length; i++)
            {
                locals[i] = il.DeclareLocal(paramTypes[i], true);
            }
            for (int i = 0; i < paramTypes.Length; i++)
            {
                il.Emit(OpCodes.Ldarg_1);
                EmitFastInt(il, i);
                il.Emit(OpCodes.Ldelem_Ref);
                EmitCastToReference(il, paramTypes[i]);
                il.Emit(OpCodes.Stloc, locals[i]);
            }
            if (!methodInfo.IsStatic)
            {
                il.Emit(OpCodes.Ldarg_0);
            }
            for (int i = 0; i < paramTypes.Length; i++)
            {
                if (ps[i].ParameterType.IsByRef)
                {
                    il.Emit(OpCodes.Ldloca_S, locals[i]);
                }
                else
                {
                    il.Emit(OpCodes.Ldloc, locals[i]);
                }
            }
            if (methodInfo.IsStatic)
            {
                il.EmitCall(OpCodes.Call, methodInfo, null);
            }
            else
            {
                il.EmitCall(OpCodes.Callvirt, methodInfo, null);
            }
            if (methodInfo.ReturnType == typeof(void))
            {
                il.Emit(OpCodes.Ldnull);
            }
            else
            {
                EmitBoxIfNeeded(il, methodInfo.ReturnType);
            }

            for (int i = 0; i < paramTypes.Length; i++)
            {
                if (ps[i].ParameterType.IsByRef)
                {
                    il.Emit(OpCodes.Ldarg_1);
                    EmitFastInt(il, i);
                    il.Emit(OpCodes.Ldloc, locals[i]);
                    if (locals[i].LocalType.IsValueType)
                    {
                        il.Emit(OpCodes.Box, locals[i].LocalType);
                    }
                    il.Emit(OpCodes.Stelem_Ref);
                }
            }

            il.Emit(OpCodes.Ret);
            FastMethodInvoker invoder = (FastMethodInvoker)
                                        dynamicMethod.CreateDelegate(typeof(FastMethodInvoker));

            return(invoder);
        }