コード例 #1
0
        private static void GenerateLeavesByDist(QtNode node, QtLeaf active, float dist, ref List <QtLeaf> leaves)
        {
            if (!Intersects(node.Bound, active.Bound.center, dist))
            {
                return;
            }

            var leaf = node as QtLeaf;

            if (leaf != null)
            {
                if (leaves == null)
                {
                    leaves = new List <QtLeaf>();
                }
                leaves.Add(node as QtLeaf);
            }
            else
            {
                for (int i = 0; i < node.SubNodes.Length; ++i)
                {
                    GenerateLeavesByDist(node.SubNodes[i], active, dist, ref leaves);
                }
            }
        }
コード例 #2
0
        public static void GenerateSwappingLeaves(
            QtNode node, QtLeaf active, List <QtLeaf> holdingLeaves
            , out List <QtLeaf> inLeaves, out List <QtLeaf> outLeaves
            )
        {
            List <QtLeaf> inList = null;

            GenerateLeavesByDist(node, active, QtConfig.CellSwapInDist, ref inList);
            if (inList != null)
            {
                inList.RemoveAll((item) => holdingLeaves.Contains(item));
            }
            inLeaves = inList;

            List <QtLeaf> outList = null;

            GenerateLeavesByDist(node, active, QtConfig.CellSwapOutDist, ref outList);
            if (outList != null)
            {
                List <QtLeaf> outFilteredList = new List <QtLeaf>();
                for (int i = 0; i < holdingLeaves.Count; ++i)
                {
                    QtLeaf leaf = holdingLeaves[i];
                    if (!outList.Contains(leaf))
                    {
                        outFilteredList.Add(leaf);
                    }
                }
                outLeaves = outFilteredList;
            }
            else
            {
                outLeaves = holdingLeaves;
            }
        }
コード例 #3
0
 private void SwapIn(List <QtLeaf> inLeaves)
 {
     for (int i = 0; i < inLeaves.Count; ++i)
     {
         QtLeaf leaf = inLeaves[i];
         leaf.SwapIn();
         _swapInQueue.Add(leaf);
     }
 }
コード例 #4
0
        private bool UpdateFocus(Vector2 focusPoint)
        {
            _focusPoint = focusPoint;

            QtLeaf newLeaf = QtAlgo.FindLeafRecursively(_root, _focusPoint);

            if (newLeaf == _focusLeaf || newLeaf == null)
            {
                return(false);
            }
            _focusLeaf = newLeaf;

            return(true);
        }
コード例 #5
0
        private void ProcessSwapQueues()
        {
            if (_swapInQueue.Count > 0)
            {
                for (int i = 0; i < _swapInQueue.Count; ++i)
                {
                    QtLeaf leaf = _swapInQueue[i];
                    if (leaf.IsSwapInCompleted())
                    {
                        _holdingLeaves.Add(leaf);
                    }
                }

                _swapInQueue.RemoveAll((leaf1) => _holdingLeaves.Contains(leaf1));
            }
            if (_swapOutQueue.Count > 0)
            {
                _swapOutQueue.RemoveAll((leaf1) => leaf1.IsSwapOutCompleted());
            }
        }
コード例 #6
0
 public void Destroy()
 {
     CellSwapDone = null;
     for (int i = 0; i < _holdingLeaves.Count; i++)
     {
         QtLeaf leaf = _holdingLeaves[i];
         leaf.Destroy();
     }
     _holdingLeaves.Clear();
     for (int i = 0; i < _swapInQueue.Count; i++)
     {
         QtLeaf leaf = _swapInQueue[i];
         leaf.Destroy();
     }
     _swapInQueue.Clear();
     for (int i = 0; i < _swapOutQueue.Count; i++)
     {
         QtLeaf leaf = _swapOutQueue[i];
         leaf.Destroy();
     }
     _swapOutQueue.Clear();
 }
コード例 #7
0
        private void SwapOut(List <QtLeaf> outLeaves)
        {
            for (int i = 0; i < outLeaves.Count; ++i)
            {
                QtLeaf leaf = outLeaves[i];
                leaf.SwapOut();
                _holdingLeaves.Remove(leaf);

                List <IQtUserData> affected = leaf.AffectedObjects;
                for (int j = 0; j < affected.Count; j++)
                {
                    IQtUserData item = affected[j];
                    if (!IsHoldingUserData(item))
                    {
                        item.SwapOut();
                    }
                }
                _swapOutQueue.Add(leaf);
                //if (CellSwapOut != null)
                //    CellSwapOut(leaf);
            }
        }
コード例 #8
0
        private void PerformSwapInOut(QtLeaf activeLeaf)
        {
            // 1. the initial in/out leaves generation
            List <QtLeaf> inLeaves;
            List <QtLeaf> outLeaves;

            QtAlgo.GenerateSwappingLeaves(_root, activeLeaf, _holdingLeaves, out inLeaves, out outLeaves);

            // 2. filter out leaves which are already in the ideal states
            if (inLeaves != null)
            {
                inLeaves.RemoveAll((leaf) => { return(_swapInQueue.Contains(leaf)); });
            }

            // 3. append these new items to in/out queue
            if (outLeaves != null && outLeaves.Count > 0)
            {
                SwapOut(outLeaves);
            }
            if (inLeaves != null & inLeaves.Count > 0)
            {
                SwapIn(inLeaves);
            }
        }
コード例 #9
0
        public static QtLeaf FindLeafRecursively(QtNode node, Vector2 point)
        {
            if (!node.Bound.Contains(point))
            {
                return(null);
            }

            var ret = node as QtLeaf;

            if (ret != null)
            {
                return(ret);
            }

            for (int i = 0; i < node.SubNodes.Length; ++i)
            {
                QtLeaf leaf = FindLeafRecursively(node.SubNodes[i], point);
                if (leaf != null)
                {
                    return(leaf);
                }
            }
            throw new System.Exception("FindLeafRecursively : should never reaches here");
        }