Beispiel #1
0
        public Controller(World world)
        {
            _bodyList = null;
            _bodyCount = 0;

            _world = world;
        }
Beispiel #2
0
        /// <summary>
        /// Adds a body to the controller list.
        /// </summary>
        public void AddBody(Body body)
        {
            ControllerEdge edge = new ControllerEdge();

            edge.body = body;
            edge.controller = this;

            //Add edge to controller list
            edge.nextBody = _bodyList;
            edge.prevBody = null;
            if (_bodyList != null)
                _bodyList.prevBody = edge;
            _bodyList = edge;
            ++_bodyCount;

            //Add edge to body list
            edge.nextController = body._controllerList;
            edge.prevController = null;
            if (body._controllerList != null)
                body._controllerList.prevController = edge;
            body._controllerList = edge;
        }
Beispiel #3
0
        /// <summary>
        /// Removes a body from the controller list.
        /// </summary>
        public void RemoveBody(Body body)
        {
            //Assert that the controller is not empty
            Box2DXDebug.Assert(_bodyCount > 0);

            //Find the corresponding edge
            ControllerEdge edge = _bodyList;
            while (edge != null && edge.body != body)
                edge = edge.nextBody;

            //Assert that we are removing a body that is currently attached to the controller
            Box2DXDebug.Assert(edge != null);

            //Remove edge from controller list
            if (edge.prevBody != null)
                edge.prevBody.nextBody = edge.nextBody;
            if (edge.nextBody != null)
                edge.nextBody.prevBody = edge.prevBody;
            if (edge == _bodyList)
                _bodyList = edge.nextBody;
            --_bodyCount;

            //Remove edge from body list
            if (edge.prevController != null)
                edge.prevController.nextController = edge.nextController;
            if (edge.nextController != null)
                edge.nextController.prevController = edge.prevController;
            if (edge == body._controllerList)
                body._controllerList = edge.nextController;

            //Free the edge
            edge = null;
        }
Beispiel #4
0
 public Controller()
 {
     _bodyList = null;
     _bodyCount = 0;
 }
Beispiel #5
0
        /// <summary>
        /// Removes all bodies from the controller list.
        /// </summary>
        public void Clear()
        {
#warning "Check this"
            ControllerEdge current = _bodyList;
            while (current != null)
            {
                ControllerEdge edge = current;

                //Remove edge from controller list
                _bodyList = edge.nextBody;

                //Remove edge from body list
                if (edge.prevController != null)
                    edge.prevController.nextController = edge.nextController;
                if (edge.nextController != null)
                    edge.nextController.prevController = edge.prevController;
                if (edge == edge.body._controllerList)
                    edge.body._controllerList = edge.nextController;

                //Free the edge
                //m_world->m_blockAllocator.Free(edge, sizeof(b2ControllerEdge));
            }

            _bodyCount = 0;
        }