public void Execute() { DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity]; pathPositionBuffer.Clear(); PathfindingParams pathfindingParams = pathfindingParamsComponentDataFromEntity[entity]; int endNodeIndex = CalculateIndex(pathfindingParams.endPosition.x, pathfindingParams.endPosition.y, gridSize.x); PathNode endNode = pathNodeArray[endNodeIndex]; if (endNode.cameFromNodeIndex == -1) { // Didn't find a path! //Debug.Log("Didn't find a path!"); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = -1 }; } else { // Found a path CalculatePath(pathNodeArray, endNode, pathPositionBuffer); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = pathPositionBuffer.Length - 1 }; } }
public void Execute() { DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity]; pathPositionBuffer.Clear(); PathfindingParams pathfindingParams = pathfindingParamsComponentDataFromEntity[entity]; int endNodeIndex = CalculateIndex(pathfindingParams.endPosition.x, pathfindingParams.endPosition.y, gridSize.x); // Выход за пределы карты if (endNodeIndex >= gridSize.x * gridSize.y && endNodeIndex >= 0) { pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = -1 }; return; } PathNode endNode = pathNodeArray[endNodeIndex]; if (endNode.cameFromNodeIndex == -1) { // Didn't find a path! pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = -1 }; } else { // Found a path CalculatePath(pathNodeArray, endNode, pathPositionBuffer); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = pathPositionBuffer.Length - 1 }; } }
public void Execute() { DynamicBuffer <PathPosition> pathPositionBuffer = pathPositionBufferFromEntity[entity]; pathPositionBuffer.Clear(); PathfindingParams pathfindingParams = pathfindingParamsComponentDataFromEntity[entity]; CalculatePath(startPosition, endPosition, pathPositionBuffer, pathFound); pathFollowComponentDataFromEntity[entity] = new PathFollow { pathIndex = pathPositionBuffer.Length - 2, NewPath = true }; var buffer = CostSoFar.GetUnsafePtr(); UnsafeUtility.MemClear(buffer, (long)CostSoFar.Length * UnsafeUtility.SizeOf <float>()); OpenSet.Clear(); }
protected override JobHandle OnUpdate(JobHandle jobHandle) { if (!initialized) { initializePersistentArrays(numberWorkerThreads, gridParams); initialized = true; } //QuadTree.ClearAndBulkInsert(obstacleArray); //NativeList<ObstacleStruct> queryResult = new NativeList<ObstacleStruct>(Allocator.Temp); //QuadTree.RangeQuery(new NativeQuadTree.AABB2D(new float2(500, 500), new float2(1000, 1000)), queryResult); //Debug.Log(queryResult); EntityCommandBuffer concurrentCommandBuffer = entityCommandBufferSystem.CreateCommandBuffer(); EntityQuery entityQuery = GetEntityQuery(ComponentType.ReadOnly <PathfindingParams>()); NativeArray <PathfindingParams> pathFindingArray = entityQuery.ToComponentDataArray <PathfindingParams>(Allocator.TempJob); NativeArray <Entity> entityArray = entityQuery.ToEntityArray(Allocator.TempJob); NativeArray <JobHandle> jobHandles = new NativeArray <JobHandle>(jobCollections.Count, Allocator.TempJob); for (int index = 0; index < jobCollections.Count; index++) { jobHandles[index] = jobHandle; } for (int r = 0; r < entityArray.Length; r++) { int index = r % jobCollections.Count; jobCollection data = jobCollections[index]; PathfindingParams pathfindingParams = pathFindingArray[r]; FindPathJob findPathJob = new FindPathJob { DimX = gridParams.x, DimY = gridParams.y, Neighbours = neighbourOffsetArray, startPosition = pathfindingParams.startPosition, endPosition = pathfindingParams.endPosition, itterationLimit = itterationLimit, Grid = ObstacleController.instance.getNativeMap(), CostSoFar = data.CostSoFar, CameFrom = data.CameFrom, entity = entityArray[r], OpenSet = data.OpenSet }; JobHandle findPathHandle = findPathJob.Schedule(jobHandles[index]); ResetJob resetJob = new ResetJob { CostSoFar = data.CostSoFar, OpenSet = data.OpenSet, CameFrom = data.CameFrom, DimX = gridParams.x, entity = entityArray[r], pathFound = data.foundPath, pathfindingParamsComponentDataFromEntity = GetComponentDataFromEntity <PathfindingParams>(), pathFollowComponentDataFromEntity = GetComponentDataFromEntity <PathFollow>(), pathPositionBufferFromEntity = GetBufferFromEntity <PathPosition>(), startPosition = pathfindingParams.startPosition, endPosition = pathfindingParams.endPosition, }; jobHandles[index] = resetJob.Schedule(findPathHandle); //PostUpdateCommands.RemoveComponent<PathfindingParams>(entity); concurrentCommandBuffer.RemoveComponent <PathfindingParams>(entityArray[r]); } jobHandle = JobHandle.CombineDependencies(jobHandles); entityCommandBufferSystem.AddJobHandleForProducer(jobHandle); entityArray.Dispose(); pathFindingArray.Dispose(); jobHandles.Dispose(); return(jobHandle); }