I've finally managed to implement an infinite chunk loading system for my voxel engine. Since every chunk needs to have information about the border of the neighbouring chunks, I need to access them fast. First some information about how I'm storing the voxel data: I have an Integer array of block information on each chunk (rather than byte because of the read/write access speed), which is stored in an Dictionary(Vector3i chunkPos, Chunk chunk). When building a chunk I have to access the voxel data of the chunk and of the neighbouring chunks several times.
Without information about their neighbours it currently looks like this:
So I've tried the following two things:
getting the chunk data every time like this:
public static int getBlockAt(int x, int y, int z) { Vector3i chunkIndex = new Vector3i( x >> ChunkManager.logChunkSize, y >> ChunkManager.logChunkSize, z >> ChunkManager.logChunkSize ); if (chunkManager.chunkData.ContainsKey(chunkIndex)) { return chunkManager.chunkData[chunkIndex].data[x & ChunkManager.chunkMask, y & ChunkManager.chunkMask, z & ChunkManager.chunkMask]} return 0;
storing chunkSize + 2 information on each chunk, which makes editing much, much slower, but improves chunk loading alot
In general I want to implement something like using approach 1 only when the block data isn't on the chunk.
I really don't know how I could do it! Do you have an idea, or experience from writing voxel engines?
Thanks in advance!