public override Leaf Remove(PhysicalObject obj) { if (this.Contains(this.GetObjPosition(obj))) { 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 MemberPhysicalObject(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent) : base() { this.parent = parent; this.positionRelativeToParent = positionRelativeToParent; this.directionRelativeToParent = directionRelativeToParent; this.parent.Add(this); }
public override Leaf Remove(PhysicalObject unit) { if (unitList.Contains(unit)) { leafDictionary.SetLeaf(unit, null); unitList.Remove(unit); return this; } return null; }
public bool Add(PhysicalObject unit) { if(root.Add(unit)) { return true; } else { //throw new Exception("add failed"); return false; } }
public Leaf GetLeaf(PhysicalObject 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(PhysicalObject 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(PhysicalObject unit) { if (this.Contains(this.GetObjPosition(unit))) { unitList.Add(unit); leafDictionary.SetLeaf(unit, this); if (ObjectCount() > max_count) { this.Expand(); } return true; } return false; }
public void SetLeaf(PhysicalObject 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 bool Add(PhysicalObject obj) { if (this.Contains(this.GetObjPosition(obj))) { 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; }
protected Vector2 GetObjPosition(PhysicalObject obj) { return positionFunc(obj); }
public static Vector2 GetDrawPosition(PhysicalObject obj) { return obj.position.DrawValue; }
public static void ServerInitialize(PhysicalObject obj, Vector2 position, float direction) { obj.position.Value = position; obj.direction.Value = direction; }
public override void Move(PhysicalObject obj) { unitCount--; if (this.Contains(this.GetObjPosition(obj))) { this.Add(obj); } else { if (this.Parent != null) { this.Parent.Move(obj); } else { throw new Exception("move out of bounds"); } } }
public static Vector2 GetPreviousPosition(PhysicalObject obj) { return obj.position.PreviousValue; }
public Boolean CollidesWith(PhysicalObject other) { return this.Collidable.CollidesWith(this.Position, this.Direction, other.Collidable, other.Position, other.Direction); }
public Boolean Contains(PhysicalObject obj) { return this.unitList.Contains(obj); }
public void Move(PhysicalObject obj) { leafDictionary.GetLeaf(obj).Move(obj); }
public Turret(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent, float range) : base(parent, positionRelativeToParent, directionRelativeToParent) { this.range = range; gun = new Gun(this, new Vector2(50f, 0), 0); }
public Gun(PhysicalObject parent, Vector2 positionRelativeToParent, float directionRelativeToParent) : base(parent, positionRelativeToParent, directionRelativeToParent) { }
public abstract bool Add(PhysicalObject unit);
public abstract Leaf Remove(PhysicalObject unit);
public abstract void Move(PhysicalObject obj);
public override void Move(PhysicalObject obj) { if(unitList.Contains(obj)) { if (!this.Contains(this.GetObjPosition(obj))) { 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 static Vector2 GetSimulationPosition(PhysicalObject obj) { return obj.position.SimulationValue; }