示例#1
0
        protected override bool InitLibrary(IntPtr mainWindowHandle,
                                            int maxReal2DChannels, int maxReal3DChannels)
        {
            instance = this;

            NativeLibraryManager.PreLoadLibrary("libogg");
            NativeLibraryManager.PreLoadLibrary("libvorbis");
            NativeLibraryManager.PreLoadLibrary("libvorbisfile");

            //preload OpenAL32
            {
                string fileName;
                if (PlatformInfo.Platform == PlatformInfo.Platforms.Windows)
                {
                    fileName = "OpenAL32.dll";
                }
                else if (PlatformInfo.Platform == PlatformInfo.Platforms.MacOSX)
                {
                    fileName = "OpenAL32.dylib";
                }
                else if (PlatformInfo.Platform == PlatformInfo.Platforms.Android)
                {
                    fileName = "libOpenAL32.so";
                }
                else
                {
                    Log.Fatal("OpenALSoundWorld: InitLibrary: Unknown platform.");
                    return(false);
                }

                string path = Path.Combine(NativeLibraryManager.GetNativeLibrariesDirectory(), fileName);
                if (File.Exists(path))
                {
                    NativeLibraryManager.PreLoadLibrary("OpenAL32");
                }
            }

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

            Alc.alcMakeContextCurrent(alContext);

            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));
            thread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
            thread.IsBackground   = true;
            thread.Start();

            hWnd = mainWindowHandle;

            Al.alDistanceModel(Al.AL_NONE);

            return(true);
        }
示例#2
0
        //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);
        }