48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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++;
|
|
}
|
|
}
|