]> git.localhorst.tv Git - blank.git/blob - src/block.hpp
don't add obstructed blocks to meshes
[blank.git] / src / block.hpp
1 #ifndef BLANK_BLOCK_HPP_
2 #define BLANK_BLOCK_HPP_
3
4 #include "geometry.hpp"
5 #include "model.hpp"
6 #include "shape.hpp"
7
8 #include <vector>
9 #include <glm/glm.hpp>
10
11
12 namespace blank {
13
14 /// single 1x1x1 cube
15 struct Block {
16
17         using Type = unsigned short;
18         using Pos = glm::vec3;
19
20         Type type;
21
22         constexpr explicit Block(Type type = 0)
23         : type(type) { }
24
25 };
26
27
28 /// attributes of a type of block
29 struct BlockType {
30
31         const Shape *shape;
32         glm::vec3 color;
33         glm::vec3 outline_color;
34
35         Block::Type id;
36
37         bool visible;
38
39         struct Faces {
40                 bool right;
41                 bool left;
42                 bool top;
43                 bool bottom;
44                 bool front;
45                 bool back;
46         } fill;
47
48         explicit BlockType(
49                 bool v = false,
50                 const glm::vec3 &color = { 1, 1, 1 },
51                 const Shape *shape = &DEFAULT_SHAPE
52         );
53
54         static const NullShape DEFAULT_SHAPE;
55
56
57         void FillModel(
58                 Model::Buffer &m,
59                 const glm::vec3 &pos_offset = { 0, 0, 0 },
60                 Model::Index idx_offset = 0
61         ) const;
62         void FillOutlineModel(
63                 OutlineModel &m,
64                 const glm::vec3 &pos_offset = { 0, 0, 0 },
65                 OutlineModel::Index idx_offset = 0
66         ) const;
67
68 };
69
70
71 class BlockTypeRegistry {
72
73 public:
74         BlockTypeRegistry();
75
76 public:
77         Block::Type Add(const BlockType &);
78
79         size_t Size() const { return types.size(); }
80
81         BlockType *operator [](Block::Type id) { return &types[id]; }
82         const BlockType *Get(Block::Type id) const { return &types[id]; }
83
84 private:
85         std::vector<BlockType> types;
86
87 };
88
89 }
90
91 #endif