public static void ReadCompletedThreadedChunkWork(CompletedThreadedChunkWork ctcw) { AssignedWorkContainer awc; switch (ctcw.WorkType) { case CompletedWorkType.Generate: { //add the chunk to the dict. CompletedChunkGenerationWork ccgw = ctcw as CompletedChunkGenerationWork; AssignedWork.TryGetValue(ccgw.Chunk.ChunkPos, out awc); awc.RemoveAssignedJob(JobType.Generate); ChunkCollection.TryAdd(ccgw.Chunk.ChunkPos, ccgw.Chunk); ccgw.Chunk.SetGenerated(); break; } case CompletedWorkType.ValidateDrawing: { CompletedChunkPendingDrawingWork ccpdw = ctcw as CompletedChunkPendingDrawingWork; AssignedWork.TryGetValue(ccpdw.ChunkPos, out awc); awc.RemoveAssignedJob(JobType.Draw); if (ccpdw.CanDraw) { DrawChunk(ccpdw.ChunkPos); } else { foreach (Vector3 pos in ccpdw.ChunksToGenerate) { GenerateChunk(pos); } TryDrawingChunk(ccpdw.ChunkPos); } break; } case CompletedWorkType.Draw: { CheckCompletedDrawingWork(ctcw as CompletedSubChunkDrawingWork); break; } case CompletedWorkType.LoadViewDistance: { CheckCompletedViewDistanceLoaderWork(ctcw as CompletedViewDistanceLoaderWork); break; } case CompletedWorkType.UnloadOutsideViewDistance: { CheckCompletedViewDistanceUnloaderWork(ctcw as CompletedThreadedViewDistanceUnloader); break; } } }
public void TestChunkGeneration(Vector3 cPos) { ThreadedChunkGeneration tcg = new ThreadedChunkGeneration(cPos); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); CompletedChunkGenerationWork ccgw = tcg.Work() as CompletedChunkGenerationWork; watch.Stop(); Debug.Log("Completed generation of chunk " + cPos.ToString() + " in " + ((double)watch.Elapsed.Ticks / (double)System.TimeSpan.TicksPerMillisecond).ToString() + "ms"); ChunkHandler.TryAddChunk(ccgw.Chunk); }