Greatly decrease time to write catalog.xml by pulling THEME->GetMetricB out of the inner loop and passing it along to RadarValues. (Also don't copy the vector of Song*.) The time to generate the XNode for Songs was cut down by a fifth (from 2.5 seconds to .5 seconds for me, fully optimized).

This commit is contained in:
Steve Checkoway
2007-02-04 09:35:02 +00:00
parent e17ccc6bdb
commit 169d7c8b44
4 changed files with 33 additions and 26 deletions
+26 -18
View File
@@ -22,6 +22,7 @@
#include "UnlockManager.h"
#include "arch/LoadingWindow/LoadingWindow.h"
#include "LocalizedString.h"
#include "RageTimer.h"
#define SHOW_PLAY_MODE(pm) THEME->GetMetricB("CatalogXml",ssprintf("ShowPlayMode%s",PlayModeToString(pm).c_str()))
#define SHOW_STYLE(ps) THEME->GetMetricB("CatalogXml",ssprintf("ShowStyle%s",Capitalize((ps)->m_szName).c_str()))
@@ -49,11 +50,17 @@ void CatalogXml::Save( LoadingWindow *loading_window )
RString fn = CATALOG_XML_FILE;
LOG->Trace( "Writing %s ...", fn.c_str() );
RageTimer timer;
float f;
#define TIME(x) {f = timer.Ago(); LOG->Trace( "Writing " #x " took %f seconds.", f ); timer.Touch();}
XNode xml( "Catalog" );
const vector<StepsType> &vStepsTypesToShow = CommonMetrics::STEPS_TYPES_TO_SHOW.GetValue();
const vector<Difficulty> &vDifficultiesToShow = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue();
const vector<CourseDifficulty> &vCourseDifficultiesToShow = CommonMetrics::COURSE_DIFFICULTIES_TO_SHOW.GetValue();
const bool bWriteSimpleValues = THEME->GetMetricB( "RadarValues", "WriteSimpleValues" );
const bool bWriteComplexValues = THEME->GetMetricB( "RadarValues", "WriteComplexValues" );
{
XNode* pNode = xml.AppendChild( "Totals" );
XNode* pNumSongsByGroup = pNode->AppendChild( "NumSongsByGroup" );
@@ -97,7 +104,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
continue; // skip: Locked song.
iTotalSongs++;
iNumSongsInGroup++;
FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), dc )
FOREACH_CONST( Difficulty, vDifficultiesToShow, dc )
{
Steps* pSteps = SongUtil::GetStepsByDifficulty( pSong, *st, *dc, false ); // no autogen
@@ -158,14 +165,15 @@ void CatalogXml::Save( LoadingWindow *loading_window )
pNode->AppendChild( "NumUnlockedSteps", iNumUnlockedSteps );
pNode->AppendChild( "NumUnlockedCourses", iNumUnlockedCourses );
}
TIME(Totals)
{
XNode* pNode = xml.AppendChild( "Songs" );
vector<Song*> vpSongs = SONGMAN->GetAllSongs();
const vector<Song*>& vpSongs = SONGMAN->GetAllSongs();
for( unsigned i=0; i<vpSongs.size(); i++ )
{
Song* pSong = vpSongs[i];
const Song* pSong = vpSongs[i];
/*
* Not all songs should be stored in Catalog.xml. Tutorial songs
@@ -191,7 +199,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
FOREACH_CONST( StepsType, vStepsTypesToShow, st )
{
FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), dc )
FOREACH_CONST( Difficulty, vDifficultiesToShow, dc )
{
Steps* pSteps = SongUtil::GetStepsByDifficulty( pSong, *st, *dc, false ); // no autogen
if( pSteps == NULL )
@@ -206,12 +214,12 @@ void CatalogXml::Save( LoadingWindow *loading_window )
pSongNode->AppendChild( pStepsIDNode );
pStepsIDNode->AppendChild( "Meter", pSteps->GetMeter() );
pStepsIDNode->AppendChild( pSteps->GetRadarValues(PLAYER_1).CreateNode() );
pStepsIDNode->AppendChild( pSteps->GetRadarValues(PLAYER_1).CreateNode(bWriteSimpleValues, bWriteComplexValues) );
}
}
}
}
TIME(Songs)
{
XNode* pNode = xml.AppendChild( "Courses" );
@@ -240,11 +248,10 @@ void CatalogXml::Save( LoadingWindow *loading_window )
pCourseNode->AppendChild( "SubTitle", pCourse->GetDisplaySubTitle() );
pCourseNode->AppendChild( "HasMods", pCourse->HasMods() );
const vector<CourseDifficulty> &vDiffs = CommonMetrics::COURSE_DIFFICULTIES_TO_SHOW.GetValue();
FOREACH_CONST( StepsType, vStepsTypesToShow, st )
{
FOREACH_CONST( CourseDifficulty, vDiffs, dc )
FOREACH_CONST( CourseDifficulty, vCourseDifficultiesToShow, dc )
{
Trail *pTrail = pCourse->GetTrail( *st, *dc );
if( pTrail == NULL )
@@ -259,18 +266,18 @@ void CatalogXml::Save( LoadingWindow *loading_window )
pCourseNode->AppendChild( pTrailIDNode );
pTrailIDNode->AppendChild( "Meter", pTrail->GetMeter() );
pTrailIDNode->AppendChild( pTrail->GetRadarValues().CreateNode() );
pTrailIDNode->AppendChild( pTrail->GetRadarValues().CreateNode(bWriteSimpleValues, bWriteComplexValues) );
}
}
}
}
TIME(Courses)
{
XNode* pNode = xml.AppendChild( "Types" );
{
XNode* pNode2 = pNode->AppendChild( "Difficulty" );
FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), iter )
FOREACH_CONST( Difficulty, vDifficultiesToShow, iter )
{
XNode* pNode3 = pNode2->AppendChild( "Difficulty", DifficultyToString(*iter) );
pNode3->AppendAttr( "DisplayAs", DifficultyToLocalizedString(*iter) );
@@ -279,7 +286,7 @@ void CatalogXml::Save( LoadingWindow *loading_window )
{
XNode* pNode2 = pNode->AppendChild( "CourseDifficulty" );
FOREACH_CONST( CourseDifficulty, CommonMetrics::COURSE_DIFFICULTIES_TO_SHOW.GetValue(), iter )
FOREACH_CONST( CourseDifficulty, vCourseDifficultiesToShow, iter )
{
XNode* pNode3 = pNode2->AppendChild( "CourseDifficulty", DifficultyToString(*iter) );
pNode3->AppendAttr( "DisplayAs", CourseDifficultyToLocalizedString(*iter) );
@@ -384,16 +391,17 @@ void CatalogXml::Save( LoadingWindow *loading_window )
}
}
}
TIME(Types)
xml.AppendChild( "InternetRankingHomeUrl", INTERNET_RANKING_HOME_URL );
xml.AppendChild( "InternetRankingUploadUrl", INTERNET_RANKING_UPLOAD_URL );
xml.AppendChild( "InternetRankingViewGuidUrl", INTERNET_RANKING_VIEW_GUID_URL );
xml.AppendChild( "ProductTitle", PRODUCT_TITLE );
xml.AppendChild( "FooterText", FOOTER_TEXT );
xml.AppendChild( "FooterLink", FOOTER_LINK );
TIME(Misc)
XmlFileUtil::SaveToFile( &xml, fn, CATALOG_XSL, false );
TIME(to disk)
#undef TIME
LOG->Trace( "Done." );
}
+3 -1
View File
@@ -80,6 +80,8 @@ HighScoreImpl::HighScoreImpl()
XNode *HighScoreImpl::CreateNode() const
{
XNode *pNode = new XNode( "HighScore" );
const bool bWriteSimpleValues = THEME->GetMetricB( "RadarValues", "WriteSimpleValues" );
const bool bWriteComplexValues = THEME->GetMetricB( "RadarValues", "WriteComplexValues" );
// TRICKY: Don't write "name to fill in" markers.
pNode->AppendChild( "Name", IsRankingToFillIn(sName) ? RString("") : sName );
@@ -100,7 +102,7 @@ XNode *HighScoreImpl::CreateNode() const
FOREACH_HoldNoteScore( hns )
if( hns != HNS_None ) // HACK: don't save meaningless "none" count
pHoldNoteScores->AppendChild( HoldNoteScoreToString(hns), iHoldNoteScores[hns] );
pNode->AppendChild( radarValues.CreateNode() );
pNode->AppendChild( radarValues.CreateNode(bWriteSimpleValues, bWriteComplexValues) );
pNode->AppendChild( "LifeRemainingSeconds", fLifeRemainingSeconds );
return pNode;
+3 -6
View File
@@ -5,9 +5,6 @@
#include "XmlFile.h"
#include "ThemeManager.h"
#define WRITE_COMPLEX_VALUES THEME->GetMetricB("RadarValues","WriteComplexValues")
#define WRITE_SIMPLE_VALUES THEME->GetMetricB("RadarValues","WriteSimpleValues")
RadarValues::RadarValues()
{
MakeUnknown();
@@ -25,7 +22,7 @@ void RadarValues::Zero()
m_Values.f[rc] = 0;
}
XNode* RadarValues::CreateNode() const
XNode* RadarValues::CreateNode( bool bIncludeSimpleValues, bool bIncludeComplexValues ) const
{
XNode* pNode = new XNode( "RadarValues" );
@@ -34,12 +31,12 @@ XNode* RadarValues::CreateNode() const
{
if( rc >= RadarCategory_TapsAndHolds )
{
if( WRITE_SIMPLE_VALUES )
if( bIncludeSimpleValues )
pNode->AppendChild( RadarCategoryToString(rc), (int)m_Values.f[rc] );
}
else
{
if( WRITE_COMPLEX_VALUES )
if( bIncludeComplexValues )
pNode->AppendChild( RadarCategoryToString(rc), m_Values.f[rc] );
}
}
+1 -1
View File
@@ -59,7 +59,7 @@ struct RadarValues
return !operator==( other );
}
XNode* CreateNode() const;
XNode* CreateNode( bool bIncludeSimpleValues, bool bIncludeComplexValues ) const;
void LoadFromNode( const XNode* pNode );
RString ToString( int iMaxValues = -1 ) const; // default = all