using LanLib.UpdateManager.Jobs.Internal;
using Unity.Jobs;
namespace LanLib.UpdateManager.Jobs
{
///
/// Singleton class that schedules 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 UpdateJobManager : AUpdateJobManager, UpdateJobData>>
where TData : struct, IUpdateJob
{
public static readonly int JobBatchSize = UpdateJobOptions.GetBatchSize();
/// Get or create the singleton instance
public static UpdateJobManager Instance => _instance != null ? _instance : (_instance = new UpdateJobManager());
private static UpdateJobManager _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, IInternalUpdateJob
{
return new TJob
{
Data = _jobData.Data,
}.Schedule(_jobData.Length, JobBatchSize, dependsOn);
}
}
}