public void GenerateThread() { EventWaitHandle[] waitHandles = { NeedsGenerationEvent, Program.ShutdownEvent }; #if CREATE_CRASH_LOGS try #endif { while (!ExitThreads) { EventWaitHandle wh = Datastructures.WaitFor(waitHandles); //GeneratorLock.WaitOne(); if (!PauseThreads && ToGenerate != null && ToGenerate.Count > 0) { Point3 box = ToGenerate[0]; if (!ChunkData.ChunkMap.ContainsKey(box)) { Vector3 worldPos = new Vector3(box.X * ChunkData.ChunkSizeX, box.Y * ChunkData.ChunkSizeY, box.Z * ChunkData.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, (int)ChunkData.ChunkSizeX, (int)ChunkData.ChunkSizeY, (int)ChunkData.ChunkSizeZ, Components, Content, Graphics); Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.1f); chunk.ShouldRebuild = true; chunk.ShouldRecalculateLighting = true; GeneratedChunks.Enqueue(chunk); } ToGenerate.Remove(box); } //GeneratorLock.ReleaseMutex(); if (wh == Program.ShutdownEvent) { break; } } } #if CREATE_CRASH_LOGS catch (Exception exception) { ProgramData.WriteExceptionLog(exception); } #endif }
public void GenerateThread() { EventWaitHandle[] waitHandles = { NeedsGenerationEvent, Program.ShutdownEvent }; #if CREATE_CRASH_LOGS try #endif { while (!ExitThreads) { EventWaitHandle wh = Datastructures.WaitFor(waitHandles); //GeneratorLock.WaitOne(); if (!PauseThreads && ToGenerate != null && ToGenerate.Count > 0) { System.Threading.Tasks.Parallel.ForEach(ToGenerate, box => { //if (!ChunkData.CheckBounds(box)) //{ Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World); //Drawer3D.DrawBox(chunk.GetBoundingBox(), Color.Red, 0.1f, false); //} }); ToGenerate.Clear(); } //GeneratorLock.ReleaseMutex(); if (wh == Program.ShutdownEvent) { break; } } } #if CREATE_CRASH_LOGS catch (Exception exception) { ProgramData.WriteExceptionLog(exception); } #endif }