54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using MoonTools.ECS;
|
|
using Nerfed.Runtime.Scheduling;
|
|
|
|
namespace Nerfed.Runtime.Systems.Synthetic;
|
|
|
|
public sealed class DummyLongJobProducerSystem : MoonTools.ECS.System, IParallelSystemMetadata
|
|
{
|
|
private readonly JobSystem jobs;
|
|
private readonly DummyLongJobSharedState state;
|
|
private readonly TimeSpan duration;
|
|
private readonly DummyWorkloadMode mode;
|
|
private readonly JobDeadlineMode deadline;
|
|
private int seed;
|
|
|
|
public DummyLongJobProducerSystem(
|
|
World world,
|
|
DummyLongJobSharedState state,
|
|
JobSystem jobs,
|
|
TimeSpan duration,
|
|
DummyWorkloadMode mode,
|
|
JobDeadlineMode deadline,
|
|
int initialSeed = 1) : base(world)
|
|
{
|
|
this.state = state;
|
|
this.jobs = jobs;
|
|
this.duration = duration;
|
|
this.mode = mode;
|
|
this.deadline = deadline;
|
|
seed = initialSeed;
|
|
}
|
|
|
|
public string ScheduleName => nameof(DummyLongJobProducerSystem);
|
|
|
|
// Producer pattern: reads current world state and emits immutable job payload.
|
|
public SystemAccessDeclaration AccessDeclaration => SystemAccessDeclaration.Empty;
|
|
|
|
public override void Update(TimeSpan delta)
|
|
{
|
|
if (state.InFlight.IsValid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
int capturedSeed = seed;
|
|
state.InFlight = jobs.Submit(
|
|
() => state.LastResult = DummyWorkloadRunner.Run(duration, mode, capturedSeed),
|
|
deadline,
|
|
nameof(DummyLongJobProducerSystem));
|
|
|
|
seed = unchecked(capturedSeed + 1);
|
|
state.SubmitCount++;
|
|
}
|
|
}
|