示例#1
0
        /// <summary>
        ///     Gathers all cell IDs the player is currently inside or nearby.
        /// </summary>
        /// <param name="activeCells">The list to add all cell IDs to the player is currently inside or nearby.</param>
        /// <param name="yIsUpAxis">Describes if the y-axis is used as up-axis.</param>
        /// <param name="position">The current position of the player.</param>
        public void GetActiveCells(List <byte> activeCells, bool yIsUpAxis, Vector3 position)
        {
            if (this.NodeType != ENodeType.Leaf)
            {
                foreach (CellTreeNode node in this.Childs)
                {
                    node.GetActiveCells(activeCells, yIsUpAxis, position);
                }
            }
            else
            {
                if (this.IsPointNearCell(yIsUpAxis, position))
                {
                    if (this.IsPointInsideCell(yIsUpAxis, position))
                    {
                        activeCells.Insert(0, this.Id);

                        CellTreeNode p = this.Parent;
                        while (p != null)
                        {
                            activeCells.Insert(0, p.Id);

                            p = p.Parent;
                        }
                    }
                    else
                    {
                        activeCells.Add(this.Id);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        ///     Constructor to define the ID and the node type as well as setting a parent node.
        /// </summary>
        /// <param name="id">The ID of the cell is used as the interest group.</param>
        /// <param name="nodeType">The node type of the cell tree node.</param>
        /// <param name="parent">The parent node of the cell tree node.</param>
        public CellTreeNode(byte id, ENodeType nodeType, CellTreeNode parent)
        {
            this.Id = id;

            this.NodeType = nodeType;

            this.Parent = parent;
        }
示例#3
0
        /// <summary>
        ///     Adds the given child to the node.
        /// </summary>
        /// <param name="child">The child which is added to the node.</param>
        public void AddChild(CellTreeNode child)
        {
            if (this.Childs == null)
            {
                this.Childs = new List <CellTreeNode>(1);
            }

            this.Childs.Add(child);
        }
示例#4
0
        /// <summary>
        ///     Creates all child cells.
        /// </summary>
        /// <param name="parent">The current parent node.</param>
        /// <param name="cellLevelInHierarchy">The cell level within the current hierarchy.</param>
        private void CreateChildCells(CellTreeNode parent, int cellLevelInHierarchy)
        {
            if (cellLevelInHierarchy > this.NumberOfSubdivisions)
            {
                return;
            }

            int rowCount    = (int)this.Subdivisions[(cellLevelInHierarchy - 1)].x;
            int columnCount = (int)this.Subdivisions[(cellLevelInHierarchy - 1)].y;

            float startX = parent.Center.x - (parent.Size.x / 2.0f);
            float width  = parent.Size.x / rowCount;

            for (int row = 0; row < rowCount; ++row)
            {
                for (int column = 0; column < columnCount; ++column)
                {
                    float xPos = startX + (row * width) + (width / 2.0f);

                    CellTreeNode node = new CellTreeNode(this.idCounter++,
                                                         (this.NumberOfSubdivisions == cellLevelInHierarchy)
                            ? CellTreeNode.ENodeType.Leaf
                            : CellTreeNode.ENodeType.Node, parent);

                    if (this.YIsUpAxis)
                    {
                        float startY = parent.Center.y - (parent.Size.y / 2.0f);
                        float height = parent.Size.y / columnCount;
                        float yPos   = startY + (column * height) + (height / 2.0f);

                        node.Center      = new Vector3(xPos, yPos, 0.0f);
                        node.Size        = new Vector3(width, height, 0.0f);
                        node.TopLeft     = new Vector3(xPos - (width / 2.0f), yPos - (height / 2.0f), 0.0f);
                        node.BottomRight = new Vector3(xPos + (width / 2.0f), yPos + (height / 2.0f), 0.0f);
                    }
                    else
                    {
                        float startZ = parent.Center.z - (parent.Size.z / 2.0f);
                        float depth  = parent.Size.z / columnCount;
                        float zPos   = startZ + (column * depth) + (depth / 2.0f);

                        node.Center      = new Vector3(xPos, 0.0f, zPos);
                        node.Size        = new Vector3(width, 0.0f, depth);
                        node.TopLeft     = new Vector3(xPos - (width / 2.0f), 0.0f, zPos - (depth / 2.0f));
                        node.BottomRight = new Vector3(xPos + (width / 2.0f), 0.0f, zPos + (depth / 2.0f));
                    }

                    parent.AddChild(node);

                    this.CreateChildCells(node, (cellLevelInHierarchy + 1));
                }
            }
        }
示例#5
0
        /// <summary>
        ///     Creates the cell hierarchy.
        /// </summary>
        private void CreateCellHierarchy()
        {
            if (!this.IsCellCountAllowed())
            {
                if (Debug.isDebugBuild)
                {
                    Debug.LogError(
                        "There are too many cells created by your subdivision options. Maximum allowed number of cells is " +
                        (MAX_NUMBER_OF_ALLOWED_CELLS - this.FIRST_GROUP_ID) +
                        ". Current number of cells is " + this.CellCount + ".");
                    return;
                }
                else
                {
                    Application.Quit();
                }
            }

            CellTreeNode rootNode = new CellTreeNode(this.idCounter++, CellTreeNode.ENodeType.Root, null);

            if (this.YIsUpAxis)
            {
                this.Center = new Vector2(transform.position.x, transform.position.y);
                this.Size   = new Vector2(transform.localScale.x, transform.localScale.y);

                rootNode.Center  = new Vector3(this.Center.x, this.Center.y, 0.0f);
                rootNode.Size    = new Vector3(this.Size.x, this.Size.y, 0.0f);
                rootNode.TopLeft = new Vector3((this.Center.x - (this.Size.x / 2.0f)),
                                               (this.Center.y - (this.Size.y / 2.0f)), 0.0f);
                rootNode.BottomRight = new Vector3((this.Center.x + (this.Size.x / 2.0f)),
                                                   (this.Center.y + (this.Size.y / 2.0f)), 0.0f);
            }
            else
            {
                this.Center = new Vector2(transform.position.x, transform.position.z);
                this.Size   = new Vector2(transform.localScale.x, transform.localScale.z);

                rootNode.Center  = new Vector3(this.Center.x, 0.0f, this.Center.y);
                rootNode.Size    = new Vector3(this.Size.x, 0.0f, this.Size.y);
                rootNode.TopLeft = new Vector3((this.Center.x - (this.Size.x / 2.0f)), 0.0f,
                                               (this.Center.y - (this.Size.y / 2.0f)));
                rootNode.BottomRight = new Vector3((this.Center.x + (this.Size.x / 2.0f)), 0.0f,
                                                   (this.Center.y + (this.Size.y / 2.0f)));
            }

            this.CreateChildCells(rootNode, 1);

            this.CellTree = new CellTree(rootNode);

            this.RecreateCellHierarchy = false;
        }
示例#6
0
 /// <summary>
 ///     Constructor to define the root node.
 /// </summary>
 /// <param name="root">The root node of the tree.</param>
 public CellTree(CellTreeNode root)
 {
     this.RootNode = root;
 }
示例#7
0
        }                                                                                // 0x0000000181275B50-0x0000000181275BA0

        // Methods
        public void AddChild(CellTreeNode child)
        {
        }                                                   // 0x00000001812755D0-0x0000000181275670
示例#8
0
        }                                // 0x00000001802466A0-0x00000001802466B0

        public CellTreeNode(byte id, ENodeType nodeType, CellTreeNode parent)
        {
        }                                                                                // 0x0000000181275B50-0x0000000181275BA0
示例#9
0
        }                            // 0x00000001802466A0-0x00000001802466B0

        public CellTree(CellTreeNode root)
        {
        }                                             // 0x000000018024B380-0x000000018024B3B0
示例#10
0
        }                                             // 0x0000000181276E10-0x0000000181277650

        private void CreateChildCells(CellTreeNode parent, int cellLevelInHierarchy)
        {
        }                                                                                       // 0x0000000181277650-0x0000000181277B30