public static JobHandle SliceArray <T>(NativeList <T> source, int length, int sliceCount, NativeList <T>[] buffers, JobHandle inputDeps) where T : struct, IComparable <T> { var sliceLength = (int)math.ceil((float)length / sliceCount); var copyHandle = inputDeps; var offset = 0; for (var i = 0; i < sliceCount; ++i) { var bufferLength = math.min(sliceLength, length); inputDeps = buffers[i].Resize(bufferLength, inputDeps); copyHandle = JobHandle.CombineDependencies( copyHandle, source.CopyTo(buffers[i].AsDeferredJobArray(), i * sliceLength, 0, bufferLength, inputDeps)); length -= sliceLength; offset += bufferLength; } return(copyHandle); }
// Schedules a collision events job only for UnityPhysics simulation internal static unsafe JobHandle ScheduleUnityPhysicsCollisionEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ICollisionEventsJobBase { SafetyChecks.CheckAreEqualAndThrow(SimulationType.UnityPhysics, simulation.Type); var data = new CollisionEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).CollisionEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
private JobHandle SetMousePos2World(JobHandle inputDeps) { var mousePos = Input.mousePosition; var ray = m_mainCamera.ScreenPointToRay(mousePos); // Todo: cam2WDistance & Filter might change later. var rayCastInput = new RaycastInput { Start = ray.origin, End = ray.origin + ray.direction * CameraToWorldDistance, Filter = CollisionFilter.Default }; var handle = m_physicsDetectionUtilitySystem.SingleRayCast(rayCastInput, ref m_result); inputDeps = JobHandle.CombineDependencies(inputDeps, handle); return(inputDeps); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var rotationFromHeadingJob = new RotationFromHeading { rotations = m_HeadingsGroup.rotations, headings = m_HeadingsGroup.headings, }; var rotationFromHeadingJobHandle = rotationFromHeadingJob.Schedule(m_HeadingsGroup.Length, 64, inputDeps); var localRotationFromLocalHeadingJob = new LocalRotationFromLocalHeading { rotations = m_LocalHeadingsGroup.rotations, headings = m_LocalHeadingsGroup.headings, }; var localRotationFromLocalHeadingJobHandle = localRotationFromLocalHeadingJob.Schedule(m_LocalHeadingsGroup.Length, 64, inputDeps); return(JobHandle.CombineDependencies(rotationFromHeadingJobHandle, localRotationFromLocalHeadingJobHandle)); }
public void ConsecutiveSampleBatchesChangesState() { var state0 = m_Sampler.state; var samples1 = m_Sampler.Samples(k_TestSampleCount, out var handle1); var state1 = m_Sampler.state; var samples2 = m_Sampler.Samples(k_TestSampleCount, out var handle2); var state2 = m_Sampler.state; JobHandle.CombineDependencies(handle1, handle2).Complete(); Assert.AreEqual(samples1.Length, samples2.Length); Assert.AreNotEqual(state0, state1); Assert.AreNotEqual(state1, state2); Assert.AreNotEqual(samples1[0], samples2[0]); samples1.Dispose(); samples2.Dispose(); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var cleanClicksJob = new CleanClicksJob { CommandBuffer = _commandBuffer.CreateCommandBuffer(), Entities = _clickedQuery.ToEntityArray(Allocator.TempJob) }; var clicksJobHandle = cleanClicksJob.Schedule(inputDeps); var cleanInGroupsJob = new CleanInGroupsJob(); var cleanInGroupsJobHandle = cleanInGroupsJob.Schedule(this, inputDeps); _commandBuffer.AddJobHandleForProducer(clicksJobHandle); return(JobHandle.CombineDependencies(clicksJobHandle, cleanInGroupsJobHandle)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var handle = inputDeps; Entities.WithStructuralChanges().WithoutBurst().ForEach((Entity entity, in TerrainGenerator g) => { for (int x = 0; x < g.X; x++) { handle = JobHandle.CombineDependencies(new J { xMax = g.X, yMax = g.Y, Archetype = _archetype, Buffer = _barrier.CreateCommandBuffer().ToConcurrent() }.Schedule(g.X * g.Y * g.Z, 128, handle), handle); } EntityManager.DestroyEntity(entity); }).Run(); _barrier.AddJobHandleForProducer(handle); return(handle); }
protected override JobHandle OnUpdate(JobHandle inputDependencies) { inputDependencies = JobHandle.CombineDependencies(inputDependencies, buildPhysicsWorldSystem.FinalJobHandle); var physicsWorld = buildPhysicsWorldSystem.PhysicsWorld; var collsionJob = new ExplosionCollsionJob() { damageGroup = GetBufferFromEntity <Damage>(), explosionComponent = GetComponentDataFromEntity <ExplosionComponent>(), enemiesGroup = GetComponentDataFromEntity <AIData>(), movementGroup = GetComponentDataFromEntity <MovementData>() }; JobHandle collisionHandle = collsionJob.Schedule(stepPhysicsWorldSystem.Simulation, ref physicsWorld, inputDependencies); return(collisionHandle); }
public JobHandle Execute(JobHandle _jobHandle) { //Iterate EATING RED doofuses to move toward locked food and move to NOEATING if food is ATE //todo: this is a double responsibility. Move toward food and eating the food may work in separate engines var handle1 = CreateJobForDoofusesAndFood( _jobHandle, GroupCompound <GameGroups.DOOFUSES, GameGroups.RED, GameGroups.EATING> .Groups , GroupCompound <GameGroups.DOOFUSES, GameGroups.RED, GameGroups.NOTEATING> .BuildGroup , GroupCompound <GameGroups.FOOD, GameGroups.RED, GameGroups.EATING> .BuildGroup); //Iterate EATING BLUE doofuses to look for BLUE food and MOVE them to NOEATING if food is ATE //todo: this is a double responsibility. Move toward food and eating the food may work in separate engines var handle2 = CreateJobForDoofusesAndFood( _jobHandle, GroupCompound <GameGroups.DOOFUSES, GameGroups.BLUE, GameGroups.EATING> .Groups , GroupCompound <GameGroups.DOOFUSES, GameGroups.BLUE, GameGroups.NOTEATING> .BuildGroup , GroupCompound <GameGroups.FOOD, GameGroups.BLUE, GameGroups.EATING> .BuildGroup); //can run in parallel return(JobHandle.CombineDependencies(handle1, handle2)); }
protected override void OnUpdate() { if (AudioSpectrumManager.Instance == null) { return; } frequencyBands.CopyFrom(AudioSpectrumManager.Instance.AudioBandBuffer); var job = new VisualizeJob { FrequencyBands = frequencyBands, AudioVisualizationDataType = GetComponentTypeHandle <AudioVisualizationData>(true), NonUniformScaleType = GetComponentTypeHandle <NonUniformScale>(), }; Dependency = JobHandle.CombineDependencies(job.Schedule(audioBarQuery, Dependency), Dependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var handle = JobHandle.CombineDependencies(m_BuildPhysicsWorldSystem.FinalJobHandle, inputDeps); PhysicsStep stepComponent = PhysicsStep.Default; if (HasSingleton <PhysicsStep>()) { stepComponent = GetSingleton <PhysicsStep>(); } // Swap the simulation implementation if the requested type changed if (Simulation.Type != stepComponent.SimulationType) { Simulation.Dispose(); Simulation = m_SimulationCreators[(int)stepComponent.SimulationType](); } #if !UNITY_DOTSPLAYER float timeStep = UnityEngine.Time.fixedDeltaTime; #else float timeStep = Time.DeltaTime; #endif // Schedule the simulation jobs var stepInput = new SimulationStepInput { World = m_BuildPhysicsWorldSystem.PhysicsWorld, TimeStep = timeStep, ThreadCountHint = stepComponent.ThreadCountHint, Gravity = stepComponent.Gravity, SynchronizeCollisionWorld = false, NumSolverIterations = stepComponent.SolverIterationCount, Callbacks = m_Callbacks }; Simulation.ScheduleStepJobs(stepInput, handle); FinalSimulationJobHandle = Simulation.FinalSimulationJobHandle; FinalJobHandle = Simulation.FinalJobHandle; // Clear the callbacks. User must enqueue them again before the next step. m_Callbacks.Clear(); return(handle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { //---------check condition and set sysSchedule---------// var entSchedule = GetSingletonEntity <CpSysSchedule>(); var cpSchedule = GetSingleton <CpSysSchedule>(); if (!cpSchedule.CanRunSysModData()) { return(inputDeps); } if (!mod_att.IsCreated && !mod_link.IsCreated) //check if data is available { return(inputDeps); } cpSchedule.Finish_SysModData(); _cmdBufferSys.CreateCommandBuffer().SetComponent(entSchedule, cpSchedule); //---------start---------// _lastRunFrame = Time.frameCount; //---------modifications---------// var jobModAtt = new ModAttJob { mods = mod_att, ro_relation_buf = GetBufferFromEntity <CpRelationBuf>(isReadOnly: true), rw_att = GetComponentDataFromEntity <CpAttitude>(isReadOnly: false), rw_isDirty = GetComponentDataFromEntity <CpIsDirty>(isReadOnly: false), }.Schedule(mod_att.Length, 16, inputDeps); var jobClearAtt = mod_att.ClearWithJob(jobModAtt); var jobModLink = new ModLinkJob { mods = mod_link, rw_rel = GetComponentDataFromEntity <CpRelation>(isReadOnly: false), rw_isDirty = GetComponentDataFromEntity <CpIsDirty>(isReadOnly: false), max_relation_strength = this.max_relation_strength, }.Schedule(mod_link.Length, 16, jobModAtt); var jobClearLink = mod_link.ClearWithJob(jobModLink); //---------finish---------// var final_handle = JobHandle.CombineDependencies(jobClearAtt, jobClearLink); return(final_handle); }
public void Generate(GridGeneratorOptions options) { _timer = Stopwatch.StartNew(); var count = options.gridRows * options.gridCols; _gridState = new NativeArray <byte>(count, options.allocatorType); _cellStack = new NativeArray <int>(count, options.allocatorType); _floodState = new NativeArray <byte>(count, options.allocatorType); // Mark starting cell as such _gridState[options.startIndex] = GridStateConstants.START; var gridBoundsBlockerJob = new GridBoundsBlockerJob(_gridState, options.gridCols, options.gridRows); var gridBoundsBlockerJobHandle = gridBoundsBlockerJob.Schedule(_gridState.Length, options.innerloopBatchCount); var gridTanBlockerJob = new GridTanBlockerJob(_gridState, options.gridRows, options.sensitivity); var gridTanBlockerJobHandle = gridTanBlockerJob.Schedule(_gridState.Length, options.innerloopBatchCount, gridBoundsBlockerJobHandle); var floodFillJob = new GridFloodFillJob(_gridState, _cellStack, _floodState, options.gridCols, options.gridRows, options.startIndex); var floodFillJobHandle = floodFillJob.Schedule(gridTanBlockerJobHandle); var gridFloodGateJob = new GridFloodGateJob(_gridState, _floodState, options.gridCols, options.gridRows); var gridFloodGateJobHandle = gridFloodGateJob.Schedule(floodFillJobHandle); var floodFillJob2 = new GridFloodFillJob(_gridState, _cellStack, _floodState, options.gridCols, options.gridRows, options.startIndex); var floodFillJob2Handle = floodFillJob2.Schedule(gridFloodGateJobHandle); var gridFillerJob = new GridFillerJob(_gridState, _floodState); var gridFillerJobHandle = gridFillerJob.Schedule(_gridState.Length, options.innerloopBatchCount, floodFillJob2Handle); var gridExitJob = new GridExitJob(_gridState, _floodState, options.gridCols, options.gridRows, options.startIndex); var gridExitJobHandle = gridExitJob.Schedule(gridFillerJobHandle); _jobHandles[0] = gridBoundsBlockerJobHandle; _jobHandles[1] = gridTanBlockerJobHandle; _jobHandles[2] = floodFillJobHandle; _jobHandles[3] = gridFloodGateJobHandle; _jobHandles[4] = floodFillJob2Handle; _jobHandles[5] = gridFillerJobHandle; _jobHandles[6] = gridExitJobHandle; _jobHandle = JobHandle.CombineDependencies(_jobHandles); }
protected override void OnUpdate() { JobHandle.CombineDependencies(_handlesToWaitFor.AsArray()).Complete(); _handlesToWaitFor.Clear(); bool isGameReadyForGameActions = HasSingleton<GridInfo>(); while (_actionRequests.Count > 0 || _actionRequestsManaged.Count > 0) { _processingRequests.Clear(); for (int i = 0; i < _actionRequests.Count; i++) { _processingRequests.AddRange(_actionRequests[i]); _actionRequests[i].Dispose(); } _actionRequests.Clear(); _processingRequestsManaged.Clear(); _processingRequestsManaged.AddRange(_actionRequestsManaged); _actionRequestsManaged.Clear(); if (isGameReadyForGameActions) { if (_processingRequests.Length > 0) { foreach (var request in _processingRequests) { var targets = new NativeArray<Entity>(1, Allocator.Temp); targets[0] = request.Target; ExecuteGameAction(request.Instigator, request.ActionEntity, targets); } } if (_processingRequestsManaged.Count > 0) { foreach (var request in _processingRequestsManaged) { ExecuteGameAction(request.Instigator, request.ActionEntity, request.Targets, request.Parameters); } } } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { // var inputDepsA = new PowerLevelJob { } .Schedule(this, inputDeps); // var inputDepsB = new DisableInputTimeJob { fixedDeltaTime = Time.fixedDeltaTime, ShipDisableInputState = typeof(ShipLostInputState), endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(), } .Schedule(this, inputDeps); // inputDepsA = new ActorAttribute3ServerSystem <_Power> .SampleAttribute3ModifysJob { } .Schedule(this, inputDepsA); // inputDepsA = new DisableInputJob { endCommandBuffer = endBarrier.CreateCommandBuffer().ToConcurrent(), } .Schedule(this, inputDepsA); // inputDepsA = new PowerRegainJob { fixedDeltaTime = Time.fixedDeltaTime, } .Schedule(this, inputDepsA); // inputDeps = JobHandle.CombineDependencies(inputDepsA, inputDepsB); endBarrier.AddJobHandleForProducer(inputDeps); return(inputDeps); }
protected override JobHandle StartGeneration(JobHandle lastHandle = default) { Dispose(); CheckData(data, info); CreateMeshData(); bool useHeightData = info.UseHeightData && data.HasHeights; bool needsNormalsData = info.ScaledOffset > 0 || info.BottomScaledOffset > 0; var infoArray = new NativeArray <SideCellInfo>(data.RawData.Length, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); AddTemp(infoArray); lastHandle = ScheduleCalculateInfoJob(data, info, infoArray, vertices, triangles, normals, uvs, lastHandle); NativeArray <EdgeNormals> edgeNormalsArray = default; if (needsNormalsData) { edgeNormalsArray = new NativeArray <EdgeNormals>(data.RawData.Length, Allocator.TempJob, NativeArrayOptions.ClearMemory); AddTemp(edgeNormalsArray); lastHandle = ScheduleEdgeNormalsJob(new SideEdgeNormalCalculator(), data.ColNum, data.RowNum, infoArray, edgeNormalsArray, info.LerpToExactEdge, lastHandle); } JobHandle vertexHandle = ScheduleCalculateVerticesJob(data, info, useHeightData, cellSize, infoArray, edgeNormalsArray, vertices, lastHandle); if (info.GenerateUvs) { vertexHandle = ScheduleCalculateUVJob(data, info, cellSize, infoArray, vertices, uvs, vertexHandle); } JobHandle triangleHandle = ScheduleCalculateTrianglesJob(data.ColNum, data.RowNum, infoArray, triangles, info.IsFlipped, lastHandle); lastHandle = JobHandle.CombineDependencies(vertexHandle, triangleHandle); if (info.GenerateNormals) { lastHandle = CalculateNormals.ScheduleDeferred(vertices, triangles, normals, lastHandle); } return(lastHandle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { int length = componentGroup.CalculateLength(); for (int j = 0; j < positionResolutionSystems.Count; j++) { inputDeps = JobHandle.CombineDependencies(inputDeps, positionResolutionSystems[j].GetDependencies()); } inputDeps = JobHandle.CombineDependencies(inputDeps, componentGroup.GetDependency()); bool firstUpdate = true; for (int i = 0; i < IterationCount; i++) { var positionOutput = hashMaps[i]; for (int j = 0; j < positionResolutionSystems.Count; j++) { inputDeps = positionResolutionSystems[j].OnUpdate(inputDeps, firstUpdate, positionOutput); } inputDeps = new ReadPositionOutput() { positionInput = positionOutput, positions = componentGroup.GetComponentDataArray <Position2D>(), entities = componentGroup.GetEntityArray() }.Schedule(length, 64, inputDeps); JobHandle.ScheduleBatchedJobs(); firstUpdate = false; } var handles = NativeManager.AllocateAndAutoDisposeNativeArray <JobHandle>(IterationCount, Allocator.Temp); for (int i = 0; i < IterationCount; i++) { handles[i] = new HashJobs.ClearMultiHashMapJob <Entity, float2>() { hashMap = hashMaps[i] }.Schedule(inputDeps); } return(JobHandle.CombineDependencies(handles)); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var handles = new NativeArray <JobHandle>(2, Allocator.Temp); var curPosJob = new UpdateCurrentPosJob(); curPosJob.positionType = GetArchetypeChunkComponentType <Translation>(true); curPosJob.curPositionType = GetArchetypeChunkComponentType <CurrentSimulatedPosition>(); curPosJob.simStartComponentVersion = beforeSystem.simStartComponentVersion; handles[0] = curPosJob.Schedule(positionInterpolationGroup, inputDeps); var curRotJob = new UpdateCurrentRotJob(); curRotJob.rotationType = GetArchetypeChunkComponentType <Rotation>(true); curRotJob.curRotationType = GetArchetypeChunkComponentType <CurrentSimulatedRotation>(); curRotJob.simStartComponentVersion = beforeSystem.simStartComponentVersion; handles[1] = curRotJob.Schedule(rotationInterpolationGroup, inputDeps); var initPosJob = new InitCurrentPosJob(); initPosJob.positionType = curPosJob.positionType; initPosJob.curPositionType = curPosJob.curPositionType; initPosJob.entityType = GetArchetypeChunkEntityType(); var initRotJob = new InitCurrentRotJob(); initRotJob.rotationType = curRotJob.rotationType; initRotJob.curRotationType = curRotJob.curRotationType; initRotJob.entityType = initPosJob.entityType; if (!newPositionInterpolationGroup.IsEmptyIgnoreFilter || !newRotationInterpolationGroup.IsEmptyIgnoreFilter) { initPosJob.commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); initRotJob.commandBuffer = barrier.CreateCommandBuffer().ToConcurrent(); handles[0] = initPosJob.Schedule(newPositionInterpolationGroup, handles[0]); handles[1] = initRotJob.Schedule(newRotationInterpolationGroup, handles[1]); } beforeSystem.simEndComponentVersion = GlobalSystemVersion; var handle = JobHandle.CombineDependencies(handles); barrier.AddJobHandleForProducer(handle); return(handle); }
protected override void OnUpdate() { var physicsWorld = buildPhysicsWorld.PhysicsWorld; var settings = navSystem.Settings; Dependency = JobHandle.CombineDependencies(Dependency, buildPhysicsWorld.GetOutputDependency()); var isDebugging = IsDebugging; Entities .WithNone <NavProblem>() .WithNone <NavPlanning, NavJumping, NavFalling>() .WithAll <NavWalking, LocalToParent, NavTerrainCapable>() .WithReadOnly(physicsWorld) .ForEach((Entity entity, int entityInQueryIndex, ref Translation translation, ref NavAgent agent, in LocalToWorld localToWorld, in Parent surface) => { var rayInput = new RaycastInput { Start = localToWorld.Position + agent.Offset, End = -math.up() * settings.SurfaceRaycastDistanceMax, Filter = new CollisionFilter() { BelongsTo = NavUtil.ToBitMask(settings.ColliderLayer), CollidesWith = NavUtil.ToBitMask(settings.SurfaceLayer), } }; if (physicsWorld.CastRay(rayInput, out RaycastHit hit)) { if (isDebugging) { UnityEngine.Debug.DrawLine(hit.Position, hit.Position + hit.SurfaceNormal * 15, UnityEngine.Color.green); UnityEngine.Debug.DrawLine(hit.Position, hit.Position + localToWorld.Up * 7, UnityEngine.Color.cyan); UnityEngine.Debug.DrawLine(hit.Position, hit.Position + localToWorld.Right * 7, UnityEngine.Color.cyan); UnityEngine.Debug.DrawLine(hit.Position, hit.Position + localToWorld.Forward * 7, UnityEngine.Color.cyan); } agent.SurfacePointNormal = hit.SurfaceNormal; var currentPosition = translation.Value; currentPosition.y = hit.Position.y + agent.Offset.y; translation.Value = currentPosition; } })
void PreSubmissionPhase(ref JobHandle jobHandle, PlatformProfiler profiler) { JobHandle BeforeECBFlushEngines() { JobHandle jobHandle = default; //execute submission engines and complete jobs because of this I don't need to do _ECBSystem.AddJobHandleForProducer(Dependency); for (var index = 0; index < _beforeSubmissionEngines.count; index++) { ref var engine = ref _beforeSubmissionEngines[index]; using (profiler.Sample(engine.name)) { jobHandle = JobHandle.CombineDependencies(jobHandle, engine.BeforeSubmissionUpdate(jobHandle)); } } return(jobHandle); }
private JobHandle CullingCallback(BatchRendererGroup rendererGroup, BatchCullingContext cullingContext) { var inputDependency = _jobDependency; for (var i = 0; i < cullingContext.batchVisibility.Length; ++i) { var job = new CullingJob { CullingContext = cullingContext, Matrices = rendererGroup.GetBatchMatrices(i), BatchIndex = i }.Schedule(inputDependency); // Jobの依存関係を更新 _jobDependency = JobHandle.CombineDependencies(job, _jobDependency); } return(_jobDependency); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var settings = GetSingleton <ServerSettings>(); JobHandle levelHandle; var spawnJob = new SpawnJob { commandBuffer = barrier.CreateCommandBuffer(), playerStateFromEntity = GetComponentDataFromEntity <PlayerStateComponentData>(), networkIdFromEntity = GetComponentDataFromEntity <NetworkIdComponent>(), shipArchetype = settings.shipArchetype, playerRadius = settings.playerRadius, level = m_LevelGroup.ToComponentDataArray <LevelComponent>(Allocator.TempJob, out levelHandle), rand = new Unity.Mathematics.Random((uint)Stopwatch.GetTimestamp()) }; var handle = spawnJob.ScheduleSingle(this, JobHandle.CombineDependencies(inputDeps, levelHandle)); barrier.AddJobHandleForProducer(handle); return(handle); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (!(HasSingleton <PhysicsDebugDisplayData>() && GetSingleton <PhysicsDebugDisplayData>().DrawMassProperties != 0)) { return(inputDeps); } inputDeps = JobHandle.CombineDependencies(inputDeps, m_StepPhysicsWorld.FinalSimulationJobHandle); JobHandle handle = new DisplayMassPropertiesJob { OutputStream = m_DebugStreamSystem.GetContext(1), MotionDatas = m_BuildPhysicsWorldSystem.PhysicsWorld.MotionDatas, MotionVelocities = m_BuildPhysicsWorldSystem.PhysicsWorld.MotionVelocities }.Schedule(inputDeps); m_EndFramePhysicsSystem.HandlesToWaitFor.Add(handle); return(handle); }
// ---------------------------------------------------- #region // Private Methods void ExecuteJobs() { var handles = new NativeArray <JobHandle>(this._currentBuffers.Count, Allocator.TempJob); for (var i = 0; i < this._currentBuffers.Count; ++i) { var buff = this._currentBuffers[i]; if (buff.ColliderHashMap.IsCreated) { buff.ColliderHashMap.Dispose(); } // コライダーの更新 buff.ColliderHashMap = new NativeMultiHashMap <int, SphereCollider>( buff.ColliderHashMapLength, Allocator.TempJob); var handle = new UpdateColliderHashJob { GroupParams = buff.ColliderGroupJobDataValue.GroupParams, ColliderHashMap = buff.ColliderHashMap.ToConcurrent(), }.Schedule(buff.ColliderGroupJobDataValue.TransformAccessArray); // 親の回転の取得 handle = new UpdateParentRotationJob { ParentRotations = buff.ParentRotations, }.Schedule(buff.SpringBoneJobDataValue.ParentTransformAccessArray, handle); // 物理演算 handles[i] = new LogicJob { ImmutableNodeParams = buff.SpringBoneJobDataValue.ImmutableNodeParams, ParentRotations = buff.ParentRotations, DeltaTime = Time.deltaTime, ColliderHashMap = buff.ColliderHashMap, VariableNodeParams = buff.SpringBoneJobDataValue.VariableNodeParams, }.Schedule(buff.SpringBoneJobDataValue.TransformAccessArray, handle); } this._jobHandle = JobHandle.CombineDependencies(handles); handles.Dispose(); JobHandle.ScheduleBatchedJobs(); }
protected override JobHandle OnUpdate(JobHandle dep) { k_Marker.Begin(); var globalSpaceOnlyJob = new ComputeGlobalSpaceJob { LocalToWorlds = GetArchetypeChunkComponentType <LocalToWorld>(true), Rigs = GetArchetypeChunkComponentType <Rig>(true), Floats = GetArchetypeChunkBufferType <AnimatedData>(true), LocalToWorld = GetArchetypeChunkBufferType <AnimatedLocalToWorld>() }; var globalSpaceOnlyHandle = globalSpaceOnlyJob.Schedule(m_GlobalSpaceOnlyQuery, dep); var rigSpaceOnlyJob = new ComputeRigSpaceJob { Rigs = GetArchetypeChunkComponentType <Rig>(true), Floats = GetArchetypeChunkBufferType <AnimatedData>(true), LocalToRoot = GetArchetypeChunkBufferType <AnimatedLocalToRoot>() }; var rigSpaceOnlyHandle = rigSpaceOnlyJob.Schedule(m_RigSpaceOnlyQuery, dep); var globalAndRigSpaceJob = new ComputeGlobalAndRigSpaceJob { LocalToWorlds = GetArchetypeChunkComponentType <LocalToWorld>(true), Rigs = GetArchetypeChunkComponentType <Rig>(true), Floats = GetArchetypeChunkBufferType <AnimatedData>(true), LocalToWorld = GetArchetypeChunkBufferType <AnimatedLocalToWorld>(), LocalToRoot = GetArchetypeChunkBufferType <AnimatedLocalToRoot>() }; // TODO : These jobs should ideally all run in parallel since the queries are mutually exclusive. // For now, in order to prevent the safety system from throwing errors schedule // globalAndRigSpaceJob with a dependency on the two others. var inputDep = globalAndRigSpaceJob.Schedule( m_GlobalAndRigSpaceQuery, JobHandle.CombineDependencies(globalSpaceOnlyHandle, rigSpaceOnlyHandle) ); k_Marker.End(); return(inputDep); }
public override unsafe XRPointCloudData GetPointCloudData( TrackableId trackableId, Allocator allocator) { void *dataPtr, identifierPtr; int numPoints = NativeApi.UnityARCore_depth_getPointCloudPtrs( trackableId, out dataPtr, out identifierPtr); var data = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Quaternion>(dataPtr, numPoints, Allocator.None); var positions = new NativeArray <Vector3>(numPoints, allocator); var positionsJob = new TransformPositionsJob { positionsIn = data, positionsOut = positions }; var positionsHandle = positionsJob.Schedule(numPoints, 32); var confidenceValues = new NativeArray <float>(numPoints, allocator); var confidenceJob = new ExtractConfidenceValuesJob { confidenceIn = data, confidenceOut = confidenceValues }; var confidenceHandle = confidenceJob.Schedule(numPoints, 32); var identifiers = new NativeArray <ulong>(numPoints, allocator); var identifiersJob = new CopyIdentifiersJob { identifiersIn = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(identifierPtr, numPoints, Allocator.None), identifiersOut = identifiers }; var identifiersHandle = identifiersJob.Schedule(numPoints, 32); JobHandle.CombineDependencies(positionsHandle, confidenceHandle, identifiersHandle).Complete(); return(new XRPointCloudData { positions = positions, identifiers = identifiers, confidenceValues = confidenceValues }); }
public JobHandle Execute(JobHandle inputDeps) { JobHandle combineDependencies = inputDeps; //Completely abstract engine. There is no assumption of in which groups the component can be. //I am planning to add the concept of disabled groups in future as the state enabled/disable is very //abstract and it makes sense to have the concept at framework level foreach (var((positions, count), group) in entitiesDB.QueryEntities <PositionEntityComponent>()) { Check.Require(_goManager.Transforms((int)(uint)group).length == count , $"component array length doesn't match. Expected {count} - found {_goManager.Transforms((int) (uint) group).length} - group {group.ToName()}"); combineDependencies = JobHandle.CombineDependencies(inputDeps, new ParallelLabelTransformJob() { _position = positions }.Schedule(_goManager.Transforms((int)(uint)group), inputDeps), combineDependencies); } return(combineDependencies); }
public JobHandle Initialize(JobHandle inputDeps, float deltaTime) { // initialize all batches in parallel: if (batches.Count > 0) { NativeArray <JobHandle> deps = new NativeArray <JobHandle>(batches.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); for (int i = 0; i < batches.Count; ++i) { deps[i] = batches[i].enabled ? batches[i].Initialize(inputDeps, deltaTime) : inputDeps; } JobHandle result = JobHandle.CombineDependencies(deps); deps.Dispose(); return(result); } return(inputDeps); }
public JobHandle Dispose(JobHandle inputDeps) { var handles = new NativeArray <JobHandle>(10, Allocator.TempJob); handles[0] = cpuShort.Dispose(inputDeps); handles[1] = cpuMin.Dispose(inputDeps); handles[2] = cpuAverage.Dispose(inputDeps); handles[3] = cpuMax.Dispose(inputDeps); handles[4] = gpuShort.Dispose(inputDeps); handles[5] = gpuMin.Dispose(inputDeps); handles[6] = gpuAverage.Dispose(inputDeps); handles[7] = gpuMax.Dispose(inputDeps); handles[8] = image.Dispose(inputDeps); handles[9] = barValues.Dispose(inputDeps); var result = JobHandle.CombineDependencies(handles); handles.Dispose(); return(result); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { if (Input.GetMouseButtonUp(0) || (Input.touchCount > 0 && Input.touches[0].phase == TouchPhase.Ended)) { if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject()) { return(inputDeps); } inputDeps = JobHandle.CombineDependencies(inputDeps, _buildPhysicsWorldSystem.GetOutputDependency()); if (MainCameraController.CurrentCamera == null) { return(inputDeps); } var screenRay = MainCameraController.CurrentCamera.ScreenPointToRay(Input.mousePosition); Raycast(screenRay.origin, screenRay.GetPoint(110)); // var handle = new FindClosestInteractable // { // Input = new RaycastInput // { // Start = screenRay.origin, // End = screenRay.GetPoint(100), // Filter = new CollisionFilter // { // BelongsTo = 1u << 3, // CollidesWith = 1u << 3, // GroupIndex = 0 // } // }, // EventQueue = EventQueue.AsParallelWriter(), // World = _buildPhysicsWorldSystem.PhysicsWorld // }.Schedule(inputDeps); // // return handle; } return(inputDeps); }