Ejemplo n.º 1
0
        protected override void OnShutdownLibrary()
        {
            if (shapesDictionary.Count != 0)
            {
                Log.Warning("PhysXPhysicsWorld: OnShutdownLibrary: shapesDictionary.Count != 0.");
            }

            PhysXNativeWorld.Destroy();

            if (hacdInstance != null)
            {
                try
                {
                    HACDWrapper.Shutdown(hacdInstance);
                }
                catch { }
                hacdInstance = null;
            }

            instance = null;
        }
Ejemplo n.º 2
0
        protected override void OnShutdownLibrary()
        {
            if( shapesDictionary.Count != 0 )
                Log.Warning( "PhysXPhysicsWorld: OnShutdownLibrary: shapesDictionary.Count != 0." );

            PhysXNativeWorld.Destroy();

            if( hacdInstance != null )
            {
                try
                {
                    HACDWrapper.Shutdown( hacdInstance );
                }
                catch { }
                hacdInstance = null;
            }

            instance = null;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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);
        }