Hi! I have this IJobEntity
code to map the two type of elements on two maps. They are identical except for the WithAny()
attribute.
[BurstCompile]
[WithAny(typeof(Tag_Massing))]
partial struct JDrawMap_Massing : IJobEntity
{
[NativeDisableParallelForRestriction] public NativeArray2D<bool> map;
public void Execute(in Coordinate coordinate)
{
for (int x = coordinate.pos.x; x < coordinate.pos.x + coordinate.width; x++)
{
for (int y = coordinate.pos.y; y < coordinate.pos.y + coordinate.height; y++)
{
map[x, y] = true;
}
}
}
}
[BurstCompile]
[WithAny(typeof(Tag_Walkable))]
partial struct JDrawMap_Walkable : IJobEntity
{
[NativeDisableParallelForRestriction] public NativeArray2D<bool> map;
public void Execute(in Coordinate coordinate)
{
for (int x = coordinate.pos.x; x < coordinate.pos.x + coordinate.width; x++)
{
for (int y = coordinate.pos.y; y < coordinate.pos.y + coordinate.height; y++)
{
map[x, y] = true;
}
}
}
}
Is there a way to replace them with one job with “flexible query”? For example:
void OnUpdate()
{
...
var jh1 = new JDrawMap
{
map = massingMap.ValueRW.Map
}.WithAll(typeof(Tag_Massing)).Schedule(state.Dependency);
var jh2 = new JDrawMap
{
map = walkableMap.ValueRW.Map
}.WithAll(typeof(Tag_Walkable)).Schedule(state.Dependency);
...
}
[BurstCompile]
partial struct JDrawMap: IJobEntity
{
[NativeDisableParallelForRestriction] public NativeArray2D<bool> map;
public void Execute(in Coordinate coordinate)
{
for (int x = coordinate.pos.x; x < coordinate.pos.x + coordinate.width; x++)
{
for (int y = coordinate.pos.y; y < coordinate.pos.y + coordinate.height; y++)
{
map[x, y] = true;
}
}
}
}