preventing name conflicts

This commit is contained in:
ikpil 2023-05-06 11:44:57 +09:00
parent e8e328d6af
commit 0f9e61f51e
22 changed files with 66 additions and 66 deletions

View File

@ -4,21 +4,21 @@ namespace DotRecast.Core
{
public class FRand
{
private readonly Random r;
private readonly Random _r;
public FRand()
{
r = new Random();
_r = new Random();
}
public FRand(long seed)
{
r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요
_r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요
}
public float Frand()
public float Next()
{
return (float)r.NextDouble();
return (float)_r.NextDouble();
}
}
}

View File

@ -2,7 +2,7 @@
namespace DotRecast.Core
{
public class AtomicBoolean
public class RcAtomicBoolean
{
private volatile int _location;

View File

@ -2,11 +2,11 @@
namespace DotRecast.Core
{
public class AtomicFloat
public class RcAtomicFloat
{
private volatile float _location;
public AtomicFloat(float location)
public RcAtomicFloat(float location)
{
_location = location;
}

View File

@ -2,15 +2,15 @@
namespace DotRecast.Core
{
public class AtomicInteger
public class RcAtomicInteger
{
private volatile int _location;
public AtomicInteger() : this(0)
public RcAtomicInteger() : this(0)
{
}
public AtomicInteger(int location)
public RcAtomicInteger(int location)
{
_location = location;
}

View File

@ -2,15 +2,15 @@
namespace DotRecast.Core
{
public class AtomicLong
public class RcAtomicLong
{
private long _location;
public AtomicLong() : this(0)
public RcAtomicLong() : this(0)
{
}
public AtomicLong(long location)
public RcAtomicLong(long location)
{
_location = location;
}

View File

@ -3,7 +3,7 @@ using System.Diagnostics;
namespace DotRecast.Core
{
public static class FrequencyWatch
public static class RcFrequency
{
public static readonly double Frequency = (double)TimeSpan.TicksPerSecond / Stopwatch.Frequency;
public static long Ticks => unchecked((long)(Stopwatch.GetTimestamp() * Frequency));

View File

@ -142,7 +142,7 @@ namespace DotRecast.Detour.Crowd
/// dtCrowdAgentParams::queryFilterType
public const int DT_CROWD_MAX_QUERY_FILTER_TYPE = 16;
private readonly AtomicInteger _agentId = new AtomicInteger();
private readonly RcAtomicInteger _agentId = new RcAtomicInteger();
private readonly List<CrowdAgent> _agents;
private readonly PathQueue _pathQ;
private readonly ObstacleAvoidanceParams[] _obstacleQueryParams = new ObstacleAvoidanceParams[DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS];

View File

@ -66,12 +66,12 @@ namespace DotRecast.Detour.Crowd
public void Start(string name)
{
_executionTimings.Add(name, FrequencyWatch.Ticks);
_executionTimings.Add(name, RcFrequency.Ticks);
}
public void Stop(string name)
{
long duration = FrequencyWatch.Ticks - _executionTimings[name];
long duration = RcFrequency.Ticks - _executionTimings[name];
if (!_executionTimingSamples.TryGetValue(name, out var s))
{
s = new List<long>();

View File

@ -38,7 +38,7 @@ namespace DotRecast.Detour.Dynamic
private readonly Telemetry telemetry;
private readonly NavMeshParams navMeshParams;
private readonly BlockingCollection<IUpdateQueueItem> updateQueue = new BlockingCollection<IUpdateQueueItem>();
private readonly AtomicLong currentColliderId = new AtomicLong(0);
private readonly RcAtomicLong currentColliderId = new RcAtomicLong(0);
private NavMesh _navMesh;
private bool dirty = true;

View File

@ -74,8 +74,8 @@ namespace DotRecast.Detour.Extras.Jumplink
{
Vector3f halfExtents = new Vector3f { x = cs, y = heightRange, z = cs };
float maxHeight = pt.y + heightRange;
AtomicBoolean found = new AtomicBoolean();
AtomicFloat minHeight = new AtomicFloat(pt.y);
RcAtomicBoolean found = new RcAtomicBoolean();
RcAtomicFloat minHeight = new RcAtomicFloat(pt.y);
navMeshQuery.QueryPolygons(pt, halfExtents, filter, new PolyQueryInvoker((tile, poly, refs) =>
{
Result<float> h = navMeshQuery.GetPolyHeight(refs, pt);

View File

@ -104,7 +104,7 @@ namespace DotRecast.Detour
// Choose random tile using reservoi sampling.
float area = 1.0f; // Could be tile area too.
tsum += area;
float u = frand.Frand();
float u = frand.Next();
if (u * tsum <= area)
{
tile = mt;
@ -150,7 +150,7 @@ namespace DotRecast.Detour
// Choose random polygon weighted by area, using reservoi sampling.
areaSum += polyArea;
float u = frand.Frand();
float u = frand.Next();
if (u * areaSum <= polyArea)
{
poly = p;
@ -172,8 +172,8 @@ namespace DotRecast.Detour
Array.Copy(tile.data.verts, poly.verts[j] * 3, verts, j * 3, 3);
}
float s = frand.Frand();
float t = frand.Frand();
float s = frand.Next();
float t = frand.Next();
var pt = RandomPointInConvexPoly(verts, poly.vertCount, areas, s, t);
ClosestPointOnPolyResult closest = ClosestPointOnPoly(polyRef, pt).result;
@ -297,7 +297,7 @@ namespace DotRecast.Detour
// Choose random polygon weighted by area, using reservoi sampling.
areaSum += polyArea;
float u = frand.Frand();
float u = frand.Next();
if (u * areaSum <= polyArea)
{
randomPoly = bestPoly;
@ -398,8 +398,8 @@ namespace DotRecast.Detour
}
// Randomly pick point on polygon.
float s = frand.Frand();
float t = frand.Frand();
float s = frand.Next();
float t = frand.Next();
float[] areas = new float[randomPolyVerts.Length / 3];
Vector3f pt = RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t);

View File

@ -459,7 +459,7 @@ public class RecastDemo
cameraPos.y += (float)((_moveUp - _moveDown) * keySpeed * dt);
long time = FrequencyWatch.Ticks;
long time = RcFrequency.Ticks;
prevFrameTime = time;
// Update sample simulation.
@ -525,7 +525,7 @@ public class RecastDemo
float m_detailSampleDist = settingsUI.GetDetailSampleDist();
float m_detailSampleMaxError = settingsUI.GetDetailSampleMaxError();
int m_tileSize = settingsUI.GetTileSize();
long t = FrequencyWatch.Ticks;
long t = RcFrequency.Ticks;
Logger.Information($"build");
@ -549,7 +549,7 @@ public class RecastDemo
sample.Update(sample.GetInputGeom(), buildResult.Item1, buildResult.Item2);
sample.SetChanged(false);
settingsUI.SetBuildTime((FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond);
settingsUI.SetBuildTime((RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond);
//settingsUI.SetBuildTelemetry(buildResult.Item1.Select(x => x.GetTelemetry()).ToList());
toolsUI.SetSample(sample);

View File

@ -86,12 +86,12 @@ public class CrowdProfilingTool
IQueryFilter filter = new DefaultQueryFilter();
for (int i = 0; i < agents; i++)
{
float tr = rnd.Frand();
float tr = rnd.Next();
AgentType type = AgentType.MOB;
float mobsPcnt = percentMobs / 100f;
if (tr > mobsPcnt)
{
tr = rnd.Frand();
tr = rnd.Next();
float travellerPcnt = percentTravellers / 100f;
if (tr > travellerPcnt)
{
@ -161,7 +161,7 @@ public class CrowdProfilingTool
{
if (0 < zones.Count)
{
int zone = (int)(rnd.Frand() * zones.Count);
int zone = (int)(rnd.Next() * zones.Count);
Result<FindRandomPointResult> result = navquery.FindRandomPointWithinCircle(zones[zone].GetRandomRef(),
zones[zone].GetRandomPt(), zoneRadius, filter, rnd);
if (result.Succeeded())
@ -240,7 +240,7 @@ public class CrowdProfilingTool
public void Update(float dt)
{
long startTime = FrequencyWatch.Ticks;
long startTime = RcFrequency.Ticks;
if (crowd != null)
{
crowd.Config().pathQueueSize = pathQueueSize;
@ -248,7 +248,7 @@ public class CrowdProfilingTool
crowd.Update(dt, null);
}
long endTime = FrequencyWatch.Ticks;
long endTime = RcFrequency.Ticks;
if (crowd != null)
{
NavMeshQuery navquery = new NavMeshQuery(navMesh);

View File

@ -677,9 +677,9 @@ public class CrowdTool : Tool
if (nav == null)
return;
long startTime = FrequencyWatch.Ticks;
long startTime = RcFrequency.Ticks;
crowd.Update(dt, m_agentDebug);
long endTime = FrequencyWatch.Ticks;
long endTime = RcFrequency.Ticks;
// Update agent trails
foreach (CrowdAgent ag in crowd.GetActiveAgents())

View File

@ -205,9 +205,9 @@ public class DynamicUpdateTool : Tool
{
Vector3f sp = Vector3f.Of(spos.x, spos.y + 1.3f, spos.z);
Vector3f ep = Vector3f.Of(epos.x, epos.y + 1.3f, epos.z);
long t1 = FrequencyWatch.Ticks;
long t1 = RcFrequency.Ticks;
float? hitPos = dynaMesh.VoxelQuery().Raycast(sp, ep);
long t2 = FrequencyWatch.Ticks;
long t2 = RcFrequency.Ticks;
raycastTime = (t2 - t1) / TimeSpan.TicksPerMillisecond;
raycastHit = hitPos.HasValue;
raycastHitPos = hitPos.HasValue
@ -499,13 +499,13 @@ public class DynamicUpdateTool : Tool
private void UpdateDynaMesh()
{
long t = FrequencyWatch.Ticks;
long t = RcFrequency.Ticks;
try
{
bool updated = dynaMesh.Update(executor).Result;
if (updated)
{
buildTime = (FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
buildTime = (RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond;
sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
sample.SetChanged(false);
}
@ -728,7 +728,7 @@ public class DynamicUpdateTool : Tool
private void BuildDynaMesh()
{
ConfigDynaMesh();
long t = FrequencyWatch.Ticks;
long t = RcFrequency.Ticks;
try
{
var _ = dynaMesh.Build(executor).Result;
@ -738,7 +738,7 @@ public class DynamicUpdateTool : Tool
Console.WriteLine(e);
}
buildTime = (FrequencyWatch.Ticks - t) / TimeSpan.TicksPerMillisecond;
buildTime = (RcFrequency.Ticks - t) / TimeSpan.TicksPerMillisecond;
sample.Update(null, dynaMesh.RecastResults(), dynaMesh.NavMesh());
}

View File

@ -90,7 +90,7 @@ namespace DotRecast.Recast
private Task BuildSingleThreadAsync(IInputGeomProvider geom, RecastConfig cfg, Vector3f bmin, Vector3f bmax,
int tw, int th, List<RecastBuilderResult> results)
{
AtomicInteger counter = new AtomicInteger(0);
RcAtomicInteger counter = new RcAtomicInteger(0);
for (int y = 0; y < th; ++y)
{
for (int x = 0; x < tw; ++x)
@ -105,7 +105,7 @@ namespace DotRecast.Recast
private Task BuildMultiThreadAsync(IInputGeomProvider geom, RecastConfig cfg, Vector3f bmin, Vector3f bmax,
int tw, int th, List<RecastBuilderResult> results, TaskFactory taskFactory, CancellationToken cancellationToken)
{
AtomicInteger counter = new AtomicInteger(0);
RcAtomicInteger counter = new RcAtomicInteger(0);
CountdownEvent latch = new CountdownEvent(tw * th);
List<Task> tasks = new List<Task>();
@ -153,7 +153,7 @@ namespace DotRecast.Recast
}
private RecastBuilderResult BuildTile(IInputGeomProvider geom, RecastConfig cfg, Vector3f bmin, Vector3f bmax, int tx,
int ty, AtomicInteger counter, int total)
int ty, RcAtomicInteger counter, int total)
{
RecastBuilderResult result = Build(geom, new RecastBuilderConfig(cfg, bmin, bmax, tx, ty));
if (progressListener != null)

View File

@ -162,7 +162,7 @@ namespace DotRecast.Recast
}
private static bool CircumCircle(float[] verts, int p1, int p2, int p3, ref Vector3f c, AtomicFloat r)
private static bool CircumCircle(float[] verts, int p1, int p2, int p3, ref Vector3f c, RcAtomicFloat r)
{
float EPS = 1e-6f;
// Calculate the circle relative to p1, to avoid some precision issues.
@ -545,7 +545,7 @@ namespace DotRecast.Recast
// Find best point on left of edge.
int pt = npts;
Vector3f c = new Vector3f();
AtomicFloat r = new AtomicFloat(-1f);
RcAtomicFloat r = new RcAtomicFloat(-1f);
for (int u = 0; u < npts; ++u)
{
if (u == s || u == t)

View File

@ -28,19 +28,19 @@ namespace DotRecast.Recast
{
public class Telemetry
{
private readonly ThreadLocal<Dictionary<string, AtomicLong>> timerStart = new ThreadLocal<Dictionary<string, AtomicLong>>(() => new Dictionary<string, AtomicLong>());
private readonly ConcurrentDictionary<string, AtomicLong> timerAccum = new ConcurrentDictionary<string, AtomicLong>();
private readonly ThreadLocal<Dictionary<string, RcAtomicLong>> timerStart = new ThreadLocal<Dictionary<string, RcAtomicLong>>(() => new Dictionary<string, RcAtomicLong>());
private readonly ConcurrentDictionary<string, RcAtomicLong> timerAccum = new ConcurrentDictionary<string, RcAtomicLong>();
public void StartTimer(string name)
{
timerStart.Value[name] = new AtomicLong(FrequencyWatch.Ticks);
timerStart.Value[name] = new RcAtomicLong(RcFrequency.Ticks);
}
public void StopTimer(string name)
{
timerAccum
.GetOrAdd(name, _ => new AtomicLong(0))
.AddAndGet(FrequencyWatch.Ticks - timerStart.Value?[name].Read() ?? 0);
.GetOrAdd(name, _ => new RcAtomicLong(0))
.AddAndGet(RcFrequency.Ticks - timerStart.Value?[name].Read() ?? 0);
}
public void Warn(string @string)

View File

@ -123,19 +123,19 @@ public class RandomPointTest : AbstractDetourTest
query.FindRandomPointWithinCircle(point.GetRandomRef(), point.GetRandomPt(), radius, filter, f);
}
long t1 = FrequencyWatch.Ticks;
long t1 = RcFrequency.Ticks;
for (int i = 0; i < 10000; i++)
{
query.FindRandomPointAroundCircle(point.GetRandomRef(), point.GetRandomPt(), radius, filter, f);
}
long t2 = FrequencyWatch.Ticks;
long t2 = RcFrequency.Ticks;
for (int i = 0; i < 10000; i++)
{
query.FindRandomPointWithinCircle(point.GetRandomRef(), point.GetRandomPt(), radius, filter, f);
}
long t3 = FrequencyWatch.Ticks;
long t3 = RcFrequency.Ticks;
Console.WriteLine("Random point around circle: " + (t2 - t1) / TimeSpan.TicksPerMillisecond + "ms");
Console.WriteLine("Random point within circle: " + (t3 - t2) / TimeSpan.TicksPerMillisecond + "ms");
}

View File

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

View File

@ -97,7 +97,7 @@ public class RecastSoloMeshTest
{
m_partitionType = partitionType;
IInputGeomProvider geomProvider = ObjImporter.Load(Loader.ToBytes(filename));
long time = FrequencyWatch.Ticks;
long time = RcFrequency.Ticks;
Vector3f bmin = geomProvider.GetMeshBoundsMin();
Vector3f bmax = geomProvider.GetMeshBoundsMax();
Telemetry m_ctx = new Telemetry();
@ -205,7 +205,7 @@ public class RecastSoloMeshTest
// you use tiles)
// * good choice to use for tiled navmesh with medium and small sized
// tiles
long time3 = FrequencyWatch.Ticks;
long time3 = RcFrequency.Ticks;
if (m_partitionType == PartitionType.WATERSHED)
{
@ -257,7 +257,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 = FrequencyWatch.Ticks;
long time2 = RcFrequency.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);

View File

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