@@ -188,9 +188,8 @@ bool wouldCollideWithCeiling(
188
188
189
189
assert (y_increase >= 0 ); // pre-condition
190
190
191
- for (std::vector<NearbyCollisionInfo>::const_iterator it = cinfo.begin ();
192
- it != cinfo.end (); ++it) {
193
- const aabb3f &staticbox = it->box ;
191
+ for (const auto &it : cinfo) {
192
+ const aabb3f &staticbox = it.box ;
194
193
if ((movingbox.MaxEdge .Y - d <= staticbox.MinEdge .Y ) &&
195
194
(movingbox.MaxEdge .Y + y_increase > staticbox.MinEdge .Y ) &&
196
195
(movingbox.MinEdge .X < staticbox.MaxEdge .X ) &&
@@ -203,7 +202,7 @@ bool wouldCollideWithCeiling(
203
202
return false ;
204
203
}
205
204
206
- static inline void getNeighborConnectingFace (v3s16 p, INodeDefManager *nodedef,
205
+ static inline void getNeighborConnectingFace (const v3s16 & p, INodeDefManager *nodedef,
207
206
Map *map, MapNode n, int v, int *neighbors)
208
207
{
209
208
MapNode n2 = map->getNodeNoEx (p);
@@ -255,7 +254,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
255
254
std::vector<NearbyCollisionInfo> cinfo;
256
255
{
257
256
// TimeTaker tt2("collisionMoveSimple collect boxes");
258
- ScopeProfiler sp (g_profiler, " collisionMoveSimple collect boxes avg" , SPT_AVG);
257
+ ScopeProfiler sp2 (g_profiler, " collisionMoveSimple collect boxes avg" , SPT_AVG);
259
258
260
259
v3f newpos_f = *pos_f + *speed_f * dtime;
261
260
v3f minpos_f (
@@ -273,12 +272,10 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
273
272
274
273
bool any_position_valid = false ;
275
274
276
- for (s16 x = min.X ; x <= max.X ; x++)
277
- for (s16 y = min.Y ; y <= max.Y ; y++)
278
- for (s16 z = min.Z ; z <= max.Z ; z++)
279
- {
280
- v3s16 p (x,y,z);
281
-
275
+ v3s16 p;
276
+ for (p.X = min.X ; p.X <= max.X ; p.X ++)
277
+ for (p.Y = min.Y ; p.Y <= max.Y ; p.Y ++)
278
+ for (p.Z = min.Z ; p.Z <= max.Z ; p.Z ++) {
282
279
bool is_position_valid;
283
280
MapNode n = map->getNodeNoEx (p, &is_position_valid);
284
281
@@ -288,12 +285,15 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
288
285
any_position_valid = true ;
289
286
INodeDefManager *nodedef = gamedef->getNodeDefManager ();
290
287
const ContentFeatures &f = nodedef->get (n);
291
- if (f.walkable == false )
288
+
289
+ if (!f.walkable )
292
290
continue ;
291
+
293
292
int n_bouncy_value = itemgroup_get (f.groups , " bouncy" );
294
293
295
294
int neighbors = 0 ;
296
- if (f.drawtype == NDT_NODEBOX && f.node_box .type == NODEBOX_CONNECTED) {
295
+ if (f.drawtype == NDT_NODEBOX &&
296
+ f.node_box .type == NODEBOX_CONNECTED) {
297
297
v3s16 p2 = p;
298
298
299
299
p2.Y ++;
@@ -321,20 +321,15 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
321
321
}
322
322
std::vector<aabb3f> nodeboxes;
323
323
n.getCollisionBoxes (gamedef->ndef (), &nodeboxes, neighbors);
324
- for (std::vector<aabb3f>::iterator
325
- i = nodeboxes.begin ();
326
- i != nodeboxes.end (); ++i)
327
- {
328
- aabb3f box = *i;
329
- box.MinEdge += v3f (x, y, z)*BS;
330
- box.MaxEdge += v3f (x, y, z)*BS;
331
- cinfo.push_back (NearbyCollisionInfo (false ,
332
- false , n_bouncy_value, p, box));
324
+ for (auto box : nodeboxes) {
325
+ box.MinEdge += intToFloat (p, BS);
326
+ box.MaxEdge += intToFloat (p, BS);
327
+ cinfo.emplace_back (false , false , n_bouncy_value, p, box);
333
328
}
334
329
} else {
335
330
// Collide with unloaded nodes
336
331
aabb3f box = getNodeBox (p, BS);
337
- cinfo.push_back ( NearbyCollisionInfo ( true , false , 0 , p, box) );
332
+ cinfo.emplace_back ( true , false , 0 , p, box);
338
333
}
339
334
}
340
335
@@ -349,7 +344,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
349
344
350
345
if (collideWithObjects)
351
346
{
352
- ScopeProfiler sp (g_profiler, " collisionMoveSimple objects avg" , SPT_AVG);
347
+ ScopeProfiler sp2 (g_profiler, " collisionMoveSimple objects avg" , SPT_AVG);
353
348
// TimeTaker tt3("collisionMoveSimple collect object boxes");
354
349
355
350
/* add object boxes to cinfo */
@@ -361,9 +356,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
361
356
f32 distance = speed_f->getLength ();
362
357
std::vector<DistanceSortedActiveObject> clientobjects;
363
358
c_env->getActiveObjects (*pos_f, distance * 1.5 , clientobjects);
364
- for (size_t i= 0 ; i < clientobjects. size (); i++ ) {
365
- if (( self == 0 ) || (self != clientobjects[i] .obj )) {
366
- objects.push_back ((ActiveObject*)clientobjects[i] .obj );
359
+ for (auto &clientobject : clientobjects) {
360
+ if (! self || (self != clientobject .obj )) {
361
+ objects.push_back ((ActiveObject*) clientobject .obj );
367
362
}
368
363
}
369
364
}
@@ -375,9 +370,9 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
375
370
f32 distance = speed_f->getLength ();
376
371
std::vector<u16> s_objects;
377
372
s_env->getObjectsInsideRadius (s_objects, *pos_f, distance * 1.5 );
378
- for (std::vector< u16>::iterator iter = s_objects. begin (); iter != s_objects. end (); ++iter ) {
379
- ServerActiveObject *current = s_env->getActiveObject (*iter );
380
- if (( self == 0 ) || (self != current)) {
373
+ for (u16 obj_id : s_objects) {
374
+ ServerActiveObject *current = s_env->getActiveObject (obj_id );
375
+ if (! self || (self != current)) {
381
376
objects.push_back ((ActiveObject*)current);
382
377
}
383
378
}
@@ -388,11 +383,11 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
388
383
iter != objects.end (); ++iter) {
389
384
ActiveObject *object = *iter;
390
385
391
- if (object != NULL ) {
386
+ if (object) {
392
387
aabb3f object_collisionbox;
393
388
if (object->getCollisionBox (&object_collisionbox) &&
394
389
object->collideWithObjects ()) {
395
- cinfo.push_back ( NearbyCollisionInfo ( false , true , 0 , v3s16 (), object_collisionbox) );
390
+ cinfo.emplace_back ( false , true , 0 , v3s16 (), object_collisionbox);
396
391
}
397
392
}
398
393
}
@@ -417,7 +412,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
417
412
418
413
while (dtime > BS * 1e-10 ) {
419
414
// TimeTaker tt3("collisionMoveSimple dtime loop");
420
- ScopeProfiler sp (g_profiler, " collisionMoveSimple dtime loop avg" , SPT_AVG);
415
+ ScopeProfiler sp2 (g_profiler, " collisionMoveSimple dtime loop avg" , SPT_AVG);
421
416
422
417
// Avoid infinite loop
423
418
loopcount++;
@@ -545,8 +540,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
545
540
aabb3f box = box_0;
546
541
box.MinEdge += *pos_f;
547
542
box.MaxEdge += *pos_f;
548
- for (u32 boxindex = 0 ; boxindex < cinfo.size (); boxindex++) {
549
- NearbyCollisionInfo &box_info = cinfo[boxindex];
543
+ for (const auto &box_info : cinfo) {
550
544
const aabb3f &cbox = box_info.box ;
551
545
552
546
/*
0 commit comments