Example #1
0
        /// <summary>
        /// Updates the object and returns whether it still belongs to this node
        /// </summary>
        /// <param name="obj">Object to Update in the quad tree</param>
        /// <returns>Whether the object moved</returns>
        private bool UpdateObject(Collidable obj)
        {
            obj.ClearMapArea();
            lock (_locker)
            {
                this.Contents.Remove(obj);
            }

            // Check if object has left the bounds of this node and is not root
            if (!this.Bounds.Contains(obj.GetBounds()) && this.Parent != null)
            {
                // We now belong to a parent
                this.Parent.ReverseInsert(obj);
                return(true);
            }
            else // We're within the same node, but could be in children, must insert
            {
                this.Insert(obj);
                // If we didn't move quad tree nodes
                if (obj.GetMapArea() == this)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Updates the object and returns whether it still belongs to this node
        /// </summary>
        /// <param name="obj">Object to Update in the quad tree</param>
        /// <returns>Whether the object moved</returns>
        private bool UpdateObject(Collidable obj)
        {
            obj.ClearMapArea();
            lock (_locker)
            {
                this.Contents.Remove(obj);
            }

            // Check if object has left the bounds of this node and is not root
            if (!this.Bounds.Contains(obj.GetBounds()) && this.Parent != null)
            {
                // We now belong to a parent
                this.Parent.ReverseInsert(obj);
                return true;
            }
            else // We're within the same node, but could be in children, must insert
            {
                this.Insert(obj);
                // If we didn't move quad tree nodes
                if (obj.GetMapArea() == this)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }