]> git.localhorst.tv Git - blank.git/blob - src/world/BlockType.hpp
3ca170a200ba65367ff604bfbada3645456714b1
[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 "BlockGravity.hpp"
6 #include "../graphics/BlockMesh.hpp"
7 #include "../graphics/EntityMesh.hpp"
8 #include "../graphics/PrimitiveMesh.hpp"
9 #include "../model/Shape.hpp"
10
11 #include <glm/glm.hpp>
12 #include <vector>
13
14
15 namespace blank {
16
17 class ResourceIndex;
18 class ShapeRegistry;
19 class TokenStreamReader;
20
21 /// single 1x1x1 cube
22 /// attributes of a type of block
23 struct BlockType {
24
25         const Shape *shape;
26         std::vector<float> textures;
27         glm::tvec3<unsigned char> hsl_mod;
28         glm::tvec3<unsigned char> rgb_mod;
29         glm::tvec3<unsigned char> outline_color;
30
31         /// gravity configuration or null if not emitting gravity
32         std::unique_ptr<BlockGravity> gravity;
33
34         /// a string identifying in contexts where numbers just won't do
35         /// must be unique within any given set
36         std::string name;
37         /// a string to display to the user
38         std::string label;
39
40         int place_sound;
41         int remove_sound;
42
43         Block::Type id;
44
45         /// light level that blocks of this type emit
46         int luminosity;
47
48         /// whether to draw
49         bool visible;
50         /// if true, stops light from propagating and fixes level to luminosity
51         bool block_light;
52
53         /// whether to check for collisions at all
54         bool collision;
55         /// if the block should be impenetrable
56         bool collide_block;
57
58         // generation properties
59         /// whether to use this block in generation at all
60         bool generate;
61         // min/mid/max points for the respective properties
62         // should all be in the (-1,1) range
63         float min_solidity;
64         float mid_solidity;
65         float max_solidity;
66         float min_humidity;
67         float mid_humidity;
68         float max_humidity;
69         float min_temperature;
70         float mid_temperature;
71         float max_temperature;
72         float min_richness;
73         float mid_richness;
74         float max_richness;
75         /// commonness factor, random chance is multiplied by this
76         float commonness;
77
78         BlockType() noexcept;
79
80         /// clone values of given type
81         /// this copies everything except for ID, name, label, and gravity
82         void Copy(const BlockType &) noexcept;
83
84         void Read(
85                 TokenStreamReader &in,
86                 ResourceIndex &snd_index,
87                 ResourceIndex &tex_index,
88                 const ShapeRegistry &shapes);
89
90         bool FaceFilled(const Block &block, Block::Face face) const noexcept {
91                 return shape && shape->FaceFilled(block.OrientedFace(face));
92         }
93
94         void FillEntityMesh(
95                 EntityMesh::Buffer &m,
96                 const glm::mat4 &transform = glm::mat4(1.0f)
97         ) const noexcept;
98         void FillBlockMesh(
99                 BlockMesh::Buffer &m,
100                 const glm::mat4 &transform = glm::mat4(1.0f),
101                 BlockMesh::Index idx_offset = 0
102         ) const noexcept;
103         void OutlinePrimitiveMesh(PrimitiveMesh::Buffer &) const noexcept;
104
105 };
106
107 }
108
109 #endif