@@ -144,9 +144,9 @@ void Client::scanModSubfolder(const std::string &mod_name, const std::string &mo
144
144
{
145
145
std::string full_path = mod_path + DIR_DELIM + mod_subpath;
146
146
std::vector<fs::DirListNode> mod = fs::GetDirListing (full_path);
147
- for (unsigned int j= 0 ; j < mod. size (); j++) {
148
- std::string filename = mod[j] .name ;
149
- if (mod[j] .dir ) {
147
+ for (const fs::DirListNode &j : mod) {
148
+ std::string filename = j .name ;
149
+ if (j .dir ) {
150
150
scanModSubfolder (mod_name, mod_path, mod_subpath
151
151
+ filename + DIR_DELIM);
152
152
continue ;
@@ -230,10 +230,8 @@ Client::~Client()
230
230
delete m_inventory_from_server;
231
231
232
232
// Delete detached inventories
233
- for (std::unordered_map<std::string, Inventory*>::iterator
234
- i = m_detached_inventories.begin ();
235
- i != m_detached_inventories.end (); ++i) {
236
- delete i->second ;
233
+ for (auto &m_detached_inventorie : m_detached_inventories) {
234
+ delete m_detached_inventorie.second ;
237
235
}
238
236
239
237
// cleanup 3d model meshes on client shutdown
@@ -556,15 +554,13 @@ void Client::step(float dtime)
556
554
Update positions of sounds attached to objects
557
555
*/
558
556
{
559
- for (std::unordered_map<int , u16>::iterator i = m_sounds_to_objects.begin ();
560
- i != m_sounds_to_objects.end (); ++i) {
561
- int client_id = i->first ;
562
- u16 object_id = i->second ;
557
+ for (auto &m_sounds_to_object : m_sounds_to_objects) {
558
+ int client_id = m_sounds_to_object.first ;
559
+ u16 object_id = m_sounds_to_object.second ;
563
560
ClientActiveObject *cao = m_env.getActiveObject (object_id);
564
- if (!cao)
561
+ if (!cao)
565
562
continue ;
566
- v3f pos = cao->getPosition ();
567
- m_sound->updateSoundPosition (client_id, pos);
563
+ m_sound->updateSoundPosition (client_id, cao->getPosition ());
568
564
}
569
565
}
570
566
@@ -628,8 +624,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
628
624
NULL
629
625
};
630
626
name = removeStringEnd (filename, image_ext);
631
- if (name != " " )
632
- {
627
+ if (!name.empty ()) {
633
628
verbosestream<<" Client: Attempting to load image "
634
629
<<" file \" " <<filename<<" \" " <<std::endl;
635
630
@@ -644,18 +639,17 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
644
639
645
640
// Read image
646
641
video::IImage *img = vdrv->createImageFromFile (rfile);
647
- if (!img){
642
+ if (!img) {
648
643
errorstream<<" Client: Cannot create image from data of "
649
644
<<" file \" " <<filename<<" \" " <<std::endl;
650
645
rfile->drop ();
651
646
return false ;
652
647
}
653
- else {
654
- m_tsrc->insertSourceImage (filename, img);
655
- img->drop ();
656
- rfile->drop ();
657
- return true ;
658
- }
648
+
649
+ m_tsrc->insertSourceImage (filename, img);
650
+ img->drop ();
651
+ rfile->drop ();
652
+ return true ;
659
653
}
660
654
661
655
const char *sound_ext[] = {
@@ -664,8 +658,7 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
664
658
" .ogg" , NULL
665
659
};
666
660
name = removeStringEnd (filename, sound_ext);
667
- if (name != " " )
668
- {
661
+ if (!name.empty ()) {
669
662
verbosestream<<" Client: Attempting to load sound "
670
663
<<" file \" " <<filename<<" \" " <<std::endl;
671
664
m_sound->loadSoundData (name, data);
@@ -676,9 +669,9 @@ bool Client::loadMedia(const std::string &data, const std::string &filename)
676
669
" .x" , " .b3d" , " .md2" , " .obj" ,
677
670
NULL
678
671
};
672
+
679
673
name = removeStringEnd (filename, model_ext);
680
- if (name != " " )
681
- {
674
+ if (!name.empty ()) {
682
675
verbosestream<<" Client: Storing model into memory: "
683
676
<<" \" " <<filename<<" \" " <<std::endl;
684
677
if (m_mesh_data.count (filename))
@@ -732,9 +725,8 @@ void Client::request_media(const std::vector<std::string> &file_requests)
732
725
733
726
pkt << (u16) (file_requests_size & 0xFFFF );
734
727
735
- for (std::vector<std::string>::const_iterator i = file_requests.begin ();
736
- i != file_requests.end (); ++i) {
737
- pkt << (*i);
728
+ for (const std::string &file_request : file_requests) {
729
+ pkt << file_request;
738
730
}
739
731
740
732
Send (&pkt);
@@ -1020,7 +1012,7 @@ void Client::startAuth(AuthMechanism chosen_auth_mechanism)
1020
1012
&verifier, &salt);
1021
1013
1022
1014
NetworkPacket resp_pkt (TOSERVER_FIRST_SRP, 0 );
1023
- resp_pkt << salt << verifier << (u8)((m_password == " " ) ? 1 : 0 );
1015
+ resp_pkt << salt << verifier << (u8)((m_password. empty () ) ? 1 : 0 );
1024
1016
1025
1017
Send (&resp_pkt);
1026
1018
break ;
@@ -1062,12 +1054,8 @@ void Client::sendDeletedBlocks(std::vector<v3s16> &blocks)
1062
1054
1063
1055
pkt << (u8) blocks.size ();
1064
1056
1065
- u32 k = 0 ;
1066
- for (std::vector<v3s16>::iterator
1067
- j = blocks.begin ();
1068
- j != blocks.end (); ++j) {
1069
- pkt << *j;
1070
- k++;
1057
+ for (const v3s16 &block : blocks) {
1058
+ pkt << block;
1071
1059
}
1072
1060
1073
1061
Send (&pkt);
@@ -1089,9 +1077,8 @@ void Client::sendRemovedSounds(std::vector<s32> &soundList)
1089
1077
1090
1078
pkt << (u16) (server_ids & 0xFFFF );
1091
1079
1092
- for (std::vector<s32>::iterator i = soundList.begin ();
1093
- i != soundList.end (); ++i)
1094
- pkt << *i;
1080
+ for (int sound_id : soundList)
1081
+ pkt << sound_id;
1095
1082
1096
1083
Send (&pkt);
1097
1084
}
@@ -1354,10 +1341,8 @@ void Client::removeNode(v3s16 p)
1354
1341
catch (InvalidPositionException &e) {
1355
1342
}
1356
1343
1357
- for (std::map<v3s16, MapBlock *>::iterator
1358
- i = modified_blocks.begin ();
1359
- i != modified_blocks.end (); ++i) {
1360
- addUpdateMeshTaskWithEdge (i->first , false , true );
1344
+ for (const auto &modified_block : modified_blocks) {
1345
+ addUpdateMeshTaskWithEdge (modified_block.first , false , true );
1361
1346
}
1362
1347
}
1363
1348
@@ -1374,7 +1359,7 @@ MapNode Client::getNode(v3s16 p, bool *is_valid_position)
1374
1359
v3s16 ppos = floatToInt (m_env.getLocalPlayer ()->getPosition (), BS);
1375
1360
if ((u32) ppos.getDistanceFrom (p) > m_csm_noderange_limit) {
1376
1361
*is_valid_position = false ;
1377
- return MapNode () ;
1362
+ return {} ;
1378
1363
}
1379
1364
}
1380
1365
return m_env.getMap ().getNodeNoEx (p, is_valid_position);
@@ -1393,10 +1378,8 @@ void Client::addNode(v3s16 p, MapNode n, bool remove_metadata)
1393
1378
catch (InvalidPositionException &e) {
1394
1379
}
1395
1380
1396
- for (std::map<v3s16, MapBlock *>::iterator
1397
- i = modified_blocks.begin ();
1398
- i != modified_blocks.end (); ++i) {
1399
- addUpdateMeshTaskWithEdge (i->first , false , true );
1381
+ for (const auto &modified_block : modified_blocks) {
1382
+ addUpdateMeshTaskWithEdge (modified_block.first , false , true );
1400
1383
}
1401
1384
}
1402
1385
@@ -1567,7 +1550,7 @@ bool Client::getChatMessage(std::wstring &res)
1567
1550
void Client::typeChatMessage (const std::wstring &message)
1568
1551
{
1569
1552
// Discard empty line
1570
- if (message == L" " )
1553
+ if (message. empty () )
1571
1554
return ;
1572
1555
1573
1556
// If message was ate by script API, don't send it to server
@@ -1677,8 +1660,8 @@ float Client::mediaReceiveProgress()
1677
1660
{
1678
1661
if (m_media_downloader)
1679
1662
return m_media_downloader->getProgress ();
1680
- else
1681
- return 1.0 ; // downloader only exists when not yet done
1663
+
1664
+ return 1.0 ; // downloader only exists when not yet done
1682
1665
}
1683
1666
1684
1667
typedef struct TextureUpdateArgs {
@@ -1746,7 +1729,7 @@ void Client::afterContentReceived()
1746
1729
RenderingEngine::draw_load_screen (text, guienv, m_tsrc, 0 , 72 );
1747
1730
m_nodedef->updateAliases (m_itemdef);
1748
1731
std::string texture_path = g_settings->get (" texture_path" );
1749
- if (texture_path != " " && fs::IsDir (texture_path))
1732
+ if (!texture_path. empty () && fs::IsDir (texture_path))
1750
1733
m_nodedef->applyTextureOverrides (texture_path + DIR_DELIM + " override.txt" );
1751
1734
m_nodedef->setNodeRegistrationStatus (true );
1752
1735
m_nodedef->runNodeResolveCallbacks ();
2 commit comments
JRottm commentedon Aug 19, 2017
Hi @nerzhul, you removed the "const" from the bool param of showGameChat()...showGameDebug() in client.h, but you forgot to make the same change in the implementation in client.cpp.
nerzhul commentedon Aug 19, 2017
yeah it's accepted by compilers, clang-tidy reported it's not necessary to add them in the declaration they have no effect, just setting it in definition