]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
caccb8f4b7ec237a014086195c6b065c875e2107
[blank.git] / src / world / BlockType.hpp
1 #ifndef BLANK_WORLD_BLOCKTYPE_HPP_
2 #define BLANK_WORLD_BLOCKTYPE_HPP_
3
4 #include "Block.hpp"
5 #include "../model/BlockModel.hpp"
6 #include "../model/Model.hpp"
7 #include "../model/OutlineModel.hpp"
8 #include "../model/shapes.hpp"
9
10 #include <glm/glm.hpp>
11
12
13 namespace blank {
14
15 /// single 1x1x1 cube
16 /// attributes of a type of block
17 struct BlockType {
18
19         const Shape *shape;
20         glm::vec3 color;
21         glm::vec3 outline_color;
22
23         // a string to display to the user
24         std::string label;
25
26         Block::Type id;
27
28         // light level that blocks of this type emit
29         int luminosity;
30
31         // whether to draw
32         bool visible;
33         // if true, stops light from propagating and fixes level to luminosity
34         bool block_light;
35
36         // whether to check for collisions at all
37         bool collision;
38         // if the block should be impenetrable
39         bool collide_block;
40
41         struct Faces {
42                 bool face[Block::FACE_COUNT];
43                 Faces &operator =(const Faces &other) noexcept {
44                         for (int i = 0; i < Block::FACE_COUNT; ++i) {
45                                 face[i] = other.face[i];
46                         }
47                         return *this;
48                 }
49                 bool operator [](Block::Face f) const noexcept {
50                         return face[f];
51                 }
52         } fill;
53
54         explicit BlockType(
55                 bool v = false,
56                 const glm::vec3 &color = { 1, 1, 1 },
57                 const Shape *shape = &DEFAULT_SHAPE
58         ) noexcept;
59
60         static const NullShape DEFAULT_SHAPE;
61
62         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
63                 return fill[block.OrientedFace(face)];
64         }
65
66         void FillModel(
67                 Model::Buffer &m,
68                 const glm::mat4 &transform = glm::mat4(1.0f),
69                 Model::Index idx_offset = 0
70         ) const noexcept;
71         void FillBlockModel(
72                 BlockModel::Buffer &m,
73                 const glm::mat4 &transform = glm::mat4(1.0f),
74                 BlockModel::Index idx_offset = 0
75         ) const noexcept;
76         void FillOutlineModel(
77                 OutlineModel &m,
78                 const glm::vec3 &pos_offset = { 0, 0, 0 },
79                 OutlineModel::Index idx_offset = 0
80         ) const noexcept;
81
82 };
83
84 }
85
86 #endif