예제 #1
0
 /**
  * Clean up memory.
  */
 public void destroy()
 {
     Object = null;
     if(next != null)
         next.destroy();
     next = null;
 }
예제 #2
0
 /**
  * Clean up memory.
  */
 public void destroy()
 {
     Object = null;
     if (next != null)
     {
         next.destroy();
     }
     next = null;
 }
예제 #3
0
        /**
         * An internal function for comparing an object against the contents of a
         * node.
         *
         * @return Whether or not any overlaps were found.
         */
        protected Boolean overlapNode()
        {
            // Walk the list and check for overlaps
            Boolean   overlapProcessed = false;
            FlxObject checkObject;

            while (_iterator != null)
            {
                if (!_object.Exists || (_object.AllowCollisions <= 0))
                {
                    break;
                }

                checkObject = _iterator.Object;
                if ((_object == checkObject) || ((_object != null) && (_object.Equals(checkObject))) || !checkObject.Exists || (checkObject.AllowCollisions <= 0))
                {
                    _iterator = _iterator.next;
                    continue;
                }

                // calculate bulk hull for _object
                _objectHullX      = (_object.X < _object.Last.X) ? _object.X : _object.Last.X;
                _objectHullY      = (_object.Y < _object.Last.Y) ? _object.Y : _object.Last.Y;
                _objectHullWidth  = _object.X - _object.Last.X;
                _objectHullWidth  = _object.Width + ((_objectHullWidth > 0) ? _objectHullWidth : -_objectHullWidth);
                _objectHullHeight = _object.Y - _object.Last.Y;
                _objectHullHeight = _object.Height + ((_objectHullHeight > 0) ? _objectHullHeight : -_objectHullHeight);

                // calculate bulk hull for checkObject
                _checkObjectHullX      = (checkObject.X < checkObject.Last.X) ? checkObject.X : checkObject.Last.X;
                _checkObjectHullY      = (checkObject.Y < checkObject.Last.Y) ? checkObject.Y : checkObject.Last.Y;
                _checkObjectHullWidth  = checkObject.X - checkObject.Last.X;
                _checkObjectHullWidth  = checkObject.Width + ((_checkObjectHullWidth > 0) ? _checkObjectHullWidth : -_checkObjectHullWidth);
                _checkObjectHullHeight = checkObject.Y - checkObject.Last.Y;
                _checkObjectHullHeight = checkObject.Height + ((_checkObjectHullHeight > 0) ? _checkObjectHullHeight : -_checkObjectHullHeight);

                // check for intersection of the two hulls
                if ((_objectHullX + _objectHullWidth > _checkObjectHullX) && (_objectHullX < _checkObjectHullX + _checkObjectHullWidth) &&
                    (_objectHullY + _objectHullHeight > _checkObjectHullY) && (_objectHullY < _checkObjectHullY + _checkObjectHullHeight))
                {
                    // Execute callback functions if they exist
                    if ((_processingCallback == null) || _processingCallback(_object, checkObject))
                    {
                        overlapProcessed = true;
                        if (_notifyCallback != null)
                        {
                            _notifyCallback(_object, checkObject);
                        }
                    }
                }
                _iterator = _iterator.next;
            }

            return(overlapProcessed);
        }
예제 #4
0
        /**
         * <code>FlxQuadTree</code>'s other main function. Call this after adding
         * objects using <code>FlxQuadTree.Load()</code> to compare the objects that
         * you loaded.
         *
         * @return Whether or not any overlaps were found.
         */
        public Boolean execute()
        {
            Boolean overlapProcessed = false;
            FlxList iterator;

            if (_headA.Object != null)
            {
                iterator = _headA;
                while (iterator != null)
                {
                    _object = iterator.Object;
                    if (_useBothLists)
                    {
                        _iterator = _headB;
                    }
                    else
                    {
                        _iterator = iterator.next;
                    }
                    if (_object.Exists && (_object.AllowCollisions > 0) && (_iterator != null) && (_iterator.Object != null) && _iterator.Object.Exists && overlapNode())
                    {
                        overlapProcessed = true;
                    }
                    iterator = iterator.next;
                }
            }

            // Advance through the tree by calling overlap on each child
            if ((_northWestTree != null) && _northWestTree.execute())
            {
                overlapProcessed = true;
            }
            if ((_northEastTree != null) && _northEastTree.execute())
            {
                overlapProcessed = true;
            }
            if ((_southEastTree != null) && _southEastTree.execute())
            {
                overlapProcessed = true;
            }
            if ((_southWestTree != null) && _southWestTree.execute())
            {
                overlapProcessed = true;
            }

            return(overlapProcessed);
        }
예제 #5
0
        /**
         * Clean up memory.
         */
        public void destroy()
        {
            if (_headA != null)
            {
                _headA.destroy();
            }
            _headA = null;
            // if(_tailA != null)
            // _tailA.destroy();
            _tailA = null;
            if (_headB != null)
            {
                _headB.destroy();
            }
            _headB = null;
            // if(_tailB != null)
            // _tailB.destroy();
            _tailB = null;

            if (_northWestTree != null)
            {
                _northWestTree.destroy();
            }
            _northWestTree = null;
            if (_northEastTree != null)
            {
                _northEastTree.destroy();
            }
            _northEastTree = null;
            if (_southEastTree != null)
            {
                _southEastTree.destroy();
            }
            _southEastTree = null;
            if (_southWestTree != null)
            {
                _southWestTree.destroy();
            }
            _southWestTree = null;

            _object             = null;
            _processingCallback = null;
            _notifyCallback     = null;

            //_pool.free(this);
        }
예제 #6
0
        /**
         * Internal function for recursively adding objects to leaf lists.
         */
        protected void addToList()
        {
            FlxList ot;

            if (_list == A_LIST)
            {
                if (_tailA.Object != null)
                {
                    ot      = _tailA;
                    _tailA  = new FlxList();
                    ot.next = _tailA;
                }
                _tailA.Object = _object;
            }
            else
            {
                if (_tailB.Object != null)
                {
                    ot      = _tailB;
                    _tailB  = new FlxList();
                    ot.next = _tailB;
                }
                _tailB.Object = _object;
            }
            if (!_canSubdivide)
            {
                return;
            }
            if (_northWestTree != null)
            {
                _northWestTree.addToList();
            }
            if (_northEastTree != null)
            {
                _northEastTree.addToList();
            }
            if (_southEastTree != null)
            {
                _southEastTree.addToList();
            }
            if (_southWestTree != null)
            {
                _southWestTree.addToList();
            }
        }
예제 #7
0
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
  */
 public FlxList()
 {
     Object = null;
     next   = null;
 }
예제 #8
0
        /**
         * Instantiate a new Quad Tree node.
         *
         * @param X The X-coordinate of the point in space.
         * @param Y The Y-coordinate of the point in space.
         * @param Width Desired width of this node.
         * @param Height Desired height of this node.
         * @param Parent The parent branch or node. Pass null to create a root.
         */
        protected void init(float X, float Y, float Width, float Height, FlxQuadTree Parent)
        {
            make(X, Y, Width, Height);
            _headA = _tailA = new FlxList();
            _headB = _tailB = new FlxList();

            // Copy the parent's children (if there are any)
            if (Parent != null)
            {
                FlxList iterator;
                FlxList ot;
                if (Parent._headA.Object != null)
                {
                    iterator = Parent._headA;
                    while (iterator != null)
                    {
                        if (_tailA.Object != null)
                        {
                            ot      = _tailA;
                            _tailA  = new FlxList();
                            ot.next = _tailA;
                        }
                        _tailA.Object = iterator.Object;
                        iterator      = iterator.next;
                    }
                }
                if (Parent._headB.Object != null)
                {
                    iterator = Parent._headB;
                    while (iterator != null)
                    {
                        if (_tailB.Object != null)
                        {
                            ot      = _tailB;
                            _tailB  = new FlxList();
                            ot.next = _tailB;
                        }
                        _tailB.Object = iterator.Object;
                        iterator      = iterator.next;
                    }
                }
            }
            else
            {
                _min = (int)((Width + Height) / (2 * divisions));
            }
            _canSubdivide = (Width > _min) || (Height > _min);

            // Set up comparison/sort helpers
            _northWestTree = null;
            _northEastTree = null;
            _southEastTree = null;
            _southWestTree = null;
            _leftEdge      = X;
            _rightEdge     = X + Width;
            _halfWidth     = Width / 2f;
            _midpointX     = _leftEdge + _halfWidth;
            _topEdge       = Y;
            _bottomEdge    = Y + Height;
            _halfHeight    = Height / 2f;
            _midpointY     = _topEdge + _halfHeight;
        }
예제 #9
0
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
  */
 public FlxList()
 {
     Object = null;
     next = null;
 }
예제 #10
0
        /**
           * An internal function for comparing an object against the contents of a
           * node.
           *
           * @return Whether or not any overlaps were found.
           */
        protected Boolean overlapNode()
        {
            // Walk the list and check for overlaps
            Boolean overlapProcessed = false;
            FlxObject checkObject;
            while (_iterator != null) {
                if (!_object.Exists || (_object.AllowCollisions <= 0))
                    break;

                checkObject = _iterator.Object;
                if ((_object == checkObject) || ((_object != null) && (_object.Equals (checkObject))) || !checkObject.Exists || (checkObject.AllowCollisions <= 0)) {
                    _iterator = _iterator.next;
                    continue;
                }

                // calculate bulk hull for _object
                _objectHullX = (_object.X < _object.Last.X) ? _object.X : _object.Last.X;
                _objectHullY = (_object.Y < _object.Last.Y) ? _object.Y : _object.Last.Y;
                _objectHullWidth = _object.X - _object.Last.X;
                _objectHullWidth = _object.Width + ((_objectHullWidth > 0) ? _objectHullWidth : -_objectHullWidth);
                _objectHullHeight = _object.Y - _object.Last.Y;
                _objectHullHeight = _object.Height + ((_objectHullHeight > 0) ? _objectHullHeight : -_objectHullHeight);

                // calculate bulk hull for checkObject
                _checkObjectHullX = (checkObject.X < checkObject.Last.X) ? checkObject.X : checkObject.Last.X;
                _checkObjectHullY = (checkObject.Y < checkObject.Last.Y) ? checkObject.Y : checkObject.Last.Y;
                _checkObjectHullWidth = checkObject.X - checkObject.Last.X;
                _checkObjectHullWidth = checkObject.Width + ((_checkObjectHullWidth > 0) ? _checkObjectHullWidth : -_checkObjectHullWidth);
                _checkObjectHullHeight = checkObject.Y - checkObject.Last.Y;
                _checkObjectHullHeight = checkObject.Height + ((_checkObjectHullHeight > 0) ? _checkObjectHullHeight : -_checkObjectHullHeight);

                // check for intersection of the two hulls
                if ((_objectHullX + _objectHullWidth > _checkObjectHullX) && (_objectHullX < _checkObjectHullX + _checkObjectHullWidth)
                   && (_objectHullY + _objectHullHeight > _checkObjectHullY) && (_objectHullY < _checkObjectHullY + _checkObjectHullHeight)) {
                    // Execute callback functions if they exist
                    if ((_processingCallback == null) || _processingCallback (_object, checkObject)) {
                        overlapProcessed = true;
                        if (_notifyCallback != null)
                            _notifyCallback (_object, checkObject);
                    }

                }
                _iterator = _iterator.next;
            }

            return overlapProcessed;
        }
예제 #11
0
        /**
           * Instantiate a new Quad Tree node.
           *
           * @param X The X-coordinate of the point in space.
           * @param Y The Y-coordinate of the point in space.
           * @param Width Desired width of this node.
           * @param Height Desired height of this node.
           * @param Parent The parent branch or node. Pass null to create a root.
           */
        protected void init(float X, float Y, float Width, float Height, FlxQuadTree Parent)
        {
            make (X, Y, Width, Height);
            _headA = _tailA = new FlxList ();
            _headB = _tailB = new FlxList ();

            // Copy the parent's children (if there are any)
            if (Parent != null) {
                FlxList iterator;
                FlxList ot;
                if (Parent._headA.Object != null) {
                    iterator = Parent._headA;
                    while (iterator != null) {
                        if (_tailA.Object != null) {
                            ot = _tailA;
                            _tailA = new FlxList ();
                            ot.next = _tailA;
                        }
                        _tailA.Object = iterator.Object;
                        iterator = iterator.next;
                    }
                }
                if (Parent._headB.Object != null) {
                    iterator = Parent._headB;
                    while (iterator != null) {
                        if (_tailB.Object != null) {
                            ot = _tailB;
                            _tailB = new FlxList ();
                            ot.next = _tailB;
                        }
                        _tailB.Object = iterator.Object;
                        iterator = iterator.next;
                    }
                }
            } else
                _min = (int)((Width + Height) / (2 * divisions));
            _canSubdivide = (Width > _min) || (Height > _min);

            // Set up comparison/sort helpers
            _northWestTree = null;
            _northEastTree = null;
            _southEastTree = null;
            _southWestTree = null;
            _leftEdge = X;
            _rightEdge = X + Width;
            _halfWidth = Width / 2f;
            _midpointX = _leftEdge + _halfWidth;
            _topEdge = Y;
            _bottomEdge = Y + Height;
            _halfHeight = Height / 2f;
            _midpointY = _topEdge + _halfHeight;
        }
예제 #12
0
 /**
    * Internal function for recursively adding objects to leaf lists.
    */
 protected void addToList()
 {
     FlxList ot;
     if (_list == A_LIST) {
         if (_tailA.Object != null) {
             ot = _tailA;
             _tailA = new FlxList ();
             ot.next = _tailA;
         }
         _tailA.Object = _object;
     } else {
         if (_tailB.Object != null) {
             ot = _tailB;
             _tailB = new FlxList ();
             ot.next = _tailB;
         }
         _tailB.Object = _object;
     }
     if (!_canSubdivide)
         return;
     if (_northWestTree != null)
         _northWestTree.addToList ();
     if (_northEastTree != null)
         _northEastTree.addToList ();
     if (_southEastTree != null)
         _southEastTree.addToList ();
     if (_southWestTree != null)
         _southWestTree.addToList ();
 }
예제 #13
0
        /**
           * <code>FlxQuadTree</code>'s other main function. Call this after adding
           * objects using <code>FlxQuadTree.Load()</code> to compare the objects that
           * you loaded.
           *
           * @return Whether or not any overlaps were found.
           */
        public Boolean execute()
        {
            Boolean overlapProcessed = false;
            FlxList iterator;

            if (_headA.Object != null) {
                iterator = _headA;
                while (iterator != null) {
                    _object = iterator.Object;
                    if (_useBothLists)
                        _iterator = _headB;
                    else
                        _iterator = iterator.next;
                    if (_object.Exists && (_object.AllowCollisions > 0) && (_iterator != null) && (_iterator.Object != null) && _iterator.Object.Exists && overlapNode ()) {
                        overlapProcessed = true;
                    }
                    iterator = iterator.next;
                }
            }

            // Advance through the tree by calling overlap on each child
            if ((_northWestTree != null) && _northWestTree.execute ())
                overlapProcessed = true;
            if ((_northEastTree != null) && _northEastTree.execute ())
                overlapProcessed = true;
            if ((_southEastTree != null) && _southEastTree.execute ())
                overlapProcessed = true;
            if ((_southWestTree != null) && _southWestTree.execute ())
                overlapProcessed = true;

            return overlapProcessed;
        }
예제 #14
0
        /**
           * Clean up memory.
           */
        public void destroy()
        {
            if (_headA != null)
                _headA.destroy ();
            _headA = null;
            // if(_tailA != null)
            // _tailA.destroy();
            _tailA = null;
            if (_headB != null)
                _headB.destroy ();
            _headB = null;
            // if(_tailB != null)
            // _tailB.destroy();
            _tailB = null;

            if (_northWestTree != null)
                _northWestTree.destroy ();
            _northWestTree = null;
            if (_northEastTree != null)
                _northEastTree.destroy ();
            _northEastTree = null;
            if (_southEastTree != null)
                _southEastTree.destroy ();
            _southEastTree = null;
            if (_southWestTree != null)
                _southWestTree.destroy ();
            _southWestTree = null;

            _object = null;
            _processingCallback = null;
            _notifyCallback = null;

            //_pool.free(this);
        }