]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
some code reorganization
[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         Block::Type id;
24
25         int luminosity;
26
27         bool visible;
28         bool block_light;
29
30         struct Faces {
31                 bool face[Block::FACE_COUNT];
32                 Faces &operator =(const Faces &other) noexcept {
33                         for (int i = 0; i < Block::FACE_COUNT; ++i) {
34                                 face[i] = other.face[i];
35                         }
36                         return *this;
37                 }
38                 bool operator [](Block::Face f) const noexcept {
39                         return face[f];
40                 }
41         } fill;
42
43         explicit BlockType(
44                 bool v = false,
45                 const glm::vec3 &color = { 1, 1, 1 },
46                 const Shape *shape = &DEFAULT_SHAPE
47         ) noexcept;
48
49         static const NullShape DEFAULT_SHAPE;
50
51         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
52                 return fill[block.OrientedFace(face)];
53         }
54
55         void FillModel(
56                 Model::Buffer &m,
57                 const glm::mat4 &transform = glm::mat4(1.0f),
58                 Model::Index idx_offset = 0
59         ) const noexcept;
60         void FillBlockModel(
61                 BlockModel::Buffer &m,
62                 const glm::mat4 &transform = glm::mat4(1.0f),
63                 BlockModel::Index idx_offset = 0
64         ) const noexcept;
65         void FillOutlineModel(
66                 OutlineModel &m,
67                 const glm::vec3 &pos_offset = { 0, 0, 0 },
68                 OutlineModel::Index idx_offset = 0
69         ) const noexcept;
70
71 };
72
73 }
74
75 #endif