Beispiel #1
0
		/** Returns all nodes reachable from the seed node.
		 * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
		 * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
		 * In the editor areas are displayed as different colors of the nodes.
		 * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
		 * but no path from the seed node to that part of the graph.
		 * 
		 * The returned list is sorted by node distance from the seed node
		 * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
		 * Note that the distance measurement does not take heuristics, penalties or tag penalties.
		 * 
		 * Depending on the number of reachable nodes, this function can take quite some time to calculate
		 * so don't use it too often or it might affect the framerate of your game.
		 * 
		 * \param seed The node to start the search from
		 * \param tagMask Optional mask for tags. This is a bitmask.
		 * 
		 * \returns A List<Node> containing all nodes reachable from the seed node.
		 * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
		 */
		public static List<GraphNode> GetReachableNodes (GraphNode seed, int tagMask = -1) {
			var stack = StackPool<GraphNode>.Claim ();
			var list = ListPool<GraphNode>.Claim ();
			
			/** \todo Pool */
			var map = new HashSet<GraphNode>();
			
			GraphNodeDelegate callback;
			if (tagMask == -1) {
				callback = delegate (GraphNode node) {
					if (node.Walkable && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			} else {
				callback = delegate (GraphNode node) {
					if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add (node)) {
						list.Add (node);
						stack.Push (node);
					}
				};
			}
			
			callback (seed);
			
			while (stack.Count > 0) {
				stack.Pop ().GetConnections (callback);
			}
			
			StackPool<GraphNode>.Release (stack);
			
			return list;
		}
Beispiel #2
0
    private void SpawnObject(StackPool pool, float posX, float posY)
    {
        GameObject obj = pool.Pop();

        obj.transform.position = new Vector2(posX, posY);
        obj.SetActive(true);
    }
Beispiel #3
0
        string GetPath(GameObject gameObject)
        {
            Transform         trans = gameObject.transform;
            Stack <Transform> stack = StackPool <Transform> .Get();

            stack.Push(trans);

            while (trans.parent != null)
            {
                trans = trans.parent;
                stack.Push(trans);
            }

            string path = "";

            while (stack.Count > 0)
            {
                var node = stack.Pop();
                path += node.name;

                if (stack.Count > 0)
                {
                    path += "/";
                }
            }

            StackPool <Transform> .Release(stack);

            return(path);
        }
Beispiel #4
0
        private void Release()
        {
            tokenStream.Release();
            StackPool <StyleOperatorNode> .Release(operatorStack);

            StackPool <StyleASTNode> .Release(expressionStack);
        }
Beispiel #5
0
        public static void TreeListChildren(TreeViewItem rootItem, IList <TreeViewItem> row)
        {
            row.Clear();
            Stack <TreeViewItem> stack = StackPool <TreeViewItem> .Get();

            for (int i = rootItem.children.Count - 1; i >= 0; i--)
            {
                stack.Push(rootItem.children[i]);
            }

            while (stack.Count > 0)
            {
                var item = stack.Pop();
                row.Add(item);

                if (item.hasChildren && item.children[0] != null)
                {
                    for (int i = item.children.Count - 1; i >= 0; i--)
                    {
                        stack.Push(item.children[i]);
                    }
                }
            }

            StackPool <TreeViewItem> .Release(stack);
        }
Beispiel #6
0
        private ASTNode ParseInternal(string input)
        {
            tokenStream     = new TokenStream(ExpressionTokenizer.Tokenize(input, StructList <ExpressionToken> .Get()));
            expressionStack = expressionStack ?? StackPool <ASTNode> .Get();

            operatorStack = operatorStack ?? StackPool <OperatorNode> .Get();

            if (tokenStream.Current == ExpressionTokenType.ExpressionOpen)
            {
                tokenStream.Advance();
            }

            if (!tokenStream.HasMoreTokens)
            {
                throw new ParseException("Failed trying to parse empty expression");
            }

            if (tokenStream.Last == ExpressionTokenType.ExpressionClose)
            {
                tokenStream.Chop();
            }

            ASTNode retn = ParseLoop();

            Release();

            return(retn);
        }
Beispiel #7
0
        public ExpressionParser(TokenStream stream)
        {
            tokenStream   = stream;
            operatorStack = StackPool <OperatorNode> .Get();

            expressionStack = StackPool <ASTNode> .Get();
        }
Beispiel #8
0
        public override QualifiedElement GetQualifiedName()
        {
            var stack = StackPool.Get();

            try
            {
                foreach (var elem in AncestorsAndSelf())
                {
                    elem.AggregateIdentities(stack);
                }
                var ret = new QualifiedElement();

                while (stack.Count != 0)
                {
                    var(scope, category, name) = stack.Pop();
                    _ = new IdentityElement(ret, scope, category, name);
                }

                return(ret);
            }
            finally
            {
                Debug.Assert(stack.Count == 0);
                StackPool.Return(stack);
            }
        }
Beispiel #9
0
        void Sort <T>(T rootItem, Comparison <TreeViewItem> func, Comparison <int> intfunc) where T : TreeViewItem
        {
            rootItem.children.Sort(func);
            Stack <TreeViewItem> itemstack = StackPool <TreeViewItem> .Get();

            foreach (var child in rootItem.children)
            {
                itemstack.Push(child);
            }

            while (itemstack.Count > 0)
            {
                var item = itemstack.Pop();
                if (_treeView.IsExpanded(item.id) && item.children.Count > 0 && item.children[0] != null)
                {
                    foreach (var child in item.children)
                    {
                        itemstack.Push(child);
                    }
                    item.children.Sort(func);
                }
            }

            StackPool <TreeViewItem> .Release(itemstack);

            _model.Sort(intfunc);
        }
Beispiel #10
0
 public TokenStream(StructList <ExpressionToken> tokens)
 {
     this.ptr            = 0;
     this.tokens         = tokens;
     this.lastTokenIndex = tokens.Count;
     this.stack          = StackPool <int> .Get();
 }
Beispiel #11
0
        private void Do(int C, int P, int M, bool noisy, bool useRAII, Func <Stack <int>, int> test)
        {
            var pool = StackPool <int> .Create(C);

            void testCore(Stack <int> stack)
            {
                var len = stack.Count;

                Assert.AreEqual(0, len);

                var L = test(stack);

                len = stack.Count;
                Assert.AreEqual(L, len);
            }

            if (useRAII)
            {
                Run(() => pool.New(), o => o.Stack, o => o.Dispose(), testCore, P, M, noisy);
            }
            else
            {
                Run(() => pool.Allocate(), o => o, o => pool.Free(o), testCore, P, M, noisy);
            }
        }
Beispiel #12
0
        public override QualifiedElement GetQualifiedName()
        {
            var accum = StackPool.Get();

            try
            {
                foreach (var identity in From.Identities.Take(Order).Cast <IdentityElement>().Reverse())
                {
                    identity.AggregateIdentities(accum);
                }

                var ret = new QualifiedElement();

                while (accum.Count != 0)
                {
                    var(scope, category, name) = accum.Pop();
                    _ = new IdentityElement(ret, scope, category, name);
                }

                return(ret);
            }
            finally
            {
                Debug.Assert(accum.Count == 0);
                StackPool.Return(accum);
            }
        }
        IList <int> GetParentsBelowStackBased(int id)
        {
            Stack <int> stack = StackPool <int> .Get();

            stack.Push(id);

            var parentsBelow = new List <int>();

            while (stack.Count > 0)
            {
                int current = stack.Pop();
                if (HasChildren(current))
                {
                    parentsBelow.Add(current);
                    var children = GetChildren(current);
                    foreach (var val in children)
                    {
                        stack.Push(val.Id);
                    }
                    ListPool <T> .Release(children);
                }
            }
            StackPool <int> .Release(stack);

            return(parentsBelow);
        }
 void Awake()
 {
     projectilePool = GameObject.Find("FireballPool").GetComponent<StackPool>();
     animator = GetComponent<Animator>();
     mainCam = GameObject.Find("Main Camera").GetComponent<Camera>();
     wanderScript = GetComponent<Wander>();
     rb2d = GetComponent<Rigidbody2D>();
 }
Beispiel #15
0
        public void Release()
        {
            StackPool <int> .Release(stack);

            StructList <ExpressionToken> .Release(ref tokens);

            stack = null;
        }
Beispiel #16
0
        public void Release()
        {
            StackPool <int> .Release(stack);

            ListPool <StyleToken> .Release(ref tokens);

            stack  = null;
            tokens = null;
        }
            public static void ApplyActionLeafFirst(GraphData graph, Action <AbstractMaterialNode> action)
            {
                var temporaryMarks = PooledHashSet <string> .Get();

                var permanentMarks = PooledHashSet <string> .Get();

                var slots = ListPool <MaterialSlot> .Get();

                // Make sure we process a node's children before the node itself.
                var stack = StackPool <AbstractMaterialNode> .Get();

                foreach (var node in graph.GetNodes <AbstractMaterialNode>())
                {
                    stack.Push(node);
                }
                while (stack.Count > 0)
                {
                    var node = stack.Pop();
                    if (permanentMarks.Contains(node.objectId))
                    {
                        continue;
                    }

                    if (temporaryMarks.Contains(node.objectId))
                    {
                        action.Invoke(node);
                        permanentMarks.Add(node.objectId);
                    }
                    else
                    {
                        temporaryMarks.Add(node.objectId);
                        stack.Push(node);
                        node.GetInputSlots(slots);
                        foreach (var inputSlot in slots)
                        {
                            var nodeEdges = graph.GetEdges(inputSlot.slotReference);
                            foreach (var edge in nodeEdges)
                            {
                                var fromSocketRef = edge.outputSlot;
                                var childNode     = fromSocketRef.node;
                                if (childNode != null)
                                {
                                    stack.Push(childNode);
                                }
                            }
                        }
                        slots.Clear();
                    }
                }

                StackPool <AbstractMaterialNode> .Release(stack);

                ListPool <MaterialSlot> .Release(slots);

                temporaryMarks.Dispose();
                permanentMarks.Dispose();
            }
Beispiel #18
0
 void Awake()
 {
     poolDictionary = new Dictionary <string, StackPool>();
     for (int x = 0; x < pools.Count; x++)
     {
         StackPool pool = pools[x];
         poolDictionary.Add(pool.PooledObject.tag, pool);
     }
 }
Beispiel #19
0
 void OnTriggerEnter2D(Collider2D other)
 {
     if (1 << other.gameObject.layer == obstacleLayerMask.value)
     {
         StackPool pool = poolDictionary[other.gameObject.tag];
         other.gameObject.SetActive(false);
         pool.Push(other.gameObject);
     }
 }
Beispiel #20
0
 void Awake()
 {
     globPool = GameObject.Find("CoffeeProjectilePool").GetComponent <StackPool>();
     anim     = GetComponent <Animator>();
     if (target == null)
     {
         target = GameObject.FindGameObjectWithTag("Player");
     }
 }
Beispiel #21
0
        public void Release(bool releaseTokenStream = true)
        {
            if (releaseTokenStream)
            {
                tokenStream.Release();
            }

            StackPool <OperatorNode> .Release(operatorStack);

            StackPool <ASTNode> .Release(expressionStack);
        }
Beispiel #22
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            StackPool <Person> pStackPool = new StackPool <Person>();

            pStackPool.Store(new Person());
            pStackPool.Store(new Person());

            Person p1 = pStackPool.Fetch();
            Person p2 = pStackPool.Fetch();

            this.TextBox1.Text += string.Format($"\r\nThe Stack class implements a Last in First Out data structure. Push() and Pop()");
        }
Beispiel #23
0
        /// <summary>
        /// Returns all nodes reachable from the seed node.
        /// This function performs a DFS (depth-first-search) or flood fill of the graph and returns all nodes which can be reached from
        /// the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
        /// In the editor areas are displayed as different colors of the nodes.
        /// The only case where it will not be so is when there is a one way path from some part of the area to the seed node
        /// but no path from the seed node to that part of the graph.
        ///
        /// The returned list is not sorted in any particular way.
        ///
        /// Depending on the number of reachable nodes, this function can take quite some time to calculate
        /// so don't use it too often or it might affect the framerate of your game.
        ///
        /// See: bitmasks (view in online documentation for working links).
        ///
        /// Returns: A List<Node> containing all nodes reachable from the seed node.
        /// For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool.
        /// </summary>
        /// <param name="seed">The node to start the search from.</param>
        /// <param name="tagMask">Optional mask for tags. This is a bitmask.</param>
        /// <param name="filter">Optional filter for which nodes to search. You can combine this with tagMask = -1 to make the filter determine everything.
        ///      Only walkable nodes are searched regardless of the filter. If the filter function returns false the node will be treated as unwalkable.</param>
        public static List <GraphNode> GetReachableNodes(GraphNode seed, int tagMask          = -1,
                                                         System.Func <GraphNode, bool> filter = null)
        {
            var dfsStack = StackPool <GraphNode> .Claim();

            var reachable = ListPool <GraphNode> .Claim();

            /// <summary>TODO: Pool</summary>
            var map = new HashSet <GraphNode>();

            System.Action <GraphNode> callback;
            // Check if we can use the fast path
            if (tagMask == -1 && filter == null)
            {
                callback = (GraphNode node) =>
                {
                    if (node.Walkable && map.Add(node))
                    {
                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                }
            }
            ;
            else
            {
                callback = (GraphNode node) =>
                {
                    if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add(node))
                    {
                        if (filter != null && !filter(node))
                        {
                            return;
                        }

                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                }
            };

            callback(seed);

            while (dfsStack.Count > 0)
            {
                dfsStack.Pop().GetConnections(callback);
            }

            StackPool <GraphNode> .Release(dfsStack);

            return(reachable);
        }
Beispiel #24
0
        private StyleParser(StyleTokenStream stream)
        {
            tokenStream = stream;
            nodes       = LightList <StyleASTNode> .Get();

            operatorStack = StackPool <StyleOperatorNode> .Get();

            expressionStack = StackPool <StyleASTNode> .Get();

            groupExpressionStack = StackPool <AttributeNodeContainer> .Get();

            groupOperatorStack = StackPool <StyleOperatorType> .Get();
        }
        void TryAddChildren(AssetTreeItem <T> rootitem, List <TreeViewItem> list, AssetTreeModel <T> model, int depth)
        {
            if (model.HasChildren(rootitem.DataId))
            {
                List <T> children = model.GetChildren(rootitem.DataId);
                Stack <AssetTreeItem <T> > stack = StackPool <AssetTreeItem <T> > .Get();

                for (int i = children.Count - 1; i >= 0; i--)
                {
                    var child = children[i];

                    //create item
                    var childItem = CreateItem(ref child, depth + 1);
                    stack.Push(childItem);
                }

                ListPool <T> .Release(children);

                while (stack.Count > 0)
                {
                    var stackChild = stack.Pop();
                    list.Add(stackChild);
                    if (model.HasChildren(stackChild.DataId))
                    {
                        if (IsExpanded(stackChild.id))
                        {
                            children = model.GetChildren(stackChild.DataId);
                            //
                            //stackChild.children = new List<TreeViewItem>();
                            for (int i = children.Count - 1; i >= 0; i--)
                            {
                                var child = children[i];

                                //create item
                                var childItem = CreateItem(ref child, stackChild.depth + 1);
                                stack.Push(childItem);
                                //stackChild.children.Add(childItem);
                            }

                            ListPool <T> .Release(children);
                        }
                        else
                        {
                            stackChild.children = CreateChildListForCollapsedParent();
                        }
                    }
                }

                StackPool <AssetTreeItem <T> > .Release(stack);
            }
        }
Beispiel #26
0
        /** Returns all nodes reachable from the seed node.
         * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
         * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
         * In the editor areas are displayed as different colors of the nodes.
         * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
         * but no path from the seed node to that part of the graph.
         *
         * The returned list is sorted by node distance from the seed node
         * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
         * Note that the distance measurement does not take heuristics, penalties or tag penalties.
         *
         * Depending on the number of reachable nodes, this function can take quite some time to calculate
         * so don't use it too often or it might affect the framerate of your game.
         *
         * \param seed The node to start the search from
         * \param tagMask Optional mask for tags. This is a bitmask.
         *
         * \returns A List<Node> containing all nodes reachable from the seed node.
         * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
         */
        public static List <GraphNode> GetReachableNodes(GraphNode seed, int tagMask = -1)
        {
#if ASTAR_PROFILE
            System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
            watch.Start();
#endif
            Stack <GraphNode> stack = StackPool <GraphNode> .Claim();

            List <GraphNode> list = ListPool <GraphNode> .Claim();

            /** \todo Pool */
            var map = new HashSet <GraphNode>();

            GraphNodeDelegate callback;
            if (tagMask == -1)
            {
                callback = delegate(GraphNode node) {
                    if (node.Walkable && map.Add(node))
                    {
                        list.Add(node);
                        stack.Push(node);
                    }
                };
            }
            else
            {
                callback = delegate(GraphNode node) {
                    if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add(node))
                    {
                        list.Add(node);
                        stack.Push(node);
                    }
                };
            }

            callback(seed);

            while (stack.Count > 0)
            {
                stack.Pop().GetConnections(callback);
            }

            StackPool <GraphNode> .Release(stack);

#if ASTAR_PROFILE
            watch.Stop();
            Debug.Log((1000 * watch.Elapsed.TotalSeconds).ToString("0.0 ms"));
#endif
            return(list);
        }
Beispiel #27
0
        private void Abort(string info = null)
        {
            string expression = tokenStream.PrintTokens();

            tokenStream.Release();
            StackPool <OperatorNode> .Release(operatorStack);

            StackPool <ASTNode> .Release(expressionStack);

            if (info != null)
            {
                throw new ParseException($"Failed to parse expression: {expression}. {info}");
            }
            else
            {
                throw new ParseException($"Failed to parse expression: {expression}");
            }
        }
Beispiel #28
0
        private static void PooledStack_Simple_Impl(StackPool <string> pool)
        {
            for (var i = 0; i < 100; i++)
            {
                using var obj = i % 2 == 0 ? pool.New() : PooledStack <string> .New(pool);

                var stack = obj.Stack;

                Assert.AreEqual(0, stack.Count);

                stack.Push("qux");
                stack.Push("foo");
                stack.Push("bar");
                stack.Push("baz");

                Assert.IsTrue(exp.SequenceEqual(stack));
            }
        }
        // Token: 0x0600279F RID: 10143 RVA: 0x001B30BC File Offset: 0x001B12BC
        public static List <GraphNode> GetReachableNodes(GraphNode seed, int tagMask = -1, Func <GraphNode, bool> filter = null)
        {
            Stack <GraphNode> dfsStack = StackPool <GraphNode> .Claim();

            List <GraphNode> reachable = ListPool <GraphNode> .Claim();

            HashSet <GraphNode> map = new HashSet <GraphNode>();
            Action <GraphNode>  action;

            if (tagMask == -1 && filter == null)
            {
                action = delegate(GraphNode node)
                {
                    if (node.Walkable && map.Add(node))
                    {
                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                };
            }
            else
            {
                action = delegate(GraphNode node)
                {
                    if (node.Walkable && (tagMask >> (int)node.Tag & 1) != 0 && map.Add(node))
                    {
                        if (filter != null && !filter(node))
                        {
                            return;
                        }
                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                };
            }
            action(seed);
            while (dfsStack.Count > 0)
            {
                dfsStack.Pop().GetConnections(action);
            }
            StackPool <GraphNode> .Release(dfsStack);

            return(reachable);
        }
Beispiel #30
0
        /** Returns all nodes reachable from the seed node.
         * This function performs a BFS (breadth-first-search) or flood fill of the graph and returns all nodes which can be reached from
         * the seed node. In almost all cases this will be identical to returning all nodes which have the same area as the seed node.
         * In the editor areas are displayed as different colors of the nodes.
         * The only case where it will not be so is when there is a one way path from some part of the area to the seed node
         * but no path from the seed node to that part of the graph.
         *
         * The returned list is sorted by node distance from the seed node
         * i.e distance is measured in the number of nodes the shortest path from \a seed to that node would pass through.
         * Note that the distance measurement does not take heuristics, penalties or tag penalties.
         *
         * Depending on the number of reachable nodes, this function can take quite some time to calculate
         * so don't use it too often or it might affect the framerate of your game.
         *
         * \param seed The node to start the search from
         * \param tagMask Optional mask for tags. This is a bitmask.
         *
         * \returns A List<Node> containing all nodes reachable from the seed node.
         * For better memory management the returned list should be pooled, see Pathfinding.Util.ListPool
         */
        public static List <GraphNode> GetReachableNodes(GraphNode seed, int tagMask = -1)
        {
            Stack <GraphNode> dfsStack = StackPool <GraphNode> .Claim();

            List <GraphNode> reachable = ListPool <GraphNode> .Claim();

            /** \todo Pool */
            var map = new HashSet <GraphNode>();

            System.Action <GraphNode> callback;
            if (tagMask == -1)
            {
                callback = (GraphNode node) => {
                    if (node.Walkable && map.Add(node))
                    {
                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                };
            }
            else
            {
                callback = (GraphNode node) => {
                    if (node.Walkable && ((tagMask >> (int)node.Tag) & 0x1) != 0 && map.Add(node))
                    {
                        reachable.Add(node);
                        dfsStack.Push(node);
                    }
                };
            }

            callback(seed);

            while (dfsStack.Count > 0)
            {
                dfsStack.Pop().GetConnections(callback);
            }

            StackPool <GraphNode> .Release(dfsStack);

            return(reachable);
        }
Beispiel #31
0
        public static List <GraphNode> GetReachableNodes(GraphNode seed, int tagMask = -1)
        {
            Stack <GraphNode> stack = StackPool <GraphNode> .Claim();

            List <GraphNode> list = ListPool <GraphNode> .Claim();

            HashSet <GraphNode> map = new HashSet <GraphNode>();
            Action <GraphNode>  action;

            if (tagMask == -1)
            {
                action = delegate(GraphNode node)
                {
                    if (node.Walkable && map.Add(node))
                    {
                        list.Add(node);
                        stack.Push(node);
                    }
                };
            }
            else
            {
                action = delegate(GraphNode node)
                {
                    if (node.Walkable && (tagMask >> (int)node.Tag & 1) != 0 && map.Add(node))
                    {
                        list.Add(node);
                        stack.Push(node);
                    }
                };
            }
            action(seed);
            while (stack.Count > 0)
            {
                stack.Pop().GetConnections(action);
            }
            StackPool <GraphNode> .Release(stack);

            return(list);
        }
 void Start()
 {
     nextFireTime = Time.time + .5f;
     projectilePool = GameObject.Find(projectilePoolName).GetComponent<StackPool>();
 }
Beispiel #33
0
 private void SpawnObject(StackPool pool, float posX, float posY)
 {
     GameObject obj = pool.Pop();
     obj.transform.position = new Vector2(posX, posY);
     obj.SetActive(true);
 }
 void Awake()
 {
     stackPool = GameObject.Find(poolName).GetComponent<StackPool>();
 }