//public int _threadFinishedCount = 0; // int _mSIdx;//main thread start idx in _allAgents // int _mEIdx;//main thread end idx in _allAgents public PathFindingManager(FP scale) { _tasks = new List <AgentsTask>(); _flowManager = new FlowFieldManager(); int taskCount = 0; // _destroyed = false; #if MULTI_THREAD int cps; ThreadPool.GetMinThreads(out taskCount, out cps); //#if UNITY_EDITOR UnityEngine.Debug.LogError("thread count______:" + taskCount); //#endif taskCount = 2; #endif // _taskEvents = new ManualResetEvent[taskCount]; _pathManagers = new PathManager[taskCount + 1]; int i = 0; for (i = 0; i < taskCount; i++) { AgentsTask task = AgentsTask.Create(i, this); _tasks.Add(task); // _taskEvents[i] = task._finished; _pathManagers[i] = new PathManager(); } _pathManagers[i] = new PathManager(); #if USING_DYNAMIC_TREE _dynamicTree = new DynamicTree <PathFindingAgentBehaviour>(); _dynamicTree.c_aabbExtension *= scale; #endif }
internal static AgentsTask Create(int idx, PathFindingManager pfm) { AgentsTask task = new AgentsTask(); task._finished = new ManualResetEvent(true); task._runFlag = new ManualResetEvent(false); // new AutoResetEvent(false); task._pathIdx = idx; task._pfm = pfm; task._threadHanldeStep = -1; task.terminate = false; task.thread = new Thread(new ThreadStart(task.ThreadHandle)); // task.thread.Priority = ThreadPriority.Highest; task.thread.Start(); // task.context = new WorkerContext(); return(task); }