forked from bit/DotRecastNetSim
bugfix - TickWatch
This commit is contained in:
parent
ecce6dcb95
commit
35591536fd
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.Crowd
|
||||
{
|
||||
|
@ -65,12 +66,12 @@ namespace DotRecast.Detour.Crowd
|
|||
|
||||
public void start(string name)
|
||||
{
|
||||
_executionTimings.Add(name, Stopwatch.GetTimestamp());
|
||||
_executionTimings.Add(name, TickWatch.Ticks);
|
||||
}
|
||||
|
||||
public void stop(string name)
|
||||
{
|
||||
long duration = Stopwatch.GetTimestamp() - _executionTimings[name];
|
||||
long duration = TickWatch.Ticks - _executionTimings[name];
|
||||
if (!_executionTimingSamples.TryGetValue(name, out var s))
|
||||
{
|
||||
s = new List<long>();
|
||||
|
|
|
@ -470,7 +470,7 @@ public class RecastDemo
|
|||
|
||||
cameraPos[1] += (float)((_moveUp - _moveDown) * keySpeed * dt);
|
||||
|
||||
long time = Stopwatch.GetTimestamp();
|
||||
long time = TickWatch.Ticks;
|
||||
prevFrameTime = time;
|
||||
|
||||
// Update sample simulation.
|
||||
|
@ -537,7 +537,7 @@ public class RecastDemo
|
|||
float m_detailSampleDist = settingsUI.getDetailSampleDist();
|
||||
float m_detailSampleMaxError = settingsUI.getDetailSampleMaxError();
|
||||
int m_tileSize = settingsUI.getTileSize();
|
||||
long t = Stopwatch.GetTimestamp();
|
||||
long t = TickWatch.Ticks;
|
||||
|
||||
Tuple<IList<RecastBuilderResult>, NavMesh> buildResult;
|
||||
if (settingsUI.isTiled())
|
||||
|
@ -559,7 +559,7 @@ public class RecastDemo
|
|||
|
||||
sample.update(sample.getInputGeom(), buildResult.Item1, buildResult.Item2);
|
||||
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());
|
||||
toolsUI.setSample(sample);
|
||||
}
|
||||
|
|
|
@ -239,7 +239,7 @@ public class CrowdProfilingTool
|
|||
|
||||
public void update(float dt)
|
||||
{
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
long startTime = TickWatch.Ticks;
|
||||
if (crowd != null)
|
||||
{
|
||||
crowd.config().pathQueueSize = pathQueueSize;
|
||||
|
@ -247,7 +247,7 @@ public class CrowdProfilingTool
|
|||
crowd.update(dt, null);
|
||||
}
|
||||
|
||||
long endTime = Stopwatch.GetTimestamp();
|
||||
long endTime = TickWatch.Ticks;
|
||||
if (crowd != null)
|
||||
{
|
||||
NavMeshQuery navquery = new NavMeshQuery(navMesh);
|
||||
|
|
|
@ -678,9 +678,9 @@ public class CrowdTool : Tool
|
|||
if (nav == null)
|
||||
return;
|
||||
|
||||
long startTime = Stopwatch.GetTimestamp();
|
||||
long startTime = TickWatch.Ticks;
|
||||
crowd.update(dt, m_agentDebug);
|
||||
long endTime = Stopwatch.GetTimestamp();
|
||||
long endTime = TickWatch.Ticks;
|
||||
|
||||
// Update agent trails
|
||||
foreach (CrowdAgent ag in crowd.getActiveAgents())
|
||||
|
|
|
@ -204,9 +204,9 @@ public class DynamicUpdateTool : Tool
|
|||
{
|
||||
Vector3f sp = Vector3f.Of(spos[0], spos[1] + 1.3f, spos[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);
|
||||
long t2 = Stopwatch.GetTimestamp();
|
||||
long t2 = TickWatch.Ticks;
|
||||
raycastTime = (t2 - t1) / TimeSpan.TicksPerMillisecond;
|
||||
raycastHit = hitPos.HasValue;
|
||||
raycastHitPos = hitPos.HasValue
|
||||
|
@ -498,13 +498,13 @@ public class DynamicUpdateTool : Tool
|
|||
|
||||
private void updateDynaMesh()
|
||||
{
|
||||
long t = Stopwatch.GetTimestamp();
|
||||
long t = TickWatch.Ticks;
|
||||
try
|
||||
{
|
||||
bool updated = dynaMesh.update(executor).Result;
|
||||
if (updated)
|
||||
{
|
||||
buildTime = (Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond;
|
||||
buildTime = (TickWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
|
||||
sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh());
|
||||
sample.setChanged(false);
|
||||
}
|
||||
|
@ -727,7 +727,7 @@ public class DynamicUpdateTool : Tool
|
|||
private void buildDynaMesh()
|
||||
{
|
||||
configDynaMesh();
|
||||
long t = Stopwatch.GetTimestamp();
|
||||
long t = TickWatch.Ticks;
|
||||
try
|
||||
{
|
||||
var _ = dynaMesh.build(executor).Result;
|
||||
|
@ -737,7 +737,7 @@ public class DynamicUpdateTool : Tool
|
|||
Console.WriteLine(e);
|
||||
}
|
||||
|
||||
buildTime = (Stopwatch.GetTimestamp() - t) / TimeSpan.TicksPerMillisecond;
|
||||
buildTime = (TickWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
|
||||
sample.update(null, dynaMesh.recastResults(), dynaMesh.navMesh());
|
||||
}
|
||||
|
||||
|
|
|
@ -33,14 +33,14 @@ namespace DotRecast.Recast
|
|||
|
||||
public void startTimer(string name)
|
||||
{
|
||||
timerStart.Value[name] = new AtomicLong(Stopwatch.GetTimestamp());
|
||||
timerStart.Value[name] = new AtomicLong(TickWatch.Ticks);
|
||||
}
|
||||
|
||||
public void stopTimer(string name)
|
||||
{
|
||||
timerAccum
|
||||
.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)
|
||||
|
|
|
@ -18,6 +18,7 @@ freely, subject to the following restrictions:
|
|||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using DotRecast.Core;
|
||||
using NUnit.Framework;
|
||||
using static DotRecast.Core.RecastMath;
|
||||
|
||||
|
@ -120,19 +121,19 @@ public class RandomPointTest : AbstractDetourTest
|
|||
query.findRandomPointWithinCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f);
|
||||
}
|
||||
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
long t1 = TickWatch.Ticks;
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
query.findRandomPointAroundCircle(point.getRandomRef(), point.getRandomPt(), radius, filter, f);
|
||||
}
|
||||
|
||||
long t2 = Stopwatch.GetTimestamp();
|
||||
long t2 = TickWatch.Ticks;
|
||||
for (int i = 0; i < 10000; i++)
|
||||
{
|
||||
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 within circle: " + (t3 - t2) / TimeSpan.TicksPerMillisecond + "ms");
|
||||
}
|
||||
|
|
|
@ -188,20 +188,20 @@ public class TileCacheTest : AbstractTileCacheTest
|
|||
layerBuilder.build(order, cCompatibility, threads);
|
||||
}
|
||||
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
long t1 = TickWatch.Ticks;
|
||||
List<byte[]> layers = null;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
layers = layerBuilder.build(order, cCompatibility, 1);
|
||||
}
|
||||
|
||||
long t2 = Stopwatch.GetTimestamp();
|
||||
long t2 = TickWatch.Ticks;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
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 MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond);
|
||||
TileCache tc = getTileCache(geom, order, cCompatibility);
|
||||
|
|
|
@ -96,7 +96,7 @@ public class RecastSoloMeshTest
|
|||
{
|
||||
m_partitionType = partitionType;
|
||||
InputGeomProvider geomProvider = ObjImporter.load(Loader.ToBytes(filename));
|
||||
long time = Stopwatch.GetTimestamp();
|
||||
long time = TickWatch.Ticks;
|
||||
Vector3f bmin = geomProvider.getMeshBoundsMin();
|
||||
Vector3f bmax = geomProvider.getMeshBoundsMax();
|
||||
Telemetry m_ctx = new Telemetry();
|
||||
|
@ -204,7 +204,7 @@ public class RecastSoloMeshTest
|
|||
// you use tiles)
|
||||
// * good choice to use for tiled navmesh with medium and small sized
|
||||
// tiles
|
||||
long time3 = Stopwatch.GetTimestamp();
|
||||
long time3 = TickWatch.Ticks;
|
||||
|
||||
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.nverts, Is.EqualTo(expDetVerts), "Mesh Detail Verts");
|
||||
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(" " + (time3 - time) / TimeSpan.TicksPerMillisecond + " ms");
|
||||
saveObj(filename.Substring(0, filename.LastIndexOf('.')) + "_" + partitionType + "_detail.obj", m_dmesh);
|
||||
|
|
|
@ -106,19 +106,19 @@ public class RecastTileMeshTest
|
|||
build(geom, builder, cfg, 4, true);
|
||||
}
|
||||
|
||||
long t1 = Stopwatch.GetTimestamp();
|
||||
long t1 = TickWatch.Ticks;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
build(geom, builder, cfg, 1, false);
|
||||
}
|
||||
|
||||
long t2 = Stopwatch.GetTimestamp();
|
||||
long t2 = TickWatch.Ticks;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
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 MT : " + (t3 - t2) / TimeSpan.TicksPerMillisecond);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue