1 #ifndef BLANK_WORLD_BLOCKTYPE_HPP_
2 #define BLANK_WORLD_BLOCKTYPE_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"
11 #include <glm/glm.hpp>
20 class TokenStreamReader;
23 /// attributes of a type of block
27 std::vector<float> textures;
28 glm::tvec3<unsigned char> hsl_mod;
29 glm::tvec3<unsigned char> rgb_mod;
30 glm::tvec3<unsigned char> outline_color;
32 /// gravity configuration or null if not emitting gravity
33 std::unique_ptr<BlockGravity> gravity;
35 /// a string identifying in contexts where numbers just won't do
36 /// must be unique within any given set
38 /// a string to display to the user
46 /// light level that blocks of this type emit
51 /// if true, stops light from propagating and fixes level to luminosity
54 /// whether to check for collisions at all
56 /// if the block should be impenetrable
59 // generation properties
60 /// whether to use this block in generation at all
63 // min/mid/max points for the respective properties
64 // should all be in the (-1,1) range
68 Distribution(float min, float mid, float max)
69 : xmin(min), xmid(mid), xmax(max) { Update(); }
71 bool Valid(float x) const noexcept {
72 return x >= xmin && x <= xmax;
74 float Map(float x) const noexcept {
75 // previous algo as was used by Generator
76 //return 4.0f - ((x - xmid) * (x - xmid));
78 // linear mapping of [min,mid,max] to [-1,0,1]
80 x *= (x < 0) ? inv_neg : inv_pos;
82 // smoothing: x^4 - 2x^2 + 1
84 return x * x - 2.0f * x + 1.0f;
87 void Min(float m) noexcept { xmin = m; Update(); }
88 float Min() const noexcept { return xmin; }
89 void Mid(float m) noexcept { xmid = m; Update(); }
90 float Mid() const noexcept { return xmid; }
91 void Max(float m) noexcept { xmax = m; Update(); }
92 float Max() const noexcept { return xmax; }
96 float abs_min = std::abs(xmin - xmid);
97 inv_neg = abs_min < std::numeric_limits<float>::epsilon() ? 0.0f : 1.0f / abs_min;
98 float abs_max = std::abs(xmax - xmid);
99 inv_pos = abs_max < std::numeric_limits<float>::epsilon() ? 0.0f : 1.0f / abs_max;
110 Distribution solidity;
111 Distribution humidity;
112 Distribution temperature;
113 Distribution richness;
114 /// commonness factor, random chance is multiplied by this
117 BlockType() noexcept;
119 /// clone values of given type
120 /// this copies everything except for ID, name, label, and gravity
121 void Copy(const BlockType &) noexcept;
124 TokenStreamReader &in,
125 ResourceIndex &snd_index,
126 ResourceIndex &tex_index,
127 const ShapeRegistry &shapes);
129 bool FaceFilled(const Block &block, Block::Face face) const noexcept {
130 return shape && shape->FaceFilled(block.OrientedFace(face));
134 EntityMesh::Buffer &m,
135 const glm::mat4 &transform = glm::mat4(1.0f)
138 BlockMesh::Buffer &m,
139 const glm::mat4 &transform = glm::mat4(1.0f),
140 BlockMesh::Index idx_offset = 0
142 void OutlinePrimitiveMesh(PrimitiveMesh::Buffer &) const noexcept;