Skip to content

Question about architecure - Chunk vs ChunkLayer #142

Open

Description

@etylermoss

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions