Exemple #1
0
        private IEnumerable <Agent> InnerQuery(string quadId, Func <Agent, bool> condition = null, int anscestorLevel = 0)
        {
            var startAncestorPath = quadId.Substring(0, quadId.Length - anscestorLevel);
            var startNode         = GetNodeByPrefix(startAncestorPath);

            var queue = new Queue <QuadTreeNode <Agent> >();

            queue.Enqueue(startNode);

            foreach (var surroundingNodeId in QuaternaryUtils.GetSurroundingNodes(startAncestorPath))
            {
                try
                {
                    var surroundingNode = GetNodeByPrefix(surroundingNodeId);
                    //Debug.LogWarning(surroundingNodeId);
                    queue.Enqueue(surroundingNode);
                }
                catch (Exception e)
                {
                    continue;
                }
            }

            while (queue.Count > 0)
            {
                var node = queue.Dequeue();

                foreach (var content in node.Contents)
                {
                    if (condition != null)
                    {
                        if (condition(content))
                        {
                            yield return(content);
                        }
                    }
                    else
                    {
                        //Debug.Log((content as CharacterItem).CharacterId + " " + node);
                        yield return(content);
                    }
                }

                if (node.IsLeaf)
                {
                    continue;
                }
                foreach (var subNode in node.Nodes)
                {
                    queue.Enqueue(subNode);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Queries the node by a direction and a union tyoe
        /// </summary>
        /// <param name="quadId">queried quad path</param>
        /// <param name="directionType">which direction to query</param>
        /// <returns></returns>
        public IEnumerable <Agent> QueryOuterByDirection(string quadId, DirectionType directionType, Func <Agent, bool> condition = null)
        {
            var queue = new Queue <QuadTreeNode <Agent> >();

            foreach (var outerPath in QuaternaryUtils.GetOuterNodePathsForPath(quadId, directionType))
            {
                try
                {
                    queue.Enqueue(GetNodeByPrefix(outerPath));
                }
                catch
                {
                    continue;
                }
            }

            while (queue.Count > 0)
            {
                var node = queue.Dequeue();

                foreach (var content in node.Contents)
                {
                    //Debug.Log((content as CharacterItem).CharacterId + " " + node);
                    if (condition == null)
                    {
                        yield return(content);
                    }
                    else if (condition(content))
                    {
                        yield return(content);
                    }
                }

                if (node.IsLeaf)
                {
                    continue;
                }
                foreach (var subNode in node.Nodes)
                {
                    queue.Enqueue(subNode);
                }
            }
        }