public void GenerateInitialChunks(GlobalChunkCoordinate origin, Action <String> SetLoadingMessage) { // todo: Since the world isn't infinite we can get rid of this. float origBuildRadius = GenerateDistance; GenerateDistance = origBuildRadius * 2.0f; var initialChunkCoordinates = new List <GlobalChunkCoordinate>(); for (int dx = origin.X - WorldSize.X / 2 + 1; dx < origin.X + WorldSize.X / 2; dx++) { for (int dz = origin.Z - WorldSize.Z / 2 + 1; dz < origin.Z + WorldSize.Z / 2; dz++) { initialChunkCoordinates.Add(new GlobalChunkCoordinate(dx, 0, dz)); } } SetLoadingMessage("Generating Chunks..."); foreach (var box in initialChunkCoordinates) { Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World); chunk.IsVisible = true; ChunkData.AddChunk(chunk); } // This is critical at the beginning to allow trees to spawn on ramps correctly, // and also to ensure no inconsistencies in chunk geometry due to ramps. foreach (var chunk in ChunkData.ChunkMap) { ChunkGen.GenerateCaves(chunk, World); for (var i = 0; i < VoxelConstants.ChunkSizeY; ++i) { // Update corner ramps on all chunks so that they don't have seams when they // are initially built. //VoxelListPrimitive.UpdateCornerRamps(chunk, i); chunk.InvalidateSlice(i); } } RecalculateBounds(); SetLoadingMessage("Generating Ores..."); GenerateOres(); GenerateDistance = origBuildRadius; }
private static void InvalidateVoxel( VoxelChunk Chunk, GlobalVoxelCoordinate Coordinate, int Y) { Chunk.InvalidateSlice(Y); var localCoordinate = Coordinate.GetLocalVoxelCoordinate(); // Invalidate slice cache for neighbor chunks. if (localCoordinate.X == 0) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(-1, 0, 0), Y); if (localCoordinate.Z == 0) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(-1, 0, -1), Y); } if (localCoordinate.Z == VoxelConstants.ChunkSizeZ - 1) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(-1, 0, 1), Y); } } if (localCoordinate.X == VoxelConstants.ChunkSizeX - 1) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(1, 0, 0), Y); if (localCoordinate.Z == 0) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(1, 0, -1), Y); } if (localCoordinate.Z == VoxelConstants.ChunkSizeZ - 1) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(1, 0, 1), Y); } } if (localCoordinate.Z == 0) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(0, 0, -1), Y); } if (localCoordinate.Z == VoxelConstants.ChunkSizeZ - 1) { InvalidateNeighborSlice(Chunk.Manager.ChunkData, Chunk.ID, new Point3(0, 0, 1), Y); } }
// Todo: Move to ChunkGenerator public void GenerateInitialChunks(Rectangle spawnRect, GlobalChunkCoordinate origin, Action <String> SetLoadingMessage) { var initialChunkCoordinates = new List <GlobalChunkCoordinate>(); for (int dx = 0; dx < WorldSize.X; dx++) { for (int dz = 0; dz < WorldSize.Z; dz++) { initialChunkCoordinates.Add(new GlobalChunkCoordinate(dx, 0, dz)); } } SetLoadingMessage("Generating Chunks..."); float maxHeight = Math.Max(Overworld.GetMaxHeight(spawnRect), 0.17f); foreach (var box in initialChunkCoordinates) { Vector3 worldPos = new Vector3( box.X * VoxelConstants.ChunkSizeX, box.Y * VoxelConstants.ChunkSizeY, box.Z * VoxelConstants.ChunkSizeZ); VoxelChunk chunk = ChunkGen.GenerateChunk(worldPos, World, maxHeight); ChunkData.AddChunk(chunk); } // This is critical at the beginning to allow trees to spawn on ramps correctly, // and also to ensure no inconsistencies in chunk geometry due to ramps. foreach (var chunk in ChunkData.ChunkMap) { ChunkGen.GenerateChunkData(chunk, World, maxHeight); for (var i = 0; i < VoxelConstants.ChunkSizeY; ++i) { chunk.InvalidateSlice(i); } } RecalculateBounds(); SetLoadingMessage("Generating Ores..."); GenerateOres(); NeedsMinimapUpdate = true; }