/// <summary> /// Works exactly like the default TerrainTexturer, except that it skips the GenerateTileDataJob /// and uses the tileData generated during terrain sampling instead. /// Use the mod messaging system to obtain tileData for a map pixel in a custom TerrainTexturer. /// </summary> /// /// To access tileData in a separate mod, you can use this code: /// <code> /// byte[] tData = null; /// ModManager.Instance.SendModMessage("Interesting Terrains", "getTileData", new int[] { mapData.mapPixelX, mapData.mapPixelY }, (string message, object data) => /// { /// if (message == "error") /// Debug.LogError(data as string); /// else /// tData = data as byte[]; /// }); /// </code> public override JobHandle ScheduleAssignTilesJob(ITerrainSampler terrainSampler, ref MapPixelData mapData, JobHandle dependencies, bool march = true) { // Load tile data generated by the Terrain Sampler var tData = InterestingTerrains.tileDataCache.Get(mapData.mapPixelX, mapData.mapPixelY); NativeArray <byte> tileData = new NativeArray <byte>(tData, Allocator.TempJob); // Schedule the paint roads jobs if basic roads mod is enabled JobHandle preAssignTilesHandle = dependencies; if (CompatibilityUtils.BasicRoadsLoaded) { ModManager.Instance.SendModMessage("BasicRoads", "scheduleRoadsJob", new object[] { mapData, tileData, dependencies }, (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); }
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 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); }