// use fixed time step for bones because they involve collision resolution internal static void ExecuteBones ( BoingEffector.Params[] aEffectorParams, Dictionary <int, BoingBones> bonesMap, BoingManager.UpdateTiming updateTiming ) { Profiler.BeginSample("Update Bones (Execute)"); foreach (var itBones in bonesMap) { var bones = itBones.Value; if (bones.UpdateTiming != updateTiming) { continue; } bones.PrepareExecute(); for (int i = 0; i < aEffectorParams.Length; ++i) { bones.AccumulateTarget(ref aEffectorParams[i]); } bones.EndAccumulateTargets(); switch (bones.UpdateMode) { case BoingManager.UpdateMode.Update: bones.Params.Execute(bones, BoingManager.DeltaTime); break; case BoingManager.UpdateMode.FixedUpdate: for (int iteration = 0; iteration < BoingManager.NumFixedUpdateIterations; ++iteration) { bones.Params.Execute(bones, BoingManager.FixedDeltaTime); } break; } } Profiler.EndSample(); }
internal static void PullBonesResults ( BoingEffector.Params[] aEffectorParams, Dictionary <int, BoingBones> bonesMap, BoingManager.UpdateTiming updateTiming ) { Profiler.BeginSample("Update Bones (Pull Results)"); foreach (var itBones in bonesMap) { var bones = itBones.Value; if (bones.UpdateTiming != updateTiming) { continue; } bones.Params.PullResults(bones); } Profiler.EndSample(); }
internal static void ExecuteBehaviors ( Dictionary <int, BoingBehavior> behaviorMap, BoingManager.UpdateTiming updateTiming ) { // gather job if (updateTiming == BoingManager.UpdateTiming.Early) { if (s_behaviorJobNeedsGather) { Profiler.BeginSample("Gather Behavior Job"); s_hBehaviorJob.Complete(); for (int iBehavior = 0, n = s_aBehaviorParams.Length; iBehavior < n; ++iBehavior) { s_aBehaviorOutput[iBehavior].GatherOutput(behaviorMap); } s_aBehaviorParams.Dispose(); s_aBehaviorOutput.Dispose(); Profiler.EndSample(); s_behaviorJobNeedsGather = false; } } // kick job if (updateTiming == BoingManager.UpdateTiming.Late) { Profiler.BeginSample("Kick Behavior Job"); Profiler.BeginSample("Allocate"); s_aBehaviorParams = new NativeArray <BoingWork.Params>(behaviorMap.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); s_aBehaviorOutput = new NativeArray <BoingWork.Output>(behaviorMap.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); Profiler.EndSample(); { Profiler.BeginSample("Push Data"); int iBehavior = 0; foreach (var itBehavior in behaviorMap) { var behavior = itBehavior.Value; behavior.PrepareExecute(); s_aBehaviorParams[iBehavior++] = behavior.Params; } Profiler.EndSample(); } float dt = Time.deltaTime; var job = new BehaviorJob() { Params = s_aBehaviorParams, Output = s_aBehaviorOutput, DeltaTime = BoingManager.DeltaTime, FixedDeltaTime = BoingManager.FixedDeltaTime, NumFixedUpdateIterations = BoingManager.NumFixedUpdateIterations, LateUpdateTiming = (updateTiming == BoingManager.UpdateTiming.Late) }; s_hBehaviorJob = job.Schedule(s_aBehaviorParams.Length, 32); JobHandle.ScheduleBatchedJobs(); Profiler.EndSample(); s_behaviorJobNeedsGather = true; } }
internal static void ExecuteReactors ( Dictionary <int, BoingEffector> effectorMap, Dictionary <int, BoingReactor> reactorMap, Dictionary <int, BoingReactorField> fieldMap, Dictionary <int, BoingReactorFieldCPUSampler> cpuSamplerMap, BoingManager.UpdateTiming updateTiming ) { float dt = Time.deltaTime; // gather job if (updateTiming == BoingManager.UpdateTiming.Early) { if (s_reactorJobNeedsGather) { Profiler.BeginSample("Gather Reactor Job"); if (s_aEffectors.Length > 0 && s_aReactorExecParams.Length > 0) { s_hReactorJob.Complete(); Profiler.BeginSample("Pull Data"); for (int iReactor = 0, n = s_aReactorExecParams.Length; iReactor < n; ++iReactor) { s_aReactorExecOutput[iReactor].GatherOutput(reactorMap); } Profiler.EndSample(); } s_aEffectors.Dispose(); s_aReactorExecParams.Dispose(); s_aReactorExecOutput.Dispose(); Profiler.EndSample(); s_reactorJobNeedsGather = false; } } // kick job if (updateTiming == BoingManager.UpdateTiming.Late) { Profiler.BeginSample("Kick Reactor Job"); s_aEffectors = new NativeArray <BoingEffector.Params>(effectorMap.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); s_aReactorExecParams = new NativeArray <BoingWork.Params>(reactorMap.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); s_aReactorExecOutput = new NativeArray <BoingWork.Output>(reactorMap.Count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory); { Profiler.BeginSample("Push Data"); int iEffector = 0; var eep = new BoingEffector.Params(); foreach (var itEffector in effectorMap) { var effector = itEffector.Value; eep.Fill(itEffector.Value); s_aEffectors[iEffector++] = eep; } int iReactor = 0; foreach (var itReactor in reactorMap) { var reactor = itReactor.Value; reactor.PrepareExecute(); s_aReactorExecParams[iReactor++] = reactor.Params; } Profiler.EndSample(); } if (s_aEffectors.Length > 0 && s_aReactorExecParams.Length > 0) { var job = new ReactorJob() { Effectors = s_aEffectors, Params = s_aReactorExecParams, Output = s_aReactorExecOutput, DeltaTime = dt, FixedDeltaTime = BoingManager.FixedDeltaTime, NumFixedUpdateIterations = BoingManager.NumFixedUpdateIterations, LateUpdateTiming = (updateTiming == BoingManager.UpdateTiming.Late) }; s_hReactorJob = job.Schedule(s_aReactorExecParams.Length, 32); JobHandle.ScheduleBatchedJobs(); } Profiler.EndSample(); Profiler.BeginSample("Update Fields (CPU)"); foreach (var itField in fieldMap) { var field = itField.Value; switch (field.HardwareMode) { case BoingReactorField.HardwareModeEnum.CPU: field.ExecuteCpu(dt); break; } } Profiler.EndSample(); Profiler.BeginSample("Update Field Samplers"); foreach (var itSampler in cpuSamplerMap) { var sampler = itSampler.Value; //sampler.SampleFromField(); } Profiler.EndSample(); s_reactorJobNeedsGather = true; } }
internal static void ExecuteReactors ( BoingEffector.Params[] aEffectorParams, Dictionary <int, BoingReactor> reactorMap, Dictionary <int, BoingReactorField> fieldMap, Dictionary <int, BoingReactorFieldCPUSampler> cpuSamplerMap, BoingManager.UpdateTiming updateTiming ) { float dt = Time.deltaTime; Profiler.BeginSample("Update Reactors"); foreach (var itReactor in reactorMap) { var reactor = itReactor.Value; if (reactor.UpdateTiming != updateTiming) { continue; } reactor.PrepareExecute(); for (int i = 0; i < aEffectorParams.Length; ++i) { reactor.Params.AccumulateTarget(ref aEffectorParams[i]); } reactor.Params.EndAccumulateTargets(); switch (reactor.UpdateMode) { case BoingManager.UpdateMode.Update: reactor.Execute(dt); break; case BoingManager.UpdateMode.FixedUpdate: for (int iteration = 0; iteration < BoingManager.NumFixedUpdateIterations; ++iteration) { reactor.Execute(BoingManager.FixedDeltaTime); } break; } } Profiler.EndSample(); Profiler.BeginSample("Update Fields (CPU)"); foreach (var itField in fieldMap) { var field = itField.Value; switch (field.HardwareMode) { case BoingReactorField.HardwareModeEnum.CPU: field.ExecuteCpu(dt); break; } } Profiler.EndSample(); Profiler.BeginSample("Update Field Samplers"); foreach (var itSampler in cpuSamplerMap) { var sampler = itSampler.Value; //sampler.SampleFromField(); } Profiler.EndSample(); }
internal static void ExecuteBehaviors(Dictionary <int, BoingBehavior> behaviorMap, BoingManager.UpdateTiming updateTiming) { float dt = Time.deltaTime; foreach (var itBehavior in behaviorMap) { var behavior = itBehavior.Value; if (behavior.UpdateTiming != updateTiming) { continue; } behavior.PrepareExecute(); switch (behavior.UpdateMode) { case BoingManager.UpdateMode.Update: behavior.Execute(dt); break; case BoingManager.UpdateMode.FixedUpdate: for (int iteration = 0; iteration < BoingManager.NumFixedUpdateIterations; ++iteration) { behavior.Execute(BoingManager.FixedDeltaTime); } break; } } }