Пример #1
0
 /// <summary>
 /// Removes a unit from quadnode management.
 /// </summary>
 /// <param name="unit"></param>
 public void UnregisterUnit(IQuadNodeReferring unit)
 {
     if (unit.GetQuadNode(mType) != null) unit.GetQuadNode(mType).RemoveUnit(unit);
 }
Пример #2
0
 /// <summary>
 /// Called by the Position-setter in GameObject.cs
 /// If the given unit has moved, it may be that it now belongs to
 /// another quadNode. This method checks that and changes stuff if necessary.
 /// </summary>
 /// <param name="unit"></param>
 public void UpdateUnitPosition(IQuadNodeReferring unit)
 {
     QuadNode oldNode = unit.GetQuadNode(mType);
     if (!oldNode.mArea.Contains(unit.Position))
     {
         oldNode.RemoveUnit(unit);
         Debug.Assert(unit.GetQuadNode(mType) == null);
         Root.ReArrangeUnit(unit);
     }
 }
Пример #3
0
        /// <summary>
        /// Note: Does not delete the unit from source node!
        /// Will sink a unit down into a leaf.
        /// </summary>
        /// <param name="unit"></param>
        public void ReArrangeUnit(IQuadNodeReferring unit)
        {
            if (IsLeaf())
            {
                mUnits.Add(unit);
                Debug.Assert(unit.GetQuadNode(mType) == null);
                unit.SetQuadNode(mType, this);
                if (mUnits.Count > 0 && !mManager.FilledLeaves.Contains(this))
                {
                    mManager.FilledLeaves.Add(this);
                }
                if (CanBeDivided()) Subdivide();

            }
            else
            {
                // No leaf
                if (unit.Position.X < mArea.mX + mArea.mWidth / 2)
                {
                    if (unit.Position.Y < mArea.mY + mArea.mHeight / 2)
                    {
                        mChild[Orientation.LeftUpper].ReArrangeUnit(unit);
                    }
                    else
                    {
                        mChild[Orientation.LeftLower].ReArrangeUnit(unit);
                    }
                }
                else
                {
                    if (unit.Position.Y < mArea.mY + mArea.mHeight / 2)
                    {
                        mChild[Orientation.RightUpper].ReArrangeUnit(unit);
                    }
                    else
                    {
                        mChild[Orientation.RightLower].ReArrangeUnit(unit);
                    }
                }
            }
        }