diff options
| author | est31 <MTest31@outlook.com> | 2016-12-22 23:16:00 +0100 |
|---|---|---|
| committer | est31 <MTest31@outlook.com> | 2016-12-22 23:16:00 +0100 |
| commit | 81d56b94919dceb7b2e51d70b21a7ca22f852bd5 (patch) | |
| tree | 1e9ef1be1b3295a8673d6e4f0bdeb4c2d3a6015f /src/util/numeric.cpp | |
| parent | 8077612dcb48221281e726a60eb97bf73fde462b (diff) | |
| parent | 231ac33d34dfaaddf292c5f31b1eae43eeefba2d (diff) | |
| download | minetest-81d56b94919dceb7b2e51d70b21a7ca22f852bd5.tar.xz | |
Merge 0.4.15 changes into stable-0.4
0.4.15 release!
Diffstat (limited to 'src/util/numeric.cpp')
| -rw-r--r-- | src/util/numeric.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 42ebd9022..a9e7ae584 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include <string.h> #include <iostream> -std::map<u16, std::vector<v3s16> > FacePositionCache::m_cache; +UNORDERED_MAP<u16, std::vector<v3s16> > FacePositionCache::m_cache; Mutex FacePositionCache::m_cache_mutex; // Calculate the borders of a "d-radius" cube // TODO: Make it work without mutex and data races, probably thread-local @@ -188,14 +188,19 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) } /* - blockpos: position of block in block coordinates + blockpos_b: position of block in block coordinates camera_pos: position of camera in nodes camera_dir: an unit vector pointing to camera direction 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) { + // Maximum radius of a block. The magic number is + // sqrt(3.0) / 2.0 in literal form. + const f32 block_max_radius = 0.866025403784 * MAP_BLOCKSIZE * BS; + v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE; // Block center position @@ -209,7 +214,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, v3f blockpos_relative = blockpos - camera_pos; // Total distance - f32 d = blockpos_relative.getLength(); + f32 d = MYMAX(0, blockpos_relative.getLength() - block_max_radius); if(distance_ptr) *distance_ptr = d; @@ -218,13 +223,9 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir, if(d > range) return false; - // Maximum radius of a block. The magic number is - // sqrt(3.0) / 2.0 in literal form. - f32 block_max_radius = 0.866025403784 * MAP_BLOCKSIZE * BS; - // If block is (nearly) touching the camera, don't // bother validating further (that is, render it anyway) - if(d < block_max_radius) + if(d == 0) return true; // Adjust camera position, for purposes of computing the angle, |
