@@ -60,6 +60,24 @@ void RemoteClient::ResendBlockIfOnWire(v3s16 p)
60
60
}
61
61
}
62
62
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
+
63
81
void RemoteClient::GetNextBlocks (
64
82
ServerEnvironment *env,
65
83
EmergeManager * emerge,
@@ -91,7 +109,9 @@ void RemoteClient::GetNextBlocks (
91
109
}
92
110
93
111
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 ();
95
115
v3f playerspeeddir (0 ,0 ,0 );
96
116
if (playerspeed.getLength () > 1.0 *BS)
97
117
playerspeeddir = playerspeed / playerspeed.getLength ();
@@ -170,11 +190,8 @@ void RemoteClient::GetNextBlocks (
170
190
s32 new_nearest_unsent_d = -1 ;
171
191
172
192
// get view range and camera fov from the client
173
- s16 wanted_range = sao->getWantedRange ();
193
+ s16 wanted_range = sao->getWantedRange () + 1 ;
174
194
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 .;
178
195
179
196
const s16 full_d_max = MYMIN (g_settings->getS16 (" max_block_send_distance" ), wanted_range);
180
197
const s16 d_opt = MYMIN (g_settings->getS16 (" block_send_optimize_distance" ), wanted_range);
@@ -185,7 +202,7 @@ void RemoteClient::GetNextBlocks (
185
202
s16 d_max_gen = MYMIN (g_settings->getS16 (" max_block_generate_distance" ), wanted_range);
186
203
187
204
// Don't loop very much at a time
188
- s16 max_d_increment_at_time = 2 ;
205
+ s16 max_d_increment_at_time = 1 ;
189
206
if (d_max > d_start + max_d_increment_at_time)
190
207
d_max = d_start + max_d_increment_at_time;
191
208
@@ -247,10 +264,16 @@ void RemoteClient::GetNextBlocks (
247
264
Don't generate or send if not in sight
248
265
FIXME This only works if the client uses a small enough
249
266
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)
250
270
*/
251
-
252
271
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)))) {
254
277
continue ;
255
278
}
256
279
0 commit comments