Ejemplo n.º 1
0
        private void AddToList()
        {
            FlxLinkedList ot;

            if (_list == A_LIST)
            {
                if (_tailA.FlxObject != null)
                {
                    ot      = _tailA;
                    _tailA  = FlxLinkedList.Recycle();
                    ot.Next = _tailA;
                }
                _tailA.FlxObject = _object;
            }
            else
            {
                if (_tailB.FlxObject != null)
                {
                    ot      = _tailB;
                    _tailB  = FlxLinkedList.Recycle();
                    ot.Next = _tailB;
                }
                _tailB.FlxObject = _object;
            }
            if (!_canSubdivide)
            {
                return;
            }
            if (_northWestTree != null)
            {
                _northWestTree.AddToList();
            }
            if (_northEastTree != null)
            {
                _northEastTree.AddToList();
            }
            if (_southEastTree != null)
            {
                _southEastTree.AddToList();
            }
            if (_southWestTree != null)
            {
                _southWestTree.AddToList();
            }
        }
Ejemplo n.º 2
0
        public void Reset(float x, float y, float width, float height, FlxQuadTree parent = null)
        {
            Exists = true;
            Set(x, y, width, height);

            _headA = _tailA = FlxLinkedList.Recycle();
            _headB = _tailB = FlxLinkedList.Recycle();

            if (parent != null)
            {
                FlxLinkedList iterator;
                FlxLinkedList ot;
                if (parent._headA.FlxObject != null)
                {
                    iterator = parent._headA;
                    while (iterator != null)
                    {
                        if (_tailA.FlxObject != null)
                        {
                            ot      = _tailA;
                            _tailA  = FlxLinkedList.Recycle();
                            ot.Next = _tailA;
                        }
                        _tailA.FlxObject = iterator.FlxObject;
                        iterator         = iterator.Next;
                    }
                }
                if (parent._headB.FlxObject != null)
                {
                    iterator = parent._headB;
                    while (iterator != null)
                    {
                        if (_tailB.FlxObject != null)
                        {
                            ot      = _tailB;
                            _tailB  = FlxLinkedList.Recycle();
                            ot.Next = _tailB;
                        }
                        _tailB.FlxObject = iterator.FlxObject;
                        iterator         = iterator.Next;
                    }
                }
            }
            else
            {
                _min = (int)Math.Floor((Width + Height) / (2 * Divisions));
            }
            _canSubdivide = Width > _min || Height > _min;

            _northWestTree = null;
            _northEastTree = null;
            _southWestTree = null;
            _southEastTree = null;
            _leftEdge      = X;
            _rightEdge     = Right;
            _halfWidth     = Width / 2;
            _midpointX     = _leftEdge + _halfWidth;
            _topEdge       = Y;
            _bottomEdge    = Bottom;
            _halfHeight    = Height / 2;
            _midpointY     = _topEdge + _halfHeight;
        }