public void Generate(Object empty) { ArrayPool <Position> pool = ArrayPool <Position> .Create(Constants.CHUNK_SIZE3D * 6 * 4, 1); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); for (int x = 0; x < CHUNKS_TO_GENERATE; x++) { for (int y = 0; y < CHUNKS_TO_GENERATE; y++) { for (int z = 0; z < CHUNKS_TO_GENERATE; z++) { Chunk chunk = chunkFiller.GenerateChunk(x << Constants.CHUNK_EXPONENT, y << Constants.CHUNK_EXPONENT, z << Constants.CHUNK_EXPONENT, weltschmerz); if (!chunk.IsSurface) { chunk.x = (uint)x << Constants.CHUNK_EXPONENT; chunk.y = (uint)y << Constants.CHUNK_EXPONENT; chunk.z = (uint)z << Constants.CHUNK_EXPONENT; } if (!chunk.IsEmpty) { mesher.MeshChunk(chunk, pool); } } } } stopwatch.Stop(); Godot.GD.Print(CHUNKS_TO_GENERATE * CHUNKS_TO_GENERATE * CHUNKS_TO_GENERATE + " chunks generated in " + stopwatch.ElapsedMilliseconds); }
private void AddChunks(Godot.Object empty) { Dictionary <Tuple <int, int, int>, Chunk> newChunks = new Dictionary <Tuple <int, int, int>, Chunk>(); foreach (Vector3 pos in chunkPoints) { Vector3 chunkPos = player.ToGlobal(pos) / Constants.CHUNK_LENGHT; Tuple <int, int, int> tuple = new Tuple <int, int, int>((int)chunkPos.x, (int)chunkPos.y, (int)chunkPos.z); if (chunks.ContainsKey(tuple)) { newChunks.Add(tuple, chunks[tuple]); } else { Chunk chunk = server.RequestChunk(tuple.Item1, tuple.Item2, tuple.Item3); if (chunk != null && !newChunks.ContainsKey(tuple)) { if (!chunk.IsEmpty) { mesher.MeshChunk(chunk, pool); } newChunks.Add(tuple, chunk); } } } chunks = newChunks; }