From 0b8ec1f6eeef15be9798e4ebc038e44d7cd64feb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Borz=C3=AC?= Date: Mon, 7 Dec 2020 19:04:19 +0100 Subject: [PATCH] refactor(Core): apply clang-tidy modernize-loop-convert (#3822) --- .../Collision/BoundingIntervalHierarchy.h | 2 +- src/common/Utilities/Util.h | 16 +++--- .../game/AuctionHouse/AuctionHouseMgr.h | 4 +- src/server/game/Combat/ThreatManager.h | 4 +- src/server/game/Entities/Creature/Creature.h | 4 +- .../game/Entities/GameObject/GameObject.h | 4 +- src/server/game/Entities/Player/Player.h | 28 +++++----- src/server/game/Globals/ObjectMgr.h | 8 +-- src/server/shared/DataStores/DBCStructure.h | 20 +++---- src/tools/map_extractor/System.cpp | 32 +++++------ src/tools/map_extractor/mpq_libmpq.cpp | 4 +- src/tools/mmaps_generator/MapBuilder.cpp | 54 +++++++++---------- src/tools/mmaps_generator/TerrainBuilder.cpp | 36 ++++++------- .../vmap4_extractor/gameobject_extract.cpp | 6 +-- src/tools/vmap4_extractor/mpq_libmpq.cpp | 4 +- src/tools/vmap4_extractor/vmapexport.cpp | 29 +++++----- 16 files changed, 125 insertions(+), 130 deletions(-) diff --git a/src/common/Collision/BoundingIntervalHierarchy.h b/src/common/Collision/BoundingIntervalHierarchy.h index f519bbd22..d64e551eb 100644 --- a/src/common/Collision/BoundingIntervalHierarchy.h +++ b/src/common/Collision/BoundingIntervalHierarchy.h @@ -369,7 +369,7 @@ protected: maxObjects(0xFFFFFFFF), sumDepth(0), minDepth(0x0FFFFFFF), maxDepth(0xFFFFFFFF), numBVH2(0) { - for (int i = 0; i < 6; ++i) numLeavesN[i] = 0; + for (int & i : numLeavesN) i = 0; } void updateInner() { numNodes++; } diff --git a/src/common/Utilities/Util.h b/src/common/Utilities/Util.h index aaa08236f..c72574214 100644 --- a/src/common/Utilities/Util.h +++ b/src/common/Utilities/Util.h @@ -239,32 +239,32 @@ inline bool isNumericOrSpace(wchar_t wchar) inline bool isBasicLatinString(const std::wstring& wstr, bool numericOrSpace) { - for (size_t i = 0; i < wstr.size(); ++i) - if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) + for (wchar_t i : wstr) + if (!isBasicLatinCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i))) return false; return true; } inline bool isExtendedLatinString(const std::wstring& wstr, bool numericOrSpace) { - for (size_t i = 0; i < wstr.size(); ++i) - if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) + for (wchar_t i : wstr) + if (!isExtendedLatinCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i))) return false; return true; } inline bool isCyrillicString(const std::wstring& wstr, bool numericOrSpace) { - for (size_t i = 0; i < wstr.size(); ++i) - if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) + for (wchar_t i : wstr) + if (!isCyrillicCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i))) return false; return true; } inline bool isEastAsianString(const std::wstring& wstr, bool numericOrSpace) { - for (size_t i = 0; i < wstr.size(); ++i) - if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) + for (wchar_t i : wstr) + if (!isEastAsianCharacter(i) && (!numericOrSpace || !isNumericOrSpace(i))) return false; return true; } diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h index 260983964..3ab71f945 100644 --- a/src/server/game/AuctionHouse/AuctionHouseMgr.h +++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h @@ -90,8 +90,8 @@ public: AuctionHouseObject() { next = AuctionsMap.begin(); } ~AuctionHouseObject() { - for (AuctionEntryMap::iterator itr = AuctionsMap.begin(); itr != AuctionsMap.end(); ++itr) - delete itr->second; + for (auto & itr : AuctionsMap) + delete itr.second; } typedef std::map AuctionEntryMap; diff --git a/src/server/game/Combat/ThreatManager.h b/src/server/game/Combat/ThreatManager.h index 2448f2ad8..15744350f 100644 --- a/src/server/game/Combat/ThreatManager.h +++ b/src/server/game/Combat/ThreatManager.h @@ -229,10 +229,8 @@ public: if (threatList.empty()) return; - for (ThreatContainer::StorageType::iterator itr = threatList.begin(); itr != threatList.end(); ++itr) + for (auto ref : threatList) { - HostileReference* ref = (*itr); - if (predicate(ref->getTarget())) { ref->setThreat(0); diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c25c213af..0f1abaa94 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -390,8 +390,8 @@ struct TrainerSpell { TrainerSpell() : spell(0), spellCost(0), reqSkill(0), reqSkillValue(0), reqLevel(0) { - for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) - learnedSpell[i] = 0; + for (unsigned int & i : learnedSpell) + i = 0; } uint32 spell; diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h index 97ea88d33..87d00138d 100644 --- a/src/server/game/Entities/GameObject/GameObject.h +++ b/src/server/game/Entities/GameObject/GameObject.h @@ -844,8 +844,8 @@ public: void AddToSkillupList(uint32 PlayerGuidLow) { m_SkillupList.push_back(PlayerGuidLow); } [[nodiscard]] bool IsInSkillupList(uint32 PlayerGuidLow) const { - for (std::list::const_iterator i = m_SkillupList.begin(); i != m_SkillupList.end(); ++i) - if (*i == PlayerGuidLow) + for (unsigned int i : m_SkillupList) + if (i == PlayerGuidLow) return true; return false; diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 7c5910c52..bc17f6df1 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -264,7 +264,7 @@ struct PlayerClassInfo struct PlayerLevelInfo { - PlayerLevelInfo() { for (uint8 i = 0; i < MAX_STATS; ++i) stats[i] = 0; } + PlayerLevelInfo() { for (unsigned char & stat : stats) stat = 0; } uint8 stats[MAX_STATS]; }; @@ -689,8 +689,8 @@ struct EquipmentSet { EquipmentSet() : Guid(0), IgnoreMask(0), state(EQUIPMENT_SET_NEW) { - for (uint8 i = 0; i < EQUIPMENT_SLOT_END; ++i) - Items[i] = 0; + for (unsigned int & Item : Items) + Item = 0; } uint64 Guid; @@ -1876,8 +1876,8 @@ public: { Unit::SetPvP(state); if (!m_Controlled.empty()) - for (ControlSet::iterator itr = m_Controlled.begin(); itr != m_Controlled.end(); ++itr) - (*itr)->SetPvP(state); + for (auto itr : m_Controlled) + itr->SetPvP(state); } void UpdatePvP(bool state, bool _override = false); void UpdateZone(uint32 newZone, uint32 newArea); @@ -2272,8 +2272,8 @@ public: [[nodiscard]] bool InBattlegroundQueue() const { - for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i) - if (m_bgBattlegroundQueueID[i] != BATTLEGROUND_QUEUE_NONE) + for (auto i : m_bgBattlegroundQueueID) + if (i != BATTLEGROUND_QUEUE_NONE) return true; return false; } @@ -2308,18 +2308,18 @@ public: bool HasFreeBattlegroundQueueId() { - for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i) - if (m_bgBattlegroundQueueID[i] == BATTLEGROUND_QUEUE_NONE) + for (auto & i : m_bgBattlegroundQueueID) + if (i == BATTLEGROUND_QUEUE_NONE) return true; return false; } void RemoveBattlegroundQueueId(BattlegroundQueueTypeId val) { - for (uint8 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i) - if (m_bgBattlegroundQueueID[i] == val) + for (auto & i : m_bgBattlegroundQueueID) + if (i == val) { - m_bgBattlegroundQueueID[i] = BATTLEGROUND_QUEUE_NONE; + i = BATTLEGROUND_QUEUE_NONE; return; } } @@ -3031,10 +3031,8 @@ template T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T& bas if (m_spellModTakingSpell) spell = m_spellModTakingSpell; - for (SpellModList::iterator itr = m_spellMods[op].begin(); itr != m_spellMods[op].end(); ++itr) + for (auto mod : m_spellMods[op]) { - SpellModifier* mod = *itr; - // Charges can be set only for mods with auras if (!mod->ownerAura) ASSERT(mod->charges == 0); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 966d984f7..ee9129d10 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -511,7 +511,7 @@ typedef std::pairsecond.begin(); set_itr != map_itr->second.end(); ++set_itr) - if (set_itr->raceMask & raceMask) - return &*set_itr; + for (const auto & set_itr : map_itr->second) + if (set_itr.raceMask & raceMask) + return &set_itr; return nullptr; } diff --git a/src/server/shared/DataStores/DBCStructure.h b/src/server/shared/DataStores/DBCStructure.h index 37c0a356e..d3cbf8899 100644 --- a/src/server/shared/DataStores/DBCStructure.h +++ b/src/server/shared/DataStores/DBCStructure.h @@ -906,11 +906,11 @@ struct FactionTemplateEntry if (entry.faction) { - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (enemyFaction[i] == entry.faction) + for (unsigned int i : enemyFaction) + if (i == entry.faction) return false; - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (friendFaction[i] == entry.faction) + for (unsigned int i : friendFaction) + if (i == entry.faction) return true; } return (friendlyMask & entry.ourMask) || (ourMask & entry.friendlyMask); @@ -919,11 +919,11 @@ struct FactionTemplateEntry { if (entry.faction) { - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (enemyFaction[i] == entry.faction) + for (unsigned int i : enemyFaction) + if (i == entry.faction) return true; - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (friendFaction[i] == entry.faction) + for (unsigned int i : friendFaction) + if (i == entry.faction) return false; } return (hostileMask & entry.ourMask) != 0; @@ -931,8 +931,8 @@ struct FactionTemplateEntry [[nodiscard]] bool IsHostileToPlayers() const { return (hostileMask & FACTION_MASK_PLAYER) != 0; } [[nodiscard]] bool IsNeutralToAll() const { - for (uint8 i = 0; i < MAX_FACTION_RELATIONS; ++i) - if (enemyFaction[i] != 0) + for (unsigned int i : enemyFaction) + if (i != 0) return false; return hostileMask == 0 && friendlyMask == 0; } diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index a11cac3e1..8b45d1b10 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -406,11 +406,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int //============================================ bool fullAreaData = false; uint32 areaId = area_ids[0][0]; - for (int y = 0; y < ADT_CELLS_PER_GRID; ++y) + for (auto & area_id : area_ids) { for (int x = 0; x < ADT_CELLS_PER_GRID; ++x) { - if (area_ids[y][x] != areaId) + if (area_id[x] != areaId) { fullAreaData = true; break; @@ -511,11 +511,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int //============================================ float maxHeight = -20000; float minHeight = 20000; - for (int y = 0; y < ADT_GRID_SIZE; y++) + for (auto & y : V8) { for (int x = 0; x < ADT_GRID_SIZE; x++) { - float h = V8[y][x]; + float h = y[x]; if (maxHeight < h) maxHeight = h; if (minHeight > h) minHeight = h; } @@ -533,10 +533,10 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int // Check for allow limit minimum height (not store height in deep ochean - allow save some memory) if (CONF_allow_height_limit && minHeight < CONF_use_minHeight) { - for (int y = 0; y < ADT_GRID_SIZE; y++) + for (auto & y : V8) for (int x = 0; x < ADT_GRID_SIZE; x++) - if (V8[y][x] < CONF_use_minHeight) - V8[y][x] = CONF_use_minHeight; + if (y[x] < CONF_use_minHeight) + y[x] = CONF_use_minHeight; for (int y = 0; y <= ADT_GRID_SIZE; y++) for (int x = 0; x <= ADT_GRID_SIZE; x++) if (V9[y][x] < CONF_use_minHeight) @@ -1006,13 +1006,13 @@ void ExtractDBCFiles(int locale, bool basicLocale) std::set dbcfiles; // get DBC file list - for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) + for (auto & gOpenArchive : gOpenArchives) { vector files; - (*i)->GetFileListTo(files); - for (vector::iterator iter = files.begin(); iter != files.end(); ++iter) - if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) - dbcfiles.insert(*iter); + gOpenArchive->GetFileListTo(files); + for (auto & file : files) + if (file.rfind(".dbc") == file.length() - strlen(".dbc")) + dbcfiles.insert(file); } std::string path = output_path; @@ -1035,15 +1035,15 @@ void ExtractDBCFiles(int locale, bool basicLocale) // extract DBCs uint32 count = 0; - for (set::iterator iter = dbcfiles.begin(); iter != dbcfiles.end(); ++iter) + for (const auto & dbcfile : dbcfiles) { string filename = path; - filename += (iter->c_str() + strlen("DBFilesClient\\")); + filename += (dbcfile.c_str() + strlen("DBFilesClient\\")); if (FileExists(filename.c_str())) continue; - if (ExtractFile(iter->c_str(), filename)) + if (ExtractFile(dbcfile.c_str(), filename)) ++count; } printf("Extracted %u DBC files\n\n", count); @@ -1082,7 +1082,7 @@ void LoadCommonMPQFiles() inline void CloseMPQFiles() { - for (ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j) (*j)->close(); + for (auto & gOpenArchive : gOpenArchives) gOpenArchive->close(); gOpenArchives.clear(); } diff --git a/src/tools/map_extractor/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp index 980f2012d..873d7bb00 100644 --- a/src/tools/map_extractor/mpq_libmpq.cpp +++ b/src/tools/map_extractor/mpq_libmpq.cpp @@ -54,9 +54,9 @@ MPQFile::MPQFile(const char* filename): pointer(0), size(0) { - for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) + for (auto & gOpenArchive : gOpenArchives) { - mpq_archive* mpq_a = (*i)->mpq_a; + mpq_archive* mpq_a = gOpenArchive->mpq_a; uint32_t filenum; if (libmpq__file_number(mpq_a, filename, &filenum)) continue; diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 28a0595fe..07f86229f 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -75,10 +75,10 @@ namespace MMAP /**************************************************************************/ MapBuilder::~MapBuilder() { - for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) + for (auto & m_tile : m_tiles) { - (*it).m_tiles->clear(); - delete (*it).m_tiles; + m_tile.m_tiles->clear(); + delete m_tile.m_tiles; } delete m_terrainBuilder; @@ -94,9 +94,9 @@ namespace MMAP printf("Discovering maps... "); getDirContents(files, "maps"); - for (uint32 i = 0; i < files.size(); ++i) + for (auto & file : files) { - mapID = uint32(atoi(files[i].substr(0, files[i].size() - 8).c_str())); + mapID = uint32(atoi(file.substr(0, file.size() - 8).c_str())); if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end()) { m_tiles.emplace_back(MapTiles(mapID, new std::set)); @@ -106,9 +106,9 @@ namespace MMAP files.clear(); getDirContents(files, "vmaps", "*.vmtree"); - for (uint32 i = 0; i < files.size(); ++i) + for (auto & file : files) { - mapID = uint32(atoi(files[i].substr(0, files[i].size() - 7).c_str())); + mapID = uint32(atoi(file.substr(0, file.size() - 7).c_str())); if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end()) { m_tiles.emplace_back(MapTiles(mapID, new std::set)); @@ -119,20 +119,20 @@ namespace MMAP count = 0; printf("Discovering tiles... "); - for (TileList::iterator itr = m_tiles.begin(); itr != m_tiles.end(); ++itr) + for (auto & m_tile : m_tiles) { - std::set* tiles = (*itr).m_tiles; - mapID = (*itr).m_mapId; + std::set* tiles = m_tile.m_tiles; + mapID = m_tile.m_mapId; sprintf(filter, "%03u*.vmtile", mapID); files.clear(); getDirContents(files, "vmaps", filter); - for (uint32 i = 0; i < files.size(); ++i) + for (auto & file : files) { - fsize = files[i].size(); + fsize = file.size(); - tileY = uint32(atoi(files[i].substr(fsize - 12, 2).c_str())); - tileX = uint32(atoi(files[i].substr(fsize - 9, 2).c_str())); + tileY = uint32(atoi(file.substr(fsize - 12, 2).c_str())); + tileX = uint32(atoi(file.substr(fsize - 9, 2).c_str())); tileID = StaticMapTree::packTileID(tileY, tileX); tiles->insert(tileID); @@ -142,12 +142,12 @@ namespace MMAP sprintf(filter, "%03u*", mapID); files.clear(); getDirContents(files, "maps", filter); - for (uint32 i = 0; i < files.size(); ++i) + for (auto & file : files) { - fsize = files[i].size(); + fsize = file.size(); - tileY = uint32(atoi(files[i].substr(fsize - 8, 2).c_str())); - tileX = uint32(atoi(files[i].substr(fsize - 6, 2).c_str())); + tileY = uint32(atoi(file.substr(fsize - 8, 2).c_str())); + tileX = uint32(atoi(file.substr(fsize - 6, 2).c_str())); tileID = StaticMapTree::packTileID(tileX, tileY); if (tiles->insert(tileID).second) @@ -171,10 +171,10 @@ namespace MMAP printf("found %u.\n\n", count); // Calculate tiles to process in total - for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) + for (auto & m_tile : m_tiles) { - if (!shouldSkipMap(it->m_mapId)) - m_totalTiles += it->m_tiles->size(); + if (!shouldSkipMap(m_tile.m_mapId)) + m_totalTiles += m_tile.m_tiles->size(); } } @@ -205,9 +205,9 @@ namespace MMAP return a.m_tiles->size() > b.m_tiles->size(); }); - for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) + for (auto & m_tile : m_tiles) { - uint32 mapId = it->m_mapId; + uint32 mapId = m_tile.m_mapId; if (!shouldSkipMap(mapId)) { if (threads > 0) @@ -423,14 +423,14 @@ namespace MMAP // now start building mmtiles for each tile printf("[Map %03i] We have %u tiles. \n", mapID, (unsigned int)tiles->size()); - for (std::set::iterator it = tiles->begin(); it != tiles->end(); ++it) + for (unsigned int tile : *tiles) { // percentageDone - increment tiles built m_totalTilesBuilt++; uint32 tileX, tileY; // unpack tile coords - StaticMapTree::unpackTileID((*it), tileX, tileY); + StaticMapTree::unpackTileID(tile, tileX, tileY); if (shouldSkipTile(mapID, tileX, tileY)) continue; @@ -503,9 +503,9 @@ namespace MMAP /*** calculate bounds of map ***/ uint32 tileXMin = 64, tileYMin = 64, tileXMax = 0, tileYMax = 0, tileX, tileY; - for (std::set::iterator it = tiles->begin(); it != tiles->end(); ++it) + for (unsigned int tile : *tiles) { - StaticMapTree::unpackTileID(*it, tileX, tileY); + StaticMapTree::unpackTileID(tile, tileX, tileY); if (tileX > tileXMax) tileXMax = tileX; diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index 62a485d7d..b9480b1fc 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -686,14 +686,14 @@ namespace MMAP position.x -= 32 * GRID_SIZE; position.y -= 32 * GRID_SIZE; - for (std::vector::iterator it = groupModels.begin(); it != groupModels.end(); ++it) + for (auto & groupModel : groupModels) { std::vector tempVertices; std::vector transformedVertices; std::vector tempTriangles; WmoLiquid* liquid = nullptr; - it->getMeshData(tempVertices, tempTriangles, liquid); + groupModel.getMeshData(tempVertices, tempTriangles, liquid); // first handle collision mesh transform(tempVertices, transformedVertices, scale, rotation, position); @@ -778,9 +778,9 @@ namespace MMAP } uint32 liqOffset = meshData.liquidVerts.size() / 3; - for (uint32 j = 0; j < liqVerts.size(); ++j) + for (auto & liqVert : liqVerts) { - meshData.liquidVerts.append(liqVerts[j].y, liqVerts[j].z, liqVerts[j].x); + meshData.liquidVerts.append(liqVert.y, liqVert.z, liqVert.x); } for (uint32 j = 0; j < liqTris.size() / 3; ++j) @@ -802,10 +802,10 @@ namespace MMAP /**************************************************************************/ void TerrainBuilder::transform(std::vector& source, std::vector& transformedVertices, float scale, G3D::Matrix3& rotation, G3D::Vector3& position) { - for (std::vector::iterator it = source.begin(); it != source.end(); ++it) + for (auto & it : source) { // apply tranform, then mirror along the horizontal axes - G3D::Vector3 v((*it) * rotation * scale + position); + G3D::Vector3 v(it * rotation * scale + position); v.x *= -1.f; v.y *= -1.f; transformedVertices.push_back(v); @@ -815,11 +815,11 @@ namespace MMAP /**************************************************************************/ void TerrainBuilder::copyVertices(std::vector& source, G3D::Array& dest) { - for (std::vector::iterator it = source.begin(); it != source.end(); ++it) + for (auto & it : source) { - dest.push_back((*it).y); - dest.push_back((*it).z); - dest.push_back((*it).x); + dest.push_back(it.y); + dest.push_back(it.z); + dest.push_back(it.x); } } @@ -828,20 +828,20 @@ namespace MMAP { if (flip) { - for (std::vector::iterator it = source.begin(); it != source.end(); ++it) + for (auto & it : source) { - dest.push_back((*it).idx2 + offset); - dest.push_back((*it).idx1 + offset); - dest.push_back((*it).idx0 + offset); + dest.push_back(it.idx2 + offset); + dest.push_back(it.idx1 + offset); + dest.push_back(it.idx0 + offset); } } else { - for (std::vector::iterator it = source.begin(); it != source.end(); ++it) + for (auto & it : source) { - dest.push_back((*it).idx0 + offset); - dest.push_back((*it).idx1 + offset); - dest.push_back((*it).idx2 + offset); + dest.push_back(it.idx0 + offset); + dest.push_back(it.idx1 + offset); + dest.push_back(it.idx2 + offset); } } } diff --git a/src/tools/vmap4_extractor/gameobject_extract.cpp b/src/tools/vmap4_extractor/gameobject_extract.cpp index 48a2b572d..338fa79f9 100644 --- a/src/tools/vmap4_extractor/gameobject_extract.cpp +++ b/src/tools/vmap4_extractor/gameobject_extract.cpp @@ -63,9 +63,9 @@ void ExtractGameobjectModels() return; } - for (DBCFile::Iterator it = dbc.begin(); it != dbc.end(); ++it) + for (const auto & it : dbc) { - path = it->getString(1); + path = it.getString(1); if (path.length() < 4) continue; @@ -97,7 +97,7 @@ void ExtractGameobjectModels() if (result) { - uint32 displayId = it->getUInt(0); + uint32 displayId = it.getUInt(0); uint32 path_length = strlen(name); fwrite(&displayId, sizeof(uint32), 1, model_list); fwrite(&path_length, sizeof(uint32), 1, model_list); diff --git a/src/tools/vmap4_extractor/mpq_libmpq.cpp b/src/tools/vmap4_extractor/mpq_libmpq.cpp index 8c889b62b..dbc887ee3 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq.cpp +++ b/src/tools/vmap4_extractor/mpq_libmpq.cpp @@ -54,9 +54,9 @@ MPQFile::MPQFile(const char* filename): pointer(0), size(0) { - for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) + for (auto & gOpenArchive : gOpenArchives) { - mpq_archive* mpq_a = (*i)->mpq_a; + mpq_archive* mpq_a = gOpenArchive->mpq_a; uint32 filenum; if (libmpq__file_number(mpq_a, filename, &filenum)) continue; diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index abf28c7fb..74114eb5e 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -152,9 +152,8 @@ bool ExtractSingleWmo(std::string& fname) { char cpy[4]; memcpy(cpy, rchr, 4); - for (int i = 0; i < 4; ++i) + for (int m : cpy) { - int m = cpy[i]; if (isdigit(m)) p++; } @@ -314,27 +313,27 @@ bool fillArchiveNameVector(std::vector& pArchiveNames) searchLocales.emplace_back("esMX"); searchLocales.emplace_back("ruRU"); - for (std::vector::iterator i = searchLocales.begin(); i != searchLocales.end(); ++i) + for (auto & searchLocale : searchLocales) { - std::string localePath = in_path + *i; + std::string localePath = in_path + searchLocale; // check if locale exists: struct stat status; if (stat(localePath.c_str(), &status)) continue; if ((status.st_mode & S_IFDIR) == 0) continue; - printf("Found locale '%s'\n", i->c_str()); - locales.push_back(*i); + printf("Found locale '%s'\n", searchLocale.c_str()); + locales.push_back(searchLocale); } printf("\n"); // open locale expansion and common files printf("Adding data files from locale directories.\n"); - for (std::vector::iterator i = locales.begin(); i != locales.end(); ++i) + for (auto & locale : locales) { - pArchiveNames.push_back(in_path + *i + "/locale-" + *i + ".MPQ"); - pArchiveNames.push_back(in_path + *i + "/expansion-locale-" + *i + ".MPQ"); - pArchiveNames.push_back(in_path + *i + "/lichking-locale-" + *i + ".MPQ"); + pArchiveNames.push_back(in_path + locale + "/locale-" + locale + ".MPQ"); + pArchiveNames.push_back(in_path + locale + "/expansion-locale-" + locale + ".MPQ"); + pArchiveNames.push_back(in_path + locale + "/lichking-locale-" + locale + ".MPQ"); } // open expansion and common files @@ -357,10 +356,10 @@ bool fillArchiveNameVector(std::vector& pArchiveNames) // now, scan for the patch levels in locale dirs printf("Scanning patch levels from locale directories.\n"); bool foundOne = false; - for (std::vector::iterator i = locales.begin(); i != locales.end(); ++i) + for (auto & locale : locales) { - printf("Locale: %s\n", i->c_str()); - int ret2 = snprintf(path, 512, "%s%s/patch-%s", input_path, i->c_str(), i->c_str()); + printf("Locale: %s\n", locale.c_str()); + int ret2 = snprintf(path, 512, "%s%s/patch-%s", input_path, locale.c_str(), locale.c_str()); if (ret2 < 0) { printf("Error when formatting string"); @@ -481,9 +480,9 @@ int main(int argc, char** argv) // prepare archive name list std::vector archiveNames; fillArchiveNameVector(archiveNames); - for (size_t i = 0; i < archiveNames.size(); ++i) + for (auto & archiveName : archiveNames) { - MPQArchive* archive = new MPQArchive(archiveNames[i].c_str()); + MPQArchive* archive = new MPQArchive(archiveName.c_str()); if (gOpenArchives.empty() || gOpenArchives.front() != archive) delete archive; }