]> git.localhorst.tv Git - blank.git/blob - src/block.hpp
decrease block id size
[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         Block::Type id;
32
33         bool visible;
34
35         const Shape *shape;
36         glm::vec3 color;
37         glm::vec3 outline_color;
38
39         explicit BlockType(
40                 bool v = false,
41                 const glm::vec3 &color = { 1, 1, 1 },
42                 const Shape *shape = &DEFAULT_SHAPE,
43                 const glm::vec3 &outline_color = { -1, -1, -1 })
44         : id(0), visible(v), shape(shape), color(color), outline_color(outline_color) { }
45
46         static const NullShape DEFAULT_SHAPE;
47
48
49         void FillModel(
50                 Model &m,
51                 const glm::vec3 &pos_offset = { 0, 0, 0 },
52                 Model::Index idx_offset = 0
53         ) const;
54         void FillOutlineModel(
55                 OutlineModel &m,
56                 const glm::vec3 &pos_offset = { 0, 0, 0 },
57                 OutlineModel::Index idx_offset = 0
58         ) const;
59
60 };
61
62
63 class BlockTypeRegistry {
64
65 public:
66         BlockTypeRegistry();
67
68 public:
69         Block::Type Add(const BlockType &);
70
71         size_t Size() const { return types.size(); }
72
73         BlockType *operator [](Block::Type id) { return &types[id]; }
74         const BlockType *Get(Block::Type id) const { return &types[id]; }
75
76 private:
77         std::vector<BlockType> types;
78
79 };
80
81 }
82
83 #endif