@@ -52,14 +52,12 @@ ClientEnvironment::ClientEnvironment(ClientMap *map,
52
52
ClientEnvironment::~ClientEnvironment ()
53
53
{
54
54
// delete active objects
55
- for (ClientActiveObjectMap::iterator i = m_active_objects.begin ();
56
- i != m_active_objects.end (); ++i) {
57
- delete i->second ;
55
+ for (auto &active_object : m_active_objects) {
56
+ delete active_object.second ;
58
57
}
59
58
60
- for (std::vector<ClientSimpleObject*>::iterator
61
- i = m_simple_objects.begin (); i != m_simple_objects.end (); ++i) {
62
- delete *i;
59
+ for (auto &simple_object : m_simple_objects) {
60
+ delete simple_object;
63
61
}
64
62
65
63
// Drop/delete map
@@ -211,22 +209,19 @@ void ClientEnvironment::step(float dtime)
211
209
212
210
// std::cout<<"Looped "<<loopcount<<" times."<<std::endl;
213
211
214
- for (std::vector<CollisionInfo>::iterator i = player_collisions.begin ();
215
- i != player_collisions.end (); ++i) {
216
- CollisionInfo &info = *i;
212
+ for (const CollisionInfo &info : player_collisions) {
217
213
v3f speed_diff = info.new_speed - info.old_speed ;;
218
214
// Handle only fall damage
219
215
// (because otherwise walking against something in fast_move kills you)
220
- if (speed_diff.Y < 0 || info.old_speed .Y >= 0 )
216
+ if (speed_diff.Y < 0 || info.old_speed .Y >= 0 )
221
217
continue ;
222
218
// Get rid of other components
223
219
speed_diff.X = 0 ;
224
220
speed_diff.Z = 0 ;
225
221
f32 pre_factor = 1 ; // 1 hp per node/s
226
222
f32 tolerance = BS*14 ; // 5 without damage
227
223
f32 post_factor = 1 ; // 1 hp per node/s
228
- if (info.type == COLLISION_NODE)
229
- {
224
+ if (info.type == COLLISION_NODE) {
230
225
const ContentFeatures &f = m_client->ndef ()->
231
226
get (m_map->getNodeNoEx (info.node_p ));
232
227
// Determine fall damage multiplier
@@ -343,14 +338,12 @@ void ClientEnvironment::step(float dtime)
343
338
344
339
g_profiler->avg (" CEnv: num of objects" , m_active_objects.size ());
345
340
bool update_lighting = m_active_object_light_update_interval.step (dtime, 0.21 );
346
- for (ClientActiveObjectMap::iterator i = m_active_objects.begin ();
347
- i != m_active_objects.end (); ++i) {
348
- ClientActiveObject* obj = i->second ;
341
+ for (auto &ao_it : m_active_objects) {
342
+ ClientActiveObject* obj = ao_it.second ;
349
343
// Step object
350
344
obj->step (dtime, this );
351
345
352
- if (update_lighting)
353
- {
346
+ if (update_lighting) {
354
347
// Update lighting
355
348
u8 light = 0 ;
356
349
bool pos_ok;
@@ -371,9 +364,8 @@ void ClientEnvironment::step(float dtime)
371
364
Step and handle simple objects
372
365
*/
373
366
g_profiler->avg (" CEnv: num of simple objects" , m_simple_objects.size ());
374
- for (std::vector<ClientSimpleObject*>::iterator
375
- i = m_simple_objects.begin (); i != m_simple_objects.end ();) {
376
- std::vector<ClientSimpleObject*>::iterator cur = i;
367
+ for (auto i = m_simple_objects.begin (); i != m_simple_objects.end ();) {
368
+ auto cur = i;
377
369
ClientSimpleObject *simple = *cur;
378
370
379
371
simple->step (dtime);
@@ -397,13 +389,13 @@ GenericCAO* ClientEnvironment::getGenericCAO(u16 id)
397
389
ClientActiveObject *obj = getActiveObject (id);
398
390
if (obj && obj->getType () == ACTIVEOBJECT_TYPE_GENERIC)
399
391
return (GenericCAO*) obj;
400
- else
401
- return NULL ;
392
+
393
+ return NULL ;
402
394
}
403
395
404
396
ClientActiveObject* ClientEnvironment::getActiveObject (u16 id)
405
397
{
406
- ClientActiveObjectMap::iterator n = m_active_objects.find (id);
398
+ auto n = m_active_objects.find (id);
407
399
if (n == m_active_objects.end ())
408
400
return NULL ;
409
401
return n->second ;
@@ -412,10 +404,8 @@ ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
412
404
bool isFreeClientActiveObjectId (const u16 id,
413
405
ClientActiveObjectMap &objects)
414
406
{
415
- if (id == 0 )
416
- return false ;
407
+ return id != 0 && objects.find (id) == objects.end ();
417
408
418
- return objects.find (id) == objects.end ();
419
409
}
420
410
421
411
u16 getFreeClientActiveObjectId (ClientActiveObjectMap &objects)
@@ -580,18 +570,15 @@ void ClientEnvironment::updateLocalPlayerBreath(u16 breath)
580
570
void ClientEnvironment::getActiveObjects (v3f origin, f32 max_d,
581
571
std::vector<DistanceSortedActiveObject> &dest)
582
572
{
583
- for (ClientActiveObjectMap::iterator i = m_active_objects.begin ();
584
- i != m_active_objects.end (); ++i) {
585
- ClientActiveObject* obj = i->second ;
573
+ for (auto &ao_it : m_active_objects) {
574
+ ClientActiveObject* obj = ao_it.second ;
586
575
587
576
f32 d = (obj->getPosition () - origin).getLength ();
588
577
589
- if (d > max_d)
578
+ if (d > max_d)
590
579
continue ;
591
580
592
- DistanceSortedActiveObject dso (obj, d);
593
-
594
- dest.push_back (dso);
581
+ dest.emplace_back (obj, d);
595
582
}
596
583
}
597
584
@@ -614,22 +601,22 @@ void ClientEnvironment::getSelectedActiveObjects(
614
601
shootline_on_map.getLength () + 10 .0f , allObjects);
615
602
const v3f line_vector = shootline_on_map.getVector ();
616
603
617
- for (u32 i = 0 ; i < allObjects. size (); i++ ) {
618
- ClientActiveObject *obj = allObjects[i] .obj ;
604
+ for (const auto &allObject : allObjects) {
605
+ ClientActiveObject *obj = allObject .obj ;
619
606
aabb3f selection_box;
620
607
if (!obj->getSelectionBox (&selection_box))
621
608
continue ;
622
- v3f pos = obj->getPosition ();
609
+
610
+ const v3f &pos = obj->getPosition ();
623
611
aabb3f offsetted_box (selection_box.MinEdge + pos,
624
612
selection_box.MaxEdge + pos);
625
613
626
614
v3f current_intersection;
627
615
v3s16 current_normal;
628
616
if (boxLineCollision (offsetted_box, shootline_on_map.start , line_vector,
629
617
¤t_intersection, ¤t_normal)) {
630
- objects.push_back (PointedThing (
631
- (s16) obj->getId (), current_intersection, current_normal,
632
- (current_intersection - shootline_on_map.start ).getLengthSQ ()));
618
+ objects.emplace_back ((s16) obj->getId (), current_intersection, current_normal,
619
+ (current_intersection - shootline_on_map.start ).getLengthSQ ());
633
620
}
634
621
}
635
622
}
0 commit comments