i am working on voxel based game engine, in which i need to have chunks. I have tried to read a Chunk class from minecraft, but i cant understand it.
By chunk i mean: 16x16x256 array of blocks
So my question is: How chunk works and how does it store data?
Well, that defies some geometrical structure then. If this is a Micraft-esque game, then a block is either filled, or it’s void. Do you want those blocks be of different types, or just “there” or “not there”.
Lets say, for the sake of simplicity, that you want to have 2^CHAR_BIT different states for a block (CHAR_BIT is 8 on most systems). The state 0 means void. So you can store those blocks in a array of the structure
You can encapsulate this in a class.
Of course your world consists of more than one chunk, you’ll probably arrange your chunks in a grid, where each grid cell takes up one chunk
And for sure you also want to organize those Chunks in a spatial subdivision structure, so that you can quickly index chunks depending on their position in the world, a Octree works wonderfully for that
you’ll also want some functions to traverse this structure, but I’ll leave the research up to you, as a learning experimence. I’ve given you plenty of keywords to search the interwebs for.