public JobHandle ScheduleAssignTilesJob(ITerrainSampler terrainSampler, ref MapPixelData mapData, JobHandle dependencies, bool march = true)
{
// Cache tile data to minimise noise sampling during march.
NativeArray<byte> tileData = new NativeArray<byte>(tileDataDim * tileDataDim, Allocator.TempJob);
GenerateTileDataJob tileDataJob = new GenerateTileDataJob
{
heightmapData = mapData.heightmapData,
tileData = tileData,
tdDim = tileDataDim,
hDim = terrainSampler.HeightmapDimension,
maxTerrainHeight = terrainSampler.MaxTerrainHeight,
oceanElevation = terrainSampler.OceanElevation,
beachElevation = terrainSampler.BeachElevation,
mapPixelX = mapData.mapPixelX,
mapPixelY = mapData.mapPixelY,
};
JobHandle tileDataHandle = tileDataJob.Schedule(tileDataDim * tileDataDim, 64, dependencies);
// Assign tile data to terrain
NativeArray<byte> lookupData = new NativeArray<byte>(lookupTable, Allocator.TempJob);
AssignTilesJob assignTilesJob = new AssignTilesJob
{
lookupTable = lookupData,
tileData = tileData,
tilemapData = mapData.tilemapData,
tdDim = tileDataDim,
tDim = assignTilesDim,
march = march,
locationRect = mapData.locationRect,
};
JobHandle assignTilesHandle = assignTilesJob.Schedule(assignTilesDim * assignTilesDim, 64, tileDataHandle);
// Add both working native arrays to disposal list.
mapData.nativeArrayList.Add(tileData);
mapData.nativeArrayList.Add(lookupData);
return assignTilesHandle;
}