Пример #1
0
        public override void Initialise(IMesher meshmerizer, IScene scene)
        {
            Scene                = scene;
            mesher               = meshmerizer;
            _taintOperations     = new List <TaintCallbackEntry>();
            _postTaintOperations = new Dictionary <string, TaintCallbackEntry>();
            _postStepOperations  = new List <TaintCallbackEntry>();
            PhysObjects          = new Dictionary <uint, BSPhysObject>();
            Shapes               = new BSShapeCollection(this);

            // Allocate pinned memory to pass parameters.
            UnmanagedParams = new ConfigurationParameters[1];

            // Set default values for physics parameters plus any overrides from the ini file
            GetInitialParameterValues(scene.Config);

            // Get the connection to the physics engine (could be native or one of many DLLs)
            PE = SelectUnderlyingBulletEngine(BulletEngineName);

            // Enable very detailed logging.
            // By creating an empty logger when not logging, the log message invocation code
            //     can be left in and every call doesn't have to check for null.

            /*if (m_physicsLoggingEnabled)
             * {
             *  PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes);
             *  PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output error messages.
             * }
             * else
             * {
             *  PhysicsLogging = new Logging.LogWriter();
             * }*/

            // Allocate memory for returning of the updates and collisions from the physics engine
            m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
            m_updateArray    = new EntityProperties[m_maxUpdatesPerFrame];

            // The bounding box for the simulated world. The origin is 0,0,0 unless we're
            //    a child in a mega-region.
            // Bullet actually doesn't care about the extents of the simulated
            //    area. It tracks active objects no matter where they are.
            Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);

            World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray);

            Constraints = new BSConstraintCollection(World);

            TerrainManager = new BSTerrainManager(this);
            TerrainManager.CreateInitialGroundPlaneAndTerrain();

            MainConsole.Instance.WarnFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation);

            InTaintTime   = false;
            m_initialized = true;
        }
Пример #2
0
        // Select the connection to the actual Bullet implementation.
        // The main engine selection is the engineName up to the first hypen.
        // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name
        //     is passed to the engine to do its special selection, etc.
        private BSAPITemplate SelectUnderlyingBulletEngine(string engineName)
        {
            // For the moment, do a simple switch statement.
            // Someday do fancyness with looking up the interfaces in the assembly.
            BSAPITemplate ret = null;

            string selectionName = engineName.ToLower();
            int    hyphenIndex   = engineName.IndexOf("-");

            if (hyphenIndex > 0)
            {
                selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1);
            }

            switch (selectionName)
            {
            case "bullet":
            case "bulletunmanaged":
                ret = new BSAPIUnman(engineName, this);
                break;

            case "bulletxna":
                ret = new BSAPIXNA(engineName, this);
                // Disable some features that are not implemented in BulletXNA
                m_log.InfoFormat("{0} Disabling some physics features not implemented by BulletXNA", LogHeader);
                m_log.InfoFormat("{0}    Disabling ShouldUseBulletHACD", LogHeader);
                BSParam.ShouldUseBulletHACD = false;
                m_log.InfoFormat("{0}    Disabling ShouldUseSingleConvexHullForPrims", LogHeader);
                BSParam.ShouldUseSingleConvexHullForPrims = false;
                m_log.InfoFormat("{0}    Disabling ShouldUseGImpactShapeForPrims", LogHeader);
                BSParam.ShouldUseGImpactShapeForPrims = false;
                m_log.InfoFormat("{0}    Setting terrain implimentation to Heightmap", LogHeader);
                BSParam.TerrainImplementation = (float)BSTerrainPhys.TerrainImplementation.Heightmap;
                break;
            }

            if (ret == null)
            {
                m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader);
            }
            else
            {
                m_log.InfoFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion);
            }

            return(ret);
        }
Пример #3
0
        // Select the connection to the actual Bullet implementation.
        // The main engine selection is the engineName up to the first hypen.
        // So "Bullet-2.80-OpenCL-Intel" specifies the 'bullet' class here and the whole name
        //     is passed to the engine to do its special selection, etc.
        private BSAPITemplate SelectUnderlyingBulletEngine(string engineName)
        {
            // For the moment, do a simple switch statement.
            // Someday do fancyness with looking up the interfaces in the assembly.
            BSAPITemplate ret = null;

            string selectionName = engineName.ToLower();
            int    hyphenIndex   = engineName.IndexOf("-");

            if (hyphenIndex > 0)
            {
                selectionName = engineName.ToLower().Substring(0, hyphenIndex - 1);
            }

            switch (selectionName)
            {
            case "bulletunmanaged":
                ret = new BSAPIUnman(engineName, this);
                break;

            case "bulletxna":
                ret = new BSAPIXNA(engineName, this);
                break;
            }

            if (ret == null)
            {
                m_log.ErrorFormat("{0) COULD NOT SELECT BULLET ENGINE: '[BulletSim]PhysicsEngine' must be either 'BulletUnmanaged-*' or 'BulletXNA-*'", LogHeader);
            }
            else
            {
                m_log.WarnFormat("{0} Selected bullet engine {1} -> {2}/{3}", LogHeader, engineName, ret.BulletEngineName, ret.BulletEngineVersion);
            }

            return(ret);
        }
Пример #4
0
    public override void Initialise(IMesher meshmerizer, IConfigSource config)
    {
        mesher = meshmerizer;
        _taintOperations = new List<TaintCallbackEntry>();
        _postTaintOperations = new Dictionary<string, TaintCallbackEntry>();
        _postStepOperations = new List<TaintCallbackEntry>();
        PhysObjects = new Dictionary<uint, BSPhysObject>();
        Shapes = new BSShapeCollection(this);

        m_simulatedTime = 0f;
        LastTimeStep = 0.1f;

        // Allocate pinned memory to pass parameters.
        UnmanagedParams = new ConfigurationParameters[1];

        // Set default values for physics parameters plus any overrides from the ini file
        GetInitialParameterValues(config);

        // Get the connection to the physics engine (could be native or one of many DLLs)
        PE = SelectUnderlyingBulletEngine(BulletEngineName);

        // Enable very detailed logging.
        // By creating an empty logger when not logging, the log message invocation code
        //     can be left in and every call doesn't have to check for null.
        if (m_physicsLoggingEnabled)
        {
            PhysicsLogging = new Logging.LogWriter(m_physicsLoggingDir, m_physicsLoggingPrefix, m_physicsLoggingFileMinutes, m_physicsLoggingDoFlush);
            PhysicsLogging.ErrorLogger = m_log; // for DEBUG. Let's the logger output its own error messages.
        }
        else
        {
            PhysicsLogging = new Logging.LogWriter();
        }

        // Allocate memory for returning of the updates and collisions from the physics engine
        m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame];
        m_updateArray = new EntityProperties[m_maxUpdatesPerFrame];

        // The bounding box for the simulated world. The origin is 0,0,0 unless we're
        //    a child in a mega-region.
        // Bullet actually doesn't care about the extents of the simulated
        //    area. It tracks active objects no matter where they are.
        Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, Constants.RegionHeight);

        World = PE.Initialize(worldExtent, Params, m_maxCollisionsPerFrame, ref m_collisionArray, m_maxUpdatesPerFrame, ref m_updateArray);

        Constraints = new BSConstraintCollection(World);

        TerrainManager = new BSTerrainManager(this);
        TerrainManager.CreateInitialGroundPlaneAndTerrain();

        // Put some informational messages into the log file.
        m_log.InfoFormat("{0} Linksets implemented with {1}", LogHeader, (BSLinkset.LinksetImplementation)BSParam.LinksetImplementation);

        InTaintTime = false;
        m_initialized = true;

        // If the physics engine runs on its own thread, start same.
        if (BSParam.UseSeparatePhysicsThread)
        {
            // The physics simulation should happen independently of the heartbeat loop
            m_physicsThread = new Thread(BulletSPluginPhysicsThread);
            m_physicsThread.Name = BulletEngineName;
            m_physicsThread.Start();
        }
    }