Implement scheduling system with parallel execution support and dummy job systems

This commit is contained in:
max
2026-08-07 12:14:02 +02:00
parent a0f2713fdc
commit 0132c1326d
14 changed files with 844 additions and 5 deletions
@@ -0,0 +1,69 @@
namespace Nerfed.Runtime.Scheduling;
public enum SystemAccessMode
{
Read,
WriteExisting,
StructuralWrite,
}
public readonly struct ComponentAccess
{
public ComponentAccess(Type componentType, SystemAccessMode mode)
{
ComponentType = componentType;
Mode = mode;
}
public Type ComponentType { get; }
public SystemAccessMode Mode { get; }
}
public readonly struct SystemAccessDeclaration
{
private readonly ComponentAccess[] accesses;
public static readonly SystemAccessDeclaration Empty = new(Array.Empty<ComponentAccess>());
public SystemAccessDeclaration(params ComponentAccess[] accesses)
{
this.accesses = accesses ?? Array.Empty<ComponentAccess>();
}
public ReadOnlySpan<ComponentAccess> Accesses => accesses ?? Array.Empty<ComponentAccess>();
public bool ConflictsWith(in SystemAccessDeclaration other)
{
ReadOnlySpan<ComponentAccess> left = Accesses;
ReadOnlySpan<ComponentAccess> right = other.Accesses;
for (int i = 0; i < left.Length; i++)
{
for (int j = 0; j < right.Length; j++)
{
if (left[i].Mode == SystemAccessMode.StructuralWrite || right[j].Mode == SystemAccessMode.StructuralWrite)
{
return true;
}
if (left[i].ComponentType != right[j].ComponentType)
{
continue;
}
if (left[i].Mode == SystemAccessMode.Read && right[j].Mode == SystemAccessMode.Read)
{
continue;
}
return true;
}
}
return false;
}
public static ComponentAccess Read<T>() where T : unmanaged => new(typeof(T), SystemAccessMode.Read);
public static ComponentAccess WriteExisting<T>() where T : unmanaged => new(typeof(T), SystemAccessMode.WriteExisting);
public static ComponentAccess StructuralWrite<T>() where T : unmanaged => new(typeof(T), SystemAccessMode.StructuralWrite);
}