1 #ifndef BLANK_WORLD_HPP_
2 #define BLANK_WORLD_HPP_
13 /// attributes of a type of block
21 constexpr explicit BlockType(
23 const glm::vec3 &color = { 1, 1, 1 })
24 : id(-1), visible(v), color(color) { }
26 static const BlockType DEFAULT;
31 std::vector<glm::vec3> &vertices,
32 std::vector<glm::vec3> &colors,
33 std::vector<glm::vec3> &normals
36 void FillModel(const glm::vec3 &pos, Model &m) const {
37 FillVBO(pos, m.vertices, m.colors, m.normals);
43 class BlockTypeRegistry {
49 int Add(const BlockType &);
51 BlockType *operator [](int id) { return &types[id]; }
52 const BlockType *Get(int id) const { return &types[id]; }
55 std::vector<BlockType> types;
63 const BlockType *type;
65 constexpr explicit Block(const BlockType *t = &BlockType::DEFAULT)
71 /// cube of size 16 (256 tiles, 4096 blocks)
77 static constexpr int Width() { return 16; }
78 static constexpr int Height() { return 16; }
79 static constexpr int Depth() { return 16; }
80 static constexpr int Size() { return Width() * Height() * Depth(); }
82 static constexpr int ToIndex(const glm::vec3 &pos) {
83 return pos.x + pos.y * Width() + pos.z * Width() * Height();
85 static glm::vec3 ToCoords(int idx) {
88 (idx / Width()) % Height(),
89 idx / (Width() * Height())
93 void Invalidate() { dirty = true; }
95 Block &BlockAt(const glm::vec3 &pos) { return blocks[ToIndex(pos)]; }
96 const Block &BlockAt(const glm::vec3 &pos) const { return blocks[ToIndex(pos)]; }
101 int VertexCount() const;
105 std::vector<Block> blocks;