bugfix - TickWatch

This commit is contained in:
ikpil 2023-04-06 18:48:36 +09:00
parent ecce6dcb95
commit 35591536fd
11 changed files with 42 additions and 29 deletions

View File

@ -0,0 +1,11 @@
using System;
using System.Diagnostics;
namespace DotRecast.Core
{
public static class TickWatch
{
public static readonly double Frequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency;
public static long Ticks => unchecked((long)(Stopwatch.GetTimestamp() * Frequency));
}
}

View File

@ -20,6 +20,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using DotRecast.Core;
namespace DotRecast.Detour.Crowd namespace DotRecast.Detour.Crowd
{ {
@ -65,12 +66,12 @@ namespace DotRecast.Detour.Crowd
public void start(string name) public void start(string name)
{ {
_executionTimings.Add(name, Stopwatch.GetTimestamp()); _executionTimings.Add(name, TickWatch.Ticks);
} }
public void stop(string name) public void stop(string name)
{ {
long duration = Stopwatch.GetTimestamp() - _executionTimings[name]; long duration = TickWatch.Ticks - _executionTimings[name];
if (!_executionTimingSamples.TryGetValue(name, out var s)) if (!_executionTimingSamples.TryGetValue(name, out var s))
{ {
s = new List<long>(); s = new List<long>();

View File

@ -470,7 +470,7 @@ public class RecastDemo
cameraPos[1] += (float)((_moveUp - _moveDown) * keySpeed * dt); cameraPos[1] += (float)((_moveUp - _moveDown) * keySpeed * dt);
long time = Stopwatch.GetTimestamp(); long time = TickWatch.Ticks;
prevFrameTime = time; prevFrameTime = time;
// Update sample simulation. // Update sample simulation.
@ -537,7 +537,7 @@ public class RecastDemo
float m_detailSampleDist = settingsUI.getDetailSampleDist(); float m_detailSampleDist = settingsUI.getDetailSampleDist();
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError(); float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
int m_tileSize = settingsUI.getTileSize(); int m_tileSize = settingsUI.getTileSize();
long t = Stopwatch.GetTimestamp(); long t = TickWatch.Ticks;
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult; Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
if (settingsUI.isTiled()) if (settingsUI.isTiled())
@ -559,7 +559,7 @@ public class RecastDemo
sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2); sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
sample.setChanged(false); sample.setChanged(false);
settingsUI.setBuildTime((Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond); settingsUI.setBuildTime((TickWatch.Ticks - t) / TimeSpan.TicksPerMillisecond);
settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList()); settingsUI.setBuildTelemetry(buildResult.Item1.Select(x => x.getTelemetry()).ToList());
toolsUI.setSample(sample); toolsUI.setSample(sample);
} }

View File

@ -239,7 +239,7 @@ public class CrowdProfilingTool
public void update(float dt) public void update(float dt)
{ {
long startTime = Stopwatch.GetTimestamp(); long startTime = TickWatch.Ticks;
if (crowd != null) if (crowd != null)
{ {
crowd.config().pathQueueSize = pathQueueSize; crowd.config().pathQueueSize = pathQueueSize;
@ -247,7 +247,7 @@ public class CrowdProfilingTool
crowd.update(dt, null); crowd.update(dt, null);
} }
long endTime = Stopwatch.GetTimestamp(); long endTime = TickWatch.Ticks;
if (crowd != null) if (crowd != null)
{ {
NavMeshQuery navquery = new NavMeshQuery(navMesh); NavMeshQuery navquery = new NavMeshQuery(navMesh);

View File

@ -678,9 +678,9 @@ public class CrowdTool : Tool
if (nav == null) if (nav == null)
return; return;
long startTime = Stopwatch.GetTimestamp(); long startTime = TickWatch.Ticks;
crowd.update(dt, m_agentDebug); crowd.update(dt, m_agentDebug);
long endTime = Stopwatch.GetTimestamp(); long endTime = TickWatch.Ticks;
// Update agent trails // Update agent trails
foreach (CrowdAgent ag in crowd.getActiveAgents()) foreach (CrowdAgent ag in crowd.getActiveAgents())

View File

@ -204,9 +204,9 @@ public class DynamicUpdateTool : Tool
{ {
Vector3f sp = Vector3f.Of(spos[0], spos[1] + 1.3f, spos[2]); Vector3f sp = Vector3f.Of(spos[0], spos[1] + 1.3f, spos[2]);
Vector3f ep = Vector3f.Of(epos[0], epos[1] + 1.3f, epos[2]); Vector3f ep = Vector3f.Of(epos[0], epos[1] + 1.3f, epos[2]);
long t1 = Stopwatch.GetTimestamp(); long t1 = TickWatch.Ticks;
float? hitPos = dynaMesh.voxelQuery().raycast(sp, ep); float? hitPos = dynaMesh.voxelQuery().raycast(sp, ep);
long t2 = Stopwatch.GetTimestamp(); long t2 = TickWatch.Ticks;
raycastTime = (t2 - t1) / TimeSpan.TicksPerMillisecond; raycastTime = (t2 - t1) / TimeSpan.TicksPerMillisecond;
raycastHit = hitPos.HasValue; raycastHit = hitPos.HasValue;
raycastHitPos = hitPos.HasValue raycastHitPos = hitPos.HasValue
@ -498,13 +498,13 @@ public class DynamicUpdateTool : Tool
private void updateDynaMesh() private void updateDynaMesh()
{ {
long t = Stopwatch.GetTimestamp(); long t = TickWatch.Ticks;
try try
{ {
bool updated = dynaMesh.update(executor).Result; bool updated = dynaMesh.update(executor).Result;
if (updated) if (updated)
{ {
buildTime = (Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond; buildTime = (TickWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh()); sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh());
sample.setChanged(false); sample.setChanged(false);
} }
@ -727,7 +727,7 @@ public class DynamicUpdateTool : Tool
private void buildDynaMesh() private void buildDynaMesh()
{ {
configDynaMesh(); configDynaMesh();
long t = Stopwatch.GetTimestamp(); long t = TickWatch.Ticks;
try try
{ {
var _ = dynaMesh.build(executor).Result; var _ = dynaMesh.build(executor).Result;
@ -737,7 +737,7 @@ public class DynamicUpdateTool : Tool
Console.WriteLine(e); Console.WriteLine(e);
} }
buildTime = (Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond; buildTime = (TickWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh()); sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh());
} }

View File

@ -33,14 +33,14 @@ namespace DotRecast.Recast
public void startTimer(string name) public void startTimer(string name)
{ {
timerStart.Value[name] = new AtomicLong(Stopwatch.GetTimestamp()); timerStart.Value[name] = new AtomicLong(TickWatch.Ticks);
} }
public void stopTimer(string name) public void stopTimer(string name)
{ {
timerAccum timerAccum
.GetOrAdd(name, _ => new AtomicLong(0)) .GetOrAdd(name, _ => new AtomicLong(0))
.AddAndGet(Stopwatch.GetTimestamp() - timerStart.Value?[name].Read() ?? 0); .AddAndGet(TickWatch.Ticks - timerStart.Value?[name].Read() ?? 0);
} }
public void warn(string @string) public void warn(string @string)

View File

@ -18,6 +18,7 @@ freely, subject to the following restrictions:
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using DotRecast.Core;
using NUnit.Framework; using NUnit.Framework;
using static DotRecast.Core.RecastMath; using static DotRecast.Core.RecastMath;
@ -120,19 +121,19 @@ public class RandomPointTest : AbstractDetourTest
query.findRandomPointWithinCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f); query.findRandomPointWithinCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f);
} }
long t1 = Stopwatch.GetTimestamp(); long t1 = TickWatch.Ticks;
for (int i = 0; i < 10000; i++) for (int i = 0; i < 10000; i++)
{ {
query.findRandomPointAroundCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f); query.findRandomPointAroundCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f);
} }
long t2 = Stopwatch.GetTimestamp(); long t2 = TickWatch.Ticks;
for (int i = 0; i < 10000; i++) for (int i = 0; i < 10000; i++)
{ {
query.findRandomPointWithinCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f); query.findRandomPointWithinCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f);
} }
long t3 = Stopwatch.GetTimestamp(); long t3 = TickWatch.Ticks;
Console.WriteLine("Random point around circle: " + (t2 - t1) / TimeSpan.TicksPerMillisecond + "ms"); Console.WriteLine("Random point around circle: " + (t2 - t1) / TimeSpan.TicksPerMillisecond + "ms");
Console.WriteLine("Random point within circle: " + (t3 - t2) / TimeSpan.TicksPerMillisecond + "ms"); Console.WriteLine("Random point within circle: " + (t3 - t2) / TimeSpan.TicksPerMillisecond + "ms");
} }

View File

@ -188,20 +188,20 @@ public class TileCacheTest : AbstractTileCacheTest
layerBuilder.build(order, cCompatibility, threads); layerBuilder.build(order, cCompatibility, threads);
} }
long t1 = Stopwatch.GetTimestamp(); long t1 = TickWatch.Ticks;
List<byte[]> layers = null; List<byte[]> layers = null;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
layers = layerBuilder.build(order, cCompatibility, 1); layers = layerBuilder.build(order, cCompatibility, 1);
} }
long t2 = Stopwatch.GetTimestamp(); long t2 = TickWatch.Ticks;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
layers = layerBuilder.build(order, cCompatibility, threads); layers = layerBuilder.build(order, cCompatibility, threads);
} }
long t3 = Stopwatch.GetTimestamp(); long t3 = TickWatch.Ticks;
Console.WriteLine(" Time ST : " + (t2 - t1) / TimeSpan.TicksPerMillisecond); Console.WriteLine(" Time ST : " + (t2 - t1) / TimeSpan.TicksPerMillisecond);
Console.WriteLine(" Time MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond); Console.WriteLine(" Time MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond);
TileCache tc = getTileCache(geom, order, cCompatibility); TileCache tc = getTileCache(geom, order, cCompatibility);

View File

@ -96,7 +96,7 @@ public class RecastSoloMeshTest
{ {
m_partitionType = partitionType; m_partitionType = partitionType;
InputGeomProvider geomProvider = ObjImporter.load(Loader.ToBytes(filename)); InputGeomProvider geomProvider = ObjImporter.load(Loader.ToBytes(filename));
long time = Stopwatch.GetTimestamp(); long time = TickWatch.Ticks;
Vector3f bmin = geomProvider.getMeshBoundsMin(); Vector3f bmin = geomProvider.getMeshBoundsMin();
Vector3f bmax = geomProvider.getMeshBoundsMax(); Vector3f bmax = geomProvider.getMeshBoundsMax();
Telemetry m_ctx = new Telemetry(); Telemetry m_ctx = new Telemetry();
@ -204,7 +204,7 @@ public class RecastSoloMeshTest
// you use tiles) // you use tiles)
// * good choice to use for tiled navmesh with medium and small sized // * good choice to use for tiled navmesh with medium and small sized
// tiles // tiles
long time3 = Stopwatch.GetTimestamp(); long time3 = TickWatch.Ticks;
if (m_partitionType == PartitionType.WATERSHED) if (m_partitionType == PartitionType.WATERSHED)
{ {
@ -256,7 +256,7 @@ public class RecastSoloMeshTest
Assert.That(m_dmesh.nmeshes, Is.EqualTo(expDetMeshes), "Mesh Detail Meshes"); Assert.That(m_dmesh.nmeshes, Is.EqualTo(expDetMeshes), "Mesh Detail Meshes");
Assert.That(m_dmesh.nverts, Is.EqualTo(expDetVerts), "Mesh Detail Verts"); Assert.That(m_dmesh.nverts, Is.EqualTo(expDetVerts), "Mesh Detail Verts");
Assert.That(m_dmesh.ntris, Is.EqualTo(expDetTris), "Mesh Detail Tris"); Assert.That(m_dmesh.ntris, Is.EqualTo(expDetTris), "Mesh Detail Tris");
long time2 = Stopwatch.GetTimestamp(); long time2 = TickWatch.Ticks;
Console.WriteLine(filename + " : " + partitionType + " " + (time2 - time) / TimeSpan.TicksPerMillisecond + " ms"); Console.WriteLine(filename + " : " + partitionType + " " + (time2 - time) / TimeSpan.TicksPerMillisecond + " ms");
Console.WriteLine(" " + (time3 - time) / TimeSpan.TicksPerMillisecond + " ms"); Console.WriteLine(" " + (time3 - time) / TimeSpan.TicksPerMillisecond + " ms");
saveObj(filename.Substring(0, filename.LastIndexOf('.')) + "_" + partitionType + "_detail.obj", m_dmesh); saveObj(filename.Substring(0, filename.LastIndexOf('.')) + "_" + partitionType + "_detail.obj", m_dmesh);

View File

@ -106,19 +106,19 @@ public class RecastTileMeshTest
build(geom, builder, cfg, 4, true); build(geom, builder, cfg, 4, true);
} }
long t1 = Stopwatch.GetTimestamp(); long t1 = TickWatch.Ticks;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
build(geom, builder, cfg, 1, false); build(geom, builder, cfg, 1, false);
} }
long t2 = Stopwatch.GetTimestamp(); long t2 = TickWatch.Ticks;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
build(geom, builder, cfg, 4, false); build(geom, builder, cfg, 4, false);
} }
long t3 = Stopwatch.GetTimestamp(); long t3 = TickWatch.Ticks;
Console.WriteLine(" Time ST : " + (t2 - t1) / TimeSpan.TicksPerMillisecond); Console.WriteLine(" Time ST : " + (t2 - t1) / TimeSpan.TicksPerMillisecond);
Console.WriteLine(" Time MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond); Console.WriteLine(" Time MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond);
} }