From b511a9aaa3d5927e84cdb634394146793e82a425 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 1 Nov 2003 04:49:23 +0000 Subject: [PATCH] Optimize SongManager::WriteStatsWebPage (was taking 300ms for me). Don't write empty lines and don't write empty games, to get rid of pages of empty data for unused games. --- stepmania/src/SongManager.cpp | 123 +++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 38 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index c049b9c595..c82e5ee067 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1320,6 +1320,54 @@ static CString HTMLQuoteDoubleQuotes( CString str ) return str; } +static bool CompareStepsPointersByTypeAndDifficulty(const Steps *pStep1, const Steps *pStep2) +{ + if( pStep1->m_StepsType < pStep2->m_StepsType ) + return true; + if( pStep1->m_StepsType > pStep2->m_StepsType ) + return false; + return pStep1->GetDifficulty() < pStep2->GetDifficulty(); +} + +static void SortStepsByTypeAndDifficulty( vector &arraySongPointers ) +{ + sort( arraySongPointers.begin(), arraySongPointers.end(), CompareStepsPointersByTypeAndDifficulty ); +} + +static void HTMLWritePerGameHeader( FILE* fp, Game game ) +{ + const GameDef* pGameDef = GAMEMAN->GetGameDefForGame(game); + + vector aStepsTypes; + GAMEMAN->GetNotesTypesForGame( game, aStepsTypes ); + + fprintf( fp, "

%s

\n", pGameDef->m_szName ); + + fprintf( fp, "\n" ); + fprintf( fp, "" ); + + unsigned j; + for( j=0; j%s\n", NUM_DIFFICULTIES, GAMEMAN->NotesTypeToString(st).c_str() ); + } + fprintf( fp, "\n" ); + + fprintf( fp, "" ); + for( j=0; j%s\n", Capitalize(DifficultyToString(d).Left(3)).c_str() ); + } + } + + fprintf( fp, "\n" ); +} + // TODO: Move this to a different file. No need to clutter SongManager. void SongManager::WriteStatsWebPage() { @@ -1374,68 +1422,67 @@ void SongManager::WriteStatsWebPage() for( int g=0; gGetGameDefForGame(game); vector aStepsTypes; GAMEMAN->GetNotesTypesForGame( game, aStepsTypes ); - - fprintf( fp, "

%s

\n", pGameDef->m_szName ); - - - fprintf( fp, "
title
 
\n" ); - fprintf( fp, "" ); - unsigned j; - for( j=0; j%s\n", NUM_DIFFICULTIES, GAMEMAN->NotesTypeToString(st).c_str() ); - } - fprintf( fp, "\n" ); - - fprintf( fp, "" ); - for( j=0; j%s\n", Capitalize(DifficultyToString(d).Left(3)).c_str() ); - } - } - fprintf( fp, "\n" ); + bool WroteHeader = false; for( unsigned i=0; i Steps; + unsigned j; + for( j=0; j < aStepsTypes.size(); j++ ) + pSong->GetSteps( Steps, (StepsType) aStepsTypes[j], DIFFICULTY_INVALID, -1, -1, "", false ); + + /* Don't write anything for songs that have no steps at all for this + * game. Otherwise, we'll write pages and pages of empty fields for + * all of the less-used game types. */ + if( Steps.size() == 0 ) + continue; // skip + + /* We have some steps for this game. Make sure we've written the game header. */ + if( !WroteHeader ) + { + HTMLWritePerGameHeader( fp, game ); + WroteHeader = true; + } + + fprintf( fp, "\n" ); fprintf( fp, "", pSong->GetTranslitMainTitle().c_str() ); - for( unsigned j=0; jGetStepsByDifficulty( st, d, false ); - if( pSteps ) - fprintf( fp, "\n", pSteps->GetMeter() ); + if( CurSteps < Steps.size() && + Steps[CurSteps]->m_StepsType == aStepsTypes[j] && + Steps[CurSteps]->GetDifficulty() == k ) + { + fprintf( fp, "\n", Steps[CurSteps]->GetMeter() ); + ++CurSteps; + } else fprintf( fp, "\n" ); } } fprintf( fp, "" ); - } - fprintf( fp, "
title
 
%s%d%d 
\n
\n" ); + if( WroteHeader ) + fprintf( fp, "\n
\n" ); // footer } fprintf( fp, "\n" "\n" ); + + fclose( fp ); }