Skip to content

Commit

Permalink
LWO: Use C++11 range-based for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
turol committed May 23, 2016
1 parent 3031470 commit b9fbfbc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 32 deletions.
13 changes: 6 additions & 7 deletions code/LWOLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -909,12 +908,12 @@ void LWOImporter::LoadLWO2PolygonTags(unsigned int length)
template <class T>
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() );
Expand All @@ -941,8 +940,8 @@ inline void CreateNewEntry(T& chan, unsigned int srcIdx)
template <class T>
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 );
}
}

Expand Down
48 changes: 23 additions & 25 deletions code/LWOMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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>((int*)&temp,1,AI_MATKEY_UVWSRC(type,cur));

mapping = aiTextureMapping_UV;
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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<float>(&(*it).mStrength,1,AI_MATKEY_TEXBLEND(type,cur));
pcMat->AddProperty<float>(&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:
Expand Down Expand Up @@ -254,11 +254,11 @@ bool LWOImporter::HandleTextures(aiMaterial* pcMat, const TextureList& in, aiTex
pcMat->AddProperty<int>((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>((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>((int*)&temp,1,AI_MATKEY_MAPPINGMODE_V(type,cur));

++cur;
Expand Down Expand Up @@ -343,24 +343,22 @@ 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;
break;
}
else
{
DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + (*it).functionName);
DefaultLogger::get()->warn("LWO2: Unknown surface shader: " + shader.functionName);
}
}
if (surf.mMaximumSmoothAngle <= 0.0f)
Expand All @@ -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.
Expand Down

0 comments on commit b9fbfbc

Please sign in to comment.