Ejemplo n.º 1
0
            public bool MoveNext()
            {
repeat:
                if (start)
                {
                    start = false;
                    return(true);
                }
                var t = stack.Peek();

                if (t.i > 3)
                {
                    if (stack.Count > 1)
                    {
                        stack.Pop();
                        goto repeat;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    if (t.child.isLeaf)
                    {
                        if (stack.Count > 1)
                        {
                            stack.Pop();
                            goto repeat;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        var size     = t.size / 2;
                        var posIndex = Quadtree.IndexToSigns(t.i);
                        var origin   = t.origin + (new Vector2(posIndex.x * size, posIndex.y * size));

                        stack.Push(new Tracker(t.child.children[t.i], origin, size));
                        t.i++;
                        return(true);
                    }
                }
            }
Ejemplo n.º 2
0
        public void OnValidate()
        {
            tree = new Quadtree <Data>();            // 0

            int i = 0;
            var e = tree.GetEnumerator();

            Random.InitState((int)(splitChance * 1000));
            while (e.MoveNext() && i++ < 1_000_000)
            {
                if (maxDebth > e.depth && (Random.value < splitChance || e.depth == 0))
                {
                    e.Current.Split();
                }
            }
        }
Ejemplo n.º 3
0
            public bool MoveDown(int childIndex)
            {
                var t = stack.Peek();

                if (t.child.isLeaf)
                {
                    return(false);
                }
                else
                {
                    var size     = t.size / 2;
                    var posIndex = Quadtree.IndexToSigns(t.i);
                    var origin   = t.origin + (new Vector2(posIndex.x * size, posIndex.y * size));

                    stack.Push(new Tracker(t.child.children[childIndex], origin, size));
                    return(true);
                }
            }