Example #1
0
 public void ReverseInsert(Collidable obj)
 {
     // Check if object has left the bounds of this node then go up another level
     if (!this.Bounds.Contains(obj.GetBounds()))
     {
         // NOTE: If you get an error here chances are an object is out of bounds. aka off the quad tree map.
         // In order to avoid an additional check we assume that the obj is smaller than
         // the root node.
         if (this.Parent != null)
         {
             this.Parent.ReverseInsert(obj);
         }
         else
         {
             obj.SetMapArea(this);
             lock (_locker)
             {
                 this.Contents.Add(obj);
             }
         }
     }
     else
     {
         obj.SetMapArea(this);
         lock (_locker)
         {
             this.Contents.Add(obj);
         }
     }
 }
Example #2
0
        public void Insert(Collidable obj)
        {
            foreach (QuadTreeNode node in Children)
            {
                if (node.Bounds.Contains(obj.GetBounds()))
                {
                    node.Insert(obj);
                    return;
                }
            }

            // When we get here we're then "this" is currently the largest node to fit our object OR
            // We're at a leaf node caused by the smallest possible partition width/height.
            lock (_locker)
            {
                Contents.Add(obj);
            }
            obj.SetMapArea(this);
        }
Example #3
0
        public void Insert(Collidable obj)
        {
            foreach (QuadTreeNode node in Children)
            {
                if (node.Bounds.Contains(obj.GetBounds()))
                {
                    node.Insert(obj);
                    return;
                }
            }

            // When we get here we're then "this" is currently the largest node to fit our object OR
            // We're at a leaf node caused by the smallest possible partition width/height.
            lock (_locker)
            {
                Contents.Add(obj);
            }
            obj.SetMapArea(this);
        }
Example #4
0
 public void ReverseInsert(Collidable obj)
 {
     // Check if object has left the bounds of this node then go up another level
     if (!this.Bounds.Contains(obj.GetBounds()))
     {
         // NOTE: If you get an error here chances are an object is out of bounds. aka off the quad tree map.
         // In order to avoid an additional check we assume that the obj is smaller than
         // the root node.
         if (this.Parent != null)
         {
             this.Parent.ReverseInsert(obj);
         }
         else
         {
             obj.SetMapArea(this);
             lock (_locker)
             {
                 this.Contents.Add(obj);
             }
         }
     }
     else
     {
         obj.SetMapArea(this);
         lock (_locker)
         {
             this.Contents.Add(obj);
         }
     }
 }