static void UnloadChunksOutsideViewDistance() { ThreadedChunkWork tcw; if (!NonChunkSpecificWork.TryGetValue(JobType.UnloadOutsideViewDistance, out tcw)) { ThreadedViewDistanceUnloaderWork tvduw = new ThreadedViewDistanceUnloaderWork(PlayerChunkPos, ViewDistance, GetLoadedChunkPositions, ChunkGameObjectHandler.GetDrawnChunkPositions); NonChunkSpecificWork.Add(JobType.UnloadOutsideViewDistance, tvduw); ThreadHandler.EnqueuWork(tvduw); } }
public static void TryDrawingChunk(Vector3 chunkPos) { AssignedWorkContainer awc = GetWorkContainer(chunkPos); //Check if the chunk is already drawn or if it requires redrawing. if (!awc.ContainsWork(JobType.Draw)) { ThreadedPendingDrawingWork tpdw = new ThreadedPendingDrawingWork(chunkPos); awc.AddAssignedJob(JobType.Draw, new AssignedJob(chunkPos, JobType.Draw, tpdw)); ThreadHandler.EnqueuWork(tpdw); } }
public static void DrawAllChunksWithinViewDistance() { ThreadedChunkWork tcw; if (!NonChunkSpecificWork.TryGetValue(JobType.LoadViewDistance, out tcw)) { ThreadedViewDistanceLoaderWork tvdlw = new ThreadedViewDistanceLoaderWork(ViewDistance, PlayerChunkPos, PlayerPositionHasChanged); NonChunkSpecificWork.Add(JobType.LoadViewDistance, tvdlw); ThreadHandler.EnqueuWork(tvdlw); } UnloadChunksOutsideViewDistance(); }
public static void GenerateChunk(Vector3 chunkPos) { Chunk c; if (!ChunkCollection.TryGetValue(chunkPos, out c)) { AssignedWorkContainer awc = GetWorkContainer(chunkPos); if (!awc.ContainsWork(JobType.Generate)) { ThreadedChunkGeneration tcg = new ThreadedChunkGeneration(chunkPos); awc.AddAssignedJob(JobType.Generate, new AssignedJob(chunkPos, JobType.Generate, tcg)); ThreadHandler.EnqueuWork(tcg); } } }
public static void DrawChunk(Vector3 chunkPos) { AssignedWorkContainer awc = GetWorkContainer(chunkPos); if (!awc.ContainsWork(JobType.Draw)) { Chunk c; TryGetChunk(chunkPos, out c); ThreadedSubChunkDrawingWork[] workArr = c.GetSubChunksToDraw(); if (workArr.Length > 0) { awc.AddAssignedJob(JobType.Draw, new AssignedJob(chunkPos, JobType.Draw, workArr)); ThreadHandler.EnqueuWork(workArr); } else { ChunkGameObjectHandler.UpdateMesh(c.ChunkPos, c.GetMesh()).transform.position = c.ChunkPos * Chunk.CHUNKSIZE; } } }