]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
model -> mesh
[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 "../graphics/BlockMesh.hpp"
6 #include "../graphics/EntityMesh.hpp"
7 #include "../graphics/OutlineMesh.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 hsl_mod;
22         glm::vec3 rgb_mod;
23         glm::vec3 outline_color;
24
25         /// a string to display to the user
26         std::string label;
27
28         Block::Type id;
29
30         /// light level that blocks of this type emit
31         int luminosity;
32
33         /// whether to draw
34         bool visible;
35         /// if true, stops light from propagating and fixes level to luminosity
36         bool block_light;
37
38         /// whether to check for collisions at all
39         bool collision;
40         /// if the block should be impenetrable
41         bool collide_block;
42
43         // generation properties
44         /// whether to use this block in generation at all
45         bool generate;
46         // min/mid/max points for the respective properties
47         // should all be in the (-1,1) range
48         float min_solidity;
49         float mid_solidity;
50         float max_solidity;
51         float min_humidity;
52         float mid_humidity;
53         float max_humidity;
54         float min_temperature;
55         float mid_temperature;
56         float max_temperature;
57         float min_richness;
58         float mid_richness;
59         float max_richness;
60         /// commonness factor, random chance is multiplied by this
61         float commonness;
62
63         struct Faces {
64                 bool face[Block::FACE_COUNT];
65                 Faces &operator =(const Faces &other) noexcept {
66                         for (int i = 0; i < Block::FACE_COUNT; ++i) {
67                                 face[i] = other.face[i];
68                         }
69                         return *this;
70                 }
71                 bool operator [](Block::Face f) const noexcept {
72                         return face[f];
73                 }
74         } fill;
75
76         BlockType() noexcept;
77
78         static const NullShape DEFAULT_SHAPE;
79
80         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
81                 return fill[block.OrientedFace(face)];
82         }
83
84         void FillEntityMesh(
85                 EntityMesh::Buffer &m,
86                 const glm::mat4 &transform = glm::mat4(1.0f),
87                 EntityMesh::Index idx_offset = 0
88         ) const noexcept;
89         void FillBlockMesh(
90                 BlockMesh::Buffer &m,
91                 const glm::mat4 &transform = glm::mat4(1.0f),
92                 BlockMesh::Index idx_offset = 0
93         ) const noexcept;
94         void FillOutlineMesh(OutlineMesh::Buffer &m) const noexcept;
95
96 };
97
98 }
99
100 #endif