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