Skip to content

Commit b97b9a5

Browse files
committed
Retrieve a small cone of blocks in the direction of the players velocity.
This helps retrieving the right set of blocks when the player is falling, traveling on cart, or in general traveling in a direction different from the view direction.
1 parent 6b23cab commit b97b9a5

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/clientiface.cpp

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,24 @@ void RemoteClient::ResendBlockIfOnWire(v3s16 p)
6060
}
6161
}
6262

63+
LuaEntitySAO *getAttachedObject(PlayerSAO *sao, ServerEnvironment *env)
64+
{
65+
if (!sao->isAttached())
66+
return nullptr;
67+
68+
int id;
69+
std::string bone;
70+
v3f dummy;
71+
sao->getAttachment(&id, &bone, &dummy, &dummy);
72+
ServerActiveObject *ao = env->getActiveObject(id);
73+
while (id && ao) {
74+
ao->getAttachment(&id, &bone, &dummy, &dummy);
75+
if (id)
76+
ao = env->getActiveObject(id);
77+
}
78+
return dynamic_cast<LuaEntitySAO *>(ao);
79+
}
80+
6381
void RemoteClient::GetNextBlocks (
6482
ServerEnvironment *env,
6583
EmergeManager * emerge,
@@ -91,7 +109,9 @@ void RemoteClient::GetNextBlocks (
91109
}
92110

93111
v3f playerpos = sao->getBasePosition();
94-
const v3f &playerspeed = player->getSpeed();
112+
// if the player is attached, get the velocity from the attached object
113+
LuaEntitySAO *lsao = getAttachedObject(sao, env);
114+
const v3f &playerspeed = lsao? lsao->getVelocity() : player->getSpeed();
95115
v3f playerspeeddir(0,0,0);
96116
if(playerspeed.getLength() > 1.0*BS)
97117
playerspeeddir = playerspeed / playerspeed.getLength();
@@ -170,11 +190,8 @@ void RemoteClient::GetNextBlocks (
170190
s32 new_nearest_unsent_d = -1;
171191

172192
// get view range and camera fov from the client
173-
s16 wanted_range = sao->getWantedRange();
193+
s16 wanted_range = sao->getWantedRange() + 1;
174194
float camera_fov = sao->getFov();
175-
// if FOV, wanted_range are not available (old client), fall back to old default
176-
if (wanted_range <= 0) wanted_range = 1000;
177-
if (camera_fov <= 0) camera_fov = (72.0*M_PI/180) * 4./3.;
178195

179196
const s16 full_d_max = MYMIN(g_settings->getS16("max_block_send_distance"), wanted_range);
180197
const s16 d_opt = MYMIN(g_settings->getS16("block_send_optimize_distance"), wanted_range);
@@ -185,7 +202,7 @@ void RemoteClient::GetNextBlocks (
185202
s16 d_max_gen = MYMIN(g_settings->getS16("max_block_generate_distance"), wanted_range);
186203

187204
// Don't loop very much at a time
188-
s16 max_d_increment_at_time = 2;
205+
s16 max_d_increment_at_time = 1;
189206
if(d_max > d_start + max_d_increment_at_time)
190207
d_max = d_start + max_d_increment_at_time;
191208

@@ -247,10 +264,16 @@ void RemoteClient::GetNextBlocks (
247264
Don't generate or send if not in sight
248265
FIXME This only works if the client uses a small enough
249266
FOV setting. The default of 72 degrees is fine.
267+
Also retrieve a smaller view cone in the direction of the player's
268+
movement.
269+
(0.1 is about 4 degrees)
250270
*/
251-
252271
f32 dist;
253-
if (!isBlockInSight(p, camera_pos, camera_dir, camera_fov, d_blocks_in_sight, &dist)) {
272+
if (!(isBlockInSight(p, camera_pos, camera_dir, camera_fov,
273+
d_blocks_in_sight, &dist) ||
274+
(playerspeed.getLength() > 1.0f * BS &&
275+
isBlockInSight(p, camera_pos, playerspeeddir, 0.1f,
276+
d_blocks_in_sight)))) {
254277
continue;
255278
}
256279

0 commit comments

Comments
 (0)