public void ApplyGenerationResult(Vector3Int chunkId, LightmapGenerationJobResult result) { var chunkData = chunkManager.GetChunkData(chunkId); chunkData.SetLightMap(result.lights); }
public void ApplyGenerationResult(Vector3Int chunkId, LightmapGenerationJobResult result) { lightManager.ApplyGenerationResult(chunkId, result); }
public AbstractPipelineJob <LightmapGenerationJobResult> CreateGenerationJob(Vector3Int chunkId) { int[] heightMap = heightMapProvider.GetHeightMapForColumn(new Vector2Int(chunkId.x, chunkId.z)); var jobData = getJobData(chunkId); var generationJob = new LightGenerationJob() { data = jobData, dynamicPropagationQueue = new NativeQueue <int3>(Allocator.Persistent), sunlightPropagationQueue = new NativeQueue <int3>(Allocator.Persistent), heightmap = heightMap.ToNative() }; var propagationJob = new LightPropagationJob() { data = jobData, sunlightPropagationQueue = generationJob.sunlightPropagationQueue, dynamicPropagationQueue = generationJob.dynamicPropagationQueue, sunlightNeighbourUpdates = new LightJobNeighbourUpdates(Allocator.Persistent), dynamicNeighbourUpdates = new LightJobNeighbourUpdates(Allocator.Persistent), lightsChangedOnBorder = new NativeArray <bool>(DirectionExtensions.numDirections, Allocator.Persistent) }; Func <LightmapGenerationJobResult> cleanup = () => { var result = new LightmapGenerationJobResult(); result.lights = jobData.lights.ToArray(); generationJob.Dispose(); QueuePropagationUpdates(propagationJob); ///If any light value changes on any of the borders ///the corresponding neighbour will need to be re-meshed. for (int i = 0; i < propagationJob.lightsChangedOnBorder.Length; i++) { var neighbourChunkId = chunkId + DirectionExtensions.Vectors[i]; if (propagationJob.lightsChangedOnBorder[i]) { chunksWhereLightChangedOnBorderSinceLastUpdate.Add(neighbourChunkId); } } propagationJob.Dispose(); return(result); }; if (!Parallel) { return(new BasicFunctionJob <LightmapGenerationJobResult>(() => { generationJob.Run(); propagationJob.Run(); return cleanup(); })); } var genHandle = generationJob.Schedule(); var propHandle = propagationJob.Schedule(genHandle); return(new PipelineUnityJob <LightmapGenerationJobResult>(propHandle, cleanup)); }