Ejemplo n.º 1
0
        public void AddCullable(ICullable cullable)
        {
            if (cullables.Contains(cullable))
            {
                throw new InvalidOperationException();
            }
            cullables.Add(cullable);
            var item = new CullableItem {
                Cullable = cullable, Index = cullablesLookup.Count
            };

            cullablesLookup.Add(item);
            cullableItemMap[cullable] = item;


            CullNode node = RootNode.FindContainingNode(cullable);

            cullableContainingNodes[cullable] = node;

            if (node == null)
            {
                node = RootNode;
            }
            node.PlaceCullable(item);


            if (viewCullablesBufferSize <= cullablesLookup.Count)
            {
                expandCullablesBuffer();
            }
        }
Ejemplo n.º 2
0
            /// <summary>
            /// Locates the correct node to place given cullable in, and then adds it to that node
            /// Returns the node the cullable was added to
            /// </summary>
            /// <param name="cullable"></param>
            public void PlaceCullable(CullableItem cullable)
            {
                if (nodeData.BoundingBox.xna().Contains(cullable.Cullable.BoundingBox.xna()) == Microsoft.Xna.Framework.ContainmentType.Disjoint)
                {
                    return;
                }

                if (QuadTree.IsLeafNode(this))
                {
                    cullables.Add(cullable);
                    return;
                }

                nodeData.LowerLeft.PlaceCullable(cullable);
                nodeData.LowerRight.PlaceCullable(cullable);
                nodeData.UpperLeft.PlaceCullable(cullable);
                nodeData.UpperRight.PlaceCullable(cullable);
            }
Ejemplo n.º 3
0
            public void RemoveCullable(CullableItem cullable)
            {
                // This line cannot be used since data may have changed

                /*if (nodeData.BoundingBox.Contains(cullable.BoundingBox) == ContainmentType.Disjoint)
                 *  return;*/

                //WARNING: this could cause SERIOUS problems when remove a node that is contained in the root node.
                // Idea: moving cullables could store the nodes they're in and optimize themselves. This issue does
                //         not exist for static objects.

                if (QuadTree.IsLeafNode(this))
                {
                    cullables.Remove(cullable);
                    return;
                }

                nodeData.LowerLeft.PlaceCullable(cullable);
                nodeData.LowerRight.PlaceCullable(cullable);
                nodeData.UpperLeft.PlaceCullable(cullable);
                nodeData.UpperRight.PlaceCullable(cullable);
            }