瀏覽代碼

LWO: Use C++11 range-based for loop

Turo Lamminen 9 年之前
父節點
當前提交
b9fbfbc18a
共有 2 個文件被更改,包括 29 次插入32 次删除
  1. 6 7
      code/LWOLoader.cpp
  2. 23 25
      code/LWOMaterial.cpp

+ 6 - 7
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));
     apcMeshes.reserve(mLayers->size()*std::min(((unsigned int)mSurfaces->size()/2u), 1u));
 
 
     unsigned int iDefaultSurface = UINT_MAX; // index of the default surface
     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)
         if (layer.skip)
             continue;
             continue;
 
 
@@ -909,12 +908,12 @@ void LWOImporter::LoadLWO2PolygonTags(unsigned int length)
 template <class T>
 template <class T>
 VMapEntry* FindEntry(std::vector< T >& list,const std::string& name, bool perPoly)
 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)   {
             if (!perPoly)   {
                 DefaultLogger::get()->warn("LWO2: Found two VMAP sections with equal names");
                 DefaultLogger::get()->warn("LWO2: Found two VMAP sections with equal names");
             }
             }
-            return &(*it);
+            return &elem;
         }
         }
     }
     }
     list.push_back( T() );
     list.push_back( T() );
@@ -941,8 +940,8 @@ inline void CreateNewEntry(T& chan, unsigned int srcIdx)
 template <class T>
 template <class T>
 inline void CreateNewEntry(std::vector< T >& list, unsigned int srcIdx)
 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 );
     }
     }
 }
 }
 
 

+ 23 - 25
code/LWOMaterial.cpp

@@ -90,8 +90,8 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
     aiString s;
     aiString s;
     bool ret = false;
     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;
             continue;
         ret = true;
         ret = true;
 
 
@@ -100,7 +100,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
         // channels if they're not there.
         // channels if they're not there.
 
 
         aiTextureMapping mapping;
         aiTextureMapping mapping;
-        switch ((*it).mapMode)
+        switch (texture.mapMode)
         {
         {
             case LWO::Texture::Planar:
             case LWO::Texture::Planar:
                 mapping = aiTextureMapping_PLANE;
                 mapping = aiTextureMapping_PLANE;
@@ -120,13 +120,13 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
                 break;
                 break;
             case LWO::Texture::UV:
             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
                         // We have no UV index for this texture, so we can't display it
                         continue;
                         continue;
                     }
                     }
 
 
                     // add the UV source index
                     // add the UV source index
-                    temp = (*it).mRealUVIndex;
+                    temp = texture.mRealUVIndex;
                     pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_UVWSRC(type,cur));
                     pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_UVWSRC(type,cur));
 
 
                     mapping = aiTextureMapping_UV;
                     mapping = aiTextureMapping_UV;
@@ -139,7 +139,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
         if (mapping != aiTextureMapping_UV) {
         if (mapping != aiTextureMapping_UV) {
             // Setup the main axis
             // Setup the main axis
             aiVector3D v;
             aiVector3D v;
-            switch ((*it).majorAxis)    {
+            switch (texture.majorAxis) {
                 case Texture::AXIS_X:
                 case Texture::AXIS_X:
                     v = aiVector3D(1.f,0.f,0.f);
                     v = aiVector3D(1.f,0.f,0.f);
                     break;
                     break;
@@ -156,8 +156,8 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
             // Setup UV scalings for cylindric and spherical projections
             // Setup UV scalings for cylindric and spherical projections
             if (mapping == aiTextureMapping_CYLINDER || mapping == aiTextureMapping_SPHERE) {
             if (mapping == aiTextureMapping_CYLINDER || mapping == aiTextureMapping_SPHERE) {
                 aiUVTransform trafo;
                 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");
                 static_assert(sizeof(aiUVTransform)/sizeof(float) == 5, "sizeof(aiUVTransform)/sizeof(float) == 5");
                 pcMat->AddProperty(&trafo,1,AI_MATKEY_UVTRANSFORM(type,cur));
                 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
             // find the corresponding clip (take the last one if multiple
             // share the same index)
             // share the same index)
             ClipList::iterator end = mClips.end(), candidate = end;
             ClipList::iterator end = mClips.end(), candidate = end;
-            temp = (*it).mClipIdx;
+            temp = texture.mClipIdx;
             for (ClipList::iterator clip = mClips.begin(); clip != end; ++clip) {
             for (ClipList::iterator clip = mClips.begin(); clip != end; ++clip) {
                 if ((*clip).idx == temp) {
                 if ((*clip).idx == temp) {
                     candidate = clip;
                     candidate = clip;
@@ -208,7 +208,7 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
         }
         }
         else
         else
         {
         {
-            std::string ss = (*it).mFileName;
+            std::string ss = texture.mFileName;
             if (!ss.length()) {
             if (!ss.length()) {
                 DefaultLogger::get()->error("LWOB: Empty file name");
                 DefaultLogger::get()->error("LWOB: Empty file name");
                 continue;
                 continue;
@@ -219,10 +219,10 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
         pcMat->AddProperty(&s,AI_MATKEY_TEXTURE(type,cur));
         pcMat->AddProperty(&s,AI_MATKEY_TEXTURE(type,cur));
 
 
         // add the blend factor
         // add the blend factor
-        pcMat->AddProperty<float>(&(*it).mStrength,1,AI_MATKEY_TEXBLEND(type,cur));
+        pcMat->AddProperty<float>(&texture.mStrength,1,AI_MATKEY_TEXBLEND(type,cur));
 
 
         // add the blend operation
         // add the blend operation
-        switch ((*it).blendType)
+        switch (texture.blendType)
         {
         {
             case LWO::Texture::Normal:
             case LWO::Texture::Normal:
             case LWO::Texture::Multiply:
             case LWO::Texture::Multiply:
@@ -254,11 +254,11 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
         pcMat->AddProperty<int>((int*)&mapping,1,AI_MATKEY_MAPPING(type,cur));
         pcMat->AddProperty<int>((int*)&mapping,1,AI_MATKEY_MAPPING(type,cur));
 
 
         // add the u-wrapping
         // add the u-wrapping
-        temp = (unsigned int)GetMapMode((*it).wrapModeWidth);
+        temp = (unsigned int)GetMapMode(texture.wrapModeWidth);
         pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_MAPPINGMODE_U(type,cur));
         pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_MAPPINGMODE_U(type,cur));
 
 
         // add the v-wrapping
         // add the v-wrapping
-        temp = (unsigned int)GetMapMode((*it).wrapModeHeight);
+        temp = (unsigned int)GetMapMode(texture.wrapModeHeight);
         pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_MAPPINGMODE_V(type,cur));
         pcMat->AddProperty<int>((int*)&temp,1,AI_MATKEY_MAPPINGMODE_V(type,cur));
 
 
         ++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
     // 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 ...
     // 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");
             DefaultLogger::get()->info("LWO2: Mapping LW_SuperCelShader/AH_CelShader to aiShadingMode_Toon");
 
 
             m = aiShadingMode_Toon;
             m = aiShadingMode_Toon;
             break;
             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");
             DefaultLogger::get()->info("LWO2: Mapping LW_RealFresnel/LW_FastFresnel to aiShadingMode_Fresnel");
 
 
             m = aiShadingMode_Fresnel;
             m = aiShadingMode_Fresnel;
@@ -360,7 +358,7 @@ void LWOImporter::ConvertMaterial(const LWO::Surface& surf,aiMaterial* pcMat)
         }
         }
         else
         else
         {
         {
-            DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + (*it).functionName);
+            DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + shader.functionName);
         }
         }
     }
     }
     if (surf.mMaximumSmoothAngle <= 0.0f)
     if (surf.mMaximumSmoothAngle <= 0.0f)
@@ -381,20 +379,20 @@ char LWOImporter::FindUVChannels(LWO::TextureList& list,
     LWO::Layer& /*layer*/,LWO::UVChannel& uv, unsigned int next)
     LWO::Layer& /*layer*/,LWO::UVChannel& uv, unsigned int next)
 {
 {
     char ret = 0;
     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.
         // 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;
             continue;
         }
         }
 
 
-        if ((*it).mUVChannelIndex == uv.name) {
+        if (texture.mUVChannelIndex == uv.name) {
             ret = 1;
             ret = 1;
 
 
             // got it.
             // 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 {
             else {
                 // channel mismatch. need to duplicate the material.
                 // channel mismatch. need to duplicate the material.