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); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { NativeQueue <Entity> destroyedPlanetoidsQueue = new NativeQueue <Entity>(Allocator.TempJob); #region alternativeNoTWorking /* * NativeArray<int> keys = QuadrantSystem.quadrantMultiHashMap.GetKeyArray(Allocator.TempJob); * NativeArray<JobHandle> jobHandles = new NativeArray<JobHandle>(keys.Length, Allocator.TempJob); * * //make array of keys * //in a job make subarray of key, index of a key is number of array * //loop through array and add to queue * //place all the subarrays in array * //use * * 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, * sortedPositionsArray = entityWithPropsArray, * realTimeSinceStartUp = Time.realtimeSinceStartup, * keys = keys, * index = i * }; * * jobHandles[i] = sortPositionsJob.Schedule(); * } * * JobHandle.CompleteAll(jobHandles); * keys.Dispose(); * jobHandles.Dispose(); * destroyedPlanetoidsQueue.Dispose(); */ #endregion CollisionDetectionInQuadrantsJob collisionDetectionInQuadrantsJob = new CollisionDetectionInQuadrantsJob { quadrantMultiHashMap = QuadrantSystem.quadrantMultiHashMap, destroyedPlanetoidsQueue = destroyedPlanetoidsQueue.ToConcurrent(), explosionCoordsQueue = AnimationHandler.explosionCoordsQueue.ToConcurrent(), //entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().ToConcurrent(), realTimeSinceStartUp = Time.realtimeSinceStartup, }; JobHandle jobHandle = collisionDetectionInQuadrantsJob.Schedule(this, inputDeps); //endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); AddDisabledComponentJob removeTranslationJob = new AddDisabledComponentJob { destroyedPlanetoidQueue = destroyedPlanetoidsQueue, entityCommandBuffer = endSimulationEntityCommandBufferSystem.CreateCommandBuffer() }; jobHandle = removeTranslationJob.Schedule(jobHandle); endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(jobHandle); //executes only after job has been completed jobHandle.Complete(); destroyedPlanetoidsQueue.Dispose(); 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); }