Skip to content

Commit 160d5f6

Browse files
committed
Code simplify, remove unused, replace list to vector, lower scope code
1 parent 79ef6b1 commit 160d5f6

File tree

1 file changed

+38
-40
lines changed

1 file changed

+38
-40
lines changed

OgreMain/src/OgreScriptTranslator.cpp

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ namespace Ogre{
13611361
AbstractNodeList::const_iterator i0 = getNodeAt(prop->values, 0), i1 = getNodeAt(prop->values, 1);
13621362
String name, value;
13631363
if(getString(*i0, &name) && getString(*i1, &value))
1364-
mTextureAliases.emplace(name, value);
1364+
mTextureAliases.emplace( name, value );
13651365
else
13661366
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
13671367
"set_texture_alias must have 2 string argument");
@@ -2399,10 +2399,11 @@ namespace Ogre{
23992399
}
24002400
else
24012401
{
2402-
AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1), i2 = getNodeAt(prop->values, 2);
2402+
AbstractNodeList::const_iterator i1 = getNodeAt(prop->values, 1);
24032403
bool val = false;
24042404
if(getBoolean(prop->values.front(), &val))
24052405
{
2406+
AbstractNodeList::const_iterator i2 = getNodeAt( prop->values, 2 );
24062407
FogMode mode = FOG_NONE;
24072408
ColourValue clr = ColourValue::White;
24082409
Real dens = Real( 0.001 ), start = 0.0f, end = 1.0f;
@@ -4685,7 +4686,7 @@ namespace Ogre{
46854686
//-------------------------------------------------------------------------
46864687
void GpuProgramTranslator::translateGpuProgram(ScriptCompiler *compiler, ObjectAbstractNode *obj)
46874688
{
4688-
list<std::pair<String,String> >::type customParameters;
4689+
vector<std::pair<String,String> >::type customParameters;
46894690
String syntax, source;
46904691
AbstractNodePtr params;
46914692
for(AbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
@@ -4740,7 +4741,7 @@ namespace Ogre{
47404741
value += ((AtomAbstractNode*)(*it).get())->value;
47414742
}
47424743
}
4743-
customParameters.emplace_back(name, value);
4744+
customParameters.emplace_back( name, value );
47444745
}
47454746
}
47464747
else if((*i)->type == ANT_OBJECT)
@@ -4790,7 +4791,7 @@ namespace Ogre{
47904791
prog->_notifyOrigin(obj->file);
47914792

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

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

48194820
ProcessResourceNameScriptCompilerEvent evt(ProcessResourceNameScriptCompilerEvent::GPU_PROGRAM, value);
48204821
compiler->_fireEvent(&evt, 0);
4821-
customParameters.emplace_back("delegate", evt.mName);
4822+
customParameters.emplace_back( "delegate", evt.mName );
48224823
}
48234824
else
48244825
{
@@ -4835,7 +4836,7 @@ namespace Ogre{
48354836
value += ((AtomAbstractNode*)(*it).get())->value;
48364837
}
48374838
}
4838-
customParameters.emplace_back(name, value);
4839+
customParameters.emplace_back( name, value );
48394840
}
48404841
}
48414842
else if((*i)->type == ANT_OBJECT)
@@ -4874,7 +4875,7 @@ namespace Ogre{
48744875
prog->_notifyOrigin(obj->file);
48754876

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

48804881
// Set up default parameters
@@ -4900,7 +4901,7 @@ namespace Ogre{
49004901
return;
49014902
}
49024903

4903-
list<std::pair<String,String> >::type customParameters;
4904+
vector<std::pair<String,String> >::type customParameters;
49044905
String source;
49054906
AbstractNodePtr params;
49064907
for(AbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
@@ -4949,7 +4950,7 @@ namespace Ogre{
49494950
}
49504951
}
49514952
}
4952-
customParameters.emplace_back(name, value);
4953+
customParameters.emplace_back( name, value );
49534954
}
49544955
}
49554956
else if((*i)->type == ANT_OBJECT)
@@ -4991,7 +4992,7 @@ namespace Ogre{
49914992
prog->_notifyOrigin(obj->file);
49924993

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

49974998
// Set up default parameters
@@ -5003,7 +5004,7 @@ namespace Ogre{
50035004

50045005
}
50055006
//-------------------------------------------------------------------------
5006-
uint32 parseProgramParameterDimensions(String& declarator, String type)
5007+
uint32 parseProgramParameterDimensions(const String& declarator, const String& type)
50075008
{
50085009
// Assume 1 unless otherwise specified
50095010
uint32 dimensions = 1;
@@ -5012,7 +5013,7 @@ namespace Ogre{
50125013

50135014
if (start != String::npos)
50145015
{
5015-
size_t end = declarator.find_first_of("[", start);
5016+
size_t end = declarator.find_first_of('[', start);
50165017

50175018
// int1, int2, etc.
50185019
if (end != start)
@@ -5025,10 +5026,10 @@ namespace Ogre{
50255026
// C-style array
50265027
while (start != String::npos)
50275028
{
5028-
end = declarator.find_first_of("]", start);
5029+
end = declarator.find_first_of(']', start);
50295030
dimensions *= StringConverter::parseUnsignedInt(
50305031
declarator.substr(start + 1, end - start - 1));
5031-
start = declarator.find_first_of("[", end);
5032+
start = declarator.find_first_of('[', end);
50325033
}
50335034
}
50345035

@@ -7702,7 +7703,7 @@ namespace Ogre{
77027703
else
77037704
{
77047705
AbstractNodeList::const_iterator it1 = prop->values.begin();
7705-
AbstractNodeList::const_iterator it0 = it1++;
7706+
AbstractNodeList::const_iterator it0 = std::next( it1 );
77067707

77077708
uint32 outChannel;
77087709
IdString bufferName;
@@ -8627,7 +8628,7 @@ namespace Ogre{
86278628
uint32 colourIdx;
86288629
LoadAction::LoadAction loadAction;
86298630
AbstractNodeList::const_iterator it1 = prop->values.begin();
8630-
AbstractNodeList::const_iterator it0 = it1++;
8631+
AbstractNodeList::const_iterator it0 = std::next( it1 );
86318632
if( getUInt( *it0, &colourIdx ) && getLoadAction( *it1, &loadAction ) )
86328633
{
86338634
if( colourIdx < OGRE_MAX_MULTIPLE_RENDER_TARGETS )
@@ -8912,7 +8913,7 @@ namespace Ogre{
89128913
uint32 colourIdx;
89138914
StoreAction::StoreAction storeAction;
89148915
AbstractNodeList::const_iterator it1 = prop->values.begin();
8915-
AbstractNodeList::const_iterator it0 = it1++;
8916+
AbstractNodeList::const_iterator it0 = std::next( it1 );
89168917
if( getUInt( *it0, &colourIdx ) && getStoreAction( *it1, &storeAction ) )
89178918
{
89188919
if( colourIdx < OGRE_MAX_MULTIPLE_RENDER_TARGETS )
@@ -9307,8 +9308,8 @@ namespace Ogre{
93079308
else
93089309
{
93099310
AbstractNodeList::const_iterator it2 = prop->values.begin();
9310-
AbstractNodeList::const_iterator it0 = it2++;
9311-
AbstractNodeList::const_iterator it1 = it2++;
9311+
AbstractNodeList::const_iterator it0 = std::next( it2 );
9312+
AbstractNodeList::const_iterator it1 = std::next( it2, 2 );
93129313

93139314
uint32 id;
93149315
String name;
@@ -9717,9 +9718,9 @@ namespace Ogre{
97179718
gbuffer.resize( 2 );
97189719

97199720
AbstractNodeList::const_iterator it3 = prop->values.begin();
9720-
AbstractNodeList::const_iterator it0 = it3++;
9721-
AbstractNodeList::const_iterator it1 = it3++;
9722-
AbstractNodeList::const_iterator it2 = it3++;
9721+
AbstractNodeList::const_iterator it0 = std::next( it3 );
9722+
AbstractNodeList::const_iterator it1 = std::next( it3, 2 );
9723+
AbstractNodeList::const_iterator it2 = std::next( it3, 3 );
97239724

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

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

97719772
if( !getIdString( *it0, &depthTexture ) || !getIdString( *it1, &refractions ) )
97729773
{
@@ -9812,7 +9813,7 @@ namespace Ogre{
98129813
else
98139814
{
98149815
AbstractNodeList::const_iterator it1 = prop->values.begin();
9815-
AbstractNodeList::const_iterator it0 = it1++;
9816+
AbstractNodeList::const_iterator it0 = std::next( it1 );
98169817

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

99459946
AbstractNodeList::const_iterator it0 = prop->values.begin();
9946-
AbstractNodeList::const_iterator it1 = it0;
9947-
if( prop->values.size() > 1 )
9948-
++it1;
9949-
99509947
String str;
99519948
if( getString( *it0, &str ) )
99529949
{
@@ -10719,8 +10716,8 @@ namespace Ogre{
1071910716
else
1072010717
{
1072110718
AbstractNodeList::const_iterator it2 = prop->values.begin();
10722-
AbstractNodeList::const_iterator it0 = it2++;
10723-
AbstractNodeList::const_iterator it1 = it2++;
10719+
AbstractNodeList::const_iterator it0 = std::next( it2 );
10720+
AbstractNodeList::const_iterator it1 = std::next( it2, 2 );
1072410721

1072510722
uint32 id;
1072610723
String name;
@@ -10772,6 +10769,7 @@ namespace Ogre{
1077210769
else if((*i)->type == ANT_PROPERTY)
1077310770
{
1077410771
PropertyAbstractNode *prop = reinterpret_cast<PropertyAbstractNode*>((*i).get());
10772+
const AbstractNodePtr beginNode = prop->values.front();
1077510773
switch(prop->id)
1077610774
{
1077710775
case ID_MIPMAP_METHOD:
@@ -10786,9 +10784,9 @@ namespace Ogre{
1078610784
}
1078710785
else
1078810786
{
10789-
if(prop->values.front()->type == ANT_ATOM)
10787+
if( beginNode->type == ANT_ATOM )
1079010788
{
10791-
AtomAbstractNode *atom = (AtomAbstractNode*)prop->values.front().get();
10789+
AtomAbstractNode *atom = (AtomAbstractNode *)beginNode.get();
1079210790
switch(atom->id)
1079310791
{
1079410792
case ID_API_DEFAULT:
@@ -10802,14 +10800,14 @@ namespace Ogre{
1080210800
break;
1080310801
default:
1080410802
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
10805-
prop->values.front()->getValue() +
10803+
beginNode->getValue() +
1080610804
" is not a valid miprmap_method (api_default, compute, or compute_hq)");
1080710805
}
1080810806
}
1080910807
else
1081010808
{
1081110809
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
10812-
prop->values.front()->getValue() +
10810+
beginNode->getValue() +
1081310811
" is not a valid miprmap_method (api_default, compute, or compute_hq)");
1081410812
}
1081510813
}
@@ -10827,10 +10825,10 @@ namespace Ogre{
1082710825
else
1082810826
{
1082910827
int value = 8;
10830-
if( !getInt( prop->values.front(), &value ) )
10828+
if( !getInt( beginNode, &value ) )
1083110829
{
1083210830
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
10833-
prop->values.front()->getValue() + " is not a valid integer argument");
10831+
beginNode->getValue() + " is not a valid integer argument" );
1083410832
}
1083510833
else
1083610834
{
@@ -10850,10 +10848,10 @@ namespace Ogre{
1085010848
}
1085110849
else
1085210850
{
10853-
if( !getFloat( prop->values.front(), &passMipmap->mGaussianDeviationFactor ) )
10851+
if( !getFloat( beginNode, &passMipmap->mGaussianDeviationFactor ) )
1085410852
{
1085510853
compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, prop->file, prop->line,
10856-
prop->values.front()->getValue() + " is not a valid integer argument");
10854+
beginNode->getValue() + " is not a valid integer argument" );
1085710855
}
1085810856
}
1085910857
break;

0 commit comments

Comments
 (0)