示例#1
0
        public static void Initialize(string[] args, Libraries libraryNames)
        {
            DllLoadUtils = Platform.IsLinux()
            ? (IDllLoadUtils) new DllLoadUtilsLinux()
            : new DllLoadUtilsWindows();

            string platformMain;

            if (Platform.IsLinux())
            {
                platformMain = "unixmain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.Linux64bit : libraryNames.Linux32bit;
            }
            else if (Platform.IsOSX())
            {
                platformMain = "osxmain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.OSX64bit : libraryNames.OSX32bit;
            }
            else
            {
                platformMain = "winmain";
                LibraryName  = IntPtr.Size == 8 ? libraryNames.Windows64bit : libraryNames.Windows32bit;
            }

            Torque6LibHandle = DllLoadUtils.LoadLibrary(LibraryName);
            if (Torque6LibHandle == IntPtr.Zero)
            {
                throw new Exception("Unable to load " + (IntPtr.Size == 8 ? "64" : "32") + " bit dll: " + LibraryName);
            }
            var mainHandle         = DllLoadUtils.GetProcAddress(Torque6LibHandle, platformMain);
            var setCallbacksHandle = DllLoadUtils.GetProcAddress(Torque6LibHandle, "SetCallbacks");

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

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

            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);

            main(args.Length, args, IntPtr.Zero);

            DllLoadUtils.FreeLibrary(Torque6LibHandle);
        }
示例#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 + ", in directory: " + Directory.GetCurrentDirectory());
            }

            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)
            {
            }

            engineShutdown();

            SimDictionary.Shutdown();

            DllLoadUtils.FreeLibrary(Torque3DLibHandle);
        }