aboutsummaryrefslogtreecommitdiff
path: root/src/util/numeric.cpp
diff options
context:
space:
mode:
authorElias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com>2020-11-04 16:57:47 +0100
committerGitHub <noreply@github.com>2020-11-04 16:57:47 +0100
commit3e16c3a78fff61c20e63ba730d15e94e3bb877b4 (patch)
treec070350db219f2c4241d22bc31949685c7b42fe9 /src/util/numeric.cpp
parent5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (diff)
parent6ccb5835ff55d85156be91473c598eca9d6cb9a6 (diff)
downloaddragonfireclient-3e16c3a78fff61c20e63ba730d15e94e3bb877b4.tar.xz
Merge branch 'master' into master
Diffstat (limited to 'src/util/numeric.cpp')
-rw-r--r--src/util/numeric.cpp48
1 files changed, 22 insertions, 26 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp
index d464c5836..1af3f66be 100644
--- a/src/util/numeric.cpp
+++ b/src/util/numeric.cpp
@@ -21,11 +21,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "log.h"
#include "constants.h" // BS, MAP_BLOCKSIZE
-#include "noise.h" // PseudoRandom, PcgRandom
+#include "noise.h" // PseudoRandom, PcgRandom
#include "threading/mutex_auto_lock.h"
#include <cstring>
#include <cmath>
+
// myrand
PcgRandom g_pcgrand;
@@ -50,6 +51,7 @@ int myrand_range(int min, int max)
return g_pcgrand.range(min, max);
}
+
/*
64-bit unaligned version of MurmurHash
*/
@@ -77,21 +79,14 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
const unsigned char *data2 = (const unsigned char *)data;
switch (len & 7) {
- case 7:
- h ^= (u64)data2[6] << 48;
- case 6:
- h ^= (u64)data2[5] << 40;
- case 5:
- h ^= (u64)data2[4] << 32;
- case 4:
- h ^= (u64)data2[3] << 24;
- case 3:
- h ^= (u64)data2[2] << 16;
- case 2:
- h ^= (u64)data2[1] << 8;
- case 1:
- h ^= (u64)data2[0];
- h *= m;
+ case 7: h ^= (u64)data2[6] << 48;
+ case 6: h ^= (u64)data2[5] << 40;
+ case 5: h ^= (u64)data2[4] << 32;
+ case 4: h ^= (u64)data2[3] << 24;
+ case 3: h ^= (u64)data2[2] << 16;
+ case 2: h ^= (u64)data2[1] << 8;
+ case 1: h ^= (u64)data2[0];
+ h *= m;
}
h ^= h >> r;
@@ -108,20 +103,21 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
range: viewing range
distance_ptr: return location for distance from the camera
*/
-bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, f32 camera_fov,
- f32 range, f32 *distance_ptr)
+bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
+ f32 camera_fov, f32 range, f32 *distance_ptr)
{
// Maximum radius of a block. The magic number is
// sqrt(3.0) / 2.0 in literal form.
- static constexpr const f32 block_max_radius =
- 0.866025403784f * MAP_BLOCKSIZE * BS;
+ static constexpr const f32 block_max_radius = 0.866025403784f * MAP_BLOCKSIZE * BS;
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
// Block center position
- v3f blockpos(((float)blockpos_nodes.X + MAP_BLOCKSIZE / 2) * BS,
- ((float)blockpos_nodes.Y + MAP_BLOCKSIZE / 2) * BS,
- ((float)blockpos_nodes.Z + MAP_BLOCKSIZE / 2) * BS);
+ v3f blockpos(
+ ((float)blockpos_nodes.X + MAP_BLOCKSIZE/2) * BS,
+ ((float)blockpos_nodes.Y + MAP_BLOCKSIZE/2) * BS,
+ ((float)blockpos_nodes.Z + MAP_BLOCKSIZE/2) * BS
+ );
// Block position relative to camera
v3f blockpos_relative = blockpos - camera_pos;
@@ -176,7 +172,7 @@ s16 adjustDist(s16 dist, float zoom_fov)
return dist;
return std::round(dist * std::cbrt((1.0f - std::cos(threshold_fov)) /
- (1.0f - std::cos(zoom_fov / 2.0f))));
+ (1.0f - std::cos(zoom_fov / 2.0f))));
}
void setPitchYawRollRad(core::matrix4 &m, const v3f &rot)
@@ -205,11 +201,11 @@ v3f getPitchYawRollRad(const core::matrix4 &m)
const f32 *M = m.pointer();
f64 a1 = atan2(M[1], M[5]);
- f32 c2 = std::sqrt((f64)M[10] * M[10] + (f64)M[8] * M[8]);
+ f32 c2 = std::sqrt((f64)M[10]*M[10] + (f64)M[8]*M[8]);
f32 a2 = atan2f(-M[9], c2);
f64 c1 = cos(a1);
f64 s1 = sin(a1);
- f32 a3 = atan2f(s1 * M[6] - c1 * M[2], c1 * M[0] - s1 * M[4]);
+ f32 a3 = atan2f(s1*M[6] - c1*M[2], c1*M[0] - s1*M[4]);
return v3f(a2, a3, a1);
}