refactor(Core): apply clang-tidy modernize-loop-convert (#3822)

This commit is contained in:
Francesco Borzì
2020-12-07 19:04:19 +01:00
committed by GitHub
parent 0b7b36f20c
commit 0b8ec1f6ee
16 changed files with 125 additions and 130 deletions

View File

@@ -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<std::string> dbcfiles;
// get DBC file list
for (ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i)
for (auto & gOpenArchive : gOpenArchives)
{
vector<string> files;
(*i)->GetFileListTo(files);
for (vector<string>::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<string>::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();
}

View File

@@ -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;

View File

@@ -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<uint32>));
@@ -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<uint32>));
@@ -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<uint32>* tiles = (*itr).m_tiles;
mapID = (*itr).m_mapId;
std::set<uint32>* 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<uint32>::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<uint32>::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;

View File

@@ -686,14 +686,14 @@ namespace MMAP
position.x -= 32 * GRID_SIZE;
position.y -= 32 * GRID_SIZE;
for (std::vector<GroupModel>::iterator it = groupModels.begin(); it != groupModels.end(); ++it)
for (auto & groupModel : groupModels)
{
std::vector<G3D::Vector3> tempVertices;
std::vector<G3D::Vector3> transformedVertices;
std::vector<MeshTriangle> 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<G3D::Vector3>& source, std::vector<G3D::Vector3>& transformedVertices, float scale, G3D::Matrix3& rotation, G3D::Vector3& position)
{
for (std::vector<G3D::Vector3>::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<G3D::Vector3>& source, G3D::Array<float>& dest)
{
for (std::vector<G3D::Vector3>::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<MeshTriangle>::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<MeshTriangle>::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);
}
}
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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<std::string>& pArchiveNames)
searchLocales.emplace_back("esMX");
searchLocales.emplace_back("ruRU");
for (std::vector<std::string>::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<std::string>::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<std::string>& pArchiveNames)
// now, scan for the patch levels in locale dirs
printf("Scanning patch levels from locale directories.\n");
bool foundOne = false;
for (std::vector<std::string>::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<std::string> 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;
}