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