]> git.localhorst.tv Git - blank.git/blob - src/block.hpp
use indices for model rendering
[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 /// attributes of a type of block
15 struct BlockType {
16
17         int id;
18
19         bool visible;
20
21         const Shape *shape;
22         glm::vec3 color;
23         glm::vec3 outline_color;
24
25         explicit BlockType(
26                 bool v = false,
27                 const glm::vec3 &color = { 1, 1, 1 },
28                 const Shape *shape = &DEFAULT_SHAPE,
29                 const glm::vec3 &outline_color = { -1, -1, -1 })
30         : id(-1), visible(v), shape(shape), color(color), outline_color(outline_color) { }
31
32         static const NullShape DEFAULT_SHAPE;
33
34
35         void FillModel(
36                 Model &m,
37                 const glm::vec3 &pos_offset = { 0, 0, 0 },
38                 Model::Index idx_offset = 0
39         ) const;
40         void FillOutlineModel(
41                 OutlineModel &m,
42                 const glm::vec3 &pos_offset = { 0, 0, 0 },
43                 OutlineModel::Index idx_offset = 0
44         ) const;
45
46 };
47
48
49 class BlockTypeRegistry {
50
51 public:
52         BlockTypeRegistry();
53
54 public:
55         int Add(const BlockType &);
56
57         size_t Size() const { return types.size(); }
58
59         BlockType *operator [](int id) { return &types[id]; }
60         const BlockType *Get(int id) const { return &types[id]; }
61
62 private:
63         std::vector<BlockType> types;
64
65 };
66
67
68 /// single 1x1x1 cube
69 struct Block {
70
71         using Pos = glm::vec3;
72
73         int type;
74
75         constexpr explicit Block(int type = 0)
76         : type(type) { }
77
78 };
79
80 }
81
82 #endif