From b6bf776716064bd96166e65dd2ebb1663d5aeddd Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Thu, 9 Jun 2011 13:46:30 -0400 Subject: [PATCH] New branch: [notesloader] Time to better unify our files and refactor properly. --- src/GameSoundManager.cpp | 10 ++++++---- src/NotesLoader.cpp | 17 ++++++++++------- src/NotesLoaderSM.h | 8 +++++--- src/NotesLoaderSMA.h | 3 ++- src/NotesLoaderSSC.cpp | 13 +------------ src/NotesLoaderSSC.h | 6 ++++-- src/ScreenGameplaySyncMachine.cpp | 6 ++++-- src/ScreenHowToPlay.cpp | 6 ++++-- src/ScreenServiceAction.cpp | 3 ++- src/Song.cpp | 8 +++++--- src/SongManager.cpp | 9 ++++++--- src/Steps.cpp | 6 ++++-- 12 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/GameSoundManager.cpp b/src/GameSoundManager.cpp index a9e71fce24..8b878c50ef 100644 --- a/src/GameSoundManager.cpp +++ b/src/GameSoundManager.cpp @@ -142,8 +142,10 @@ static void StartMusic( MusicToPlay &ToPlay ) { LOG->Trace( "Found '%s'", ToPlay.m_sTimingFile.c_str() ); Song song; - if( GetExtension(ToPlay.m_sTimingFile) == ".ssc" && - SSCLoader::LoadFromSSCFile(ToPlay.m_sTimingFile, song) ) + SSCLoader loaderSSC; + SMLoader loaderSM; + if(GetExtension(ToPlay.m_sTimingFile) == ".ssc" && + loaderSSC.LoadFromSSCFile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; @@ -152,8 +154,8 @@ static void StartMusic( MusicToPlay &ToPlay ) if( pStepsCabinetLights ) pStepsCabinetLights->GetNoteData( ToPlay.m_LightsData ); } - else if( GetExtension(ToPlay.m_sTimingFile) == ".sm" && - SMLoader::LoadFromSMFile(ToPlay.m_sTimingFile, song) ) + else if(GetExtension(ToPlay.m_sTimingFile) == ".sm" && + loaderSM.LoadFromSMFile(ToPlay.m_sTimingFile, song) ) { ToPlay.HasTiming = true; ToPlay.m_TimingData = song.m_SongTiming; diff --git a/src/NotesLoader.cpp b/src/NotesLoader.cpp index 88f68787aa..983f35cedb 100644 --- a/src/NotesLoader.cpp +++ b/src/NotesLoader.cpp @@ -32,20 +32,23 @@ bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set &Bl vector list; BlacklistedImages.clear(); - SSCLoader::GetApplicableFiles( sPath, list ); + SSCLoader loaderSSC; + loaderSSC.GetApplicableFiles( sPath, list ); if( !list.empty() ) { - if( !SSCLoader::LoadFromDir( sPath, out ) ) + if( !loaderSSC.LoadFromDir( sPath, out ) ) return false; - SSCLoader::TidyUpData( out, false ); + loaderSSC.TidyUpData( out, false ); return true; } - SMALoader::GetApplicableFiles( sPath, list ); + SMALoader loaderSMA; + loaderSMA.GetApplicableFiles( sPath, list ); if (!list.empty() ) - return SMALoader::LoadFromDir( sPath, out ); - SMLoader::GetApplicableFiles( sPath, list ); + return loaderSMA.LoadFromDir( sPath, out ); + SMLoader loaderSM; + loaderSM.GetApplicableFiles( sPath, list ); if (!list.empty() ) - return SMLoader::LoadFromDir( sPath, out ); + return loaderSM.LoadFromDir( sPath, out ); DWILoader::GetApplicableFiles( sPath, list ); if( !list.empty() ) return DWILoader::LoadFromDir( sPath, out, BlacklistedImages ); diff --git a/src/NotesLoaderSM.h b/src/NotesLoaderSM.h index 94dfdd2dfe..0d947ea28a 100644 --- a/src/NotesLoaderSM.h +++ b/src/NotesLoaderSM.h @@ -16,8 +16,9 @@ class TimingData; const float FAST_BPM_WARP = 9999999.f; /** @brief Reads a Song from an .SM file. */ -namespace SMLoader +struct SMLoader { + virtual ~SMLoader() {} void LoadFromSMTokens( RString sStepsType, RString sDescription, RString sDifficulty, RString sMeter, RString sRadarValues, RString sNoteData, Steps &out ); @@ -29,7 +30,8 @@ namespace SMLoader bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - bool LoadFromBGChangesString( BackgroundChange &change, const RString &sBGChangeExpression ); + virtual bool LoadFromBGChangesString(BackgroundChange &change, + const RString &sBGChangeExpression ); bool ProcessBPMs( TimingData &, const RString ); @@ -41,7 +43,7 @@ namespace SMLoader const RString &sPath, const RString &sParam ); void ProcessAttacks( Song &out, MsdFile::value_t sParams ); void ProcessInstrumentTracks( Song &out, const RString &sParam ); -} +}; #endif diff --git a/src/NotesLoaderSMA.h b/src/NotesLoaderSMA.h index c9e3dfa811..fec87e8fce 100644 --- a/src/NotesLoaderSMA.h +++ b/src/NotesLoaderSMA.h @@ -2,6 +2,7 @@ #define NOTES_LOADER_SMA_H #include "GameConstantsAndTypes.h" +#include "NotesLoaderSM.h" #include "BackgroundUtil.h" class MsdFile; @@ -20,7 +21,7 @@ enum SMALoadingStates }; /** @brief Reads a Song from a .SMA file. */ -namespace SMALoader +struct SMALoader : public SMLoader { void LoadFromSMATokens( RString sStepsType, RString sDescription, diff --git a/src/NotesLoaderSSC.cpp b/src/NotesLoaderSSC.cpp index 04a4fdc167..b9180850ae 100644 --- a/src/NotesLoaderSSC.cpp +++ b/src/NotesLoaderSSC.cpp @@ -19,17 +19,6 @@ */ const int MAX_EDIT_STEPS_SIZE_BYTES = 60*1024; // 60 KB -/** - * @brief Attempt to load any background changes in use by this song. - * @param change a reference to the background change. - * @param sBGChangeExpression a reference to the list of changes to be made. - * @return its success or failure. - */ -bool LoadFromBGSSCChangesString( BackgroundChange &change, const RString &sBGChangeExpression ) -{ - return SMLoader::LoadFromBGChangesString( change, sBGChangeExpression ); -} - bool SSCLoader::LoadFromDir( const RString &sPath, Song &out ) { vector aFileNames; @@ -421,7 +410,7 @@ bool SSCLoader::LoadFromSSCFile( const RString &sPath, Song &out, bool bFromCach for( unsigned b=0; bGetPathO("ScreenGameplaySyncMachine","music"); // Allow themers to use either a .ssc or .sm file for this. -aj + SSCLoader loaderSSC; + SMLoader loaderSM; if(sFile.Right(4) == ".ssc") - SSCLoader::LoadFromSSCFile( sFile, m_Song ); + loaderSSC.LoadFromSSCFile( sFile, m_Song ); else - SMLoader::LoadFromSMFile( sFile, m_Song ); + loaderSM.LoadFromSMFile( sFile, m_Song ); m_Song.SetSongDir( Dirname(sFile) ); m_Song.TidyUpData(); diff --git a/src/ScreenHowToPlay.cpp b/src/ScreenHowToPlay.cpp index b38848bb7d..64ce65815c 100644 --- a/src/ScreenHowToPlay.cpp +++ b/src/ScreenHowToPlay.cpp @@ -135,10 +135,12 @@ void ScreenHowToPlay::Init() // Allow themers to use either a .ssc or .sm file for this. -aj RString sStepsPath = THEME->GetPathO(m_sName, "steps"); + SSCLoader loaderSSC; + SMLoader loaderSM; if( sStepsPath.Right(4) == ".ssc" ) - SSCLoader::LoadFromSSCFile( sStepsPath, m_Song, false ); + loaderSSC.LoadFromSSCFile( sStepsPath, m_Song, false ); else - SMLoader::LoadFromSMFile( sStepsPath, m_Song, false ); + loaderSM.LoadFromSMFile( sStepsPath, m_Song, false ); m_Song.AddAutoGenNotes(); const Style* pStyle = GAMESTATE->GetCurrentStyle(); diff --git a/src/ScreenServiceAction.cpp b/src/ScreenServiceAction.cpp index 13e1222260..c28086a72c 100644 --- a/src/ScreenServiceAction.cpp +++ b/src/ScreenServiceAction.cpp @@ -197,7 +197,8 @@ static void CopyEdits( const RString &sFromProfileDir, const RString &sToProfile iNumErrored++; // Test whether the song we need for this edit is present and ignore this edit if not present. - if( !SSCLoader::LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) ) + SSCLoader loaderSSC; + if( !loaderSSC.LoadEditFromFile( sFromDir+*i, ProfileSlot_Machine, false ) ) { iNumIgnored++; continue; diff --git a/src/Song.cpp b/src/Song.cpp index e6196ac12e..d547a02e47 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -235,12 +235,14 @@ bool Song::LoadFromSongDir( RString sDir ) if( bUseCache ) { // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); - bool bLoadedFromSSC = SSCLoader::LoadFromSSCFile( sCacheFilePath, *this, true ); + SSCLoader loaderSSC; + bool bLoadedFromSSC = loaderSSC.LoadFromSSCFile( sCacheFilePath, *this, true ); if( !bLoadedFromSSC ) { // load from .sm - SMLoader::LoadFromSMFile( sCacheFilePath, *this, true ); - SMLoader::TidyUpData( *this, true ); + SMLoader loaderSM; + loaderSM.LoadFromSMFile( sCacheFilePath, *this, true ); + loaderSM.TidyUpData( *this, true ); } } else diff --git a/src/SongManager.cpp b/src/SongManager.cpp index 48a7d3c5eb..e25374c739 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -1655,12 +1655,15 @@ void SongManager::LoadStepEditsFromProfileDir( const RString &sProfileDir, Profi for( int i=0; iWarn( "Couldn't load \"%s\"", m_sFilename.c_str() ); return;