/// <summary> /// Starts generation process. /// </summary> public void Generate(Range3I generationRange, GeneratedChunk[,,] chunks) { _totalChunks = generationRange.Count; _chunksDone = 0; generationRange.Foreach(pos => { var chunk = chunks[pos.X - generationRange.Position.X, pos.Y - generationRange.Position.Y, pos.Z - generationRange.Position.Z]; var chunkBytes = new byte[AbstractChunk.ChunkBlocksByteLength]; for (int y = 0; y < AbstractChunk.ChunkSize.Y; y++) { for (int x = 0; x < AbstractChunk.ChunkSize.X; x++) { for (int z = 0; z < AbstractChunk.ChunkSize.Z; z++) { var index = x * AbstractChunk.ChunkSize.Y + y + z * AbstractChunk.ChunkSize.Y * AbstractChunk.ChunkSize.X; if (y >= AbstractChunk.ChunkSize.Y / 2) { chunkBytes[index] = 0; //Air } else { chunkBytes[index] = FlatProcessorParams.CubeId.Ground; //First "Custom block" } } } } chunk.BlockData.SetBlockBytes(chunkBytes); _chunksDone++; }); }
public void Generate(Range3I generationRange, GeneratedChunk[,,] chunks) { generationRange.Foreach(pos => { //Get the chunk var chunk = chunks[pos.X - generationRange.Position.X, pos.Y - generationRange.Position.Y, pos.Z - generationRange.Position.Z]; var chunkWorldPosition = new Vector3D(chunk.Position.X * AbstractChunk.ChunkSize.X, 0.0, chunk.Position.Z * AbstractChunk.ChunkSize.Z); //Create the Rnd component to be used by the landscape creator var chunkRnd = new FastRandom(_worldParameters.Seed + chunk.Position.GetHashCode()); //If already generated, the buffer will take care of sending back directly the landscape from buffer zone, otherwhile landscape is generated. //The buffer has the advantage to be shared between client/server in "Single player" mode. //It means that a chunk, if generated by the server, won't need to be generated by the client because it will be stored into the buffer. //The buffer is heavily use for landscape entities that can span on multiple chunks like trees. LandscapeChunkBuffer landscapeBuffer = _landscapeBufferManager.Get(chunk.Position); while (landscapeBuffer.ProcessingState != LandscapeChunkBuffer.LandscapeChunkBufferState.Processed) { Thread.Sleep(100); landscapeBuffer = _landscapeBufferManager.Get(chunk.Position); } var columnsInfo = new ChunkColumnInfo[AbstractChunk.ChunkSize.X * AbstractChunk.ChunkSize.Z]; var chunkBytes = new byte[AbstractChunk.ChunkBlocksByteLength]; Array.Copy(landscapeBuffer.chunkBytesBuffer, chunkBytes, landscapeBuffer.chunkBytesBuffer.Length); Array.Copy(landscapeBuffer.ColumnsInfoBuffer, columnsInfo, columnsInfo.Length); var metaData = CreateChunkMetaData(columnsInfo); chunk.BlockData.ColumnsInfo = columnsInfo; //Save Columns info Array chunk.BlockData.ChunkMetaData = metaData; //Save the metaData Informations PopulateChunk(chunk, chunkBytes, metaData, chunkRnd, _entityFactory, landscapeBuffer.Entities); RefreshChunkMetaData(metaData, columnsInfo); chunk.BlockData.SetBlockBytes(chunkBytes); //Save block array }); }