public bool IsJobInQueue(Vector3 chunkLocation) { GenerateChunkJob check = new GenerateChunkJob(); check.chunkLocationToGenerate = chunkLocation; if (check.Equals(activeGenerationJob)) { return(true); } else if (generationQueue.Contains(check)) { return(true); } else if (check.Equals(activeMeshJob)) { return(true); } else if (meshGenerationQueue.Contains(check.ToMeshJob())) { return(true); } return(false); }
public void RemoveGenerationJob(GenerateChunkJob jobToRemove) { if (jobToRemove.Equals(activeGenerationJob)) { activeGenerationJob.Abort(); activeGenerationJob = null; hasActiveGenerationJob = false; } else if (!generationQueue.Contains(jobToRemove)) { if (jobToRemove.Equals(activeMeshJob)) { activeMeshJob.Abort(); activeMeshJob = null; hasActiveMeshJob = false; } else { meshGenerationQueue.Remove(jobToRemove.ToMeshJob()); } } else { generationQueue.Remove(jobToRemove); } }
void RemoveChunkJob(Vector3 targetRemovalPositon) { GenerateChunkJob removalJob = new GenerateChunkJob(); removalJob.chunkLocationToGenerate = targetRemovalPositon; generationJobManager.RemoveGenerationJob(removalJob); }
public bool Equals(GenerateChunkJob check) { if (check == null) { return(false); } if (chunkLocationToGenerate == check.chunkLocationToGenerate) { return(true); } return(false); }
private void LoadNewChunksNearPlayer(Vector3 playerChunkLocation) { for (int i = -chunksAroundPlayer; i < chunksAroundPlayer + 1; i++) { for (int k = -chunksAroundPlayer; k < chunksAroundPlayer + 1; k++) { if (!chunkMap.IsChunkLoaded(new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k))) { GenerateChunkJob chunkToGenerate = new GenerateChunkJob(); chunkToGenerate.chunkLocationToGenerate = new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k); generationJobManager.AddGenerationJob(chunkToGenerate); chunkMap.AddLoadedChunk(new Vector3(playerChunkLocation.x + i, 0, playerChunkLocation.z + k)); } } } }
private void CheckActiveGenerationJob() { if (activeGenerationJob != null) { if (activeGenerationJob.Update()) { hasActiveGenerationJob = false; GenerateMeshFromChunkJob meshJob = new GenerateMeshFromChunkJob(); meshJob.chunkCoordinates = activeGenerationJob.chunkLocationToGenerate; meshJob.chunkVoxelArray = activeGenerationJob.chunkVoxelArray; AddMeshJob(meshJob); activeGenerationJob = null; } } }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var generateBURSTJob = new GenerateChunkBURSTJob { ChunkSize = ChunkMarkGenerateJS.ChunkSize, cbd = GetBufferFromEntity <ChunkBufferData>() }; var handle = generateBURSTJob.Schedule(this, inputDeps); var generateJob = new GenerateChunkJob { commandBuffer = ecbSystem.CreateCommandBuffer().ToConcurrent(), }; handle = generateJob.Schedule(this, handle); ecbSystem.AddJobHandleForProducer(handle); return(handle); }
public void GenerateAllNewChunks(int chunkWidth, int chunkHeight) { if (newChunks.Count > 0) { NativeList <JobHandle> jobHandleList = new NativeList <JobHandle>(Allocator.Temp); foreach (TerrainChunk c in newChunks.Values) { //NativeHashMap<float2, bool> stateMap = new NativeHashMap<float2, bool>(chunkWidth * chunkHeight, Allocator.TempJob); NativeList <bool> stateList = new NativeList <bool>(chunkWidth * chunkHeight, Allocator.TempJob); GenerateChunkJob chunkJob = new GenerateChunkJob { width = chunkWidth, height = chunkHeight, position = c.position, seed = planetSettings.planetSeed, featureSize = planetSettings.planetFeatureSize, tileStates = stateList }; chunkBoolMap.Add(stateList); jobHandleList.Add(chunkJob.Schedule()); } JobHandle.CompleteAll(jobHandleList); int index = 0; foreach (TerrainChunk c in newChunks.Values) { c.SetTileStatesFromNativeList(chunkBoolMap[index]); c.GenerateChunk(); chunkBoolMap[index].Dispose(); index++; } //CombineMeshes(); jobHandleList.Dispose(); chunkBoolMap.Clear(); newChunks.Clear(); } }
public void AddGenerationJob(GenerateChunkJob jobToAdd) { generationQueue.Enqueue(jobToAdd); }
private void StartNextGenerationJob() { activeGenerationJob = generationQueue.Dequeue(); hasActiveGenerationJob = true; activeGenerationJob.Start(); }