using LanLib.UpdateManager.Jobs.Internal;
using Unity.Jobs;
using UnityEngine.Jobs;
namespace LanLib.UpdateManager.Jobs
{
///
/// Singleton class that schedules -enabled jobs from registered objects every frame using Unity's Job System.
///
///
/// Any C# object can be registered for updates, including MonoBehaviours, pure C# classes and structs, as long as they implement .
///
/// This class runs jobs in parallel, so don't rely on jobs being executed in any order.
///
///
///
public class UpdateTransformJobManager : AUpdateJobManager, UpdateTransformJobData>>
where TData : struct, IUpdateTransformJob
{
public static readonly int JobBatchSize = UpdateJobOptions.GetBatchSize();
public static readonly bool ReadOnlyTransformAccess = UpdateJobOptions.GetReadOnlyTransformAccess();
/// Get or create the singleton instance
public static UpdateTransformJobManager Instance => _instance != null ? _instance : (_instance = new UpdateTransformJobManager());
private static UpdateTransformJobManager _instance;
protected override JobHandle ScheduleJob(JobHandle dependsOn)
{
#if HAVE_BURST
if (IsJobBurstCompiled)
{
return Schedule>(dependsOn);
}
else
#endif
{
return Schedule>(dependsOn);
}
}
protected JobHandle Schedule(JobHandle dependsOn)
where TJob : struct, IInternalUpdateTransformJob
{
var job = new TJob
{
Data = _jobData.Data,
};
return ReadOnlyTransformAccess
? job.ScheduleReadOnly(_jobData.Transforms, JobBatchSize, dependsOn)
: job.Schedule(_jobData.Transforms, dependsOn);
}
}
}