コード例 #1
0
        public static string CallScriptMethod(string className, string classNamespace, SimObject objectWrapper, string methodName, object[] args, out bool found)
        {
            if (methodName.Equals("pushDialog"))
            {
                methodName = methodName;
            }
            Type   type;
            string objectName = objectWrapper.getName();

            if (objectName != null && ClassTypeDictionary.ContainsKey(objectName))
            {
                type = ClassTypeDictionary[objectName];
            }
            else if (classNamespace != null && ClassTypeDictionary.ContainsKey(classNamespace))
            {
                type = ClassTypeDictionary[classNamespace];
            }
            else if (ClassTypeDictionary.ContainsKey(className))
            {
                type = ClassTypeDictionary[className];
            }
            else if (SimDictionary.Find(objectWrapper.Name) != null)
            {
                type = SimDictionary.Find(objectWrapper.Name).GetType();
            }
            else if (SimDictionary.Find(objectWrapper.getId()) != null)
            {
                type = SimDictionary.Find(objectWrapper.getId()).GetType();
            }
            else
            {
                if (ClassTypeDictionary.ContainsKey(objectWrapper.GetType().Name))
                {
                    type = ClassTypeDictionary[objectWrapper.GetType().Name];
                }
                else
                {
                    found = false;
                    return(null);
                }
            }
            return(CallNamespaceMethod(type, objectWrapper, methodName, args, out found));
        }
コード例 #2
0
        public static void Initialize(string[] args, Libraries libraryNames)
        {
            DllLoadUtils = Platform.IsLinux()
            ? (IDllLoadUtils) new DllLoadUtilsLinux()
            : new DllLoadUtilsWindows();

            string platformMain;

            if (Platform.IsLinux())
            {
                //platformMain = "torque_unixmain";
                platformMain = "TorqueMain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.Linux64bit : libraryNames.Linux32bit;
            }
            else if (Platform.IsOSX())
            {
                //platformMain = "torque_macmain";
                platformMain = "TorqueMain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.OSX64bit : libraryNames.OSX32bit;
            }
            else
            {
                //platformMain = "torque_winmain";
                platformMain = "TorqueMain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.Windows64bit : libraryNames.Windows32bit;
            }

            Torque3DLibHandle = DllLoadUtils.LoadLibrary(LibraryName);
            if (Torque3DLibHandle == IntPtr.Zero)
            {
                throw new Exception("Unable to load " + (IntPtr.Size == 8 ? "64" : "32") + " bit dll: " + LibraryName);
            }
            var mainHandle            = DllLoadUtils.GetProcAddress(Torque3DLibHandle, platformMain);
            var setCallbacksHandle    = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "SetCallbacks");
            var engineInitHandle      = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_engineinit");
            var engineTickHandle      = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_enginetick");
            var getReturnStatusHandle = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_getreturnstatus");
            var engineShutdownHandle  = DllLoadUtils.GetProcAddress(Torque3DLibHandle, "torque_engineshutdown");

            var setCallbacks = (SetCallbacks)Marshal.GetDelegateForFunctionPointer(
                setCallbacksHandle, typeof(SetCallbacks));

            //var main = (TorqueMain)Marshal.GetDelegateForFunctionPointer(
            //   mainHandle, typeof(TorqueMain));

            var engineInit = (torque_engineinit)Marshal.GetDelegateForFunctionPointer(
                engineInitHandle, typeof(torque_engineinit));

            var engineTick = (torque_enginetick)Marshal.GetDelegateForFunctionPointer(
                engineTickHandle, typeof(torque_enginetick));

            //var engineGetReturnStatus = (torque_getreturnstatus)Marshal.GetDelegateForFunctionPointer(
            //   getReturnStatusHandle, typeof(torque_getreturnstatus));

            var engineShutdown = (torque_engineshutdown)Marshal.GetDelegateForFunctionPointer(
                engineShutdownHandle, typeof(torque_engineshutdown));

            CallFunction callDelegate      = CallFunctionDelegate;
            CallMethod   methodDelegate    = CallMethodDelegate;
            IsMethod     isMethodDelegate  = IsMethodDelegate;
            IntPtr       mainEntryPointPtr = IntPtr.Zero;

            if (Initializer.GetScriptEntry() != null)
            {
                mainEntryPointPtr =
                    Marshal.GetFunctionPointerForDelegate(
                        (MainEntryPoint)Initializer.GetScriptEntry().CreateDelegate(typeof(MainEntryPoint)));
            }

            setCallbacks(Marshal.GetFunctionPointerForDelegate(callDelegate)
                         , Marshal.GetFunctionPointerForDelegate(methodDelegate)
                         , Marshal.GetFunctionPointerForDelegate(isMethodDelegate)
                         , mainEntryPointPtr);

            if (!engineInit(args.Length, args))
            {
                return;
            }

            while (engineTick() > 0)
            {
            }
            SimDictionary.Shutdown();

            engineShutdown();

            DllLoadUtils.FreeLibrary(Torque3DLibHandle);
        }