- const BlockType *type;
-
- constexpr explicit Block(const BlockType *t = &BlockType::DEFAULT)
- : type(t) { }
-
-};
-
-
-/// cube of size 16 (256 tiles, 4096 blocks)
-class Chunk {
-
-public:
- Chunk();
-
- static constexpr int Width() { return 16; }
- static constexpr int Height() { return 16; }
- static constexpr int Depth() { return 16; }
- static constexpr int Size() { return Width() * Height() * Depth(); }
-
- static constexpr int ToIndex(const glm::vec3 &pos) {
- return pos.x + pos.y * Width() + pos.z * Width() * Height();
- }
- static glm::vec3 ToCoords(int idx) {
- return glm::vec3(
- idx % Width(),
- (idx / Width()) % Height(),
- idx / (Width() * Height())
- );
- }
-
- void Invalidate() { dirty = true; }
-
- Block &BlockAt(const glm::vec3 &pos) { return blocks[ToIndex(pos)]; }
- const Block &BlockAt(const glm::vec3 &pos) const { return blocks[ToIndex(pos)]; }
-
- void Draw();