Skip to content

Interface IRangeJob ​

Namespace: KenseiECS

Work over an index range [start, end). Implement on a struct: the runner keeps one copy of it, without boxing, and every worker and the calling thread execute that same copy. A field the job writes is therefore shared by all threads and never reaches the struct passed to Run: keep results in component data, or in an array the job references and indexes by its range.

Usage with a filter:

csharp
struct MoveJob : IRangeJob {
    public Filter Filter;
    public ComponentPool<Position> Positions;
    public ComponentPool<Velocity> Velocities;
    public void Execute(int start, int end) {
        var entities = Filter.Entities;
        for (int i = start; i < end; i++) {
            int e = entities[i];
            ref var pos = ref Positions.Get(e);
            ref var vel = ref Velocities.Get(e);
            pos.X += vel.X;
        }
    }
}
_runner.Run(new MoveJob { ... }, _filter.Count);

Usage with a group: index Data1/Data2 spans from start to end.

csharp
public interface IRangeJob

Methods ​

Execute(int, int) ​

Process indices from start (inclusive) to end (exclusive).

csharp
void Execute(int start, int end)

Parameters ​

start int

end int