Skip to content

Instantly share code, notes, and snippets.

@martindevans
Last active September 12, 2018 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martindevans/d39e0776eccfb2d601aec7a5d5b485d1 to your computer and use it in GitHub Desktop.
Save martindevans/d39e0776eccfb2d601aec7a5d5b485d1 to your computer and use it in GitHub Desktop.
[UpdateAfter(typeof(PowerSystem))]
public class LightBulbPostSystem
: JobComponentSystem
{
private struct AfterPower
: IJobParallelFor
{
[WriteOnly] private ComponentDataArray<LightBulb> _outputs;
[ReadOnly] private ComponentDataArray<PowerInput> _inputs;
public AfterPower(ComponentDataArray<LightBulb> outputs, ComponentDataArray<PowerInput> inputs)
{
_outputs = outputs;
_inputs = inputs;
}
public void Execute(int index)
{
var supply = _inputs[index].PowerSupplied;
var request = _inputs[index].PowerRequested;
var bulb = new LightBulb {
Brightness = supply / request
};
_outputs[index] = bulb;
}
}
private struct Group
{
[WriteOnly] public ComponentDataArray<LightBulb> Bulbs;
[ReadOnly] public ComponentDataArray<PowerInput> Inputs;
public readonly int Length;
}
[Inject] private Group _lights;
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
return new AfterPower(_lights.Bulbs, _lights.Inputs).Schedule(_lights.Length, 128, inputDeps);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment