aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorhecks <42101236+hecktest@users.noreply.github.com>2021-02-26 21:23:46 +0100
committerGitHub <noreply@github.com>2021-02-26 21:23:46 +0100
commit225e69063fa0c3dc96f960aa79dfc568fe3d89a8 (patch)
treeae6247d0a0d20ef26d73f1a156bb5d1467e58ae7 /src/util
parent3edb1ddb8127aa7e8de867be50c695271091cb94 (diff)
downloadminetest-225e69063fa0c3dc96f960aa79dfc568fe3d89a8.tar.gz
minetest-225e69063fa0c3dc96f960aa79dfc568fe3d89a8.tar.bz2
minetest-225e69063fa0c3dc96f960aa79dfc568fe3d89a8.zip
Keep mapblocks in memory if they're in range (#10714)
Some other minor parts of clientmap.cpp have been cleaned up along the way
Diffstat (limited to 'src/util')
-rw-r--r--src/util/numeric.cpp8
-rw-r--r--src/util/numeric.h4
2 files changed, 6 insertions, 6 deletions
diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp
index 1af3f66be..99e4cfb5c 100644
--- a/src/util/numeric.cpp
+++ b/src/util/numeric.cpp
@@ -106,10 +106,6 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed)
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;
-
v3s16 blockpos_nodes = blockpos_b * MAP_BLOCKSIZE;
// Block center position
@@ -123,7 +119,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
v3f blockpos_relative = blockpos - camera_pos;
// Total distance
- f32 d = MYMAX(0, blockpos_relative.getLength() - block_max_radius);
+ f32 d = MYMAX(0, blockpos_relative.getLength() - BLOCK_MAX_RADIUS);
if (distance_ptr)
*distance_ptr = d;
@@ -141,7 +137,7 @@ bool isBlockInSight(v3s16 blockpos_b, v3f camera_pos, v3f camera_dir,
// such that a block that has any portion visible with the
// current camera position will have the center visible at the
// adjusted postion
- f32 adjdist = block_max_radius / cos((M_PI - camera_fov) / 2);
+ f32 adjdist = BLOCK_MAX_RADIUS / cos((M_PI - camera_fov) / 2);
// Block position relative to adjusted camera
v3f blockpos_adj = blockpos - (camera_pos - camera_dir * adjdist);
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 864ab7543..32a6f4312 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once
#include "basic_macros.h"
+#include "constants.h"
#include "irrlichttypes.h"
#include "irr_v2d.h"
#include "irr_v3d.h"
@@ -36,6 +37,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
y = temp; \
} while (0)
+// 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;
inline s16 getContainerPos(s16 p, s16 d)
{