/// <summary> /// An internal function for comparing an object against the contents of a node. /// </summary> /// <param name="Iterator">An optional pointer to a linked list entry (for comparing A against itself).</param> /// <returns>hether or not any overlaps were found.</returns> protected bool overlapNode(FlxList Iterator) { //member list setup bool c = false; FlxObject co; FlxList itr = Iterator; if (itr == null) { if (_oa == A_LIST) { itr = _headA; } else { itr = _headB; } } //Make sure this is a valid list to walk first! if (itr.@object != null) { //Walk the list and check for overlaps while (itr != null) { co = itr.@object; if ((_o == co) || !co.exists || !_o.exists || !co.solid || !_o.solid || (_o.x + _o.width < co.x + FlxU.roundingError) || (_o.x + FlxU.roundingError > co.x + co.width) || (_o.y + _o.height < co.y + FlxU.roundingError) || (_o.y + FlxU.roundingError > co.y + co.height)) { itr = itr.next; continue; } if (_oc == null) { //_o.kill(); //co.kill(); c = true; //_o.overlapped(co); //co.overlapped(_o); } //else if(_oc(_o,co)) else if (_oc(this, new FlxSpriteCollisionEvent(_o, co))) { c = true; //_o.overlapped(co); //co.overlapped(_o); } itr = itr.next; } } return(c); }
/** * Internal function for recursively adding objects to leaf lists. */ protected void addToList() { FlxList ot; if (_oa == A_LIST) { if (_tailA.@object != null) { ot = _tailA; _tailA = new FlxList(); ot.next = _tailA; } _tailA.@object = _o; } else { if (_tailB.@object != null) { ot = _tailB; _tailB = new FlxList(); ot.next = _tailB; } _tailB.@object = _o; } if (!_canSubdivide) { return; } if (_nw != null) { _nw.addToList(); } if (_ne != null) { _ne.addToList(); } if (_se != null) { _se.addToList(); } if (_sw != null) { _sw.addToList(); } }
/// <summary> /// Creates a new link, and sets object and next to null.. /// </summary> public FlxList() { @object = null; next = null; }
/** * Creates a new link, and sets <code>object</code> and <code>next</code> to <code>null</null>. */ public FlxList() { @object = null; next = null; }
/** * 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. */ public FlxQuadTree(float X, float Y, float Width, float Height, FlxQuadTree Parent) { x = X; y = Y; width = Width; height = Height; //x = 0; //y = 0; //width = 0; //height = 0; _headA = _tailA = new FlxList(); _headB = _tailB = new FlxList(); /*DEBUG: draw a randomly colored rectangle indicating this quadrant (may induce seizures) * var brush:FlxSprite = new FlxSprite().createGraphic(Width,Height,0xffffffff*FlxU.random()); * FlxState.screen.draw(brush,X+FlxG.scroll.x,Y+FlxG.scroll.y);//*/ //Copy the parent's children (if there are any) if (Parent != null) { FlxList itr; FlxList ot; if (Parent._headA.@object != null) { itr = Parent._headA; while (itr != null) { if (_tailA.@object != null) { ot = _tailA; _tailA = new FlxList(); ot.next = _tailA; } _tailA.@object = itr.@object; itr = itr.next; } } if (Parent._headB.@object != null) { itr = Parent._headB; while (itr != null) { if (_tailB.@object != null) { ot = _tailB; _tailB = new FlxList(); ot.next = _tailB; } _tailB.@object = itr.@object; itr = itr.next; } } } else { _min = (uint)(width + height) / (2 * divisions); } _canSubdivide = (width > _min) || (height > _min); //Set up comparison/sort helpers _nw = null; _ne = null; _se = null; _sw = null; _l = x; _r = x + width; _hw = width / 2; _mx = _l + _hw; _t = y; _b = y + height; _hh = height / 2; _my = _t + _hh; }
protected bool overlapNode(FlxList Iterator) { //member list setup bool c = false; FlxObject co; FlxList itr = Iterator; if(itr == null) { if(_oa == A_LIST) itr = _headA; else itr = _headB; } //Make sure this is a valid list to walk first! if(itr.@object != null) { //Walk the list and check for overlaps while(itr != null) { co = itr.@object; if( (_o == co) || !co.exists || !_o.exists || !co.solid || !_o.solid || (_o.x + _o.width < co.x + FlxU.roundingError) || (_o.x + FlxU.roundingError > co.x + co.width) || (_o.y + _o.height < co.y + FlxU.roundingError) || (_o.y + FlxU.roundingError > co.y + co.height) ) { itr = itr.next; continue; } if(_oc == null) { _o.kill(); co.kill(); c = true; } //else if(_oc(_o,co)) else if (_oc(this, new FlxSpriteCollisionEvent(_o, co))) { c = true; } itr = itr.next; } } return c; }
/** * Internal function for recursively adding objects to leaf lists. */ protected void addToList() { FlxList ot; if(_oa == A_LIST) { if(_tailA.@object != null) { ot = _tailA; _tailA = new FlxList(); ot.next = _tailA; } _tailA.@object = _o; } else { if(_tailB.@object != null) { ot = _tailB; _tailB = new FlxList(); ot.next = _tailB; } _tailB.@object = _o; } if(!_canSubdivide) return; if(_nw != null) _nw.addToList(); if(_ne != null) _ne.addToList(); if(_se != null) _se.addToList(); if(_sw != null) _sw.addToList(); }
/** * 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. */ public FlxQuadTree(float X, float Y, float Width, float Height, FlxQuadTree Parent) { x = X; y = Y; width = Width; height = Height; //x = 0; //y = 0; //width = 0; //height = 0; _headA = _tailA = new FlxList(); _headB = _tailB = new FlxList(); /*DEBUG: draw a randomly colored rectangle indicating this quadrant (may induce seizures) var brush:FlxSprite = new FlxSprite().createGraphic(Width,Height,0xffffffff*FlxU.random()); FlxState.screen.draw(brush,X+FlxG.scroll.x,Y+FlxG.scroll.y);//*/ //Copy the parent's children (if there are any) if (Parent != null) { FlxList itr; FlxList ot; if (Parent._headA.@object != null) { itr = Parent._headA; while (itr != null) { if (_tailA.@object != null) { ot = _tailA; _tailA = new FlxList(); ot.next = _tailA; } _tailA.@object = itr.@object; itr = itr.next; } } if (Parent._headB.@object != null) { itr = Parent._headB; while (itr != null) { if (_tailB.@object != null) { ot = _tailB; _tailB = new FlxList(); ot.next = _tailB; } _tailB.@object = itr.@object; itr = itr.next; } } } else _min = (uint)(width + height) / (2 * divisions); _canSubdivide = (width > _min) || (height > _min); //Set up comparison/sort helpers _nw = null; _ne = null; _se = null; _sw = null; _l = x; _r = x + width; _hw = width / 2; _mx = _l + _hw; _t = y; _b = y + height; _hh = height / 2; _my = _t + _hh; }