From b345f79d45ad3de0d9ef59cdd8e743c1ab89093a Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 19:06:35 +0300 Subject: [PATCH 01/15] 3DS: Use C++11 range-based for loop --- code/3DSLoader.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/code/3DSLoader.cpp b/code/3DSLoader.cpp index f6ade56a3..7c28f1f81 100644 --- a/code/3DSLoader.cpp +++ b/code/3DSLoader.cpp @@ -186,15 +186,14 @@ void Discreet3DSImporter::InternReadFile( const std::string& pFile, // internal verbose representation. Finally compute normal // vectors from the smoothing groups we read from the // file. - for (std::vector::iterator i = mScene->mMeshes.begin(), - end = mScene->mMeshes.end(); i != end;++i) { - if ((*i).mFaces.size() > 0 && (*i).mPositions.size() == 0) { + for (auto &mesh : mScene->mMeshes) { + if (mesh.mFaces.size() > 0 && mesh.mPositions.size() == 0) { delete mScene; throw DeadlyImportError("3DS file contains faces but no vertices: " + pFile); } - CheckIndices(*i); - MakeUnique (*i); - ComputeNormalsWithSmoothingsGroups(*i); + CheckIndices(mesh); + MakeUnique (mesh); + ComputeNormalsWithSmoothingsGroups(mesh); } // Replace all occurrences of the default material with a From f0ebb40f19bbc0376901b23dea681e442101114f Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 21:32:24 +0300 Subject: [PATCH 02/15] ASE: Use C++11 range-based for loop --- code/ASELoader.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/code/ASELoader.cpp b/code/ASELoader.cpp index 6f6610786..63aff6335 100644 --- a/code/ASELoader.cpp +++ b/code/ASELoader.cpp @@ -225,17 +225,13 @@ void ASEImporter::InternReadFile( const std::string& pFile, + mParser->m_vCameras.size() + mParser->m_vDummies.size()); // Lights - for (std::vector::iterator it = mParser->m_vLights.begin(), - end = mParser->m_vLights.end();it != end; ++it)nodes.push_back(&(*it)); + for (auto &light : mParser->m_vLights)nodes.push_back(&light); // Cameras - for (std::vector::iterator it = mParser->m_vCameras.begin(), - end = mParser->m_vCameras.end();it != end; ++it)nodes.push_back(&(*it)); + for (auto &camera : mParser->m_vCameras)nodes.push_back(&camera); // Meshes - for (std::vector::iterator it = mParser->m_vMeshes.begin(), - end = mParser->m_vMeshes.end();it != end; ++it)nodes.push_back(&(*it)); + for (auto &mesh : mParser->m_vMeshes)nodes.push_back(&mesh); // Dummies - for (std::vector::iterator it = mParser->m_vDummies.begin(), - end = mParser->m_vDummies.end();it != end; ++it)nodes.push_back(&(*it)); + for (auto &dummy : mParser->m_vDummies)nodes.push_back(&dummy); // build the final node graph BuildNodes(nodes); @@ -657,8 +653,8 @@ void ASEImporter::BuildNodes(std::vector& nodes) { ch->mParent = root; // Change the transformation matrix of all nodes - for (std::vector::iterator it = nodes.begin(), end = nodes.end();it != end; ++it) { - aiMatrix4x4& m = (*it)->mTransform; + for (BaseNode *node : nodes) { + aiMatrix4x4& m = node->mTransform; m.Transpose(); // row-order vs column-order } From 52405bbe1bf647f3e53bca82a91e3e3f09c799ac Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 22:04:39 +0300 Subject: [PATCH 03/15] Collada: Use C++11 range-based for loop --- code/ColladaLoader.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/code/ColladaLoader.cpp b/code/ColladaLoader.cpp index 9338452a5..7d8b29fbf 100644 --- a/code/ColladaLoader.cpp +++ b/code/ColladaLoader.cpp @@ -276,21 +276,20 @@ void ColladaLoader::ResolveNodeInstances( const ColladaParser& pParser, const Co resolved.reserve(pNode->mNodeInstances.size()); // ... and iterate through all nodes to be instanced as children of pNode - for (std::vector::const_iterator it = pNode->mNodeInstances.begin(), - end = pNode->mNodeInstances.end(); it != end; ++it) + for (const auto &nodeInst: pNode->mNodeInstances) { // find the corresponding node in the library - const ColladaParser::NodeLibrary::const_iterator itt = pParser.mNodeLibrary.find((*it).mNode); + const ColladaParser::NodeLibrary::const_iterator itt = pParser.mNodeLibrary.find(nodeInst.mNode); const Collada::Node* nd = itt == pParser.mNodeLibrary.end() ? NULL : (*itt).second; // FIX for http://sourceforge.net/tracker/?func=detail&aid=3054873&group_id=226462&atid=1067632 // need to check for both name and ID to catch all. To avoid breaking valid files, // the workaround is only enabled when the first attempt to resolve the node has failed. if (!nd) { - nd = FindNode(pParser.mRootNode,(*it).mNode); + nd = FindNode(pParser.mRootNode, nodeInst.mNode); } if (!nd) - DefaultLogger::get()->error("Collada: Unable to resolve reference to instanced node " + (*it).mNode); + DefaultLogger::get()->error("Collada: Unable to resolve reference to instanced node " + nodeInst.mNode); else { // attach this node to the list of children @@ -1320,11 +1319,10 @@ void ColladaLoader::AddTexture ( aiMaterial& mat, const ColladaParser& pParser, // Fills materials from the collada material definitions void ColladaLoader::FillMaterials( const ColladaParser& pParser, aiScene* /*pScene*/) { - for (std::vector >::iterator it = newMats.begin(), - end = newMats.end(); it != end; ++it) + for (auto &elem : newMats) { - aiMaterial& mat = (aiMaterial&)*it->second; - Collada::Effect& effect = *it->first; + aiMaterial& mat = (aiMaterial&)*elem.second; + Collada::Effect& effect = *elem.first; // resolve shading mode int shadeMode; From 8566b9aa900e44caf2ea00dafe6e67d1d0946c4f Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 22:46:02 +0300 Subject: [PATCH 04/15] D3MF: Use C++11 range-based for loop --- code/D3MFOpcPackage.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/D3MFOpcPackage.cpp b/code/D3MFOpcPackage.cpp index acd7619e5..ae8dbccad 100644 --- a/code/D3MFOpcPackage.cpp +++ b/code/D3MFOpcPackage.cpp @@ -324,8 +324,8 @@ D3MFZipArchive::D3MFZipArchive(IOSystem* pIOHandler, const std::string& rFile) // ------------------------------------------------------------------------------------------------ // Destructor. D3MFZipArchive::~D3MFZipArchive() { - for( std::map::iterator it(m_ArchiveMap.begin()), end(m_ArchiveMap.end()); it != end; ++it ) { - delete it->second; + for(auto &file : m_ArchiveMap) { + delete file.second; } m_ArchiveMap.clear(); @@ -398,8 +398,8 @@ void D3MFZipArchive::Close(IOStream *pFile) { void D3MFZipArchive::getFileList(std::vector &rFileList) { rFileList.clear(); - for(std::map::iterator it(m_ArchiveMap.begin()), end(m_ArchiveMap.end()); it != end; ++it) { - rFileList.push_back(it->first); + for(const auto &file : m_ArchiveMap) { + rFileList.push_back(file.first); } } From c7c756d3444b9dccb1642c1b21080a71d5adaf5a Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 22:53:19 +0300 Subject: [PATCH 05/15] FBX: Use C++11 range-based for loop --- code/FBXConverter.cpp | 4 ++-- code/FBXDocument.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index cf2b8dbf2..a1633b900 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -1062,8 +1062,8 @@ void Converter::GenerateTransformationNodeChain( const Model& model, nd->mName.Set( name ); - for ( size_t i = 0; i < TransformationComp_MAXIMUM; ++i ) { - nd->mTransformation = nd->mTransformation * chain[ i ]; + for (const auto &transform : chain) { + nd->mTransformation = nd->mTransformation * transform; } } diff --git a/code/FBXDocument.cpp b/code/FBXDocument.cpp index 4eef04342..cf5f6da86 100644 --- a/code/FBXDocument.cpp +++ b/code/FBXDocument.cpp @@ -269,8 +269,8 @@ Document::Document(const Parser& parser, const ImportSettings& settings) , parser(parser) { // Cannot use array default initialization syntax because vc8 fails on it - for (unsigned int i = 0; i < sizeof(creationTimeStamp) / sizeof(creationTimeStamp[0]); ++i) { - creationTimeStamp[i] = 0; + for (auto &timeStamp : creationTimeStamp) { + timeStamp = 0; } ReadHeader(); From 3031470ec1423812ca48f8a1fe8ca0e0b19ac526 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 23:07:54 +0300 Subject: [PATCH 06/15] IRR: Use C++11 range-based for loop --- code/IRRLoader.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/code/IRRLoader.cpp b/code/IRRLoader.cpp index fcf894e6a..cc0d2c5f4 100644 --- a/code/IRRLoader.cpp +++ b/code/IRRLoader.cpp @@ -1372,8 +1372,7 @@ void IRRImporter::InternReadFile( const std::string& pFile, /* Now iterate through all cameras and compute their final (horizontal) FOV */ - for (std::vector::iterator it = cameras.begin(), end = cameras.end();it != end; ++it) { - aiCamera* cam = *it; + for (aiCamera *cam : cameras) { // screen aspect could be missing if (cam->mAspect) { From b9fbfbc18aafce9990a6dfea84f120788696c88d Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 23:28:33 +0300 Subject: [PATCH 07/15] LWO: Use C++11 range-based for loop --- code/LWOLoader.cpp | 13 ++++++------ code/LWOMaterial.cpp | 48 +++++++++++++++++++++----------------------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/code/LWOLoader.cpp b/code/LWOLoader.cpp index caaf21ecb..a8e97e7b1 100644 --- a/code/LWOLoader.cpp +++ b/code/LWOLoader.cpp @@ -246,8 +246,7 @@ void LWOImporter::InternReadFile( const std::string& pFile, apcMeshes.reserve(mLayers->size()*std::min(((unsigned int)mSurfaces->size()/2u), 1u)); unsigned int iDefaultSurface = UINT_MAX; // index of the default surface - for (LayerList::iterator lit = mLayers->begin(), lend = mLayers->end();lit != lend;++lit) { - LWO::Layer& layer = *lit; + for (LWO::Layer &layer : *mLayers) { if (layer.skip) continue; @@ -909,12 +908,12 @@ void LWOImporter::LoadLWO2PolygonTags(unsigned int length) template VMapEntry* FindEntry(std::vector< T >& list,const std::string& name, bool perPoly) { - for (typename std::vector< T >::iterator it = list.begin(), end = list.end();it != end; ++it) { - if ((*it).name == name) { + for (auto & elem : list) { + if (elem.name == name) { if (!perPoly) { DefaultLogger::get()->warn("LWO2: Found two VMAP sections with equal names"); } - return &(*it); + return &elem; } } list.push_back( T() ); @@ -941,8 +940,8 @@ inline void CreateNewEntry(T& chan, unsigned int srcIdx) template inline void CreateNewEntry(std::vector< T >& list, unsigned int srcIdx) { - for (typename std::vector< T >::iterator it = list.begin(), end = list.end();it != end;++it) { - CreateNewEntry( *it, srcIdx ); + for (auto &elem : list) { + CreateNewEntry( elem, srcIdx ); } } diff --git a/code/LWOMaterial.cpp b/code/LWOMaterial.cpp index b80dae1e8..24a2458cf 100644 --- a/code/LWOMaterial.cpp +++ b/code/LWOMaterial.cpp @@ -90,8 +90,8 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex aiString s; bool ret = false; - for (TextureList::const_iterator it = in.begin(), end = in.end();it != end;++it) { - if (!(*it).enabled || !(*it).bCanUse) + for (const auto &texture : in) { + if (!texture.enabled || !texture.bCanUse) continue; ret = true; @@ -100,7 +100,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex // channels if they're not there. aiTextureMapping mapping; - switch ((*it).mapMode) + switch (texture.mapMode) { case LWO::Texture::Planar: mapping = aiTextureMapping_PLANE; @@ -120,13 +120,13 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex break; case LWO::Texture::UV: { - if( UINT_MAX == (*it).mRealUVIndex ) { + if( UINT_MAX == texture.mRealUVIndex ) { // We have no UV index for this texture, so we can't display it continue; } // add the UV source index - temp = (*it).mRealUVIndex; + temp = texture.mRealUVIndex; pcMat->AddProperty((int*)&temp,1,AI_MATKEY_UVWSRC(type,cur)); mapping = aiTextureMapping_UV; @@ -139,7 +139,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex if (mapping != aiTextureMapping_UV) { // Setup the main axis aiVector3D v; - switch ((*it).majorAxis) { + switch (texture.majorAxis) { case Texture::AXIS_X: v = aiVector3D(1.f,0.f,0.f); break; @@ -156,8 +156,8 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex // Setup UV scalings for cylindric and spherical projections if (mapping == aiTextureMapping_CYLINDER || mapping == aiTextureMapping_SPHERE) { aiUVTransform trafo; - trafo.mScaling.x = (*it).wrapAmountW; - trafo.mScaling.y = (*it).wrapAmountH; + trafo.mScaling.x = texture.wrapAmountW; + trafo.mScaling.y = texture.wrapAmountH; static_assert(sizeof(aiUVTransform)/sizeof(float) == 5, "sizeof(aiUVTransform)/sizeof(float) == 5"); pcMat->AddProperty(&trafo,1,AI_MATKEY_UVTRANSFORM(type,cur)); @@ -171,7 +171,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex // find the corresponding clip (take the last one if multiple // share the same index) ClipList::iterator end = mClips.end(), candidate = end; - temp = (*it).mClipIdx; + temp = texture.mClipIdx; for (ClipList::iterator clip = mClips.begin(); clip != end; ++clip) { if ((*clip).idx == temp) { candidate = clip; @@ -208,7 +208,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex } else { - std::string ss = (*it).mFileName; + std::string ss = texture.mFileName; if (!ss.length()) { DefaultLogger::get()->error("LWOB: Empty file name"); continue; @@ -219,10 +219,10 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex pcMat->AddProperty(&s,AI_MATKEY_TEXTURE(type,cur)); // add the blend factor - pcMat->AddProperty(&(*it).mStrength,1,AI_MATKEY_TEXBLEND(type,cur)); + pcMat->AddProperty(&texture.mStrength,1,AI_MATKEY_TEXBLEND(type,cur)); // add the blend operation - switch ((*it).blendType) + switch (texture.blendType) { case LWO::Texture::Normal: case LWO::Texture::Multiply: @@ -254,11 +254,11 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex pcMat->AddProperty((int*)&mapping,1,AI_MATKEY_MAPPING(type,cur)); // add the u-wrapping - temp = (unsigned int)GetMapMode((*it).wrapModeWidth); + temp = (unsigned int)GetMapMode(texture.wrapModeWidth); pcMat->AddProperty((int*)&temp,1,AI_MATKEY_MAPPINGMODE_U(type,cur)); // add the v-wrapping - temp = (unsigned int)GetMapMode((*it).wrapModeHeight); + temp = (unsigned int)GetMapMode(texture.wrapModeHeight); pcMat->AddProperty((int*)&temp,1,AI_MATKEY_MAPPINGMODE_V(type,cur)); ++cur; @@ -343,16 +343,14 @@ void LWOImporter::ConvertMaterial(const LWO::Surface& surf,aiMaterial* pcMat) // Now we need to know which shader to use .. iterate through the shader list of // the surface and search for a name which we know ... - for (ShaderList::const_iterator it = surf.mShaders.begin(), end = surf.mShaders.end();it != end;++it) { - //if (!(*it).enabled)continue; - - if ((*it).functionName == "LW_SuperCelShader" || (*it).functionName == "AH_CelShader") { + for (const auto &shader : surf.mShaders) { + if (shader.functionName == "LW_SuperCelShader" || shader.functionName == "AH_CelShader") { DefaultLogger::get()->info("LWO2: Mapping LW_SuperCelShader/AH_CelShader to aiShadingMode_Toon"); m = aiShadingMode_Toon; break; } - else if ((*it).functionName == "LW_RealFresnel" || (*it).functionName == "LW_FastFresnel") { + else if (shader.functionName == "LW_RealFresnel" || shader.functionName == "LW_FastFresnel") { DefaultLogger::get()->info("LWO2: Mapping LW_RealFresnel/LW_FastFresnel to aiShadingMode_Fresnel"); m = aiShadingMode_Fresnel; @@ -360,7 +358,7 @@ void LWOImporter::ConvertMaterial(const LWO::Surface& surf,aiMaterial* pcMat) } else { - DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + (*it).functionName); + DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + shader.functionName); } } if (surf.mMaximumSmoothAngle <= 0.0f) @@ -381,20 +379,20 @@ char LWOImporter::FindUVChannels(LWO::TextureList& list, LWO::Layer& /*layer*/,LWO::UVChannel& uv, unsigned int next) { char ret = 0; - for (TextureList::iterator it = list.begin(), end = list.end();it != end;++it) { + for (auto &texture : list) { // Ignore textures with non-UV mappings for the moment. - if (!(*it).enabled || !(*it).bCanUse || (*it).mapMode != LWO::Texture::UV) { + if (!texture.enabled || !texture.bCanUse || texture.mapMode != LWO::Texture::UV) { continue; } - if ((*it).mUVChannelIndex == uv.name) { + if (texture.mUVChannelIndex == uv.name) { ret = 1; // got it. - if ((*it).mRealUVIndex == UINT_MAX || (*it).mRealUVIndex == next) + if (texture.mRealUVIndex == UINT_MAX || texture.mRealUVIndex == next) { - (*it).mRealUVIndex = next; + texture.mRealUVIndex = next; } else { // channel mismatch. need to duplicate the material. From ac676d4d3cd4865989d246caaa35d8fc9dcd1327 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sat, 21 May 2016 23:43:01 +0300 Subject: [PATCH 08/15] MD5: Use C++11 range-based for loop --- code/MD5Parser.cpp | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/code/MD5Parser.cpp b/code/MD5Parser.cpp index cf8d5a9f5..8badb84cc 100644 --- a/code/MD5Parser.cpp +++ b/code/MD5Parser.cpp @@ -193,13 +193,13 @@ bool MD5Parser::ParseSection(Section& out) // skip all spaces ... handle EOL correctly #define AI_MD5_SKIP_SPACES() if(!SkipSpaces(&sz)) \ - MD5Parser::ReportWarning("Unexpected end of line",(*eit).iLineNumber); + MD5Parser::ReportWarning("Unexpected end of line",elem.iLineNumber); // read a triple float in brackets: (1.0 1.0 1.0) #define AI_MD5_READ_TRIPLE(vec) \ AI_MD5_SKIP_SPACES(); \ if ('(' != *sz++) \ - MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber); \ + MD5Parser::ReportWarning("Unexpected token: ( was expected",elem.iLineNumber); \ AI_MD5_SKIP_SPACES(); \ sz = fast_atoreal_move(sz,(float&)vec.x); \ AI_MD5_SKIP_SPACES(); \ @@ -208,7 +208,7 @@ bool MD5Parser::ParseSection(Section& out) sz = fast_atoreal_move(sz,(float&)vec.z); \ AI_MD5_SKIP_SPACES(); \ if (')' != *sz++) \ - MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber); + MD5Parser::ReportWarning("Unexpected token: ) was expected",elem.iLineNumber); // parse a string, enclosed in quotation marks or not #define AI_MD5_PARSE_STRING(out) \ @@ -220,7 +220,7 @@ bool MD5Parser::ParseSection(Section& out) szStart++; \ if ('\"' != *(szEnd-=1)) { \ MD5Parser::ReportWarning("Expected closing quotation marks in string", \ - (*eit).iLineNumber); \ + elem.iLineNumber); \ continue; \ } \ } \ @@ -244,11 +244,11 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections) } else if ((*iter).mName == "joints") { // "origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 ) - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){ + for (const auto & elem : (*iter).mElements){ mJoints.push_back(BoneDesc()); BoneDesc& desc = mJoints.back(); - const char* sz = (*eit).szStart; + const char* sz = elem.szStart; AI_MD5_PARSE_STRING(desc.mName); AI_MD5_SKIP_SPACES(); @@ -263,8 +263,8 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections) mMeshes.push_back(MeshDesc()); MeshDesc& desc = mMeshes.back(); - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit){ - const char* sz = (*eit).szStart; + for (const auto & elem : (*iter).mElements){ + const char* sz = elem.szStart; // shader attribute if (TokenMatch(sz,"shader",6)) { @@ -297,14 +297,14 @@ MD5MeshParser::MD5MeshParser(SectionList& mSections) VertexDesc& vert = desc.mVertices[idx]; if ('(' != *sz++) - MD5Parser::ReportWarning("Unexpected token: ( was expected",(*eit).iLineNumber); + MD5Parser::ReportWarning("Unexpected token: ( was expected",elem.iLineNumber); AI_MD5_SKIP_SPACES(); sz = fast_atoreal_move(sz,(float&)vert.mUV.x); AI_MD5_SKIP_SPACES(); sz = fast_atoreal_move(sz,(float&)vert.mUV.y); AI_MD5_SKIP_SPACES(); if (')' != *sz++) - MD5Parser::ReportWarning("Unexpected token: ) was expected",(*eit).iLineNumber); + MD5Parser::ReportWarning("Unexpected token: ) was expected",elem.iLineNumber); AI_MD5_SKIP_SPACES(); vert.mFirstWeight = ::strtoul10(sz,&sz); AI_MD5_SKIP_SPACES(); @@ -357,11 +357,11 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections) for (SectionList::const_iterator iter = mSections.begin(), iterEnd = mSections.end();iter != iterEnd;++iter) { if ((*iter).mName == "hierarchy") { // "sheath" 0 63 6 - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end();eit != eitEnd; ++eit) { + for (const auto & elem : (*iter).mElements) { mAnimatedBones.push_back ( AnimBoneDesc () ); AnimBoneDesc& desc = mAnimatedBones.back(); - const char* sz = (*eit).szStart; + const char* sz = elem.szStart; AI_MD5_PARSE_STRING(desc.mName); AI_MD5_SKIP_SPACES(); @@ -371,7 +371,7 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections) // flags (highest is 2^6-1) AI_MD5_SKIP_SPACES(); if(63 < (desc.iFlags = ::strtoul10(sz,&sz))){ - MD5Parser::ReportWarning("Invalid flag combination in hierarchy section",(*eit).iLineNumber); + MD5Parser::ReportWarning("Invalid flag combination in hierarchy section",elem.iLineNumber); } AI_MD5_SKIP_SPACES(); @@ -381,8 +381,8 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections) } else if((*iter).mName == "baseframe") { // ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000242 0.707107 ) - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit) { - const char* sz = (*eit).szStart; + for (const auto & elem : (*iter).mElements) { + const char* sz = elem.szStart; mBaseFrames.push_back ( BaseFrameDesc () ); BaseFrameDesc& desc = mBaseFrames.back(); @@ -407,8 +407,8 @@ MD5AnimParser::MD5AnimParser(SectionList& mSections) } // now read all elements (continuous list of floats) - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ - const char* sz = (*eit).szStart; + for (const auto & elem : (*iter).mElements){ + const char* sz = elem.szStart; while (SkipSpacesAndLineEnd(&sz)) { float f;sz = fast_atoreal_move(sz,f); desc.mValues.push_back(f); @@ -455,13 +455,13 @@ MD5CameraParser::MD5CameraParser(SectionList& mSections) cuts.reserve(strtoul10((*iter).mGlobalValue.c_str())); } else if ((*iter).mName == "cuts") { - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ - cuts.push_back(strtoul10((*eit).szStart)+1); + for (const auto & elem : (*iter).mElements){ + cuts.push_back(strtoul10(elem.szStart)+1); } } else if ((*iter).mName == "camera") { - for (ElementList::const_iterator eit = (*iter).mElements.begin(), eitEnd = (*iter).mElements.end(); eit != eitEnd; ++eit){ - const char* sz = (*eit).szStart; + for (const auto & elem : (*iter).mElements){ + const char* sz = elem.szStart; frames.push_back(CameraAnimFrameDesc()); CameraAnimFrameDesc& cur = frames.back(); From 3eb9b8e91bb94385cc00c0b8e6271e680dcd640f Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 00:37:10 +0300 Subject: [PATCH 09/15] NFF: Use C++11 range-based for loop --- code/NFFLoader.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/code/NFFLoader.cpp b/code/NFFLoader.cpp index a3286b779..09536acdb 100644 --- a/code/NFFLoader.cpp +++ b/code/NFFLoader.cpp @@ -673,12 +673,11 @@ void NFFImporter::InternReadFile( const std::string& pFile, if ('t' == line[0]) { currentMeshWithUVCoords = NULL; - for (std::vector::iterator it = meshesWithUVCoords.begin(), end = meshesWithUVCoords.end(); - it != end;++it) + for (auto &mesh : meshesWithUVCoords) { - if ((*it).shader == s) + if (mesh.shader == s) { - currentMeshWithUVCoords = &(*it); + currentMeshWithUVCoords = &mesh; break; } } @@ -695,12 +694,11 @@ void NFFImporter::InternReadFile( const std::string& pFile, else if ('p' == line[1]) { currentMeshWithNormals = NULL; - for (std::vector::iterator it = meshesWithNormals.begin(), end = meshesWithNormals.end(); - it != end;++it) + for (auto &mesh : meshesWithNormals) { - if ((*it).shader == s) + if (mesh.shader == s) { - currentMeshWithNormals = &(*it); + currentMeshWithNormals = &mesh; break; } } @@ -717,12 +715,11 @@ void NFFImporter::InternReadFile( const std::string& pFile, else { currentMesh = NULL; - for (std::vector::iterator it = meshes.begin(), end = meshes.end(); - it != end;++it) + for (auto &mesh : meshes) { - if ((*it).shader == s) + if (mesh.shader == s) { - currentMesh = &(*it); + currentMesh = &mesh; break; } } From 32e4dd0bd1503be9419a299b8e83eaf3d53faae4 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 01:44:37 +0300 Subject: [PATCH 10/15] Ogre: Use C++11 range-based for loop --- code/OgreBinarySerializer.cpp | 10 +++---- code/OgreStructs.cpp | 51 +++++++++++++++++------------------ code/OgreXmlSerializer.cpp | 14 +++++----- 3 files changed, 34 insertions(+), 41 deletions(-) diff --git a/code/OgreBinarySerializer.cpp b/code/OgreBinarySerializer.cpp index dd0b57c00..d823d37fa 100644 --- a/code/OgreBinarySerializer.cpp +++ b/code/OgreBinarySerializer.cpp @@ -501,10 +501,8 @@ void OgreBinarySerializer::NormalizeBoneWeights(VertexData *vertexData) const Some exporters wont care if the sum of all bone weights for a single vertex equals 1 or not, so validate here. */ const float epsilon = 0.05f; - for(std::set::const_iterator iter=influencedVertices.begin(), end=influencedVertices.end(); iter != end; ++iter) + for (const uint32_t vertexIndex : influencedVertices) { - const uint32_t vertexIndex = (*iter); - float sum = 0.0f; for (VertexBoneAssignmentList::const_iterator baIter=vertexData->boneAssignments.begin(), baEnd=vertexData->boneAssignments.end(); baIter != baEnd; ++baIter) { @@ -513,10 +511,10 @@ void OgreBinarySerializer::NormalizeBoneWeights(VertexData *vertexData) const } if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon))) { - for (VertexBoneAssignmentList::iterator baIter=vertexData->boneAssignments.begin(), baEnd=vertexData->boneAssignments.end(); baIter != baEnd; ++baIter) + for (auto &boneAssign : vertexData->boneAssignments) { - if (baIter->vertexIndex == vertexIndex) - baIter->weight /= sum; + if (boneAssign.vertexIndex == vertexIndex) + boneAssign.weight /= sum; } } } diff --git a/code/OgreStructs.cpp b/code/OgreStructs.cpp index 566c51e0f..593f0b90e 100644 --- a/code/OgreStructs.cpp +++ b/code/OgreStructs.cpp @@ -258,12 +258,11 @@ void IVertexData::AddVertexMapping(uint32_t oldIndex, uint32_t newIndex) void IVertexData::BoneAssignmentsForVertex(uint32_t currentIndex, uint32_t newIndex, VertexBoneAssignmentList &dest) const { - for (VertexBoneAssignmentList::const_iterator iter=boneAssignments.begin(), end=boneAssignments.end(); - iter!=end; ++iter) + for (const auto &boneAssign : boneAssignments) { - if (iter->vertexIndex == currentIndex) + if (boneAssign.vertexIndex == currentIndex) { - VertexBoneAssignment a = (*iter); + VertexBoneAssignment a = boneAssign; a.vertexIndex = newIndex; dest.push_back(a); } @@ -289,10 +288,9 @@ AssimpVertexBoneWeightList IVertexData::AssimpBoneWeights(size_t vertices) std::set IVertexData::ReferencedBonesByWeights() const { std::set referenced; - for (VertexBoneAssignmentList::const_iterator iter=boneAssignments.begin(), end=boneAssignments.end(); - iter!=end; ++iter) + for (const auto &boneAssign : boneAssignments) { - referenced.insert(iter->boneIndex); + referenced.insert(boneAssign.boneIndex); } return referenced; } @@ -318,10 +316,10 @@ void VertexData::Reset() uint32_t VertexData::VertexSize(uint16_t source) const { uint32_t size = 0; - for(VertexElementList::const_iterator iter=vertexElements.begin(), end=vertexElements.end(); iter != end; ++iter) + for(const auto &element : vertexElements) { - if (iter->source == source) - size += iter->Size(); + if (element.source == source) + size += element.Size(); } return size; } @@ -335,9 +333,8 @@ MemoryStream *VertexData::VertexBuffer(uint16_t source) VertexElement *VertexData::GetVertexElement(VertexElement::Semantic semantic, uint16_t index) { - for(VertexElementList::iterator iter=vertexElements.begin(), end=vertexElements.end(); iter != end; ++iter) + for(auto & element : vertexElements) { - VertexElement &element = (*iter); if (element.semantic == semantic && element.index == index) return &element; } @@ -427,16 +424,16 @@ void Mesh::Reset() OGRE_SAFE_DELETE(skeleton) OGRE_SAFE_DELETE(sharedVertexData) - for(size_t i=0, len=subMeshes.size(); iBoneById(children[i]); + Bone *child = skeleton->BoneById(boneId); if (!child) { - throw DeadlyImportError(Formatter::format() << "CalculateWorldMatrixAndDefaultPose: Failed to find child bone " << children[i] << " for parent " << id << " " << name); + throw DeadlyImportError(Formatter::format() << "CalculateWorldMatrixAndDefaultPose: Failed to find child bone " << boneId << " for parent " << id << " " << name); } child->CalculateWorldMatrixAndDefaultPose(skeleton); } diff --git a/code/OgreXmlSerializer.cpp b/code/OgreXmlSerializer.cpp index 030d61d57..b011b842f 100644 --- a/code/OgreXmlSerializer.cpp +++ b/code/OgreXmlSerializer.cpp @@ -453,7 +453,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest) } else if (uvs > 0 && m_currentNodeName == nnTexCoord) { - for(size_t i=0, len=dest->uvs.size(); iuvs) { if (m_currentNodeName != nnTexCoord) { throw DeadlyImportError("Vertex buffer declared more UVs than can be found in a vertex"); @@ -462,7 +462,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest) aiVector3D uv; uv.x = ReadAttribute("u"); uv.y = (ReadAttribute("v") * -1) + 1; // Flip UV from Ogre to Assimp form - dest->uvs[i].push_back(uv); + uvs.push_back(uv); NextNode(); } @@ -657,10 +657,8 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest) Some exporters wont care if the sum of all bone weights for a single vertex equals 1 or not, so validate here. */ const float epsilon = 0.05f; - for(std::set::const_iterator iter=influencedVertices.begin(), end=influencedVertices.end(); iter != end; ++iter) + for (const uint32_t vertexIndex : influencedVertices) { - const uint32_t vertexIndex = (*iter); - float sum = 0.0f; for (VertexBoneAssignmentList::const_iterator baIter=dest->boneAssignments.begin(), baEnd=dest->boneAssignments.end(); baIter != baEnd; ++baIter) { @@ -669,10 +667,10 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest) } if ((sum < (1.0f - epsilon)) || (sum > (1.0f + epsilon))) { - for (VertexBoneAssignmentList::iterator baIter=dest->boneAssignments.begin(), baEnd=dest->boneAssignments.end(); baIter != baEnd; ++baIter) + for (auto &boneAssign : dest->boneAssignments) { - if (baIter->vertexIndex == vertexIndex) - baIter->weight /= sum; + if (boneAssign.vertexIndex == vertexIndex) + boneAssign.weight /= sum; } } } From a09a6a40c0f22bddce400ffb3899dfb57fd7a720 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 12:27:26 +0300 Subject: [PATCH 11/15] OpenGEX: Use C++11 range-based for loop --- code/OpenGEXImporter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/OpenGEXImporter.cpp b/code/OpenGEXImporter.cpp index cad33229d..d99dc3344 100644 --- a/code/OpenGEXImporter.cpp +++ b/code/OpenGEXImporter.cpp @@ -236,8 +236,8 @@ OpenGEXImporter::VertexContainer::~VertexContainer() { delete[] m_vertices; delete[] m_normals; - for( size_t i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; i++ ) { - delete [] m_textureCoords[ i ]; + for(auto &texcoords : m_textureCoords) { + delete [] texcoords; } } From 6c9c0404197bb72bc0bd2b67b7eaf8b2388fdea6 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 12:58:27 +0300 Subject: [PATCH 12/15] Q3BSP: Use C++11 range-based for loop --- code/Q3BSPFileImporter.cpp | 4 ++-- code/Q3BSPZipArchive.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/code/Q3BSPFileImporter.cpp b/code/Q3BSPFileImporter.cpp index 2526aeb26..bfdafcc96 100644 --- a/code/Q3BSPFileImporter.cpp +++ b/code/Q3BSPFileImporter.cpp @@ -131,11 +131,11 @@ static void normalizePathName( const std::string &rPath, std::string &rNormalize static const unsigned int numDelimiters = 2; const char delimiters[ numDelimiters ] = { '/', '\\' }; rNormalizedPath = rPath; - for ( unsigned int i=0; i::iterator it(m_ArchiveMap.begin()), end(m_ArchiveMap.end()); it != end; ++it ) { - delete it->second; + for(auto &file : m_ArchiveMap) { + delete file.second; } m_ArchiveMap.clear(); @@ -269,8 +269,8 @@ void Q3BSPZipArchive::Close(IOStream *pFile) { void Q3BSPZipArchive::getFileList(std::vector &rFileList) { rFileList.clear(); - for(std::map::iterator it(m_ArchiveMap.begin()), end(m_ArchiveMap.end()); it != end; ++it) { - rFileList.push_back(it->first); + for(auto &file : m_ArchiveMap) { + rFileList.push_back(file.first); } } From d238597459c92851e252c0f3f11e8f8d3a531121 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 13:45:50 +0300 Subject: [PATCH 13/15] Raw: Use C++11 range-based for loop --- code/RawLoader.cpp | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/code/RawLoader.cpp b/code/RawLoader.cpp index 654418754..582323cfd 100644 --- a/code/RawLoader.cpp +++ b/code/RawLoader.cpp @@ -183,12 +183,11 @@ void RAWImporter::InternReadFile( const std::string& pFile, } // search in the list of meshes whether we have one with this texture - for (std::vector< MeshInformation >::iterator it = (*curGroup).meshes.begin(), - end = (*curGroup).meshes.end(); it != end; ++it) + for (auto &mesh : (*curGroup).meshes) { - if (length == (*it).name.length() && (length ? !::strcmp(sz,(*it).name.c_str()) : true)) + if (length == mesh.name.length() && (length ? !::strcmp(sz, mesh.name.c_str()) : true)) { - output = &(*it); + output = &mesh; break; } } @@ -223,13 +222,12 @@ void RAWImporter::InternReadFile( const std::string& pFile, // count the number of valid groups // (meshes can't be empty) - for (std::vector< GroupInformation >::iterator it = outGroups.begin(), end = outGroups.end(); - it != end;++it) + for (auto & outGroup : outGroups) { - if (!(*it).meshes.empty()) + if (!outGroup.meshes.empty()) { ++pScene->mRootNode->mNumChildren; - pScene->mNumMeshes += (unsigned int)(*it).meshes.size(); + pScene->mNumMeshes += (unsigned int) outGroup.meshes.size(); } } @@ -251,10 +249,9 @@ void RAWImporter::InternReadFile( const std::string& pFile, aiMaterial** mats = pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials]; unsigned int meshIdx = 0; - for (std::vector< GroupInformation >::iterator it = outGroups.begin(), end = outGroups.end(); - it != end;++it) + for (auto & outGroup : outGroups) { - if ((*it).meshes.empty())continue; + if (outGroup.meshes.empty())continue; aiNode* node; if (pScene->mRootNode->mNumChildren) @@ -263,13 +260,13 @@ void RAWImporter::InternReadFile( const std::string& pFile, node->mParent = pScene->mRootNode; } else node = *cc;++cc; - node->mName.Set((*it).name); + node->mName.Set(outGroup.name); // add all meshes - node->mNumMeshes = (unsigned int)(*it).meshes.size(); + node->mNumMeshes = (unsigned int) outGroup.meshes.size(); unsigned int* pi = node->mMeshes = new unsigned int[ node->mNumMeshes ]; - for (std::vector< MeshInformation >::iterator it2 = (*it).meshes.begin(), - end2 = (*it).meshes.end(); it2 != end2; ++it2) + for (std::vector< MeshInformation >::iterator it2 = outGroup.meshes.begin(), + end2 = outGroup.meshes.end(); it2 != end2; ++it2) { ai_assert(!(*it2).vertices.empty()); From 896ab8eee2bf864740ed5d722fbde9c5bc3303cd Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 13:50:29 +0300 Subject: [PATCH 14/15] Unreal: Use C++11 range-based for loop --- code/UnrealLoader.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/code/UnrealLoader.cpp b/code/UnrealLoader.cpp index d7accacea..ad839fb25 100644 --- a/code/UnrealLoader.cpp +++ b/code/UnrealLoader.cpp @@ -171,9 +171,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile, // collect triangles std::vector triangles(numTris); - for (std::vector::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) { - Unreal::Triangle& tri = *it; - + for (auto & tri : triangles) { for (unsigned int i = 0; i < 3;++i) { tri.mVertex[i] = d_reader.GetI2(); @@ -222,9 +220,9 @@ void UnrealImporter::InternReadFile( const std::string& pFile, // collect vertices std::vector vertices(numVert); - for (std::vector::iterator it = vertices.begin(), end = vertices.end(); it != end; ++it) { + for (auto &vertex : vertices) { int32_t val = a_reader.GetI4(); - Unreal::DecompressVertex(*it,val); + Unreal::DecompressVertex(vertex ,val); } // list of textures. @@ -330,8 +328,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile, materials.reserve(textures.size()*2+5); // find out how many output meshes and materials we'll have and build material indices - for (std::vector::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) { - Unreal::Triangle& tri = *it; + for (Unreal::Triangle &tri : triangles) { Unreal::TempMat mat(tri); std::vector::iterator nt = std::find(materials.begin(),materials.end(),mat); if (nt == materials.end()) { @@ -418,8 +415,7 @@ void UnrealImporter::InternReadFile( const std::string& pFile, } // fill them. - for (std::vector::iterator it = triangles.begin(), end = triangles.end();it != end; ++it) { - Unreal::Triangle& tri = *it; + for (const Unreal::Triangle &tri : triangles) { Unreal::TempMat mat(tri); std::vector::iterator nt = std::find(materials.begin(),materials.end(),mat); From 381f87507f817af92a2c14f847fe78cee983e2a2 Mon Sep 17 00:00:00 2001 From: Turo Lamminen Date: Sun, 22 May 2016 13:55:47 +0300 Subject: [PATCH 15/15] SplitLargeMeshes: Use C++11 range-based for loop --- code/SplitLargeMeshes.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/code/SplitLargeMeshes.cpp b/code/SplitLargeMeshes.cpp index 00bdc2ee3..5e21ec6b8 100644 --- a/code/SplitLargeMeshes.cpp +++ b/code/SplitLargeMeshes.cpp @@ -459,11 +459,9 @@ void SplitLargeMeshesProcess_Vertex::SplitMesh( if (iBase) { // we can't use memset here we unsigned int needn' be 32 bits - for (std::vector::iterator - iter = avWasCopied.begin(),end = avWasCopied.end(); - iter != end;++iter) + for (auto &elem : avWasCopied) { - (*iter) = 0xffffffff; + elem = 0xffffffff; } }