/// <summary> /// Destroy a rigid body. /// Warning: This function is locked during callbacks. /// Warning: This automatically deletes all associated shapes and joints. /// </summary> /// <param name="body">The body.</param> public void RemoveBody(Body body) { Debug.Assert(BodyList.Count > 0); Debug.Assert(!IsLocked); if (IsLocked) { return; } // You tried to remove a body that is not contained in the BodyList. // Are you removing the body more than once? Debug.Assert(BodyList.Contains(body)); // Delete the attached joints. JointEdge je = body.JointList; while (je != null) { JointEdge je0 = je; je = je.Next; RemoveJoint(je0.Joint); } body.JointList = null; // Delete the attached contacts. ContactEdge ce = body.ContactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; ContactManager.Destroy(ce0.Contact); } body.ContactList = null; // Delete the attached fixtures. This destroys broad-phase proxies. foreach (Fixture fixture in body.FixtureList) { fixture.DestroyProxies(ContactManager.BroadPhase); fixture.Destroy(); } body.FixtureList = null; // Remove world body list. BodyList.Remove(body); if (BodyRemoved != null) { BodyRemoved(body); } }
private void ProcessRemovedBodies() { if (_bodyRemoveList.Count > 0) { foreach (Body body in _bodyRemoveList) { Debug.Assert(BodyList.Count > 0); // You tried to remove a body that is not contained in the BodyList. // Are you removing the body more than once? //Debug.Assert(BodyList.Contains(body)); if (!BodyList.Contains(body)) { continue; } // Delete the attached joints. foreach (Joint j in body.JointList) { RemoveJoint(j, false); } body.JointList.Clear(); // Delete the attached contacts. ContactEdge ce = body.ContactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; ContactManager.Destroy(ce0.Contact); } body.ContactList = null; // Delete the attached fixtures. This destroys broad-phase proxies. for (int i = 0; i < body.FixtureList.Count; i++) { body.FixtureList[i].DestroyProxies(ContactManager.BroadPhase); body.FixtureList[i].Destroy(); } body.FixtureList = null; // Remove world body list. BodyList.Remove(body); if (BodyRemoved != null) { BodyRemoved(body); } } _bodyRemoveList.Clear(); } }
private void ProcessRemovedItems() { //Remove any new geometries for (int i = 0; i < geomRemoveList.Count; i++) { geomRemoveList[i].isRemoved = true; geomList.Remove(geomRemoveList[i]); //Remove any arbiters associated with the geometries being removed for (int j = arbiterList.Count; j > 0; j--) { if (arbiterList[j - 1].GeometryA == geomRemoveList[i] || arbiterList[j - 1].GeometryB == geomRemoveList[i]) { arbiterList.Remove(arbiterList[j - 1]); } } } if (geomRemoveList.Count > 0) { _broadPhaseCollider.ProcessRemovedGeoms(); } geomRemoveList.Clear(); //Remove any new bodies for (int i = 0; i < bodyRemoveList.Count; i++) { bodyList.Remove(bodyRemoveList[i]); } bodyRemoveList.Clear(); //Remove any new controllers for (int i = 0; i < controllerRemoveList.Count; i++) { controllerList.Remove(controllerRemoveList[i]); } controllerRemoveList.Clear(); //Remove any new joints for (int i = 0; i < jointRemoveList.Count; i++) { jointList.Remove(jointRemoveList[i]); } jointRemoveList.Clear(); //Remove any new springs for (int i = 0; i < springRemoveList.Count; i++) { springList.Remove(springRemoveList[i]); } springRemoveList.Clear(); }
private void ProcessRemovedBodies() { if (_bodyRemoveList.Count > 0) { foreach (Body body in _bodyRemoveList) { System.Diagnostics.Debug.Assert(BodyList.Count > 0); // You tried to remove a body that is not contained in the BodyList. // Are you removing the body more than once? //Debug.Assert(BodyList.Contains(body)); // Delete the attached joints. JointEdge je = body.JointList; while (je != null) { JointEdge je0 = je; je = je.Next; RemoveJoint(je0.Joint, false); } body.JointList = null; // Delete the attached contacts. ContactEdge ce = body.ContactList; while (ce != null) { ContactEdge ce0 = ce; ce = ce.Next; ContactManager.Destroy(ce0.Contact); } body.ContactList = null; // Delete the attached fixtures. This destroys broad-phase proxies. if (body.FixtureList != null) { for (int i = 0; i < body.FixtureList.Count; i++) { body.FixtureList[i].DestroyProxies(ContactManager.BroadPhase); body.FixtureList[i].Destroy(); } } body.FixtureList = null; // Remove world body list. BodyList.Remove(body); BodyRemoved?.Invoke(body); } _bodyRemoveList.Clear(); } }
public void PopBody(Body tgtBody) { // Add Body to BodyList BodyList.Remove(tgtBody); _nBodies -= 1; }
public void Remove(Body body) { _bodyList.Remove(body); }
/// <summary> /// Processes the removed geometries (and their arbiters), bodies, controllers, joints and springs. /// </summary> private void ProcessRemovedItems() { //Remove any new geometries _tempCount = _geomRemoveList.Count; for (int i = 0; i < _tempCount; i++) { _geomRemoveList[i].InSimulation = false; GeomList.Remove(_geomRemoveList[i]); //Remove any arbiters associated with the geometries being removed for (int j = ArbiterList.Count; j > 0; j--) { if (ArbiterList[j - 1].GeometryA == _geomRemoveList[i] || ArbiterList[j - 1].GeometryB == _geomRemoveList[i]) { //TODO: Should we create a RemoveComplete method and remove all Contacts associated //with the arbiter? arbiterPool.Insert(ArbiterList[j - 1]); ArbiterList.Remove(ArbiterList[j - 1]); } } } if (_geomRemoveList.Count > 0) { _broadPhaseCollider.ProcessRemovedGeoms(); } _geomRemoveList.Clear(); //Remove any new bodies _tempCount = _bodyRemoveList.Count; for (int i = 0; i < _tempCount; i++) { BodyList.Remove(_bodyRemoveList[i]); } _bodyRemoveList.Clear(); //Remove any new controllers _tempCount = _controllerRemoveList.Count; for (int i = 0; i < _tempCount; i++) { ControllerList.Remove(_controllerRemoveList[i]); } _controllerRemoveList.Clear(); //Remove any new joints int jointRemoveCount = _jointRemoveList.Count; for (int i = 0; i < jointRemoveCount; i++) { JointList.Remove(_jointRemoveList[i]); } _jointRemoveList.Clear(); //Remove any new springs _tempCount = _springRemoveList.Count; for (int i = 0; i < _tempCount; i++) { SpringList.Remove(_springRemoveList[i]); } _springRemoveList.Clear(); }