Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.5KB

  1. #if UNITY_JOBS
  2. using System;
  3. using Svelto.ECS.Extensions.Unity;
  4. using Unity.Jobs;
  5. namespace Svelto.ECS
  6. {
  7. public static class UnityJobExtensions2
  8. {
  9. public static JobHandle ScheduleDispose
  10. <T1>(this T1 disposable, JobHandle inputDeps) where T1 : struct, IDisposable
  11. {
  12. return new DisposeJob<T1>(disposable).Schedule(inputDeps);
  13. }
  14. public static JobHandle ScheduleDispose
  15. <T1, T2>(this T1 disposable1, T2 disposable2, JobHandle inputDeps)
  16. where T1 : struct, IDisposable where T2 : struct, IDisposable
  17. {
  18. return new DisposeJob<T1, T2>(disposable1, disposable2).Schedule(inputDeps);
  19. }
  20. public static JobHandle ScheduleParallel
  21. <JOB>(this JOB job, int iterations, JobHandle inputDeps) where JOB: struct, IJobParallelFor
  22. {
  23. if (iterations <= 0)
  24. return inputDeps;
  25. var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations);
  26. return job.Schedule((int)iterations, innerloopBatchCount, inputDeps);
  27. }
  28. public static JobHandle ScheduleParallel
  29. <JOB>(this JOB job, uint iterations, JobHandle inputDeps) where JOB: struct, IJobParallelFor
  30. {
  31. if (iterations == 0)
  32. return inputDeps;
  33. var innerloopBatchCount = ProcessorCount.BatchSize(iterations);
  34. return job.Schedule((int)iterations, innerloopBatchCount, inputDeps);
  35. }
  36. }
  37. }
  38. #endif