Пример #1
0
		/// <summary>
		/// Destroy a shape. This removes the shape from the broad-phase and
		/// therefore destroys any contacts associated with this shape. All shapes
		/// attached to a body are implicitly destroyed when the body is destroyed.
		/// @warning This function is locked during callbacks.
		/// </summary>
		/// <param name="shape">The shape to be removed.</param>
		public void DestroyShape(Shape shape)
		{
			Box2DXDebug.Assert(_world._lock == false);
			if (_world._lock == true)
			{
				return;
			}

			Box2DXDebug.Assert(shape.GetBody() == this);
			shape.DestroyProxy(_world._broadPhase);

			Box2DXDebug.Assert(_shapeCount > 0);
			Shape node = _shapeList;
			bool found = false;
			while (node != null)
			{
				if (node == shape)
				{
					_shapeList = shape._next;
					found = true;
					break;
				}

				node = node._next;
			}

			// You tried to remove a shape that is not attached to this body.
			Box2DXDebug.Assert(found);

			shape._body = null;
			shape._next = null;

			--_shapeCount;

			Shape.Destroy(shape);
		}
Пример #2
0
 // STEVE BUG if shape isn't first in list (last added) FIXED
 public void DestroyShape(Shape shape)
 {
     Box2DXDebug.Assert(!this._world._lock);
     if (!this._world._lock)
     {
         Box2DXDebug.Assert(shape.GetBody() == this);
         shape.DestroyProxy(this._world._broadPhase);
         Box2DXDebug.Assert(this._shapeCount > 0);
         bool condition = false;
         if (shape == this._shapeList)
         {
             this._shapeList = shape._next;
             condition = true;
         }
         else
         {
             Shape shape2 = this._shapeList;
             Shape shapeLast = shape2;
             while (shape2 != null)
             {
                 if (shape2 == shape)
                 {
                     shapeLast._next = shape._next;
                     condition = true;
                     break;
                 }
                 shapeLast = shape2;
                 shape2 = shape2._next;
             }
         }
         Box2DXDebug.Assert(condition);
         shape._body = null;
         shape._next = null;
         this._shapeCount--;
         Shape.Destroy(shape);
     }
 }