From 80aaa5fbb9834f3e46e820d88307e81115fb2c35 Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Wed, 14 Feb 2007 11:09:20 +0000 Subject: [PATCH] Working toward stateless loader. --- stepmania/src/NotesLoaderBMS.cpp | 137 ++++++++++++++++--------------- stepmania/src/NotesLoaderBMS.h | 10 +-- 2 files changed, 72 insertions(+), 75 deletions(-) diff --git a/stepmania/src/NotesLoaderBMS.cpp b/stepmania/src/NotesLoaderBMS.cpp index 517e805619..54aa589524 100644 --- a/stepmania/src/NotesLoaderBMS.cpp +++ b/stepmania/src/NotesLoaderBMS.cpp @@ -201,6 +201,44 @@ static StepsType DetermineStepsType( int iPlayer, const NoteData &nd, const RStr } } +static bool GetTagFromMap( const NameToData_t &mapNameToData, const RString &sName, RString &sOut ) +{ + NameToData_t::const_iterator it; + it = mapNameToData.find( sName ); + if( it == mapNameToData.end() ) + return false; + + sOut = it->second; + + return true; +} + +/* Finds the longest common match for the given tag in all files. If the given tag + * was found in at least one file, returns true; otherwise returns false. */ +static bool GetCommonTagFromMapList( const vector &aBMSData, const RString &sName, RString &sCommonTag ) +{ + bool bFoundOne = false; + for( unsigned i=0; i < aBMSData.size(); i++ ) + { + RString sTag; + if( !GetTagFromMap( aBMSData[i], sName, sTag ) ) + continue; + + if( !bFoundOne ) + { + bFoundOne = true; + sCommonTag = sTag; + } + else + { + sCommonTag = FindLargestInitialSubstring( sCommonTag, sTag ); + } + } + + return bFoundOne; +} + + float BMSLoader::GetBeatsPerMeasure( const MeasureToTimeSig_t &sigs, int iMeasure ) { map::const_iterator time_sig = sigs.find( iMeasure ); @@ -552,7 +590,7 @@ void BMSLoader::GetApplicableFiles( const RString &sPath, vector &out ) GetDirListing( sPath + RString("*.bme"), out ); } -bool BMSLoader::ReadBMSFile( const RString &sPath, NameToData_t &mapNameToData ) +static bool ReadBMSFile( const RString &sPath, NameToData_t &mapNameToData ) { RageFile file; if( !file.Open(sPath) ) @@ -586,43 +624,6 @@ bool BMSLoader::ReadBMSFile( const RString &sPath, NameToData_t &mapNameToData ) return true; } -bool BMSLoader::GetTagFromMap( const NameToData_t &mapNameToData, const RString &sName, RString &sOut ) -{ - NameToData_t::const_iterator it; - it = mapNameToData.find( sName ); - if( it == mapNameToData.end() ) - return false; - - sOut = it->second; - - return true; -} - -/* Finds the longest common match for the given tag in all files. If the given tag - * was found in at least one file, returns true; otherwise returns false. */ -bool BMSLoader::GetCommonTagFromMapList( const vector &aBMSData, const RString &sName, RString &sCommonTag ) -{ - bool bFoundOne = false; - for( unsigned i=0; i < aBMSData.size(); i++ ) - { - RString sTag; - if( !GetTagFromMap( aBMSData[i], sName, sTag ) ) - continue; - - if( !bFoundOne ) - { - bFoundOne = true; - sCommonTag = sTag; - } - else - { - sCommonTag = FindLargestInitialSubstring( sCommonTag, sTag ); - } - } - - return bFoundOne; -} - enum { BMS_TRACK_TIME_SIG = 2, @@ -920,6 +921,36 @@ void BMSLoader::SetTimeSigAdjustments( const MeasureToTimeSig_t &sigs, Song *pOu } } +static void SlideDuplicateDifficulties( Song &p ) +{ + /* BMS files have to guess the Difficulty from the meter; this is inaccurate, + * and often leads to duplicates. Slide duplicate difficulties upwards. We + * only do this with BMS files, since a very common bug was having *all* + * difficulties slid upwards due to (for example) having two beginner steps. + * We do a second pass in Song::TidyUpData to eliminate any remaining duplicates + * after this. */ + FOREACH_StepsType( st ) + { + FOREACH_Difficulty( dc ) + { + if( dc == DIFFICULTY_EDIT ) + continue; + + vector vSteps; + SongUtil::GetSteps( &p, vSteps, st, dc ); + + StepsUtil::SortNotesArrayByDifficulty( vSteps ); + for( unsigned k=1; kSetDifficulty( dc2 ); + } + } + } +} + bool BMSLoader::LoadFromDir( const RString &sDir, Song &out ) { LOG->Trace( "Song::LoadFromBMSDir(%s)", sDir.c_str() ); @@ -1056,36 +1087,6 @@ bool BMSLoader::LoadFromDir( const RString &sDir, Song &out ) } -void BMSLoader::SlideDuplicateDifficulties( Song &p ) -{ - /* BMS files have to guess the Difficulty from the meter; this is inaccurate, - * and often leads to duplicates. Slide duplicate difficulties upwards. We - * only do this with BMS files, since a very common bug was having *all* - * difficulties slid upwards due to (for example) having two beginner steps. - * We do a second pass in Song::TidyUpData to eliminate any remaining duplicates - * after this. */ - FOREACH_StepsType( st ) - { - FOREACH_Difficulty( dc ) - { - if( dc == DIFFICULTY_EDIT ) - continue; - - vector vSteps; - SongUtil::GetSteps( &p, vSteps, st, dc ); - - StepsUtil::SortNotesArrayByDifficulty( vSteps ); - for( unsigned k=1; kSetDifficulty( dc2 ); - } - } - } -} - /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/NotesLoaderBMS.h b/stepmania/src/NotesLoaderBMS.h index 1cb3b692c9..32a20f04a8 100644 --- a/stepmania/src/NotesLoaderBMS.h +++ b/stepmania/src/NotesLoaderBMS.h @@ -9,19 +9,15 @@ class Song; class Steps; +typedef multimap NameToData_t; +typedef map MeasureToTimeSig_t; + class BMSLoader: public NotesLoader { - void SlideDuplicateDifficulties( Song &p ); - - typedef multimap NameToData_t; - bool ReadBMSFile( const RString &sPath, BMSLoader::NameToData_t &mapNameToData ); bool LoadFromBMSFile( const RString &sPath, const NameToData_t &mapNameToData, Steps &out1 ); void ReadGlobalTags( const NameToData_t &mapNameToData, Song &out ); - static bool GetTagFromMap( const BMSLoader::NameToData_t &mapNameToData, const RString &sName, RString &sOut ); - static bool GetCommonTagFromMapList( const vector &aBMSData, const RString &sName, RString &out ); void SearchForDifficulty( RString sTag, Steps *pOut ); - typedef map MeasureToTimeSig_t; void ReadTimeSigs( const NameToData_t &mapNameToData, MeasureToTimeSig_t &out ); float GetBeatsPerMeasure( const MeasureToTimeSig_t &sigs, int iMeasure ); int GetMeasureStartRow( const MeasureToTimeSig_t &sigs, int iMeasureNo );