Add debug info about generation time

This commit is contained in:
Kacper Donat 2019-08-18 19:59:31 +02:00
parent 8bfcb28a30
commit e7888956a8
2 changed files with 41 additions and 17 deletions

View File

@ -10,12 +10,19 @@ namespace Editor
public class GraphGeneratorUI : UnityEditor.Editor
{
private string _threshold;
private bool _showInfo = false;
public override void OnInspectorGUI()
{
GraphGenerator generator = (GraphGenerator)target;
GUILayout.Label($"Stage: {generator.Stage}");
_showInfo = EditorGUILayout.Foldout(_showInfo, "Debug info");
if (_showInfo)
{
EditorGUILayout.LabelField($"Stage: ", generator.Stage.ToString());
EditorGUILayout.LabelField($"Took: ", $"{generator.debug.generationTime:F3}s");
}
DrawDefaultInspector();

View File

@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using Assets.Common;
using Assets.Generators;
using Assets.Map;
@ -27,6 +29,8 @@ namespace Assets
public bool displayLocationCells = true;
public bool displayLocationEdges = true;
public bool displayLocationPoints = true;
[NonSerialized] public float generationTime = 0.0f;
}
[Serializable]
@ -44,7 +48,7 @@ namespace Assets
Done
};
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter)), ExecuteInEditMode]
[ExecuteInEditMode]
public class GraphGenerator : MonoBehaviour
{
private PoissonDiskSampler _sampler;
@ -55,22 +59,21 @@ namespace Assets
private List<Vector3> _points = new List<Vector3>();
private List<Location> _locations = new List<Location>();
private Graph<(Point, Location)> _locationGraph;
public List<LocationType> types = new List<LocationType>();
public VoronoiGenerator VoronoiGenerator => _voronoiGenerator;
public LocationGenerator LocationGenerator => _locationGenerator;
public int seed = Environment.TickCount;
public Vector2 size = new Vector2();
public GraphGeneratorDebug debug;
public GenerationStage Stage { get; private set; } = GenerationStage.Start;
[Range(2.0f, 64.0f)]
public float radius = 8;
private double _directrix = 0.0f;
private Graph<(Point, Location)> _locationGraph;
public int seed = Environment.TickCount;
public Vector2 size = new Vector2();
public GraphGeneratorDebug debug;
public GenerationStage Stage { get; private set; } = GenerationStage.Start;
public VoronoiGenerator VoronoiGenerator => _voronoiGenerator;
public LocationGenerator LocationGenerator => _locationGenerator;
void Start()
{
@ -104,10 +107,25 @@ namespace Assets
public void Generate()
{
while (Stage != GenerationStage.Done)
var thread = new Thread(() =>
{
Step();
}
var stopwatch = new Stopwatch();
stopwatch.Start();
debug.generationTime = 0;
while (Stage != GenerationStage.Done)
{
Step();
debug.generationTime = stopwatch.ElapsedMilliseconds / 1000.0f;
}
stopwatch.Stop();
debug.generationTime = stopwatch.ElapsedMilliseconds / 1000.0f;
});
thread.Start();
}
public void Step()
@ -115,7 +133,6 @@ namespace Assets
if (Stage == GenerationStage.Voronoi)
{
_voronoiGenerator.Step();
_directrix = _voronoiGenerator.Line.Directrix;
if (_voronoiGenerator.Done)
{