public override Leaf Remove(CompositePhysicalObject obj)
        {
            if (this.Contains(obj.Position))
            {
                if (children.Count != 4)
                {
                    throw new Exception("child");
                }

                Leaf removedFrom = null;
                foreach (Node child in children)
                {
                    removedFrom = child.Remove(obj);
                    if (removedFrom != null)
                    {
                        break;
                    }
                }

                if (removedFrom != null)
                {
                    unitCount--;
                    return(removedFrom);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
示例#2
0
 public static void ServerInitialize(MovingGameObject obj, Vector2 position, Vector2 velocity, float direction, float angularVelocity, float targetAngle)
 {
     CompositePhysicalObject.ServerInitialize(obj, position, direction);
     obj.velocity.Value     = velocity;
     obj.angularSpeed.Value = angularVelocity;
     obj.targetAngle.Value  = targetAngle;
 }
示例#3
0
 public override Leaf Remove(CompositePhysicalObject unit)
 {
     if (unitList.Contains(unit))
     {
         leafDictionary.SetLeaf(unit, null);
         unitList.Remove(unit);
         return(this);
     }
     return(null);
 }
示例#4
0
 public bool Add(CompositePhysicalObject unit)
 {
     if (root.Add(unit))
     {
         return(true);
     }
     else
     {
         //throw new Exception("add failed");
         return(false);
     }
 }
        public Leaf GetLeaf(CompositePhysicalObject obj)
        {
            //this.Invariant();
            if (leafDictionary.ContainsKey(obj))
            {
                if (!leafDictionary[obj].Contains(obj))
                {
                    throw new Exception("Incorrect leaf");
                }

                return(leafDictionary[obj]);
            }
            throw new Exception("object does not have leaf");
        }
示例#6
0
 public bool Remove(CompositePhysicalObject unit)
 {
     Leaf removeFrom = root.Remove(unit);
     if (removeFrom != null)
     {
         unit.SetLeaf(null);
         removeFrom.Collapse();
         return true;
     }
     else
     {
         throw new Exception("No object to remove");
     }
 }
示例#7
0
        public override bool Add(CompositePhysicalObject unit)
        {
            if (this.Contains(unit.Position))
            {
                unitList.Add(unit);
                leafDictionary.SetLeaf(unit, this);

                if (ObjectCount() > max_count)
                {
                    this.Expand();
                }
                return(true);
            }
            return(false);
        }
示例#8
0
        public bool Remove(CompositePhysicalObject unit)
        {
            Leaf removeFrom = root.Remove(unit);

            if (removeFrom != null)
            {
                removeFrom.Collapse();
                return(true);
            }
            else
            {
                //throw new Exception("No object to remove");
                return(false);
            }
        }
示例#9
0
        public override bool Add(CompositePhysicalObject unit)
        {
            if (this.Contains(unit.Position))
            {
                unitCount++;
                unitList.Add(unit);
                unit.SetLeaf(this);

                if (unitList.Count > max_count)
                {
                    this.Expand();
                }
                return true;
            }
            return false;
        }
        public override bool Add(CompositePhysicalObject obj)
        {
            if (this.Contains(obj.Position))
            {

                int adds = 0;
                bool returnNode = nw.Add(obj);
                if (returnNode)
                {
                    adds++;
                }

                returnNode = ne.Add(obj);
                if (returnNode)
                {
                    adds++;
                }

                returnNode = sw.Add(obj);
                if (returnNode)
                {
                    adds++;
                }

                returnNode = se.Add(obj);
                if (returnNode)
                {
                    adds++;
                }
                if (adds == 1)
                {
                    unitCount++;
                    return true;
                }
                else
                {
                    throw new Exception("failed adds to QuadTree");
                }
            }
            if (Parent == null)
            {
                throw new MoveOutOfBound();
            }

            return false;
        }
 public void SetLeaf(CompositePhysicalObject obj, Leaf leaf)
 {
     //this.Invariant();
     if (leaf != null)
     {
         if (!leafDictionary.ContainsKey(obj))
         {
             leafDictionary.Add(obj, leaf);
         }
         leafDictionary[obj] = leaf;
     }
     else
     {
         leafDictionary.Remove(obj);
     }
     //this.Invariant();
 }
 public override void Move(CompositePhysicalObject obj)
 {
     unitCount--;
     if (this.Contains(obj.Position))
     {
         this.Add(obj);
     }
     else
     {
         if (this.Parent != null)
         {
             this.Parent.Move(obj);
         }
         else
         {
             throw new Exception("move out of bounds");
         }
     }
 }
        public override bool Add(CompositePhysicalObject obj)
        {
            if (this.Contains(obj.Position))
            {
                foreach (Node child in new List <Node>(children))
                {
                    if (child.Add(obj))
                    {
                        unitCount++;
                        return(true);
                    }
                }
                throw new Exception("failed adds to QuadTree");
            }
            if (Parent == null)
            {
                //throw new Exception("move out of bounds");
            }

            return(false);
        }
示例#14
0
 public override void Move(CompositePhysicalObject obj)
 {
     if (unitList.Contains(obj))
     {
         if (!this.Contains(obj.Position))
         {
             this.Remove(obj);
             this.Parent.Move(obj);
             if (unitList.Contains(obj))
             {
                 throw new Exception("Move failed");
             }
             if (!this.Parent.IsChild(this))
             {
                 throw new Exception("incorrect child/parent");
             }
             this.Parent.Collapse();
         }
     }
     else
     {
         throw new Exception("No such object");
     }
 }
示例#15
0
 public Boolean Contains(CompositePhysicalObject obj)
 {
     return(this.unitList.Contains(obj));
 }
 public override void Move(CompositePhysicalObject obj)
 {
     unitCount--;
     if (this.Contains(obj.Position))
     {
         this.Add(obj);
     }
     else
     {
         if (this.Parent != null)
         {
             this.Parent.Move(obj);
         }
         else
         {
             throw new MoveOutOfBound();
         }
     }
 }
        public override Leaf Remove(CompositePhysicalObject obj)
        {
            if (this.Contains(obj.Position))
            {
                Leaf removedFrom = nw.Remove(obj);

                if (removedFrom == null)
                {
                    removedFrom = ne.Remove(obj);
                }

                if (removedFrom == null)
                {
                    removedFrom = se.Remove(obj);
                }

                if (removedFrom == null)
                {
                    removedFrom = sw.Remove(obj);
                }

                if (removedFrom != null)
                {
                    unitCount--;
                    //Collapse();

                    //if (removedFrom.ObjectCount() < Node.max_count && removedFrom is InternalNode)
                    //{
                        //throw new Exception("Node did not collapse");
                    //}

                    //this.Inveriant();
                    return removedFrom;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
示例#18
0
 public override Leaf Remove(CompositePhysicalObject unit)
 {
     if (unitList.Contains(unit))
     {
         unitCount--;
         unitList.Remove(unit);
         unit.SetLeaf(null);
         return this;
     }
     return null;
 }
示例#19
0
 public override void Move(CompositePhysicalObject obj)
 {
     if(unitList.Contains(obj))
     {
         if (!this.Contains(obj.Position))
         {
             unitCount--;
             unitList.Remove(obj);
             this.Parent.Move(obj);
             if (unitList.Contains(obj))
             {
                 throw new Exception("Move failed");
             }
             this.Parent.Collapse();
         }
     }
     else
     {
         throw new Exception("No such object");
     }
 }
示例#20
0
 public void Move(CompositePhysicalObject obj)
 {
     leafDictionary.GetLeaf(obj).Move(obj);
 }
示例#21
0
 public abstract bool Add(CompositePhysicalObject unit);
示例#22
0
 public abstract void Move(CompositePhysicalObject obj);
示例#23
0
 public abstract Leaf Remove(CompositePhysicalObject unit);
示例#24
0
 public abstract bool Add(CompositePhysicalObject unit);
示例#25
0
 public abstract Leaf Remove(CompositePhysicalObject unit);
示例#26
0
 public abstract void Move(CompositePhysicalObject obj);
示例#27
0
 public bool Add(CompositePhysicalObject unit)
 {
     return root.Add(unit);
 }