private static void xdirFunction(int xdir, int3 offset, Chunk[, ,] chunks) { if (xdir >= 1) { for (int i = 0; i < xdir; i++) { ChunkWorldPositionOffset.x += 1; for (int x = 0; x < worldChunkSize.x; x++) { for (int y = 0; y < worldChunkSize.y; y++) { for (int z = 0; z < worldChunkSize.z; z++) { if (x == 0) { MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x + 1, y, z].AddChunkDrawdataToMeshQueue)); } if (x == worldChunkSize.x - 1) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.chunkArray[x, y, z] = new Chunk(pos, offset); ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x - 1, y, z].AddChunkDrawdataToMeshQueue)); } else { chunks[x, y, z] = chunks[x + 1, y, z]; } /* * //newstuff after this * * if (x == worldChunkSize.x - 1) * { * * } */ } } } } } else if (xdir <= -1) { for (int i = 0; i > xdir; i--) { ChunkWorldPositionOffset.x -= 1; for (int x = worldChunkSize.x - 1; x >= 0; x--) { for (int y = worldChunkSize.y - 1; y >= 0; y--) { for (int z = worldChunkSize.z - 1; z >= 0; z--) { if (x == (worldChunkSize.x - 1)) { MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x - 1, y, z].AddChunkDrawdataToMeshQueue)); } if (x == 0) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.chunkArray[x, y, z] = new Chunk(pos, offset); ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x + 1, y, z].AddChunkDrawdataToMeshQueue)); } else { chunks[x, y, z] = chunks[x - 1, y, z]; } } } } } } }
private static List <Chunk> zdirFunction(int zdir, int3 offset) { List <Chunk> chunksToBeDrawn = new List <Chunk>(); if (zdir >= 1) { for (int i = 0; i < zdir; i++) { ChunkWorldPositionOffset.z += 1; for (int x = 0; x < worldChunkSize.x; x++) { for (int y = 0; y < worldChunkSize.y; y++) { for (int z = 0; z < worldChunkSize.z; z++) { if (z == 0) { //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue)); } else if (z == worldChunkSize.z - 1) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset)); if (!WorldInitializer.getChunk(x, y, z).anyNonAir) { continue; } chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue)); } else { //chunks[x, y, z] = chunks[x, y, z + 1]; WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z + 1)); } } } } } } else if (zdir <= -1) { for (int i = 0; i > zdir; i--) { ChunkWorldPositionOffset.z -= 1; for (int x = worldChunkSize.x - 1; x >= 0; x--) { for (int y = worldChunkSize.y - 1; y >= 0; y--) { for (int z = worldChunkSize.z - 1; z >= 0; z--) { if (z == (worldChunkSize.z - 1)) { //MeshGeneration.AddToRemoveQueue(WorldInitializer.chunkArray[x, y, z]); MeshGeneration.AddToRemoveQueue(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z - 1].AddChunkDrawdataToMeshQueue)); } else if (z == 0) { int3 pos = new int3(x + ChunkWorldPositionOffset.x, y + ChunkWorldPositionOffset.y, z + ChunkWorldPositionOffset.z); WorldInitializer.setChunk(x, y, z, new Chunk(pos, offset)); if (!WorldInitializer.getChunk(x, y, z).anyNonAir) { continue; } chunksToBeDrawn.Add(WorldInitializer.getChunk(x, y, z)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z].AddChunkDrawdataToMeshQueue)); //ThreadPool.QueueUserWorkItem(new WaitCallback(WorldInitializer.chunkArray[x, y, z + 1].AddChunkDrawdataToMeshQueue)); } else { //chunks[x, y, z] = chunks[x, y, z - 1]; WorldInitializer.setChunk(x, y, z, WorldInitializer.getChunk(x, y, z - 1)); } } } } } } return(chunksToBeDrawn); }