Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about architecure - Chunk vs ChunkLayer #142

Open
etylermoss opened this issue Dec 18, 2021 · 0 comments
Open

Question about architecure - Chunk vs ChunkLayer #142

etylermoss opened this issue Dec 18, 2021 · 0 comments

Comments

@etylermoss
Copy link

Hi all,

Wondering if anyone can answer why in the code chunks are split up into the Chunk , ChunkSection, and Layer classes. The last one I think I get, it just keeps track of if the chunk contains any opaque blocks. Not too sure on the difference between the other two though, or why they were split apart.

Firstly Chunk contains member: std::vector<ChunkSection> m_chunks, I don't get why this is a std::vector, because ChunkSection contains an array of all the blocks in the chunk (i.e. std::array<CHUNK_VOLUME, blocks>), so why would a chunk need to contain multiple sections?

Secondly, why does ChunkSection inherit (match?) IChunk, again why not make it a Chunk? Code:

class ChunkSection : public IChunk {
    friend class Chunk;
    ...
}

Thirdly, in this code:

const ChunkSection::Layer &ChunkSection::getLayer(int y) const
{
    if (y == -1) {
        return m_pWorld->getChunkManager()
            .getChunk(m_location.x, m_location.z)
            .getSection(m_location.y - 1)
            .getLayer(CHUNK_SIZE - 1);
    }
    else if (y == CHUNK_SIZE) {
        return m_pWorld->getChunkManager()
            .getChunk(m_location.x, m_location.z)
            .getSection(m_location.y + 1)
            .getLayer(0);
    }
    else {
        return m_layers[y];
    }
}

What are the first two if / else if conditions testing for exactly? Isn't the desired layer always contained within the relevant ChunkSection (it contains all blocks in a chunk, std::array<Layer, CHUNK_SIZE>? Why use the chunk manager here?

Any explanation, detail about these classes, or just suggestions for further reading around the architecture of chunks, voxel worlds etc. would be much appreciated!

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant