public override void Initialise(IMesher meshmerizer, IConfigSource config) { // Allocate pinned memory to pass parameters. m_params = new ConfigurationParameters[1]; m_paramsHandle = GCHandle.Alloc(m_params, 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 CollisionDesc[m_maxCollisionsPerFrame]; m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned); m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned); // 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); // if Debug, enable logging from the unmanaged code if (m_log.IsDebugEnabled) { m_log.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); m_DebugLogCallbackHandle = new BulletSimAPI.DebugLogCallback(BulletLogger); BulletSimAPI.SetDebugLogCallback(m_DebugLogCallbackHandle); } _taintedObjects = new List <TaintCallback>(); mesher = meshmerizer; // The bounding box for the simulated world Vector3 worldExtent = new Vector3(Constants.RegionSize, Constants.RegionSize, 4096f); // m_log.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); m_worldID = BulletSimAPI.Initialize(worldExtent, m_paramsHandle.AddrOfPinnedObject(), m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject()); m_initialized = true; }
public override void PostInitialise(IConfigSource config) { // Set default values for physics parameters plus any overrides from the ini file GetInitialParameterValues(config); if (m_initialized) { return; //Only do this once } // Allocate pinned memory to pass parameters. m_paramsHandle = GCHandle.Alloc(m_params, GCHandleType.Pinned); // allocate more pinned memory close to the above in an attempt to get the memory all together m_collisionArray = new CollisionDesc[m_maxCollisionsPerFrame]; m_collisionArrayPinnedHandle = GCHandle.Alloc(m_collisionArray, GCHandleType.Pinned); m_updateArray = new EntityProperties[m_maxUpdatesPerFrame]; m_updateArrayPinnedHandle = GCHandle.Alloc(m_updateArray, GCHandleType.Pinned); // if Debug, enable logging from the unmanaged code if (MainConsole.Instance.IsDebugEnabled) { MainConsole.Instance.DebugFormat("{0}: Initialize: Setting debug callback for unmanaged code", LogHeader); debugLogCallbackHandle = BulletLogger; BulletSimAPI.SetDebugLogCallback(debugLogCallbackHandle); } _taintedObjects = new List <TaintCallback>(); // The bounding box for the simulated world Vector3 worldExtent = new Vector3(m_region.RegionSizeX, m_region.RegionSizeY, m_region.RegionSizeZ); // MainConsole.Instance.DebugFormat("{0}: Initialize: Calling BulletSimAPI.Initialize.", LogHeader); m_worldID = BulletSimAPI.Initialize(worldExtent, m_paramsHandle.AddrOfPinnedObject(), m_maxCollisionsPerFrame, m_collisionArrayPinnedHandle.AddrOfPinnedObject(), m_maxUpdatesPerFrame, m_updateArrayPinnedHandle.AddrOfPinnedObject()); m_initialized = true; }