forked from mirror/DotRecast
added RcCylicBuffer<long> extensions
This commit is contained in:
parent
ad504fe217
commit
01b3bcf771
|
@ -0,0 +1,54 @@
|
|||
namespace DotRecast.Core.Buffers
|
||||
{
|
||||
public static class RcCyclicBuffers
|
||||
{
|
||||
public static long Sum(this RcCyclicBuffer<long> source)
|
||||
{
|
||||
long sum = 0;
|
||||
checked
|
||||
{
|
||||
source.ForEach(x => sum += x);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static double Average(this RcCyclicBuffer<long> source)
|
||||
{
|
||||
if (0 >= source.Size)
|
||||
return 0;
|
||||
|
||||
return source.Sum() / (double)source.Size;
|
||||
}
|
||||
|
||||
public static long Min(this RcCyclicBuffer<long> source)
|
||||
{
|
||||
if (0 >= source.Size)
|
||||
return 0;
|
||||
|
||||
long minValue = long.MaxValue;
|
||||
source.ForEach(x =>
|
||||
{
|
||||
if (x < minValue)
|
||||
minValue = x;
|
||||
});
|
||||
|
||||
return minValue;
|
||||
}
|
||||
|
||||
public static long Max(this RcCyclicBuffer<long> source)
|
||||
{
|
||||
if (0 >= source.Size)
|
||||
return 0;
|
||||
|
||||
long maxValue = long.MinValue;
|
||||
source.ForEach(x =>
|
||||
{
|
||||
if (x > maxValue)
|
||||
maxValue = x;
|
||||
});
|
||||
|
||||
return maxValue;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,18 +90,9 @@ namespace DotRecast.Detour.Crowd
|
|||
}
|
||||
|
||||
cb.PushBack(duration);
|
||||
_executionTimings[name] = CalculateAverage(cb);
|
||||
_executionTimings[name] = (long)cb.Average();
|
||||
}
|
||||
|
||||
private static long CalculateAverage(RcCyclicBuffer<long> buffer)
|
||||
{
|
||||
long sum = 0L;
|
||||
buffer.ForEach(item =>
|
||||
{
|
||||
sum += item;
|
||||
});
|
||||
|
||||
return sum / buffer.Size;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Core.Buffers;
|
||||
using DotRecast.Core.Collections;
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour;
|
||||
|
@ -25,7 +27,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
|
||||
private const int SamplingCount = 500;
|
||||
private long _samplingUpdateTime;
|
||||
private readonly List<long> _updateTimes;
|
||||
private readonly RcCyclicBuffer<long> _updateTimes;
|
||||
private long _curUpdateTime;
|
||||
private long _avgUpdateTime;
|
||||
private long _minUpdateTime;
|
||||
|
@ -36,7 +38,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
_cfg = new RcCrowdAgentProfilingToolConfig();
|
||||
_agCfg = new DtCrowdAgentConfig();
|
||||
_polyPoints = new List<DtPolyPoint>();
|
||||
_updateTimes = new List<long>();
|
||||
_updateTimes = new RcCyclicBuffer<long>(SamplingCount);
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
|
@ -264,12 +266,7 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
}
|
||||
|
||||
var currentTime = endTime - startTime;
|
||||
_updateTimes.Add(currentTime);
|
||||
|
||||
if ((int)(SamplingCount * 1.25f) < _updateTimes.Count)
|
||||
{
|
||||
_updateTimes.RemoveRange(0, _updateTimes.Count - SamplingCount);
|
||||
}
|
||||
_updateTimes.PushBack(currentTime);
|
||||
|
||||
// for benchmark
|
||||
_samplingUpdateTime = _updateTimes.Sum() / TimeSpan.TicksPerMillisecond;
|
||||
|
@ -277,7 +274,6 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
_avgUpdateTime = (long)(_updateTimes.Average() / TimeSpan.TicksPerMillisecond);
|
||||
_minUpdateTime = _updateTimes.Min() / TimeSpan.TicksPerMillisecond;
|
||||
_maxUpdateTime = _updateTimes.Max() / TimeSpan.TicksPerMillisecond;
|
||||
|
||||
}
|
||||
|
||||
private void MoveMob(DtNavMeshQuery navquery, IDtQueryFilter filter, DtCrowdAgent ag, RcCrowdAgentData crowAgentData)
|
||||
|
@ -402,6 +398,5 @@ namespace DotRecast.Recast.Toolset.Tools
|
|||
{
|
||||
return _maxUpdateTime;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue