예제 #1
0
        public FlxQuadTree(float X, float Y, float Width, float Height, FlxQuadTree Parent = null)
            : base(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 = (uint)(base.Width + base.Height) / (2 * divisions);
            _canSubdivide = (base.Width > _min) || (base.Height > _min);

            //Set up comparison/sort helpers
            _northWestTree = null;
            _northEastTree = null;
            _southEastTree = null;
            _southWestTree = null;
            _leftEdge = base.X;
            _rightEdge = base.X + base.Width;
            _halfWidth = base.Width / 2;
            _midpointX = _leftEdge + _halfWidth;
            _topEdge = base.Y;
            _bottomEdge = base.Y + base.Height;
            _halfHeight = base.Height / 2;
            _midpointY = _topEdge + _halfHeight;
        }
예제 #2
0
파일: FlxList.cs 프로젝트: jlorek/flxSharp
 /**
  * Clean up memory.
  */
 public void destroy()
 {
     Object = null;
     if(next != null)
         next.destroy();
     next = null;
 }
예제 #3
0
 /**
  * Clean up memory.
  */
 public void destroy()
 {
     Object = null;
     if (next != null)
     {
         next.destroy();
     }
     next = null;
 }
예제 #4
0
        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) || !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 (overlapProcessed && (_notifyCallback != null))
                    {
                        _notifyCallback(_object, checkObject);
                    }
                }
                _iterator = _iterator.next;
            }

            return(overlapProcessed);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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
        public void destroy()
        {
            _headA.destroy();
            _headA = null;
            _tailA.destroy();
            _tailA = null;
            _headB.destroy();
            _headB = 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;
        }
예제 #8
0
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
  */
 public FlxList()
 {
     Object = null;
     next   = null;
 }
예제 #9
0
        public FlxQuadTree(float X, float Y, float Width, float Height, FlxQuadTree Parent = null)
            : base(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 = (uint)(base.Width + base.Height) / (2 * divisions);
            }
            _canSubdivide = (base.Width > _min) || (base.Height > _min);

            //Set up comparison/sort helpers
            _northWestTree = null;
            _northEastTree = null;
            _southEastTree = null;
            _southWestTree = null;
            _leftEdge      = base.X;
            _rightEdge     = base.X + base.Width;
            _halfWidth     = base.Width / 2;
            _midpointX     = _leftEdge + _halfWidth;
            _topEdge       = base.Y;
            _bottomEdge    = base.Y + base.Height;
            _halfHeight    = base.Height / 2;
            _midpointY     = _topEdge + _halfHeight;
        }
예제 #10
0
파일: FlxList.cs 프로젝트: jlorek/flxSharp
 /**
  * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</code>.
  */
 public FlxList()
 {
     Object = null;
     next = null;
 }
예제 #11
0
        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) || !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(overlapProcessed && (_notifyCallback != null))
                        _notifyCallback(_object,checkObject);
                }
                _iterator = _iterator.next;
            }

            return overlapProcessed;
        }
예제 #12
0
 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
        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
        public void destroy()
        {
            _headA.destroy();
            _headA = null;
            _tailA.destroy();
            _tailA = null;
            _headB.destroy();
            _headB = 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;
        }