/// <summary> /// Construct a world object. /// </summary> /// <param name="worldAABB">A bounding box that completely encompasses all your shapes.</param> /// <param name="gravity">The world gravity vector.</param> /// <param name="doSleep">Improve performance by not simulating inactive bodies.</param> public World(Vector2 gravity) { m_destructionListener = null; m_debugDraw = null; m_bodyList = null; m_jointList = null; m_bodyCount = 0; m_jointCount = 0; m_warmStarting = true; m_continuousPhysics = true; m_subStepping = false; m_stepComplete = true; m_allowSleep = true; m_gravity = gravity; m_newContacts = false; m_locked = false; m_clearForces = true; m_inv_dt0 = 0.0f; m_contactManager = new ContactManager(); }
/// <summary> /// Construct a world object. /// </summary> /// <param name="gravity">the world gravity vector.</param> /// <param name="doSleep">improve performance by not simulating inactive bodies.</param> public World(Vec2 gravity, IWorldPool argPool) { contactStacks = new ContactRegister[ShapeTypesCount][]; for (int i = 0; i < ShapeTypesCount; i++) { contactStacks[i] = new ContactRegister[ShapeTypesCount]; } pool = argPool; m_destructionListener = null; m_debugDraw = null; m_bodyList = null; m_jointList = null; m_bodyCount = 0; m_jointCount = 0; m_warmStarting = true; m_continuousPhysics = true; m_subStepping = false; m_stepComplete = true; m_allowSleep = true; m_gravity.set_Renamed(gravity); m_flags = CLEAR_FORCES; m_inv_dt0 = 0f; m_contactManager = new ContactManager(this); m_profile = new Profile(); initializeRegisters(); }
/// Destroy a rigid body given a definition. No reference to the definition /// is retained. This function is locked during callbacks. /// @warning This automatically deletes all associated shapes and joints. /// @warning This function is locked during callbacks. public void DestroyBody(Body b) { Debug.Assert(_bodyCount > 0); Debug.Assert(!IsLocked); if (IsLocked) { return; } // Delete the attached joints. JointEdge je = b._jointList; while (je != null) { JointEdge je0 = je; je = je.Next; if (DestructionListener != null) { DestructionListener.SayGoodbye(je0.Joint); } DestroyJoint(je0.Joint); } b._jointList = null; // Delete the attached contacts. ContactEdge ce = b._contactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; _contactManager.Destroy(ce0.Contact); } b._contactList = null; // Delete the attached fixtures. This destroys broad-phase proxies. Fixture f = b._fixtureList; while (f != null) { Fixture f0 = f; f = f._next; if (DestructionListener != null) { DestructionListener.SayGoodbye(f0); } f0.DestroyProxy(_contactManager._broadPhase); f0.Destroy(); } b._fixtureList = null; b._fixtureCount = 0; // Remove world body list. if (b._prev != null) { b._prev._next = b._next; } if (b._next != null) { b._next._prev = b._prev; } if (b == _bodyList) { _bodyList = b._next; } --_bodyCount; }
public static void OnDestroy(this GameObject go, Action callback) { DestructionListener listener = go.GetOrCreate <DestructionListener>(); listener.Initialize(callback); }
public World(Vec2 gravity, IWorldPool pool, BroadPhase broadPhase) { this.pool = pool; m_destructionListener = null; m_debugDraw = null; m_bodyList = null; m_jointList = null; m_bodyCount = 0; m_jointCount = 0; m_warmStarting = true; m_continuousPhysics = true; m_subStepping = false; m_stepComplete = true; m_allowSleep = true; m_gravity.set(gravity); m_flags = CLEAR_FORCES; m_inv_dt0 = 0f; m_contactManager = new ContactManager(this, broadPhase); m_profile = new Profile(); m_particleSystem = new ParticleSystem(this); for (int i = 0; i < contactStacks.Length; i++) { contactStacks[i] = new ContactRegister[Enum.GetValues(typeof (ShapeType)).Length]; } initializeRegisters(); }
/** * Register a destruction listener. The listener is owned by you and must remain in scope. * * @param listener */ public void setDestructionListener(DestructionListener listener) { m_destructionListener = listener; }