private void PathFindThread()
{
//Stopwatch stopwatch = new Stopwatch();
//long count = 0;
//long totalMs = 0;
while (true)
{
while (!Monitor.TryEnter(this.m_queueLock, SimulationManager.SYNCHRONIZE_TIMEOUT))
{
}
try
{
while (this.m_queueFirst == 0u && !this.m_terminated)
{
Monitor.Wait(this.m_queueLock);
}
if (this.m_terminated)
{
break;
}
this.m_calculating = this.m_queueFirst;
this.m_queueFirst = this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_nextPathUnit;
if (this.m_queueFirst == 0u)
{
this.m_queueLast = 0u;
this.m_queuedPathFindCount = 0;
}
else
{
this.m_queuedPathFindCount--;
}
this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_nextPathUnit = 0u;
this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_pathFindFlags = (byte)(((int)this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_pathFindFlags & -2) | 2);
}
finally
{
Monitor.Exit(this.m_queueLock);
}
try
{
this.m_pathfindProfiler.BeginStep();
try
{
//stopwatch.Reset();
//stopwatch.Start();
this.PathFindImplementation(this.m_calculating, ref this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)]);
//stopwatch.Stop();
//totalMs += stopwatch.ElapsedMilliseconds;
//count++;
//if (count == 10000)
//{
// System.IO.File.AppendAllText("TimeThread" + Thread.CurrentThread.ManagedThreadId + ".txt", "\n\nMs\nTime to calculate 100,000 Paths: " + totalMs + " ms\nAverage time/path: " + ((double)totalMs / count) + "ms\n");
//}
}
finally
{
this.m_pathfindProfiler.EndStep();
}
}
catch (Exception ex)
{
UIView.ForwardException(ex);
CODebugBase<LogChannel>.Error(LogChannel.Core, "Path find error: " + ex.Message/* + " - " + m_vehicleType + " - " + m_vehicleTypes*/ + "\n" + ex.StackTrace);
PathUnit[] expr_1A0_cp_0 = this.m_pathUnits.m_buffer;
UIntPtr expr_1A0_cp_1 = (UIntPtr)this.m_calculating;
expr_1A0_cp_0[(int)expr_1A0_cp_1].m_pathFindFlags = (byte)(expr_1A0_cp_0[(int)expr_1A0_cp_1].m_pathFindFlags | 8);
}
while (!Monitor.TryEnter(this.m_queueLock, SimulationManager.SYNCHRONIZE_TIMEOUT))
{
}
try
{
this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_pathFindFlags = (byte)((int)this.m_pathUnits.m_buffer[(int)((UIntPtr)this.m_calculating)].m_pathFindFlags & -3);
Singleton<PathManager>.instance.ReleasePath(this.m_calculating);
this.m_calculating = 0u;
Monitor.Pulse(this.m_queueLock);
}
finally
{
Monitor.Exit(this.m_queueLock);
}
}
//System.IO.File.AppendAllText("TimeThread" + Thread.CurrentThread.ManagedThreadId + ".txt", "\n\nMs\nTime to calculate " + count + " Paths: " + totalMs + " ms\nAverage time/path: " + ((double)totalMs / count) + "ms\n");
}