static Crc32_Castagnoli() { try { #if Windows if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x86.dll"); } #endif #if Unix if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x64.so"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x86.so"); } #endif _compute = _nativeLibraryManager.GetMethod<ComputeDelegate>("compute_Crc32_Castagnoli"); } catch (Exception e) { Log.Warning(e); } }
static Unsafe() { #if Mono #else try { if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll"); } _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare"); _xor = _nativeLibraryManager.GetMethod<XorDelegate>("xor"); } catch (Exception e) { Log.Warning(e); } #endif }
static Unsafe() { try { #if Windows if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.dll"); } #endif #if Unix if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x64.so"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_x86.so"); } #endif _copy = _nativeLibraryManager.GetMethod<CopyDelegate>("copy"); _equals = _nativeLibraryManager.GetMethod<EqualsDelegate>("equals"); _compare = _nativeLibraryManager.GetMethod<CompareDelegate>("compare"); _and = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_and"); _or = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_or"); _xor = _nativeLibraryManager.GetMethod<BitwiseOperationDelegate>("math_xor"); } catch (Exception e) { Log.Warning(e); } }
static Crc32_Castagnoli() { #if Mono #else try { if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Security_x86.dll"); } _compute = _nativeLibraryManager.GetMethod <ComputeDelegate>("compute_Crc32_Castagnoli"); } catch (Exception e) { Log.Warning(e); } #endif }
static NativeMethods() { try { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (RuntimeInformation.ProcessArchitecture == Architecture.X64) { NativeLibraryManager = new NativeLibraryManager("omnius-core.x64.dll"); } else { throw new NotSupportedException(); } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { if (RuntimeInformation.ProcessArchitecture == Architecture.X64) { NativeLibraryManager = new NativeLibraryManager("omnius-core.x64.so"); } else { throw new NotSupportedException(); } } else { throw new NotSupportedException(); } } catch (Exception e) { _logger.Error(e); } }
protected override bool InitLibrary(IntPtr mainWindowHandle, int maxReal2DChannels, int maxReal3DChannels) { //NativeLibraryManager.PreLoadLibrary( "libogg" ); //NativeLibraryManager.PreLoadLibrary( "libvorbis" ); //NativeLibraryManager.PreLoadLibrary( "libvorbisfile" ); //preload dlls { var fileNames = new List <string>(); if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Windows) { fileNames.Add("OpenAL32.dll"); } else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.UWP) { fileNames.Add("SDL2.dll"); fileNames.Add("OpenAL32.dll"); } else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.MacOS) { fileNames.Add("OpenAL32.dylib"); } else if (SystemSettings.CurrentPlatform == SystemSettings.Platform.Android) { //fileNames.Add( "libOpenAL.so" ); } else { Log.Fatal("OpenALSoundWorld: InitLibrary: Unknown platform."); return(false); } foreach (var fileName in fileNames) { var path = Path.Combine(VirtualFileSystem.Directories.PlatformSpecific, fileName); if (File.Exists(path)) { NativeLibraryManager.PreLoadLibrary(fileName); } } } criticalSection = CriticalSection.Create(); //if( PlatformInfo.Platform == PlatformInfo.Platforms.Android ) //{ // Alc.alcSetJNIEnvironmentAndJavaVM( // EngineApp.Instance._CallCustomPlatformSpecificMethod( "GetJNIEnvironment", IntPtr.Zero ), // EngineApp.Instance._CallCustomPlatformSpecificMethod( "GetJavaVM", IntPtr.Zero ) ); //} //string[] devices = Alc.alcGetStringv( IntPtr.Zero, Alc.ALC_DEVICE_SPECIFIER ); try { alDevice = Alc.alcOpenDevice(null); } catch (DllNotFoundException) { Log.InvisibleInfo("OpenALSoundSystem: OpenAL not found."); return(false); } catch (Exception e) { Log.InvisibleInfo("OpenALSoundSystem: Open device failed. " + e.Message); return(false); } if (alDevice == IntPtr.Zero) { Log.InvisibleInfo("OpenALSoundSystem: No sound driver."); return(false); } alContext = Alc.alcCreateContext(alDevice, IntPtr.Zero); if (alContext == IntPtr.Zero) { Log.Error("OpenALSoundSystem: Create context failed."); return(false); } try { Alc.alcMakeContextCurrent(alContext); } catch (Exception e) { Log.InvisibleInfo("OpenALSoundSystem: alcMakeContextCurrent failed. " + e.Message); return(false); } if (CheckError()) { return(false); } //get captureDeviceName try { captureDeviceName = Alc.alcGetString(alDevice, Alc.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER); } catch { } //Channels realChannels = new List <OpenALRealChannel>(); for (int n = 0; n < maxReal2DChannels; n++) { OpenALRealChannel realChannel = new OpenALRealChannel(); AddRealChannel(realChannel, false); realChannels.Add(realChannel); } for (int n = 0; n < maxReal3DChannels; n++) { OpenALRealChannel realChannel = new OpenALRealChannel(); AddRealChannel(realChannel, true); realChannels.Add(realChannel); } fileStreamRealChannels = new List <OpenALRealChannel>(); thread = new Thread(new ThreadStart(ThreadFunction)); try { if (SystemSettings.CurrentPlatform != SystemSettings.Platform.UWP) { thread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); } } catch { } thread.IsBackground = true; thread.Start(); hWnd = mainWindowHandle; Al.alDistanceModel(Al.AL_NONE); return(true); }
protected override void Dispose(bool disposing) { if (_disposed) return; _disposed = true; if (disposing) { #if Mono #else if (_nativeLibraryManager != null) { try { _nativeLibraryManager.Dispose(); } catch (Exception) { } _nativeLibraryManager = null; } #endif } }
public Math() { #if Mono #else try { if (System.Environment.Is64BitProcess) { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Correction_x64.dll"); } else { _nativeLibraryManager = new NativeLibraryManager("Assemblies/Library_Correction_x86.dll"); } _mul = _nativeLibraryManager.GetMethod<MulDelegate>("mul"); } catch (Exception e) { Log.Warning(e); } #endif _gfSize = ((1 << _gfBits) - 1); _gf_exp = new byte[2 * _gfSize]; _gf_log = new int[_gfSize + 1]; _inverse = new byte[_gfSize + 1]; GenerateGF(); InitMulTable(); }
unsafe protected override bool InitLibrary(IntPtr mainWindowHandle, int maxReal2DChannels, int maxReal3DChannels) { NativeLibraryManager.PreLoadLibrary("libogg"); NativeLibraryManager.PreLoadLibrary("libvorbis"); NativeLibraryManager.PreLoadLibrary("libvorbisfile"); NativeLibraryManager.PreLoadLibrary("DirectSoundNativeWrapper"); { DSoundStructureSizes sizes = new DSoundStructureSizes(); sizes.Init(); DSoundStructureSizes originalSizes; DSound.GetStructureSizes(out originalSizes); FieldInfo[] fields = sizes.GetType().GetFields( BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); foreach (FieldInfo field in fields) { int originalSize = (int)field.GetValue(originalSizes); int size = (int)field.GetValue(sizes); if (originalSize != size) { Log.Fatal("DirectXSoundSystem: Invalid unmanaged bridge. " + "Invalid \"{0}\". Native size = \"{1}\". Managed size = \"{2}\".", field.Name, originalSize, size); return(false); } } } instance = this; criticalSection = CriticalSection.Create(); DSound.CoInitialize(null); int hr; //create IDirectSound using the primary sound device void */*IDirectSound8*/ directSoundTemp; hr = DSound.DirectSoundCreate8(null, out directSoundTemp, null); if (Wrapper.FAILED(hr)) { if (hr == DSound.Get_DSERR_NODRIVER()) { Log.InvisibleInfo("DirectXSoundSystem: No sound driver."); return(false); } Error("DirectSoundCreate8", hr); return(false); } directSound = (IDirectSound8 *)directSoundTemp; //set DirectSound cooperative level hWnd = mainWindowHandle; hr = IDirectSound8.SetCooperativeLevel(directSound, hWnd, DSound.DSSCL_PRIORITY); if (Wrapper.FAILED(hr)) { Error("SetCooperativeLevel", hr); return(false); } //set primary buffer format { hr = SetPrimaryBufferFormat(2, 44100, 16, false); if (Wrapper.FAILED(hr)) { hr = SetPrimaryBufferFormat(2, 22050, 16, true); } if (Wrapper.FAILED(hr)) { return(false); } } //get listener { void */*IDirectSoundBuffer*/ primaryBuffer = null; // Obtain primary buffer, asking it for 3D control DSBUFFERDESC bufferDesc = new DSBUFFERDESC(); //ZeroMemory( &bufferDesc, sizeof( DSBUFFERDESC ) ); bufferDesc.dwSize = (uint)sizeof(DSBUFFERDESC); bufferDesc.dwFlags = DSound.DSBCAPS_CTRL3D | DSound.DSBCAPS_PRIMARYBUFFER; hr = IDirectSound8.CreateSoundBuffer(directSound, ref bufferDesc, out primaryBuffer, null); if (Wrapper.FAILED(hr)) { Error("CreateSoundBuffer", hr); return(false); } void */*IDirectSound3DListener*/ listenerTemp = null; GUID guid = DSound.IID_IDirectSound3DListener; if (Wrapper.FAILED(hr = IDirectSoundBuffer.QueryInterface(primaryBuffer, ref guid, &listenerTemp))) { IDirectSoundBuffer.Release(primaryBuffer); Error("QueryInterface", hr); return(false); } listener = (IDirectSound3DListener *)listenerTemp; IDirectSoundBuffer.Release(primaryBuffer); } //update general parameters { DS3DLISTENER parameters = new DS3DLISTENER(); parameters.dwSize = (uint)sizeof(DS3DLISTENER); IDirectSound3DListener.GetAllParameters(listener, ref parameters); parameters.flDistanceFactor = 1; parameters.flRolloffFactor = 0; parameters.flDopplerFactor = DopplerScale; hr = IDirectSound3DListener.SetAllParameters(listener, ref parameters, DSound.DS3D_IMMEDIATE); if (Wrapper.FAILED(hr)) { Warning("IDirectSound3DListener.SetAllParameters", hr); } } GenerateRecordDriverList(); //Channels realChannels = new List <DirectSoundRealChannel>(); for (int n = 0; n < maxReal2DChannels; n++) { DirectSoundRealChannel realChannel = new DirectSoundRealChannel(); AddRealChannel(realChannel, false); realChannels.Add(realChannel); } for (int n = 0; n < maxReal3DChannels; n++) { DirectSoundRealChannel realChannel = new DirectSoundRealChannel(); AddRealChannel(realChannel, true); realChannels.Add(realChannel); } fileStreamRealChannels = new List <DirectSoundRealChannel>(); thread = new Thread(new ThreadStart(ThreadFunction)); thread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); thread.IsBackground = true; thread.Start(); return(true); }
static void InitializeCefRuntime() { if (cefRuntimeUnableToLoad) { return; } if (!IsSupportedByThisPlatform()) { return; } if (cefRuntimeInitialized) { throw new InvalidOperationException("The CefRuntime is already initialized. Call ShutdownCefRuntime() before initializing it again."); } //load native libraries { if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows) { try { string error = NativeLibraryManager.PreLoadLibrary(Path.Combine("CefGlue", "libcef"), true); if (!string.IsNullOrEmpty(error)) { cefRuntimeUnableToLoad = true; cefRuntimeUnableToLoadError = error; } } catch { cefRuntimeUnableToLoad = true; cefRuntimeUnableToLoadError = "Crash inside NativeLibraryManager.PreLoadLibrary."; } } } //delete log file string realLogFileName = VirtualFileSystem.GetRealPathByVirtual("user:Logs\\WebBrowserControl_CefGlue.log"); try { if (File.Exists(realLogFileName)) { File.Delete(realLogFileName); } } catch { } if (!cefRuntimeUnableToLoad) { try { CefRuntime.Load(); } catch (DllNotFoundException ex) { Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message); return; } catch (CefRuntimeException ex) { Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message); return; } catch (Exception ex) { Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Load(): " + ex.Message); return; } var mainArgs = new CefMainArgs(null); var cefApp = new SimpleApp(); var exitCode = CefRuntime.ExecuteProcess(mainArgs, cefApp, IntPtr.Zero); if (exitCode != -1) { Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.ExecuteProcess: Exit code: {0}", exitCode); return; } var cefSettings = new CefSettings { SingleProcess = true, WindowlessRenderingEnabled = true, MultiThreadedMessageLoop = true, LogSeverity = CefLogSeverity.Verbose, LogFile = realLogFileName, BrowserSubprocessPath = "", CachePath = "", }; ///// <summary> ///// Set to <c>true</c> to disable configuration of browser process features using ///// standard CEF and Chromium command-line arguments. Configuration can still ///// be specified using CEF data structures or via the ///// CefApp::OnBeforeCommandLineProcessing() method. ///// </summary> //public bool CommandLineArgsDisabled { get; set; } ///// <summary> ///// The fully qualified path for the resources directory. If this value is ///// empty the cef.pak and/or devtools_resources.pak files must be located in ///// the module directory on Windows/Linux or the app bundle Resources directory ///// on Mac OS X. Also configurable using the "resources-dir-path" command-line ///// switch. ///// </summary> //public string ResourcesDirPath { get; set; } try { CefRuntime.Initialize(mainArgs, cefSettings, cefApp, IntPtr.Zero); } catch (CefRuntimeException ex) { Log.Error("WebBrowserControl: InitializeCefRuntime: CefRuntime.Initialize: " + ex.Message); return; } cefRuntimeInitialized = true; if (!subscribedToEngineAppDestroy) { subscribedToEngineAppDestroy = true; EngineApp.DestroyEvent += EngineApp_DestroyEvent; } } }
//static NxAssertResponse ReportAssertViolation( IntPtr pMessage, IntPtr pFile, int line ) //{ // string message = Wrapper.GetOutString( pMessage ); // string file = Wrapper.GetOutString( pFile ); // if( file == null ) // file = "NULL"; // string text = string.Format( "PhysXPhysicsSystem: {0} ({1}:{2})", message, file, line ); // Log.Fatal( text ); // return NxAssertResponse.NX_AR_BREAKPOINT; //} protected override bool OnInitLibrary(bool allowHardwareAcceleration, bool editor) { instance = this; NativeLibraryManager.PreLoadLibrary("PhysXNativeWrapper"); //change current directory for loading PhysX dlls from specified NativeDlls directory. string saveCurrentDirectory = null; if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows) { saveCurrentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(NativeLibraryManager.GetNativeLibrariesDirectory()); } try { preventLogErrors = true; reportErrorDelegate = ReportError; logDelegate = LogMessage; IntPtr errorStringPtr; if (!PhysXNativeWorld.Init(reportErrorDelegate, out errorStringPtr, logDelegate, skinWidth)) { string errorString = Wrapper.GetOutString(errorStringPtr); if (string.IsNullOrEmpty(errorString)) { errorString = "Unknown error."; } Log.Fatal("PhysX: Initialization error: " + errorString); return(false); } preventLogErrors = false; } finally { //restore current directory if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows) { Directory.SetCurrentDirectory(saveCurrentDirectory); } } //configs if (VirtualFile.Exists("Base/Constants/PhysicsSystem.config")) { TextBlock block = TextBlockUtils.LoadFromVirtualFile("Base/Constants/PhysicsSystem.config"); if (block != null) { TextBlock physXBlock = block.FindChild("physXSpecific"); if (physXBlock != null) { if (physXBlock.IsAttributeExist("supportHeightFields")) { supportHeightFields = bool.Parse(physXBlock.GetAttribute("supportHeightFields")); } if (physXBlock.IsAttributeExist("supportVehicles")) { supportVehicles = bool.Parse(physXBlock.GetAttribute("supportVehicles")); } if (physXBlock.IsAttributeExist("writeCacheForCookedTriangleMeshes")) { writeCacheForCookedTriangleMeshes = bool.Parse( physXBlock.GetAttribute("writeCacheForCookedTriangleMeshes")); } if (physXBlock.IsAttributeExist("mainSceneMaxThreads")) { mainSceneMaxThreads = int.Parse(physXBlock.GetAttribute("mainSceneMaxThreads")); } } } } return(true); }