/// <summary> /// Internal method. /// Performs trajectory processing procedures. /// (asynchronous execution is assumed) /// </summary> /// <param name="inpData"></param> void PathProcessThreadMethod(object inpData) { CancellationToken cTInstance = cTSInstance.Token; PathProcessParamContainer pPPCInstance = (PathProcessParamContainer)inpData; List <Vector3> newPath = new List <Vector3>(); lock (pPPCInstance.pathToProcess) newPath.AddRange(pPPCInstance.pathToProcess); newPath[newPath.Count - 1] = targetCoord; newPath.Insert(0, pPPCInstance.startPos); if (cTInstance.IsCancellationRequested) { return; } //call optimization functions and smooth trajectory if (pPPCInstance.trajectoryOptimization) { newPath = PathHandler.PathFancification(newPath, pPPCInstance.pathfindingLevel); newPath = PathHandler.PathOptimization(newPath, pPPCInstance.pathfindingLevel); } if (pPPCInstance.trajectorySmoothing) { newPath = PathHandler.PathSmoothing(newPath, pPPCInstance.pathfindingLevel); } if (cTInstance.IsCancellationRequested) { return; } for (int i = 1; i <= newPath.Count - 1; i++) { totalLength += Vector3.Distance(newPath[i - 1], newPath[i]); } lock (finalPath) { finalPath.AddRange(newPath); } if (cTInstance.IsCancellationRequested) { return; } lock (actionsQueue) actionsQueue.Enqueue(pPPCInstance.furtherActions); }
/// <summary> /// Starts trajectory processing procedures (optimization & smoothing) asyncronously. /// </summary> /// <param name="path">Path to process.</param> void ProcessPath(List <Vector3> path) { PathProcessParamContainer pPPCInstance = new PathProcessParamContainer { trajectoryOptimization = trajectoryOptimization, trajectorySmoothing = trajectorySmoothing, pathfindingLevel = this.pathfindingLevel, pathToProcess = foundPath, startPos = thisTransformInstance.position, furtherActions = () => { if (tracePath) { DrawAPath(finalPath); } ThrowUniversalEvent("EventProcessingFinished"); ThrowUniversalEvent("EventMovementStarted"); curCond = Movement; } }; ThreadPool.QueueUserWorkItem(PathProcessThreadMethod, pPPCInstance); }