Skip to content
Snippets Groups Projects
Commit fd54bbc2 authored by Chang, Ryan's avatar Chang, Ryan
Browse files

Timer to check time differences between jobs/threads.

parent c66b5b95
No related branches found
No related tags found
No related merge requests found
using Unity.Jobs; using System.Diagnostics;
using UnityEngine; using UnityEngine;
/// <summary> /// <summary>
...@@ -36,6 +36,8 @@ public abstract class TerrainChunker : MonoBehaviour ...@@ -36,6 +36,8 @@ public abstract class TerrainChunker : MonoBehaviour
private bool lookForCompletion = false; private bool lookForCompletion = false;
private Stopwatch createTimer = new();
public void Initialize(TerrainMaster master, Vector2Int gridPosition, public void Initialize(TerrainMaster master, Vector2Int gridPosition,
Vector2 crawlOffset) Vector2 crawlOffset)
{ {
...@@ -70,11 +72,8 @@ public abstract class TerrainChunker : MonoBehaviour ...@@ -70,11 +72,8 @@ public abstract class TerrainChunker : MonoBehaviour
private void UpdateTerrain() private void UpdateTerrain()
{ {
print($"Updating {gameObject.name} terrain."); print($"Updating {gameObject.name} terrain.");
//if (!CheckIfFinished()) createTimer.Start();
//{
// CancelRunning();
//}
CreateRunning(); CreateRunning();
lookForCompletion = true; lookForCompletion = true;
...@@ -93,7 +92,9 @@ public abstract class TerrainChunker : MonoBehaviour ...@@ -93,7 +92,9 @@ public abstract class TerrainChunker : MonoBehaviour
private void ApplyTerrain(float[,] heights) private void ApplyTerrain(float[,] heights)
{ {
print($"Apply {gameObject.name} terrain."); createTimer.Stop();
print($"Apply {gameObject.name} terrain. " +
$"Took {createTimer.Elapsed} with mode {master.mode}.");
// Calculate position of game object // Calculate position of game object
Vector2 flatPosition = (Vector2)gridPosition * terrainWidth; Vector2 flatPosition = (Vector2)gridPosition * terrainWidth;
......
...@@ -17,13 +17,6 @@ public class TerrainChunkerJobs : TerrainChunker ...@@ -17,13 +17,6 @@ public class TerrainChunkerJobs : TerrainChunker
return shapeGenerator.Cancelled; return shapeGenerator.Cancelled;
} }
//protected override void CancelRunning()
//{
// //// Cancel thread if its running.
// //shapeGenerator.Cancel(runningShape);
// //print($"{gameObject.name} has running job, which has been cancelled.");
//}
protected override void CreateRunning() protected override void CreateRunning()
{ {
shapeGenerator = new(crawlOffset, gridPosition, heightResolution, shapeGenerator = new(crawlOffset, gridPosition, heightResolution,
......
...@@ -16,11 +16,6 @@ public class TerrainChunkerThreads : TerrainChunker ...@@ -16,11 +16,6 @@ public class TerrainChunkerThreads : TerrainChunker
{ {
return shapeGenerator.Cancelled; return shapeGenerator.Cancelled;
} }
//protected override void CancelRunning()
//{
// cts.Cancel();
//}
protected override void CreateRunning() protected override void CreateRunning()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment