]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
entity/world collision response
[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         // light level that blocks of this type emit
26         int luminosity;
27
28         // whether to draw
29         bool visible;
30         // if true, stops light from propagating and fixes level to luminosity
31         bool block_light;
32
33         // whether to check for collisions at all
34         bool collision;
35         // if the block should be impenetrable
36         bool collide_block;
37
38         struct Faces {
39                 bool face[Block::FACE_COUNT];
40                 Faces &operator =(const Faces &other) noexcept {
41                         for (int i = 0; i < Block::FACE_COUNT; ++i) {
42                                 face[i] = other.face[i];
43                         }
44                         return *this;
45                 }
46                 bool operator [](Block::Face f) const noexcept {
47                         return face[f];
48                 }
49         } fill;
50
51         explicit BlockType(
52                 bool v = false,
53                 const glm::vec3 &color = { 1, 1, 1 },
54                 const Shape *shape = &DEFAULT_SHAPE
55         ) noexcept;
56
57         static const NullShape DEFAULT_SHAPE;
58
59         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
60                 return fill[block.OrientedFace(face)];
61         }
62
63         void FillModel(
64                 Model::Buffer &m,
65                 const glm::mat4 &transform = glm::mat4(1.0f),
66                 Model::Index idx_offset = 0
67         ) const noexcept;
68         void FillBlockModel(
69                 BlockModel::Buffer &m,
70                 const glm::mat4 &transform = glm::mat4(1.0f),
71                 BlockModel::Index idx_offset = 0
72         ) const noexcept;
73         void FillOutlineModel(
74                 OutlineModel &m,
75                 const glm::vec3 &pos_offset = { 0, 0, 0 },
76                 OutlineModel::Index idx_offset = 0
77         ) const noexcept;
78
79 };
80
81 }
82
83 #endif