Exemple #1
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);

        // Allocate pinned memory to pass parameters.
        UnmanagedParams = new ConfigurationParameters[1];
        //m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);

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

        // allocate more pinned memory close to the above in an attempt to get the memory all together
        m_collisionArray = new List<BulletXNA.CollisionDesc>();
        //m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
        m_updateArray = new List<BulletXNA.EntityProperties>();
        //m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);

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

        // If Debug logging level, enable logging from the unmanaged code
        m_DebugLogCallbackHandle = null;
        if (m_log.IsDebugEnabled || PhysicsLogging.Enabled)
        {
            m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader);
            if (PhysicsLogging.Enabled)
                // The handle is saved in a variable to make sure it doesn't get freed after this call
                m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog);
            else
                m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger);
        }

        // Get the version of the DLL
        // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
        // BulletSimVersion = BulletSimAPI.GetVersion();
        // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion);

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

        // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader);

        World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, UnmanagedParams,
                                        m_maxCollisionsPerFrame, ref m_collisionArray,
                                        m_maxUpdatesPerFrame,ref m_updateArray,
                                        m_DebugLogCallbackHandle));

        Constraints = new BSConstraintCollection(World);

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

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

        InTaintTime = false;
        m_initialized = true;
    }
Exemple #2
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);

            // Allocate pinned memory to pass parameters.
            UnmanagedParams = new ConfigurationParameters[1];
            //m_paramsHandle = GCHandle.Alloc(UnmanagedParams, GCHandleType.Pinned);

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

            // allocate more pinned memory close to the above in an attempt to get the memory all together
            m_collisionArray = new List <BulletXNA.CollisionDesc>();
            //m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned);
            m_updateArray = new List <BulletXNA.EntityProperties>();
            //m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned);

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

            // If Debug logging level, enable logging from the unmanaged code
            m_DebugLogCallbackHandle = null;
            if (m_log.IsDebugEnabled || PhysicsLogging.Enabled)
            {
                m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader);
                if (PhysicsLogging.Enabled)
                {
                    // The handle is saved in a variable to make sure it doesn't get freed after this call
                    m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLoggerPhysLog);
                }
                else
                {
                    m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger);
                }
            }

            // Get the version of the DLL
            // TODO: this doesn't work yet. Something wrong with marshaling the returned string.
            // BulletSimVersion = BulletSimAPI.GetVersion();
            // m_log.WarnFormat("{0}: BulletSim.dll version='{1}'", LogHeader, BulletSimVersion);

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

            // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader);

            World = new BulletWorld(0, this, BulletSimAPI.Initialize2(worldExtent, UnmanagedParams,
                                                                      m_maxCollisionsPerFrame, ref m_collisionArray,
                                                                      m_maxUpdatesPerFrame, ref m_updateArray,
                                                                      m_DebugLogCallbackHandle));

            Constraints = new BSConstraintCollection(World);

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

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

            InTaintTime   = false;
            m_initialized = true;
        }