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); } }
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; }
public override Leaf Remove(CompositePhysicalObject unit) { if (unitList.Contains(unit)) { leafDictionary.SetLeaf(unit, null); unitList.Remove(unit); return(this); } return(null); }
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"); }
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"); } }
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); }
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); } }
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); }
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"); } }
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; } }
public override Leaf Remove(CompositePhysicalObject unit) { if (unitList.Contains(unit)) { unitCount--; unitList.Remove(unit); unit.SetLeaf(null); return this; } return null; }
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"); } }
public void Move(CompositePhysicalObject obj) { leafDictionary.GetLeaf(obj).Move(obj); }
public abstract bool Add(CompositePhysicalObject unit);
public abstract void Move(CompositePhysicalObject obj);
public abstract Leaf Remove(CompositePhysicalObject unit);
public bool Add(CompositePhysicalObject unit) { return root.Add(unit); }