I think this topic is in the wrong section but I’ll continue.
My original idea looks very cyclic but here it is.
public class JobComponentSystem : ComponentSystem , IJob
{
JobHandle? dependency; //cached?
public void Init()
{
dependency = this.Schedule();
}
protected virtual void OnUpdate()
{
dependency.Complete();
}
public void Execute()//Called by the main manager?
{
OnUpdate(); //This calls the child most update? or we are in cyclic hell
}
public void AddDependency(JobHandle handle)
{
}
JobHandle GetDependency()
{
if(dependency == null)
{
//Create one?
}
}
}
I later realized that in one of the Unites Joachim spoke of making the code writing part easier (less boiler plate) to speed up the coding process and automate job scheduling.
UniteCode Example
//For simplicity and auto scheduling
public struct GravityMinionJob : IJobProcessComponentData<MinionVelocity>, IAutoComponentSystemJob
{
float dt;
Vector3 gravity;
//probably called before scheduling
public void Prepare()
{
dt = Time.deltaTime;
gravity = Vector3.up * -9.81f;
}
//Can have multiple components that refer to the same entity, How?
public void Execute(ref MinionVelocity minion)
{
minion.velocity += gravity * dt;
}
}
I tried using it as an inspiration so my first assumption was
//assumptions
public interface IAutoComponentSystemJob
{
void Prepare(); //Maybe not
}
public interface IJobProcessComponentData<T> where T : IComponentData, stuct
{
void Execute(ref T t);
}
But then Joachim said we can have multiple components
Here is some confused ugly idea
//Allowing multiple components
public interface IJobProcessComponentData<T, U, V>
{
void Execute(ref T t);
void Execute(ref U u);
void Execute(ref V v);
}
It seemed like a dead end so I assume they must be using some nifty extension methods to keep everything neat similar to IJobExtensions as he constantly reference how tightly packed everything was
Example IJobExtensions
/// <summary>
/// <para>Extension methods for Jobs using the IJob interface.</para>
/// </summary>
public static class IJobExtensions
{
[StructLayout(LayoutKind.Sequential, Size = 1)]
private struct JobStruct<T> where T : struct, IJob
{
public delegate void ExecuteJobFunction(ref T data, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex);
public static IntPtr jobReflectionData;
[CompilerGenerated]
private static IJobExtensions.JobStruct<T>.ExecuteJobFunction genericCache0;
public static IntPtr Initialize()
{
if (IJobExtensions.JobStruct<T>.jobReflectionData == IntPtr.Zero)
{
Type tType = typeof(T);
if (IJobExtensions.JobStruct<T>.genericCache0 == null)
{
IJobExtensions.JobStruct<T>.genericCache0 = new IJobExtensions.JobStruct<T>.ExecuteJobFunction(IJobExtensions.JobStruct<T>.Execute);
}
IJobExtensions.JobStruct<T>.jobReflectionData = JobsUtility.CreateJobReflectionData(tType, IJobExtensions.JobStruct<T>.genericCache0, null, null);
}
return IJobExtensions.JobStruct<T>.jobReflectionData;
}
public static void Execute(ref T data, IntPtr additionalPtr, IntPtr bufferRangePatchData, ref JobRanges ranges, int jobIndex)
{
data.Execute();
}
}
public static JobHandle Schedule<T>(this T jobData, JobHandle dependsOn = default(JobHandle)) where T : struct, IJob
{
JobsUtility.JobScheduleParameters jobScheduleParameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf<T>(ref jobData), IJobExtensions.JobStruct<T>.Initialize(), dependsOn, ScheduleMode.Batched);
return JobsUtility.Schedule(ref jobScheduleParameters);
}
public static void Run<T>(this T jobData) where T : struct, IJob
{
JobsUtility.JobScheduleParameters jobScheduleParameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf<T>(ref jobData), IJobExtensions.JobStruct<T>.Initialize(), default(JobHandle), ScheduleMode.Run);
JobsUtility.Schedule(ref jobScheduleParameters);
}
}