, move_velocity(0.003f)
, pitch_sensitivity(-0.0025f)
, yaw_sensitivity(-0.001f)
-, testBlockType(true)
+, blockType()
, cam()
, chunk()
, light_position(17.0f, 17.0f, 17.0f)
, light_color(1.0f, 1.0f, 1.0f)
-, light_power(100.0f)
+, light_power(250.0f)
, m_handle(0)
, v_handle(0)
, mv_handle(0)
cam.Position(glm::vec3(0, 4, 4));
- chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(&testBlockType);
- chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(&testBlockType);
- chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(&testBlockType);
- chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(&testBlockType);
- chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(&testBlockType);
- chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(&testBlockType);
+ blockType.Add(BlockType(true, glm::vec3(1, 1, 1)));
+ blockType.Add(BlockType(true, glm::vec3(1, 0, 0)));
+ blockType.Add(BlockType(true, glm::vec3(0, 1, 0)));
+ blockType.Add(BlockType(true, glm::vec3(0, 0, 1)));
+
+ chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(blockType[4]);
+ chunk.BlockAt(glm::vec3(0, 0, 1)) = Block(blockType[1]);
+ chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(blockType[2]);
+ chunk.BlockAt(glm::vec3(1, 0, 1)) = Block(blockType[3]);
+ chunk.BlockAt(glm::vec3(2, 0, 0)) = Block(blockType[4]);
+ chunk.BlockAt(glm::vec3(2, 0, 1)) = Block(blockType[1]);
+ chunk.BlockAt(glm::vec3(3, 0, 0)) = Block(blockType[2]);
+ chunk.BlockAt(glm::vec3(3, 0, 1)) = Block(blockType[3]);
+ chunk.BlockAt(glm::vec3(2, 0, 2)) = Block(blockType[4]);
+ chunk.BlockAt(glm::vec3(2, 0, 3)) = Block(blockType[1]);
+ chunk.BlockAt(glm::vec3(3, 0, 2)) = Block(blockType[2]);
+ chunk.BlockAt(glm::vec3(3, 0, 3)) = Block(blockType[3]);
+ chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(blockType[1]);
+ chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(blockType[4]);
+ chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(blockType[3]);
+ chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(blockType[2]);
chunk.Invalidate();
m_handle = program.UniformLocation("M");
vertices.emplace_back(pos.x + 1, pos.y + 1, pos.z );
vertices.emplace_back(pos.x + 1, pos.y + 1, pos.z + 1);
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // front
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // back
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // top
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // bottom
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // left
- colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // right
+ colors.insert(colors.end(), 6 * 6, color);
normals.insert(normals.end(), 6, glm::vec3( 0.0f, 0.0f, 1.0f)); // front
normals.insert(normals.end(), 6, glm::vec3( 0.0f, 0.0f, -1.0f)); // back
}
+BlockTypeRegistry::BlockTypeRegistry() {
+ Add(BlockType::DEFAULT);
+}
+
+int BlockTypeRegistry::Add(const BlockType &t) {
+ int id = types.size();
+ types.push_back(t);
+ types.back().id = id;
+ return id;
+}
+
+
Chunk::Chunk()
: blocks(Size())
, model()
/// attributes of a type of block
struct BlockType {
+ int id;
+
bool visible;
+ glm::vec3 color;
- constexpr explicit BlockType(bool v = false)
- : visible(v) { }
+ constexpr explicit BlockType(
+ bool v = false,
+ const glm::vec3 &color = { 1, 1, 1 })
+ : id(-1), visible(v), color(color) { }
static const BlockType DEFAULT;
};
+class BlockTypeRegistry {
+
+public:
+ BlockTypeRegistry();
+
+public:
+ int Add(const BlockType &);
+
+ BlockType *operator [](int id) { return &types[id]; }
+ const BlockType *Get(int id) const { return &types[id]; }
+
+private:
+ std::vector<BlockType> types;
+
+};
+
+
/// single 1x1x1 cube
struct Block {