protected override void OnUpdate() { if (pathNodeArray.IsCreated == false) { ObstacleController.instance.initializePathNodeArray(gridWidth, gridHeight); //TODO: I don't know if in need to fetch this from the obstacle controller each update because it is a struct and not a reference pathNodeArray = ObstacleController.instance.GetPathNodeArray(); } if (nativeInt == null) { nativeInt = new NativeArray <int>(); } List <FindPathJob> findPathJobList = new List <FindPathJob>(); NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); Entities.ForEach((Entity entity, ref PathfindingParams pathfindingParams) => { // NativeArray<PathNode> tmpPathNodeArray = new NativeArray<PathNode>(pathNodeArray, Allocator.TempJob); FindPathJob findPathJob = new FindPathJob { gridSize = gridSize, pathNodeArray = new NativeArray <OldPathNode>(pathNodeArray, Allocator.TempJob), startPosition = pathfindingParams.startPosition, endPosition = pathfindingParams.endPosition, entity = entity, neighbourOffsetArray = neighbourOffsetArray }; findPathJobList.Add(findPathJob); jobHandleList.Add(findPathJob.Schedule()); //tmpPathNodeArray.Dispose(); PostUpdateCommands.RemoveComponent <PathfindingParams>(entity); }); JobHandle.CompleteAll(jobHandleList); foreach (FindPathJob findPathJob in findPathJobList) { new SetBufferPathJob { entity = findPathJob.entity, gridSize = findPathJob.gridSize, pathNodeArray = findPathJob.pathNodeArray, pathfindingParamsComponentDataFromEntity = GetComponentDataFromEntity <PathfindingParams>(), pathFollowComponentDataFromEntity = GetComponentDataFromEntity <PathFollow>(), pathPositionBufferFromEntity = GetBufferFromEntity <PathPosition>(), }.Run(); } //pathNodeArray.Dispose(); }
protected override void OnUpdate() { Profiler.BeginSample("GatherChunks"); for (var i = 0; i < authorityLossDetails.Count; i++) { var replicator = authorityLossDetails[i]; chunkArrayCache[i] = replicator.Group.CreateArchetypeChunkArray(Allocator.TempJob, out var jobHandle); gatheringJobs[i] = jobHandle; } Profiler.EndSample(); JobHandle.CompleteAll(gatheringJobs); for (var i = 0; i < authorityLossDetails.Count; i++) { var details = authorityLossDetails[i]; var chunkArray = chunkArrayCache[i]; Profiler.BeginSample("AcknowledgingAuthorityLoss"); details.Handler.AcknowledgeAuthorityLoss(chunkArray, this, updateSystem); Profiler.EndSample(); chunkArray.Dispose(); } }
protected override void OnUpdate() { var jobHandlerArray = new NativeList <JobHandle>(Allocator.TempJob); gird = PathFindingSetup.Instance.pathfindingGrid; Entities.ForEach((Entity entity, ref MonkeyPrefab monkeyPrefab, ref Translation translation) => { for (var i = 0; i < SpwanNum; i++) { // var job = new SpawnMonkeyJob // { // monkeyEntity = monkeyPrefab.monkeyEntity, // entityManager = EntityManager, // }; // // jobHandlerArray.Add(job.Schedule()); var newEntity = EntityManager.Instantiate(monkeyPrefab.monkeyEntity); gird.GetXY(translation.Value, out var startX, out var startY); EntityManager.AddComponentData(newEntity, new PathFindingParam { startPos = new int2(startX, startY), endPos = new int2(random.NextInt(0, 30), random.NextInt(0, 15)), }); } }); JobHandle.CompleteAll(jobHandlerArray); jobHandlerArray.Dispose(); SpwanNum = 0; }
// Update is called once per frame void Update() { float startTime = Time.realtimeSinceStartup; if (!useJobs) { for (int i = 0; i < 10; i++) { Helper.ReallyToughTask(); } } else { NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); for (int i = 0; i < 10; i++) { JobHandle jobHandle = ReallyTouchTaskJob(); jobHandleList.Add(jobHandle); } //等待所有线程完成 JobHandle.CompleteAll(jobHandleList); jobHandleList.Dispose(); } float endTime = Time.realtimeSinceStartup; Debug.Log($"Cost Time:{(endTime-startTime)*1000} ms"); }
//Pass in a list of chunks to be generated, and it will call jobs to get noise values for private void GenerateMap(List <chunkCenter> cCenters, int size) { if (cCenters.Count <= 0) { return; } NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); List <List <NativeArray <float> > > tileNoiseLists = new List <List <NativeArray <float> > >(); int index = 0; bool newTilesGenerated = false; foreach (var noise in noiseParameterLists) { tileNoiseLists.Add(new List <NativeArray <float> >()); } foreach (var c in cCenters) { if (!chunkExistsOnFile(c)) { index = 0; foreach (var nList in tileNoiseLists) { jobHandleList.Add(GenerateNewChunk(c, size, nList, noiseParameterLists[index++])); } newTilesGenerated = true; } } JobHandle.CompleteAll(jobHandleList); if (newTilesGenerated) { StartCoroutine(SetMapTiles(tileNoiseLists, cCenters, size)); } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //NativeQueue<CrashInfo> destroyedPlanetoidsQueue = new NativeQueue<CrashInfo>(Allocator.TempJob); EntityQuery entityQuery = GetEntityQuery(typeof(Planetoid)); NativeArray <Planetoid> planetoids = entityQuery.ToComponentDataArray <Planetoid>(Allocator.TempJob); NativeArray <int> keys = QuadrantSystem.quadrantMultiHashMap.GetKeyArray(Allocator.TempJob); NativeArray <JobHandle> jobHandles = new NativeArray <JobHandle>(keys.Length, Allocator.TempJob); for (int i = 0; i < keys.Length; i++) { NativeArray <EntityWithProps> entityWithPropsArray = new NativeArray <EntityWithProps>(QuadrantSystem.GetEntityCountInQuadrant(QuadrantSystem.quadrantMultiHashMap, keys[i]), Allocator.TempJob); SortPositionsJob sortPositionsJob = new SortPositionsJob { quadrantMultiHashMap = QuadrantSystem.quadrantMultiHashMap, entityWithPropsArray = entityWithPropsArray, realtimeSinceStartUp = Time.realtimeSinceStartup, planetoids = planetoids, keys = keys, index = i }; jobHandles[i] = sortPositionsJob.Schedule(); } JobHandle job = JobHandle.CombineDependencies(jobHandles); JobHandle.CompleteAll(jobHandles); jobHandles.Dispose(); keys.Dispose(); //destroyedPlanetoidsQueue.Dispose(); DisableJob disableJob = new DisableJob { entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent() }; JobHandle jobHandle = disableJob.Schedule(this, job);//TODO try job handles combine endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); AddTranslationJob addTranslationJob = new AddTranslationJob { seed = UnityEngine.Random.Range(1, 1000000), realTimeSinceStartUp = Time.realtimeSinceStartup, entityCommandBuffer = endPresentationSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), cameraMaxLeftDown = Camera.main.ViewportToWorldPoint(new Vector3(0, 0)), cameraMaxRightUp = Camera.main.ViewportToWorldPoint(new Vector3(1, 1)) }; jobHandle = addTranslationJob.Schedule(this, jobHandle); endPresentationSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); return(jobHandle); }
private void Update_Original() { float startTime = Time.realtimeSinceStartup; if (useJobs) { NativeList <JobHandle> jobHandles = new NativeList <JobHandle>(Allocator.Temp); for (int i = 0; i < 10; i++) { JobHandle jobHandle = ReallyToughTaskJob(); jobHandles.Add(jobHandle); } JobHandle.CompleteAll(jobHandles); jobHandles.Dispose(); } else { for (int i = 0; i < 10; i++) { ReallyToughTask(50000); } } Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms"); }
protected override void OnUpdate() { int2 gridSize = new int2(PathfindingGridSetup.Instance.pathfindingGrid.GetWidth(), PathfindingGridSetup.Instance.pathfindingGrid.GetHeight()); // Everytime an entity recieves a pathfinding param, its going to run pathfinding and then // remove the pathfinding param NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); Entities.ForEach((Entity entity, DynamicBuffer <PathPositionBuffer> pathPositionBuffer, ref PathfindingParams pathfindingParams) => { //Debug.Log("Find Path!"); FindPathJob findPathJob = new FindPathJob { pathNodeArray = GetPathNodeArray(), gridSize = gridSize, startPosition = pathfindingParams.startPosition, endPosition = pathfindingParams.endPosition, pathPositionBufferFromEntity = GetBufferFromEntity <PathPositionBuffer>(), pathFollowComponentDataFromEntity = GetComponentDataFromEntity <PathFollowComp>(), entity = entity }; jobHandleList.Add(findPathJob.Schedule()); //findPathJob.Run(); // remove to make sure pathfinding only runs once per entity PostUpdateCommands.RemoveComponent <PathfindingParams>(entity); }); JobHandle.CompleteAll(jobHandleList); jobHandleList.Dispose(); }
protected override void OnUpdate() { //List<PathfindingJobGrid> jobs = new List<PathfindingJobGrid>(); NativeList <JobHandle> handles = new NativeList <JobHandle>(Allocator.Temp); Grid <GridPathNode> grid = GameWorldManager.Instance().grid; NativeArray <GridPathNode> nodes = GetArrayFromGrid(grid); int2 gridSize = new int2(grid.Width, grid.Height); //double startA = UnityEngine.Time.realtimeSinceStartup; Entities.ForEach((Entity e, ref GridPathRequest pathRequest) => { NativeArray <GridPathNode> tmpNodes = new NativeArray <GridPathNode>(nodes, Allocator.TempJob); handles.Add(new PathfindingJobGrid { gridSize = gridSize, nodes = tmpNodes, start = pathRequest.start, end = pathRequest.end }.Schedule()); //jobs.Add(job); //job.Schedule()); PostUpdateCommands.RemoveComponent <PathRequest>(e); }); //double endA = UnityEngine.Time.realtimeSinceStartup; //Debug.Log("A: " + (endA - startA)); JobHandle.CompleteAll(handles); //jobs.Clear(); nodes.Dispose(); handles.Dispose(); }
protected override void OnUpdate() { if (m_DiffersPerContainer.Count == 0) { return; } var version = World.EntityManager.GlobalSystemVersion; var handles = new NativeArray <JobHandle>(m_DiffersPerContainer.Count, Allocator.Temp); var handleIdx = 0; foreach (var differ in m_DiffersPerContainer.Values) { handles[handleIdx++] = differ.GetDiffSinceLastFrameAsync(); } JobHandle.CompleteAll(handles); handles.Dispose(); var sceneManagerDirty = m_SceneMappingSystem.SceneManagerDirty; m_SceneMappingSystem.Update(); foreach (var kvp in m_DiffersPerContainer) { kvp.Value.ApplyDiffResultsToStrategy(version, out var strategyStateChanged); if (sceneManagerDirty || strategyStateChanged) { kvp.Key.OnStructuralChangeDetected(); } } }
void Update() { float startTime = Time.realtimeSinceStartup; if (useJob) { // В одном потоке //JobHandle jobHandle = ReallyToughTaskJob(); //jobHandle.Complete(); // Вызов в различных потоках // Выигрыш составит в [ количество процессоров ] раз. Это если без [BurstCompile]. // C [BurstCompile] выигрыш огромный NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); for (int i = 0; i < 10; i++) { JobHandle jobHandle = ReallyToughTaskJob(); jobHandleList.Add(jobHandle); } JobHandle.CompleteAll(jobHandleList); jobHandleList.Dispose(); } else { ReallyToughTask(); } Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms"); }
private void OnDestroy() { JobHandle.ScheduleBatchedJobs(); JobHandle.CompleteAll(ref _MoveJob, ref _SceneJob); _Transforms.Dispose(); _Positions.Dispose(); }
protected override void OnUpdate() { if (!connection.IsConnected()) { return; } Profiler.BeginSample("GatherChunks"); for (var i = 0; i < componentReplicators.Count; i++) { var replicator = componentReplicators[i]; var eventIndex = i; var commandIndex = componentReplicators.Count + i; chunkArrayCache[eventIndex] = replicator.EventGroup.CreateArchetypeChunkArray(Allocator.TempJob, out var eventJobHandle); chunkArrayCache[commandIndex] = replicator.CommandGroup.CreateArchetypeChunkArray(Allocator.TempJob, out var commandJobHandle); gatheringJobs[eventIndex] = eventJobHandle; gatheringJobs[commandIndex] = commandJobHandle; } Profiler.EndSample(); JobHandle.CompleteAll(gatheringJobs); ReplicateEvents(); ReplicateCommands(); }
void Update() { float time = Time.realtimeSinceStartup; if (useJobs == true) { NativeList <JobHandle> joblist = new NativeList <JobHandle>(Allocator.Temp); for (int j = 0; j < 100; j++) { JobHandle job = GetJob(); joblist.Add(job); } JobHandle.CompleteAll(joblist); joblist.Dispose(); } else { for (int j = 0; j < 100; j++) { float x = 0.0f; for (int i = 0; i < 10000; i++) { x = math.exp10(math.sqrt(x)); } } } Debug.Log((Time.realtimeSinceStartup - time) * 1000f + " ms"); }
/// <summary> /// 释放,如果为true,则重新加载数据 /// 注意,该操作会释放大量GC /// </summary> /// <param name="isReset"></param> public void Dispose(bool isReset) { JobHandle.CompleteAll(handleList.AsArray()); pointReadList.Dispose(); pointReadWriteList.Dispose(); pointTransformsList.Dispose(); constraintReadList1.Dispose(); ConstraintReadByPointIndex.Dispose(); for (int i = 0; i < constraintReadList.Length; i++) { constraintReadList[i].Dispose(); } if (isReset) { pointTransformsList = new TransformAccessArray(0); m_constraintList = new List <ConstraintRead[]>(); m_pointReadList = new List <PointRead>(); m_pointReadWriteList = new List <PointReadWrite>(); } else { handleList.Dispose(); collidersReadList.Dispose(); collidersReadWriteList.Dispose(); colliderTransformsList.Dispose(); } }
// Start is called before the first frame update private void Update() { float numbershit = Time.realtimeSinceStartup; if (useJobs) { NativeList <JobHandle> jobHandlesList = new NativeList <JobHandle>(Allocator.Temp); for (int i = 0; i < 10; i++) // Create 10 jobs { jobHandlesList.Add(TaskJob()); } JobHandle.CompleteAll(jobHandlesList); jobHandlesList.Dispose(); // Always dispose lists } else { for (int i = 0; i < 10; i++) // Create 10 jobs { Task(); } } Debug.Log($"{(Time.realtimeSinceStartup - numbershit) * 1000f } ms"); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var sumNoTag = CreateJob(_noTagEntities, _allocatedArrays[0]); var noTagHandler = sumNoTag.ScheduleBatch(_noTagEntities.CalculateLength(), sumNoTag.EntitiesInButch); var sumFirstTag = CreateJob(_firstTagEntities, _allocatedArrays[1]); var firstTagHandler = sumFirstTag.ScheduleBatch(_firstTagEntities.CalculateLength(), sumFirstTag.EntitiesInButch); var sumSecodTag = CreateJob(_secondTagEntities, _allocatedArrays[2]); var secondTagHandler = sumSecodTag.ScheduleBatch(_secondTagEntities.CalculateLength(), sumSecodTag.EntitiesInButch); var sumAll = CreateJob(_allRandomEntities, _allocatedArrays[3]); var handlerAll = sumAll.ScheduleBatch(_allRandomEntities.CalculateLength(), sumAll.EntitiesInButch); _jobHandler[0] = handlerAll; _jobHandler[1] = noTagHandler; _jobHandler[2] = firstTagHandler; _jobHandler[3] = secondTagHandler; JobHandle.CompleteAll(_jobHandler); double noTagsSum = CalcSum(sumNoTag.Sums); double firstTagSum = CalcSum(sumFirstTag.Sums); double secondTagSum = CalcSum(sumSecodTag.Sums); double totalSum = CalcSum(sumAll.Sums); InitializeChunkIterationWorld.LogSumResults(this, noTagsSum, firstTagSum, secondTagSum, totalSum); return(base.OnUpdate(inputDeps)); }
public override void Dispose() { var jhs = new NativeArray <JobHandle>(readHandles.Values.Count + writeHandles.Values.Count, Allocator.TempJob); int i = 0; foreach (var h in readHandles.Values) { jhs[i] = h; i++; } foreach (var h in writeHandles.Values) { jhs[i] = h; i++; } JobHandle.CompleteAll(jhs); jhs.Dispose(); var djhs = new NativeList <JobHandle>(isNotInitialized.Count, Allocator.TempJob); foreach (var pair in isNotInitialized) { if (!pair.Value) { djhs.AddNoResize(storage[pair.Key].Dispose(default));
/// <inheritdoc /> protected override void OnUpdate() { this.producerHandle.Complete(); this.producerHandle = default; var handles = new NativeArray <JobHandle>(this.types.Count + this.bufferTypes.Count, Allocator.TempJob); int index = 0; foreach (var t in this.types) { handles[index++] = t.Value.Update(this.EntityManager); } foreach (var t in this.bufferTypes) { handles[index++] = t.Value.Update(this.EntityManager); } JobHandle.CompleteAll(handles); handles.Dispose(); foreach (var t in this.types) { t.Value.Reset(); } foreach (var t in this.bufferTypes) { t.Value.Reset(); } }
private void Update() { float startTime = Time.realtimeSinceStartup; if (useJobs) { NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); for (int i = 0; i < 10; i++) { JobHandle jobHandle = ExampleThoughTaskJob(); jobHandleList.Add(jobHandle); //jobHandle.Complete(); } JobHandle.CompleteAll(jobHandleList); jobHandleList.Dispose(); } else { for (int i = 0; i < 10; i++) { ExampleThoughTask(); } } Debug.Log(((Time.realtimeSinceStartup - startTime) * 1000f) + "ms"); }
protected override void OnUpdate() { var componentUpdateSystem = World.GetExistingSystem <ComponentUpdateSystem>(); Profiler.BeginSample("GatherChunks"); for (var i = 0; i < componentReplicators.Count; i++) { var replicator = componentReplicators[i]; chunkArrayCache[i] = replicator.Group.CreateArchetypeChunkArray(Allocator.TempJob, out var jobHandle); gatheringJobs[i] = jobHandle; } Profiler.EndSample(); JobHandle.CompleteAll(gatheringJobs); for (var i = 0; i < componentReplicators.Count; i++) { var replicator = componentReplicators[i]; var chunkArray = chunkArrayCache[i]; Profiler.BeginSample("ExecuteReplication"); replicator.Handler.SendUpdates(chunkArray, this, EntityManager, componentUpdateSystem); Profiler.EndSample(); chunkArray.Dispose(); } }
private void OnDestroy() { JobHandle.ScheduleBatchedJobs(); JobHandle.CompleteAll(ref _moveJob, ref _updateTransformJob); _positions.Dispose(); _transforms.Dispose(); }
protected override void OnDestroy() { m_playbackInstances.Clear(); JobHandle.CompleteAll(m_jobHandles); m_jobHandles.Dispose(); foreach (var ecb in m_entityCommandBuffers) { ecb.Dispose(); } foreach (var ecb in m_enableCommandBuffers) { ecb.Dispose(); } foreach (var dcb in m_disableCommandBuffers) { dcb.Dispose(); } foreach (var dcb in m_destroyCommandBuffers) { dcb.Dispose(); } foreach (var icb in m_instantiateCommandBuffersWithoutData) { icb.Dispose(); } foreach (var icb in m_instantiateCommandBuffersUntyped) { icb.Dispose(); } }
protected override void OnUpdate() { var chunks = _group.CreateArchetypeChunkArray(Allocator.TempJob); var jobHandles = new NativeArray <JobHandle>(SetUpData.ChunkCount, Allocator.Persistent); var archetypeDataComponent = GetArchetypeChunkBufferType <DataComponent>(); var counter = 0; // ReSharper disable once ForCanBeConvertedToForeach for (var i = 0; i < chunks.Length; i++) { var chunk = chunks[i]; var dataComponents = chunk.GetBufferAccessor(archetypeDataComponent); for (var j = 0; j < dataComponents.Length; j++) { var dataComponent = dataComponents[j]; jobHandles[counter] = new Job { DataComponent = (DataComponent *)dataComponent.GetUnsafePtr(), }.Schedule(dataComponent.Length, SetUpData.BatchCountMultipleJobs); counter++; } } JobHandle.CompleteAll(jobHandles); jobHandles.Dispose(); chunks.Dispose(); }
protected override void OnUpdate() { using (completingJobsMarker.Auto()) { JobHandle.CompleteAll(replicationHandles); } replicationHandles.Clear(); using (updateQueueMarker.Auto()) { foreach (var componentQueue in componentQueues) { while (componentQueue.TryDequeue(out var updateToSend)) { worker.MessagesToSend.AddSerializedComponentUpdate(updateToSend); } componentQueue.Dispose(); } } worker.SendMessages(netFrameStats); networkStatisticsSystem.AddOutgoingSample(netFrameStats); netFrameStats.Clear(); componentQueues.Clear(); }
protected override void OnUpdate() { Profiler.BeginSample("GatherChunks"); for (var i = 0; i < componentCleanups.Count; i++) { var replicator = componentCleanups[i]; chunkArrayCache[i] = replicator.Group.CreateArchetypeChunkArray(Allocator.TempJob, out var jobHandle); gatheringJobs[i] = jobHandle; } Profiler.EndSample(); JobHandle.CompleteAll(gatheringJobs); for (var i = 0; i < componentCleanups.Count; i++) { var cleanup = componentCleanups[i]; var chunkArray = chunkArrayCache[i]; Profiler.BeginSample("CleanReactiveComponents"); cleanup.Handler.CleanComponents(chunkArray, this, PostUpdateCommands); Profiler.EndSample(); chunkArray.Dispose(); } }
protected override void OnUpdate() { int2 gridSize = new int2(WorldManager.MapWorld.regionSize, WorldManager.MapWorld.regionSize); NativeList <JobHandle> jobHandles = new NativeList <JobHandle>(Allocator.Temp); Entities.ForEach((Entity entity, DynamicBuffer <PathfindingRoute> pathRoute, ref PathfindingParams pathfindingParams) => { List <MapGrowth> mapGrowths = WorldManager.MapWorld.GetMapGrowths(pathfindingParams.growthCode); NativeArray <int2> targetLocations = new NativeArray <int2>(GetAllTargetsFromGrowth(mapGrowths), Allocator.TempJob); PathFinderJob pathfinderJob = new PathFinderJob { pathfindingType = pathfindingParams.pathfindingType, positionStart = pathfindingParams.startPosition, positionEnd = pathfindingParams.endPosition, gridSize = gridSize, entity = entity, routeFollow = GetComponentDataFromEntity <PathfindingRouteFollow>(), pathRoute = pathRoute, pathNodes = WorldManager.PathNodesNA, targets = targetLocations }; jobHandles.Add(pathfinderJob.Schedule()); PostUpdateCommands.RemoveComponent <PathfindingParams>(entity); }); JobHandle.CompleteAll(jobHandles); }
private void ImpactAnimationFinding( NativeArray <BoneData> currentPose, NativeArray <float2> whereWeCanFindingPosition, NativeArray <FrameContact> contactPoints, NativeArray <TrajectoryPoint> currentTrajectory ) { for (int jobIndex = 0; jobIndex < jobsHandle.Length; jobIndex++) { isJobs[jobIndex].SetChangingOptions( this.dataState.poseCostType, this.dataState.csFeatures.contactCostType, currentPose, contactPoints, this.dataState.poseCostWeight, this.dataState.csFeatures.contactPointsWeight ); jobsHandle[jobIndex] = isJobs[jobIndex].Schedule(); } JobHandle.ScheduleBatchedJobs(); JobHandle.CompleteAll(jobsHandle); JoinJobsOutput(); }
private void Start() { FunctionPeriodic.Create(() => { float startTime = Time.realtimeSinceStartup; if (!useJobs) { for (int i = 0; i < 5; i++) { FindPath(new int2(0, 0), new int2(19, 19)); } } else { int findPathJobCount = 5; NativeArray <JobHandle> jobHandleArray = new NativeArray <JobHandle>(findPathJobCount, Allocator.Temp); for (int i = 0; i < findPathJobCount; i++) { FindPathJob findPathJob = new FindPathJob { startPosition = new int2(0, 0), endPosition = new int2(19, 19) }; jobHandleArray[i] = findPathJob.Schedule(); } JobHandle.CompleteAll(jobHandleArray); jobHandleArray.Dispose(); } Debug.Log("Time: " + ((Time.realtimeSinceStartup - startTime) * 1000f)); }, 1f); }
private void _Update_PreArray_Job() //total 2ms { Profiler.BeginSample("Pre_array"); for (int i = 0; i < ITEM_CNT; ++i) { _native_prearray[i] = _lst[i].v; } _native_indices.CopyFrom(_randIndices[0]); Profiler.EndSample(); Profiler.BeginSample("Prepare jobs"); var jobs = new NativeArray <JobHandle>(CORE, Allocator.Temp, NativeArrayOptions.UninitializedMemory); for (int i = 0; i < CORE; ++i) { var job = new PreArray_Job { _preArray = _native_prearray, _indices = _native_indices, _loopcnt = Mathf.CeilToInt(RUN_LOOP / (float)CORE), }; jobs[i] = job.Schedule(); } Profiler.EndSample(); Profiler.BeginSample("Wait jobs"); JobHandle.CompleteAll(jobs); Profiler.EndSample(); jobs.Dispose(); }