more efficient BGA loading: iterate keys in ini file to find layers

This commit is contained in:
Chris Danford
2004-12-25 08:44:12 +00:00
parent e01f6ed77e
commit 4563395b4b
+48 -26
View File
@@ -11,8 +11,8 @@
#include "ActorUtil.h" #include "ActorUtil.h"
#include "LuaHelpers.h" #include "LuaHelpers.h"
#include "arch/Dialog/Dialog.h" #include "arch/Dialog/Dialog.h"
#include "Foreach.h"
const int MAX_LAYERS = 1000;
BGAnimation::BGAnimation( bool Generic ) BGAnimation::BGAnimation( bool Generic )
{ {
@@ -40,6 +40,18 @@ void BGAnimation::LoadFromStaticGraphic( CString sPath )
AddChild( pLayer ); AddChild( pLayer );
} }
static bool CompareLayerNames( const CString& s1, const CString& s2 )
{
int i1, i2;
int ret;
ret = sscanf( s1, "Layer%d", &i1 );
ASSERT( ret == 1 );
ret = sscanf( s2, "Layer%d", &i2 );
ASSERT( ret == 1 );
return i1 < i2;
}
void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Generic ) void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Generic )
{ {
if( sAniDir.empty() ) if( sAniDir.empty() )
@@ -64,37 +76,47 @@ void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Gen
} }
} }
for( int i=0; i<MAX_LAYERS; i++ )
{ {
CString sLayer = ssprintf("Layer%d",i+1); vector<CString> vsLayerNames;
const IniFile::key* pKey = ini.GetKey( sLayer ); for( IniFile::const_iterator iter = ini.begin(); iter != ini.end(); iter++ )
if( pKey == NULL )
continue; // skip
CString sImportDir;
if( ini.GetValue(sLayer, "Import", sImportDir) )
{ {
CString expr; if( strncmp(iter->first, "Layer", 5) == 0 )
if( ini.GetValue(sLayer,"Condition",expr) ) vsLayerNames.push_back( iter->first );
{
if( !Lua::RunExpressionB( expr ) )
continue;
}
// import a whole BGAnimation
sImportDir = sAniDir + sImportDir;
CollapsePath( sImportDir );
AddLayersFromAniDir( sImportDir, layersAddTo, Generic );
} }
else
sort( vsLayerNames.begin(), vsLayerNames.end(), CompareLayerNames );
FOREACH_CONST( CString, vsLayerNames, s )
{ {
// import as a single layer const CString sLayer = *s;
BGAnimationLayer* pLayer = new BGAnimationLayer( Generic ); const IniFile::key* pKey = ini.GetKey( sLayer );
pLayer->LoadFromIni( sAniDir, sLayer ); ASSERT( pKey );
layersAddTo.push_back( pLayer );
CString sImportDir;
if( ini.GetValue(sLayer, "Import", sImportDir) )
{
CString expr;
if( ini.GetValue(sLayer,"Condition",expr) )
{
if( !Lua::RunExpressionB( expr ) )
continue;
}
// import a whole BGAnimation
sImportDir = sAniDir + sImportDir;
CollapsePath( sImportDir );
AddLayersFromAniDir( sImportDir, layersAddTo, Generic );
}
else
{
// import as a single layer
BGAnimationLayer* pLayer = new BGAnimationLayer( Generic );
pLayer->LoadFromIni( sAniDir, sLayer );
layersAddTo.push_back( pLayer );
}
} }
} }
} }
void BGAnimation::LoadFromAniDir( CString sAniDir ) void BGAnimation::LoadFromAniDir( CString sAniDir )