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,47 @@
using MoonTools.ECS;
using Nerfed.Runtime.Scheduling;
namespace Nerfed.Runtime.Systems.Synthetic;
public sealed class DummyLongJobConsumerSystem : MoonTools.ECS.System, IParallelSystemMetadata
{
private readonly JobSystem jobs;
private readonly DummyLongJobSharedState state;
private readonly bool requireCompletion;
public DummyLongJobConsumerSystem(
World world,
DummyLongJobSharedState state,
JobSystem jobs,
bool requireCompletion) : base(world)
{
this.state = state;
this.jobs = jobs;
this.requireCompletion = requireCompletion;
}
public string ScheduleName => nameof(DummyLongJobConsumerSystem);
// Consumer/apply stage is where structural world work should happen in real systems.
public SystemAccessDeclaration AccessDeclaration => SystemAccessDeclaration.Empty;
public override void Update(TimeSpan delta)
{
JobHandle handle = state.InFlight;
if (!handle.IsValid)
{
return;
}
if (!requireCompletion && !jobs.IsCompleted(handle))
{
return;
}
jobs.Wait(handle);
jobs.TryForget(handle);
state.InFlight = default;
state.ConsumeCount++;
}
}