Exemple #1
0
        private void PopulateBuffer(ComputeBuffer constructedBuffer, int targetPointCount)
        {
            // Copy data from nodes until either all nodes are processed or quota for this step is reached
            while (lastProcessedNodeIndex < queuedNodes.Count && constructedBufferItemsCount < targetPointCount)
            {
                if (!nodeLoader.TryGetNode(queuedNodes[lastProcessedNodeIndex++], out var node))
                {
                    continue;
                }

                var count            = node.Points.Length;
                var afterAppendCount = constructedBufferItemsCount + count;

                if (afterAppendCount > maxBufferElements)
                {
                    Debug.LogWarning($"Total amount of points in requested nodes exceeds buffer size ({maxBufferElements.ToString()}). Truncating.");
                    lastProcessedNodeIndex = queuedNodes.Count;
                    break;
                }

                constructedBuffer.SetData(node.Points, 0, constructedBufferItemsCount, count);

                constructedBufferItemsCount += count;
            }
        }
Exemple #2
0
        /// <summary>
        /// <para>Performs as single step in buffer building process. Buffer will be ready after up to [<see cref="rebuildSteps"/>] steps.</para>
        /// <para>Note that this method is not bound to update loop and has to be called externally.</para>
        /// </summary>
        protected void PerformBuildStep()
        {
            // Calculate amount of points that should be reached during this step
            currentStepCount++;
            var targetPointCount = (currentStepCount == rebuildSteps)
                ? maxBufferElements
                : (int)((float)currentStepCount / rebuildSteps * maxBufferElements);

            var constructedBuffer = ConstructedBuffer;

            // Copy data from nodes until either all nodes are processed or quota for this step is reached
            while (lastProcessedNodeIndex < queuedNodes.Count && constructedBufferItemsCount < targetPointCount)
            {
                if (!nodeLoader.TryGetNode(queuedNodes[lastProcessedNodeIndex++], out var node))
                {
                    continue;
                }

                var count            = node.Points.Length;
                var afterAppendCount = constructedBufferItemsCount + count;

                if (afterAppendCount > maxBufferElements)
                {
                    Debug.LogWarning($"Total amount of points in requested nodes exceeds buffer size ({maxBufferElements.ToString()}). Truncating.");
                    lastProcessedNodeIndex = queuedNodes.Count;
                    break;
                }

                constructedBuffer.SetData(node.Points, 0, constructedBufferItemsCount, count);

                constructedBufferItemsCount += count;
            }

            // This was the last step - reset progress, swap ready and under-construction buffers
            if (lastProcessedNodeIndex == queuedNodes.Count)
            {
                lastProcessedNodeIndex      = 0;
                readyBufferItemsCount       = constructedBufferItemsCount;
                constructedBufferItemsCount = 0;
                currentStepCount            = 0;

                bufferSwapFlag = !bufferSwapFlag;
                busy           = false;
            }
        }