Add debug info about generation time
This commit is contained in:
parent
8bfcb28a30
commit
e7888956a8
@ -10,12 +10,19 @@ namespace Editor
|
|||||||
public class GraphGeneratorUI : UnityEditor.Editor
|
public class GraphGeneratorUI : UnityEditor.Editor
|
||||||
{
|
{
|
||||||
private string _threshold;
|
private string _threshold;
|
||||||
|
private bool _showInfo = false;
|
||||||
|
|
||||||
public override void OnInspectorGUI()
|
public override void OnInspectorGUI()
|
||||||
{
|
{
|
||||||
GraphGenerator generator = (GraphGenerator)target;
|
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();
|
DrawDefaultInspector();
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
using Assets.Common;
|
using Assets.Common;
|
||||||
using Assets.Generators;
|
using Assets.Generators;
|
||||||
using Assets.Map;
|
using Assets.Map;
|
||||||
@ -27,6 +29,8 @@ namespace Assets
|
|||||||
public bool displayLocationCells = true;
|
public bool displayLocationCells = true;
|
||||||
public bool displayLocationEdges = true;
|
public bool displayLocationEdges = true;
|
||||||
public bool displayLocationPoints = true;
|
public bool displayLocationPoints = true;
|
||||||
|
|
||||||
|
[NonSerialized] public float generationTime = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
@ -44,7 +48,7 @@ namespace Assets
|
|||||||
Done
|
Done
|
||||||
};
|
};
|
||||||
|
|
||||||
[RequireComponent(typeof(MeshRenderer), typeof(MeshFilter)), ExecuteInEditMode]
|
[ExecuteInEditMode]
|
||||||
public class GraphGenerator : MonoBehaviour
|
public class GraphGenerator : MonoBehaviour
|
||||||
{
|
{
|
||||||
private PoissonDiskSampler _sampler;
|
private PoissonDiskSampler _sampler;
|
||||||
@ -55,22 +59,21 @@ namespace Assets
|
|||||||
|
|
||||||
private List<Vector3> _points = new List<Vector3>();
|
private List<Vector3> _points = new List<Vector3>();
|
||||||
private List<Location> _locations = new List<Location>();
|
private List<Location> _locations = new List<Location>();
|
||||||
|
private Graph<(Point, Location)> _locationGraph;
|
||||||
|
|
||||||
public List<LocationType> types = new List<LocationType>();
|
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)]
|
[Range(2.0f, 64.0f)]
|
||||||
public float radius = 8;
|
public float radius = 8;
|
||||||
|
public int seed = Environment.TickCount;
|
||||||
private double _directrix = 0.0f;
|
public Vector2 size = new Vector2();
|
||||||
private Graph<(Point, Location)> _locationGraph;
|
|
||||||
|
public GraphGeneratorDebug debug;
|
||||||
|
|
||||||
|
public GenerationStage Stage { get; private set; } = GenerationStage.Start;
|
||||||
|
|
||||||
|
public VoronoiGenerator VoronoiGenerator => _voronoiGenerator;
|
||||||
|
public LocationGenerator LocationGenerator => _locationGenerator;
|
||||||
|
|
||||||
void Start()
|
void Start()
|
||||||
{
|
{
|
||||||
@ -104,10 +107,25 @@ namespace Assets
|
|||||||
|
|
||||||
public void Generate()
|
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()
|
public void Step()
|
||||||
@ -115,7 +133,6 @@ namespace Assets
|
|||||||
if (Stage == GenerationStage.Voronoi)
|
if (Stage == GenerationStage.Voronoi)
|
||||||
{
|
{
|
||||||
_voronoiGenerator.Step();
|
_voronoiGenerator.Step();
|
||||||
_directrix = _voronoiGenerator.Line.Directrix;
|
|
||||||
|
|
||||||
if (_voronoiGenerator.Done)
|
if (_voronoiGenerator.Done)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user