private JobHandle ScheduleTileGeneration(TileVolume resultTiles, DataVolume data, int batchCount, JobHandle dependOn) { var tileGeneration = new GenerateTileDataJob { tileExtents = tileExtents, dataExtents = dataExtents, themeIndex = FillValue, yLevel = YLevel, centerRandomRotation = MesherSettings.centerRandomRotation, emptyBoundaries = MesherSettings.emptyBoundaries, skipCenter = MesherSettings.skipCenter, skipBorder = MesherSettings.skipBorder, configs = Theme.Configs, data = data.Data, tiles = resultTiles.Data }; return(tileGeneration.Schedule(resultTiles.Data.Length, batchCount, dependOn)); }
public override JobHandle ScheduleAssignTilesJob(ITerrainSampler terrainSampler, ref MapPixelData mapData, JobHandle dependencies, bool march = true) { // Cache tile data to minimise noise sampling during march (using default job) 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); // Schedule painting of roads, including smoothing if enabled JobHandle paintRoadsHandle = SchedulePaintRoadsJob(ref mapData, ref tileData, tileDataHandle); // Assign tile data to terrain (using default job) 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, paintRoadsHandle); // Add both working native arrays to disposal list. mapData.nativeArrayList.Add(tileData); mapData.nativeArrayList.Add(lookupData); return(assignTilesHandle); }
public override 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, painting paths in the process int pathsIndex = mapData.mapPixelX + (mapData.mapPixelY * MapsFile.MaxMapPixelX); byte roadDataPt = pathsData[roads][pathsIndex]; byte roadCorners = (byte)(InRange(pathsIndex) ? (pathsData[roads][pathsIndex + 1] & 0x5) | (pathsData[roads][pathsIndex - 1] & 0x50) : 0); byte trackDataPt = pathsData[tracks][pathsIndex]; byte trackCorners = (byte)(InRange(pathsIndex) ? (pathsData[tracks][pathsIndex + 1] & 0x5) | (pathsData[tracks][pathsIndex - 1] & 0x50) : 0); if (editorEnabled) { roadDataPt = BasicRoadsPathEditor.pathsData[roads][pathsIndex]; roadCorners = (byte)(InRange(pathsIndex) ? (BasicRoadsPathEditor.pathsData[roads][pathsIndex + 1] & 0x5) | (BasicRoadsPathEditor.pathsData[roads][pathsIndex - 1] & 0x50) : 0); trackDataPt = BasicRoadsPathEditor.pathsData[tracks][pathsIndex]; trackCorners = (byte)(InRange(pathsIndex) ? (BasicRoadsPathEditor.pathsData[tracks][pathsIndex + 1] & 0x5) | (BasicRoadsPathEditor.pathsData[tracks][pathsIndex - 1] & 0x50) : 0); } NativeArray <byte> lookupData = new NativeArray <byte>(lookupTable, Allocator.TempJob); AssignTilesWithRoadsJob assignTilesJob = new AssignTilesWithRoadsJob { lookupTable = lookupData, tileData = tileData, tilemapData = mapData.tilemapData, tdDim = tileDataDim, tDim = assignTilesDim, hDim = terrainSampler.HeightmapDimension, march = march, locationRect = mapData.locationRect, midLo = (assignTilesDim / 2) - 1, midHi = assignTilesDim / 2, roadDataPt = roadDataPt, roadCorners = roadCorners, trackDataPt = trackDataPt, trackCorners = trackCorners, }; JobHandle assignTilesHandle = assignTilesJob.Schedule(assignTilesDim * assignTilesDim, 64, tileDataHandle); JobHandle returnHandle = assignTilesHandle; if (smoothPaths) { SmoothRoadsTerrainJob smoothRoadTerrainJob = new SmoothRoadsTerrainJob() { heightmapData = mapData.heightmapData, tilemapData = mapData.tilemapData, hDim = DaggerfallUnity.Instance.TerrainSampler.HeightmapDimension, tDim = assignTilesDim, locationRect = mapData.locationRect, }; JobHandle smoothRoadHandle = smoothRoadTerrainJob.Schedule(assignTilesHandle); returnHandle = smoothRoadHandle; } // Add both working native arrays to disposal list. mapData.nativeArrayList.Add(tileData); mapData.nativeArrayList.Add(lookupData); return(returnHandle); }
public virtual 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); currentMapData = mapData; 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, worldClimate = mapData.worldClimate, }; JobHandle tileDataHandle = tileDataJob.Schedule(tileDataDim * tileDataDim, 64, dependencies); // Schedule the paint roads jobs if basic roads mod is enabled JobHandle preAssignTilesHandle = tileDataHandle; if (basicRoadsEnabled) { ModManager.Instance.SendModMessage("BasicRoads", "scheduleRoadsJob", new object[] { mapData, tileData, tileDataHandle }, (string message, object data) => { if (message == "error") { Debug.LogError(data as string); } else { preAssignTilesHandle = (JobHandle)data; } }); } // 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, preAssignTilesHandle); // Add both working native arrays to disposal list. mapData.nativeArrayList.Add(tileData); mapData.nativeArrayList.Add(lookupData); return(assignTilesHandle); }