Skip to content

Commit

Permalink
Code simplify, remove unused, replace list to vector, lower scope code
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanAizek committed Oct 7, 2022
1 parent 79ef6b1 commit 160d5f6
Showing 1 changed file with 38 additions and 40 deletions.
78 changes: 38 additions & 40 deletions OgreMain/src/OgreScriptTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ namespace Ogre{
AbstractNodeList::const_iterator i0 = getNodeAt(prop->values, 0), i1 = getNodeAt(prop->values, 1);
String name, value;
if(getString(*i0, &name) && getString(*i1, &value))
mTextureAliases.emplace(name, value);
mTextureAliases.emplace( name, value );
else
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
"set_texture_alias must have 2 string argument");
Expand Down Expand Up @@ -2399,10 +2399,11 @@ namespace Ogre{
}
else
{
AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1), i2 = getNodeAt(prop->values, 2);
AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1);
bool val = false;
if(getBoolean(prop->values.front(), &val))
{
AbstractNodeList::const_iterator i2 = getNodeAt( prop->values, 2 );
FogMode mode = FOG_NONE;
ColourValue clr = ColourValue::White;
Real dens = Real( 0.001 ), start = 0.0f, end = 1.0f;
Expand Down Expand Up @@ -4685,7 +4686,7 @@ namespace Ogre{
//-------------------------------------------------------------------------
void GpuProgramTranslator::translateGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj)
{
list<std::pair<String,String> >::type customParameters;
vector<std::pair<String,String> >::type customParameters;
String syntax, source;
AbstractNodePtr params;
for(AbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
Expand Down Expand Up @@ -4740,7 +4741,7 @@ namespace Ogre{
value += ((AtomAbstractNode*)(*it).get())->value;
}
}
customParameters.emplace_back(name, value);
customParameters.emplace_back( name, value );
}
}
else if((*i)->type == ANT_OBJECT)
Expand Down Expand Up @@ -4790,7 +4791,7 @@ namespace Ogre{
prog->_notifyOrigin(obj->file);

// Set the custom parameters
for(list<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
for(vector<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
prog->setParameter(i->first, i->second);

// Set up default parameters
Expand All @@ -4803,7 +4804,7 @@ namespace Ogre{
//-------------------------------------------------------------------------
void GpuProgramTranslator::translateUnifiedGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj)
{
list<std::pair<String,String> >::type customParameters;
vector<std::pair<String,String> >::type customParameters;
AbstractNodePtr params;
for(AbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
{
Expand All @@ -4818,7 +4819,7 @@ namespace Ogre{

ProcessResourceNameScriptCompilerEvent evt(ProcessResourceNameScriptCompilerEvent::GPU_PROGRAM, value);
compiler->_fireEvent(&evt, 0);
customParameters.emplace_back("delegate", evt.mName);
customParameters.emplace_back( "delegate", evt.mName );
}
else
{
Expand All @@ -4835,7 +4836,7 @@ namespace Ogre{
value += ((AtomAbstractNode*)(*it).get())->value;
}
}
customParameters.emplace_back(name, value);
customParameters.emplace_back( name, value );
}
}
else if((*i)->type == ANT_OBJECT)
Expand Down Expand Up @@ -4874,7 +4875,7 @@ namespace Ogre{
prog->_notifyOrigin(obj->file);

// Set the custom parameters
for(list<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
for(vector<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
prog->setParameter(i->first, i->second);

// Set up default parameters
Expand All @@ -4900,7 +4901,7 @@ namespace Ogre{
return;
}

list<std::pair<String,String> >::type customParameters;
vector<std::pair<String,String> >::type customParameters;
String source;
AbstractNodePtr params;
for(AbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
Expand Down Expand Up @@ -4949,7 +4950,7 @@ namespace Ogre{
}
}
}
customParameters.emplace_back(name, value);
customParameters.emplace_back( name, value );
}
}
else if((*i)->type == ANT_OBJECT)
Expand Down Expand Up @@ -4991,7 +4992,7 @@ namespace Ogre{
prog->_notifyOrigin(obj->file);

// Set the custom parameters
for(list<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
for(vector<std::pair<String,String> >::type::iterator i = customParameters.begin(); i != customParameters.end(); ++i)
prog->setParameter(i->first, i->second);

// Set up default parameters
Expand All @@ -5003,7 +5004,7 @@ namespace Ogre{

}
//-------------------------------------------------------------------------
uint32 parseProgramParameterDimensions(String& declarator, String type)
uint32 parseProgramParameterDimensions(const String& declarator, const String& type)
{
// Assume 1 unless otherwise specified
uint32 dimensions = 1;
Expand All @@ -5012,7 +5013,7 @@ namespace Ogre{

if (start != String::npos)
{
size_t end = declarator.find_first_of("[", start);
size_t end = declarator.find_first_of('[', start);

// int1, int2, etc.
if (end != start)
Expand All @@ -5025,10 +5026,10 @@ namespace Ogre{
// C-style array
while (start != String::npos)
{
end = declarator.find_first_of("]", start);
end = declarator.find_first_of(']', start);
dimensions *= StringConverter::parseUnsignedInt(
declarator.substr(start + 1, end - start - 1));
start = declarator.find_first_of("[", end);
start = declarator.find_first_of('[', end);
}
}

Expand Down Expand Up @@ -7702,7 +7703,7 @@ namespace Ogre{
else
{
AbstractNodeList::const_iterator it1 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it1++;
AbstractNodeList::const_iterator it0 = std::next( it1 );

uint32 outChannel;
IdString bufferName;
Expand Down Expand Up @@ -8627,7 +8628,7 @@ namespace Ogre{
uint32 colourIdx;
LoadAction::LoadAction loadAction;
AbstractNodeList::const_iterator it1 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it1++;
AbstractNodeList::const_iterator it0 = std::next( it1 );
if( getUInt( *it0, &colourIdx ) && getLoadAction( *it1, &loadAction ) )
{
if( colourIdx < OGRE_MAX_MULTIPLE_RENDER_TARGETS )
Expand Down Expand Up @@ -8912,7 +8913,7 @@ namespace Ogre{
uint32 colourIdx;
StoreAction::StoreAction storeAction;
AbstractNodeList::const_iterator it1 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it1++;
AbstractNodeList::const_iterator it0 = std::next( it1 );
if( getUInt( *it0, &colourIdx ) && getStoreAction( *it1, &storeAction ) )
{
if( colourIdx < OGRE_MAX_MULTIPLE_RENDER_TARGETS )
Expand Down Expand Up @@ -9307,8 +9308,8 @@ namespace Ogre{
else
{
AbstractNodeList::const_iterator it2 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it2++;
AbstractNodeList::const_iterator it1 = it2++;
AbstractNodeList::const_iterator it0 = std::next( it2 );
AbstractNodeList::const_iterator it1 = std::next( it2, 2 );

uint32 id;
String name;
Expand Down Expand Up @@ -9717,9 +9718,9 @@ namespace Ogre{
gbuffer.resize( 2 );

AbstractNodeList::const_iterator it3 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it3++;
AbstractNodeList::const_iterator it1 = it3++;
AbstractNodeList::const_iterator it2 = it3++;
AbstractNodeList::const_iterator it0 = std::next( it3 );
AbstractNodeList::const_iterator it1 = std::next( it3, 2 );
AbstractNodeList::const_iterator it2 = std::next( it3, 3 );

if( !getIdString( *it0, &gbuffer[0] ) ||
!getIdString( *it1, &gbuffer[1] ) ||
Expand Down Expand Up @@ -9766,7 +9767,7 @@ namespace Ogre{
IdString depthTexture, refractions;

AbstractNodeList::const_iterator it1 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it1++;
AbstractNodeList::const_iterator it0 = std::next( it1 );

if( !getIdString( *it0, &depthTexture ) || !getIdString( *it1, &refractions ) )
{
Expand Down Expand Up @@ -9812,7 +9813,7 @@ namespace Ogre{
else
{
AbstractNodeList::const_iterator it1 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it1++;
AbstractNodeList::const_iterator it0 = std::next( it1 );

if( !getReal( *it0, &passScene->mUvBakingOffset.x ) ||
!getReal( *it1, &passScene->mUvBakingOffset.y ) )
Expand Down Expand Up @@ -9943,10 +9944,6 @@ namespace Ogre{
}

AbstractNodeList::const_iterator it0 = prop->values.begin();
AbstractNodeList::const_iterator it1 = it0;
if( prop->values.size() > 1 )
++it1;

String str;
if( getString( *it0, &str ) )
{
Expand Down Expand Up @@ -10719,8 +10716,8 @@ namespace Ogre{
else
{
AbstractNodeList::const_iterator it2 = prop->values.begin();
AbstractNodeList::const_iterator it0 = it2++;
AbstractNodeList::const_iterator it1 = it2++;
AbstractNodeList::const_iterator it0 = std::next( it2 );
AbstractNodeList::const_iterator it1 = std::next( it2, 2 );

uint32 id;
String name;
Expand Down Expand Up @@ -10772,6 +10769,7 @@ namespace Ogre{
else if((*i)->type == ANT_PROPERTY)
{
PropertyAbstractNode *prop = reinterpret_cast<PropertyAbstractNode*>((*i).get());
const AbstractNodePtr beginNode = prop->values.front();
switch(prop->id)
{
case ID_MIPMAP_METHOD:
Expand All @@ -10786,9 +10784,9 @@ namespace Ogre{
}
else
{
if(prop->values.front()->type == ANT_ATOM)
if( beginNode->type == ANT_ATOM )
{
AtomAbstractNode *atom = (AtomAbstractNode*)prop->values.front().get();
AtomAbstractNode *atom = (AtomAbstractNode *)beginNode.get();
switch(atom->id)
{
case ID_API_DEFAULT:
Expand All @@ -10802,14 +10800,14 @@ namespace Ogre{
break;
default:
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
prop->values.front()->getValue() +
beginNode->getValue() +
" is not a valid miprmap_method (api_default, compute, or compute_hq)");
}
}
else
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
prop->values.front()->getValue() +
beginNode->getValue() +
" is not a valid miprmap_method (api_default, compute, or compute_hq)");
}
}
Expand All @@ -10827,10 +10825,10 @@ namespace Ogre{
else
{
int value = 8;
if( !getInt( prop->values.front(), &value ) )
if( !getInt( beginNode, &value ) )
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
prop->values.front()->getValue() + " is not a valid integer argument");
beginNode->getValue() + " is not a valid integer argument" );
}
else
{
Expand All @@ -10850,10 +10848,10 @@ namespace Ogre{
}
else
{
if( !getFloat( prop->values.front(), &passMipmap->mGaussianDeviationFactor ) )
if( !getFloat( beginNode, &passMipmap->mGaussianDeviationFactor ) )
{
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
prop->values.front()->getValue() + " is not a valid integer argument");
beginNode->getValue() + " is not a valid integer argument" );
}
}
break;
Expand Down

0 comments on commit 160d5f6

Please sign in to comment.