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
+28 -6
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,12 +76,22 @@ 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;
for( IniFile::const_iterator iter = ini.begin(); iter != ini.end(); iter++ )
{
if( strncmp(iter->first, "Layer", 5) == 0 )
vsLayerNames.push_back( iter->first );
}
sort( vsLayerNames.begin(), vsLayerNames.end(), CompareLayerNames );
FOREACH_CONST( CString, vsLayerNames, s )
{
const CString sLayer = *s;
const IniFile::key* pKey = ini.GetKey( sLayer ); const IniFile::key* pKey = ini.GetKey( sLayer );
if( pKey == NULL ) ASSERT( pKey );
continue; // skip
CString sImportDir; CString sImportDir;
if( ini.GetValue(sLayer, "Import", sImportDir) ) if( ini.GetValue(sLayer, "Import", sImportDir) )
@@ -94,7 +116,7 @@ void AddLayersFromAniDir( CString sAniDir, vector<Actor*> &layersAddTo, bool Gen
layersAddTo.push_back( pLayer ); layersAddTo.push_back( pLayer );
} }
} }
}
} }
void BGAnimation::LoadFromAniDir( CString sAniDir ) void BGAnimation::LoadFromAniDir( CString sAniDir )