Esempio n. 1
0
        private void Update()
        {
            if (targetIterations <= 0)
            {
                return;
            }

            Stopwatch sw = Stopwatch.StartNew();

            int iterationsThisFrame = 0;
            int remainingIterations = targetIterations - currentIterations;

            for (int i = 0; i < remainingIterations; i++)
            {
                if (sw.Elapsed.TotalSeconds >= PerFrameAnalysisTime)
                {
                    break;
                }

                if (generator.Generate())
                {
                    analysis.IncrementSuccessCount();
                    analysis.Add(generator.GenerationStats);
                }

                currentIterations++;
                iterationsThisFrame++;
            }

            analysisTime += sw.Elapsed.TotalSeconds;

            if (MaximumAnalysisTime > 0 && analysisTime >= MaximumAnalysisTime)
            {
                targetIterations = currentIterations;
                finishedEarly    = true;
            }

            if (currentIterations >= targetIterations)
            {
                targetIterations = 0;
                analysis.Analyze();

                UnityUtil.Destroy(generator.Root);
                OnAnalysisComplete();
            }
        }
        private void OnGenerationStatusChanged(DungeonGenerator generator, GenerationStatus status)
        {
            if (status != GenerationStatus.Complete)
            {
                return;
            }

            analysis.IncrementSuccessCount();
            analysis.Add(generator.GenerationStats);

            remainingIterations--;

            if (remainingIterations <= 0)
            {
                generator.OnGenerationStatusChanged -= OnGenerationStatusChanged;
                CompleteAnalysis();
            }
            else
            {
                generateNextFrame = true;
            }
        }