public void AddFinishedTask(ChunkNeighbourTask task) { lock (neighbourTaskLocker) { finishedNeighbourTasks.Enqueue(task); } }
public void OnTaskDone(ChunkNeighbourTask task) { lock (mutex) { activeTasks--; //activeTask.Remove(task); } handler.AddFinishedTask(task); }
protected IEnumerator WaitTillAsynGenerationDone() { Time.timeScale = 0; mainCam.enabled = false; bool repeat = true; List <Exception> x = CompressedMarchingCubeChunk.xs; while (repeat) { Vector3 next; bool isNextInProgress; if (totalTriBuild < maxTrianglesLeft) { //TODO: while waiting create mesh displayers! -> leads to worse performance? while (finishedNeighbourTasks.Count > 0) { ChunkNeighbourTask task = GetFinishedTask(); BuildNeighbourChunks(task); } } while (closestNeighbours.size > 0) { do { next = closestNeighbours.Dequeue(); isNextInProgress = chunkGroup.HasChunkStartedAt(VectorExtension.ToArray(next)); } while (isNextInProgress && closestNeighbours.size > 0); if (!isNextInProgress) { CreateChunkWithAsyncGPUReadback(next, FindNeighbourOfChunk); } } if (neighbourFinder.InitializationDone) { repeat = false; Time.timeScale = 1; mainCam.enabled = true; watch.Stop(); Debug.Log("Total millis: " + watch.Elapsed.TotalMilliseconds); if (totalTriBuild >= maxTrianglesLeft) { Debug.Log("Aborted"); } Debug.Log("Total triangles: " + totalTriBuild); StartCoroutine(CreateEmptyChunks()); OnInitialializationDone(); } yield return(null); } }
protected void CreatePlanetFromMeshData() { MeshData data; CompressedMarchingCubeChunk start = FindNonEmptyChunkAround(startPos, out data); ChunkNeighbourTask task = new ChunkNeighbourTask(start, data); task.NeighbourSearch(); BuildRelevantChunksFromMeshDataBlockingAround(task); }
protected IEnumerator CreateEmptyChunks() { while (finishedNeighbourTasks.Count > 0) { ChunkNeighbourTask task = GetFinishedTask(); BuildSpawnersAround(task); } yield return(new WaitForSeconds(0.1f)); //maybe dont create empty but check if normal chunk should be build. //since no new chunks are searched for increasing lod a small connection //to neighbour chunk may be missed resulting in hole in mesh yield return(CreateEmptyChunks()); }
public bool TryGetTask(out ChunkNeighbourTask task) { lock (locker) { if (waitingTasks.Count > 0) { task = waitingTasks.Dequeue(); activeTasks++; } else { task = null; } } return(task != null); }
public void AddTask(ChunkNeighbourTask task) { ThreadPool.QueueUserWorkItem((o) => { try { lock (mutex) { //activeTask.Add(task); activeTasks++; } task.FindNeighbours(); OnTaskDone(task); } catch (Exception x) { CompressedMarchingCubeChunk.xs.Add(x); } }); //lock(locker) // waitingTasks.Enqueue(task); }
public void BuildRelevantChunksFromMeshDataBlockingAround(ChunkNeighbourTask task) { bool[] dirs = task.HasNeighbourInDirection; CompressedMarchingCubeChunk chunk = task.chunk; int count = dirs.Length; for (int i = 0; i < count; ++i) { if (!dirs[i]) { continue; } Vector3Int v3 = VectorExtension.DirectionFromIndex[i] * (chunk.ChunkSize + 1) + chunk.CenterPos; closestNeighbours.Enqueue(0, v3); ///for initial neighbours build additional chunks to not just wait for first thread to be done ///seems to worsen performance? //v3 = 2 * VectorExtension.DirectionFromIndex[i] * (chunk.ChunkSize + 1) + chunk.CenterPos; //closestNeighbours.Enqueue(0, v3); //v3 = 3 * VectorExtension.DirectionFromIndex[i] * (chunk.ChunkSize + 1) + chunk.CenterPos; //closestNeighbours.Enqueue(0, v3); } if (closestNeighbours.size > 0) { BuildRelevantChunksFromMeshDataBlockingAround(); } watch.Stop(); Debug.Log("Total millis: " + watch.Elapsed.TotalMilliseconds); if (totalTriBuild >= maxTrianglesLeft) { Debug.Log("Aborted"); } Debug.Log("Total triangles: " + totalTriBuild); OnInitialializationDone(); // Debug.Log($"Number of chunks: {ChunkGroups.Count}"); }
public void BuildSpawnersAround(ChunkNeighbourTask task) { BuildSpawnersAround(task.HasNeighbourInDirection, task.chunk.ChunkSize, task.chunk.CenterPos); }
public void BuildNeighbourChunks(ChunkNeighbourTask task) { BuildNeighbourChunks(task.HasNeighbourInDirection, task.chunk.ChunkSize, task.chunk.CenterPos); }