Beispiel #1
0
        private static bool TraverseAndStream(QtNode <GrassPatch> node, TraversalData data)
        {
            Vector3 position = To3D(node.GetCenter());

            position.y = node.Value.Height;

            bool isInRange = Vector3.SqrMagnitude(data.SubjectPosition - position) <= data.LodRanges[node.Depth];

            // Todo: save memory by only assigning values to nodes that will actually carry a payload; the leaves

            if (!node.HasChildren)
            {
                if (isInRange)
                {
                    data.LoadRequests.Add(node);
                }
                else
                {
                    data.UnloadRequests.Add(node);
                }
            }

            bool stateChange = node.Value.WasInRange != isInRange;

            node.Value.WasInRange = isInRange;

            return(isInRange || stateChange);
        }
Beispiel #2
0
 /// <summary>
 /// Inserts an element to the back of the list and returns an index to it.
 /// </summary>
 /// <returns>The index where the new element was inserted</returns>
 private int PushBack(QtNode elt)
 {
     // Check if the array is full
     if (Count == Capacity)
     {
         // Use double the size for the new capacity.
         SetCapacity(Count * 2);
     }
     _data[Count].element = elt;
     return(Count++);
 }
Beispiel #3
0
 private static bool TraverseAndDrawGizmos(QtNode <GrassPatch> node, TraversalData data)
 {
     if (node.Value.State != NodeState.Unloaded)
     {
         Vector3 position = To3D(node.GetCenter());
         position.y   = node.Value.Height;
         Gizmos.color = NodeStateColors[(int)node.Value.State];
         Gizmos.DrawWireCube(position, new Vector3(node.Size, 1f, node.Size));
     }
     return(node.Value.WasInRange);
 }
Beispiel #4
0
        /// <summary>
        /// Inserts an element to a vacant position in the list and returns an index to it.
        /// </summary>
        /// <returns>index of the slot where the element was inserted</returns>
        public int Insert(QtNode elt)
        {
            //if there's an open slot in the free list, pop that and use it
            if (_freeElement != -1)
            {
                int index = _freeElement;

                //set the free index to the next open index in the free list
                _freeElement = _data[index].next;

                //actually insert the element
                _data[index].element = elt;
                //return the index where the element was inserted
                return(index);
            }
            // Otherwise insert to the back of the array.
            return(PushBack(elt));
        }