Implement scheduling system with parallel execution support and dummy job systems
This commit is contained in:
@@ -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++;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user