]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
merge common parts of pre- and unload states
[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         // generation properties
43         /// whether to use this block in generation at all
44         bool generate;
45         // min/mid/max points for the respective properties
46         // should all be in the (-1,1) range
47         float min_solidity;
48         float mid_solidity;
49         float max_solidity;
50         float min_humidity;
51         float mid_humidity;
52         float max_humidity;
53         float min_temperature;
54         float mid_temperature;
55         float max_temperature;
56         float min_richness;
57         float mid_richness;
58         float max_richness;
59         /// commonness factor, random chance is multiplied by this
60         float commonness;
61
62         struct Faces {
63                 bool face[Block::FACE_COUNT];
64                 Faces &operator =(const Faces &other) noexcept {
65                         for (int i = 0; i < Block::FACE_COUNT; ++i) {
66                                 face[i] = other.face[i];
67                         }
68                         return *this;
69                 }
70                 bool operator [](Block::Face f) const noexcept {
71                         return face[f];
72                 }
73         } fill;
74
75         explicit BlockType(
76                 bool v = false,
77                 const glm::vec3 &color = { 1, 1, 1 },
78                 const Shape *shape = &DEFAULT_SHAPE
79         ) noexcept;
80
81         static const NullShape DEFAULT_SHAPE;
82
83         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
84                 return fill[block.OrientedFace(face)];
85         }
86
87         void FillEntityModel(
88                 EntityModel::Buffer &m,
89                 const glm::mat4 &transform = glm::mat4(1.0f),
90                 EntityModel::Index idx_offset = 0
91         ) const noexcept;
92         void FillBlockModel(
93                 BlockModel::Buffer &m,
94                 const glm::mat4 &transform = glm::mat4(1.0f),
95                 BlockModel::Index idx_offset = 0
96         ) const noexcept;
97         void FillOutlineModel(OutlineModel::Buffer &m) const noexcept;
98
99 };
100
101 }
102
103 #endif