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