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 RemoveChunk(VoxelChunk chunk) { VoxelChunk removed = null; while (!ChunkMap.TryRemove(chunk.ID, out removed)) { Thread.Sleep(10); } HashSet <Body> locatables = new HashSet <Body>(); chunkManager.Components.CollisionManager.GetObjectsIntersecting(chunk.GetBoundingBox(), locatables, CollisionManager.CollisionType.Static | CollisionManager.CollisionType.Dynamic); foreach (Body component in locatables) { component.IsDead = true; } chunk.Destroy(chunkManager.Graphics); }
public void RemoveChunk(VoxelChunk chunk) { VoxelChunk removed = null; while (!ChunkMap.TryRemove(chunk.ID, out removed)) { Thread.Sleep(10); } HashSet <IBoundedObject> locatables = new HashSet <IBoundedObject>(); chunkManager.Components.CollisionManager.GetObjectsIntersecting(chunk.GetBoundingBox(), locatables, CollisionManager.CollisionType.Static | CollisionManager.CollisionType.Dynamic); foreach (var component in locatables.Where(o => o is Body).Select(o => o as Body)) { component.Die(); } chunk.Destroy(chunkManager.Graphics); }
public void RemoveChunk(VoxelChunk chunk) { VoxelChunk removed = null; while (!ChunkMap.TryRemove(chunk.ID, out removed)) { Thread.Sleep(10); } HashSet<Body> locatables = new HashSet<Body>(); chunkManager.Components.CollisionManager.GetObjectsIntersecting(chunk.GetBoundingBox(), locatables, CollisionManager.CollisionType.Static | CollisionManager.CollisionType.Dynamic); foreach(Body component in locatables) { component.IsDead = true; } chunk.Destroy(chunkManager.Graphics); }