From 61ae8c3c1b600fe4073a3154c604154fcb66236f Mon Sep 17 00:00:00 2001 From: Steve Checkoway Date: Wed, 14 Feb 2007 12:26:36 +0000 Subject: [PATCH] NotesLoader is just a namespace. If you want to load a particular directory, there's no need to create a specialized loader, just call NotesLoader::LoadFromDir(). --- stepmania/src/NotesLoader.cpp | 31 +++++++++++++++++++++---------- stepmania/src/NotesLoader.h | 17 ++++------------- stepmania/src/NotesLoaderBMS.cpp | 4 ++-- stepmania/src/NotesLoaderBMS.h | 10 +++------- stepmania/src/NotesLoaderDWI.cpp | 5 +++-- stepmania/src/NotesLoaderDWI.h | 12 +++++------- stepmania/src/NotesLoaderKSF.h | 9 +++------ stepmania/src/NotesLoaderSM.h | 25 +++++++++++-------------- stepmania/src/Song.cpp | 27 ++++----------------------- 9 files changed, 56 insertions(+), 84 deletions(-) diff --git a/stepmania/src/NotesLoader.cpp b/stepmania/src/NotesLoader.cpp index fe4aebb32a..657d831087 100644 --- a/stepmania/src/NotesLoader.cpp +++ b/stepmania/src/NotesLoader.cpp @@ -22,18 +22,29 @@ void NotesLoader::GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, R sSubTitleOut = ""; }; -NotesLoader *NotesLoader::MakeLoader( const RString &sDir ) +bool NotesLoader::LoadFromDir( const RString &sPath, Song &out, set &BlacklistedImages ) { vector list; - -#define CHECK_LOADER(x) x::GetApplicableFiles( sDir, list ); if( list.size() ) return new x - CHECK_LOADER( SMLoader ); - CHECK_LOADER( DWILoader ); - CHECK_LOADER( BMSLoader ); - CHECK_LOADER( KSFLoader ); -#undef CHECK_LOADER - - return NULL; + + BlacklistedImages.clear(); + SMLoader::GetApplicableFiles( sPath, list ); + if( !list.empty() ) + { + if( !SMLoader::LoadFromDir(sPath, out) ) + return false; + SMLoader::TidyUpData( out, false ); + return true; + } + DWILoader::GetApplicableFiles( sPath, list ); + if( !list.empty() ) + return DWILoader::LoadFromDir( sPath, out, BlacklistedImages ); + BMSLoader::GetApplicableFiles( sPath, list ); + if( !list.empty() ) + return BMSLoader::LoadFromDir( sPath, out ); + KSFLoader::GetApplicableFiles( sPath, list ); + if( !list.empty() ) + return KSFLoader::LoadFromDir( sPath, out ); + return false; } diff --git a/stepmania/src/NotesLoader.h b/stepmania/src/NotesLoader.h index 02fd697773..7db95d1066 100644 --- a/stepmania/src/NotesLoader.h +++ b/stepmania/src/NotesLoader.h @@ -7,20 +7,11 @@ class Song; -class NotesLoader +namespace NotesLoader { -protected: - set BlacklistedImages; - -public: - virtual ~NotesLoader() { } - const set &GetBlacklistedImages() const { return BlacklistedImages; } - static void GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, RString &sMainTitleOut, RString &sSubTitleOut ); - virtual bool LoadFromDir( const RString &sPath, Song &out ) = 0; - virtual void TidyUpData( Song &song, bool cache ) { } - - static NotesLoader *MakeLoader( const RString& sDir ); -}; + void GetMainAndSubTitlesFromFullTitle( const RString &sFullTitle, RString &sMainTitleOut, RString &sSubTitleOut ); + bool LoadFromDir( const RString &sPath, Song &out, set &BlacklistedImages ); +} #endif diff --git a/stepmania/src/NotesLoaderBMS.cpp b/stepmania/src/NotesLoaderBMS.cpp index 0453351179..e7ce542d7f 100644 --- a/stepmania/src/NotesLoaderBMS.cpp +++ b/stepmania/src/NotesLoaderBMS.cpp @@ -11,7 +11,7 @@ #include "Steps.h" #include "RageUtil_CharConversions.h" #include "NoteTypes.h" - +#include "NotesLoader.h" typedef multimap NameToData_t; typedef map MeasureToTimeSig_t; @@ -1071,7 +1071,7 @@ bool BMSLoader::LoadFromDir( const RString &sDir, Song &out ) // Prevents clobbering and catches "MySong (7keys)" / "MySong (Another) (7keys)" // Also catches "MySong (7keys)" / "MySong (14keys)" if( commonSubstring != "" ) - GetMainAndSubTitlesFromFullTitle( commonSubstring, out.m_sMainTitle, out.m_sSubTitle ); + NotesLoader::GetMainAndSubTitlesFromFullTitle( commonSubstring, out.m_sMainTitle, out.m_sSubTitle ); // Now that we've parsed the keysound data, load the Steps from the rest // of the .bms files. diff --git a/stepmania/src/NotesLoaderBMS.h b/stepmania/src/NotesLoaderBMS.h index 2a72c1b21d..8890f2852d 100644 --- a/stepmania/src/NotesLoaderBMS.h +++ b/stepmania/src/NotesLoaderBMS.h @@ -3,17 +3,13 @@ #ifndef NOTES_LOADER_BMS_H #define NOTES_LOADER_BMS_H -#include "NotesLoader.h" -#include - class Song; -class BMSLoader: public NotesLoader +namespace BMSLoader { -public: - static void GetApplicableFiles( const RString &sPath, vector &out ); + void GetApplicableFiles( const RString &sPath, vector &out ); bool LoadFromDir( const RString &sDir, Song &out ); -}; +} #endif diff --git a/stepmania/src/NotesLoaderDWI.cpp b/stepmania/src/NotesLoaderDWI.cpp index 19b57c4132..51163449e3 100644 --- a/stepmania/src/NotesLoaderDWI.cpp +++ b/stepmania/src/NotesLoaderDWI.cpp @@ -7,9 +7,10 @@ #include "NoteData.h" #include "song.h" #include "Steps.h" +#include "GameInput.h" +#include "NotesLoader.h" #include -using namespace std; static std::map g_mapDanceNoteToNoteDataColumn; @@ -363,7 +364,7 @@ void DWILoader::GetApplicableFiles( const RString &sPath, vector &out ) GetDirListing( sPath + RString("*.dwi"), out ); } -bool DWILoader::LoadFromDir( const RString &sPath_, Song &out ) +bool DWILoader::LoadFromDir( const RString &sPath_, Song &out, set &BlacklistedImages ) { vector aFileNames; GetApplicableFiles( sPath_, aFileNames ); diff --git a/stepmania/src/NotesLoaderDWI.h b/stepmania/src/NotesLoaderDWI.h index 0cf2acf231..20cf29118b 100644 --- a/stepmania/src/NotesLoaderDWI.h +++ b/stepmania/src/NotesLoaderDWI.h @@ -3,17 +3,15 @@ #ifndef NOTES_LOADER_DWI_H #define NOTES_LOADER_DWI_H -#include "GameInput.h" -#include "NotesLoader.h" +#include class Song; -class DWILoader: public NotesLoader +namespace DWILoader { -public: - static void GetApplicableFiles( const RString &sPath, vector &out ); - bool LoadFromDir( const RString &sPath, Song &out ); -}; + void GetApplicableFiles( const RString &sPath, vector &out ); + bool LoadFromDir( const RString &sPath, Song &out, set &BlacklistedImages ); +} #endif diff --git a/stepmania/src/NotesLoaderKSF.h b/stepmania/src/NotesLoaderKSF.h index c6f935147e..fa71e9ba91 100644 --- a/stepmania/src/NotesLoaderKSF.h +++ b/stepmania/src/NotesLoaderKSF.h @@ -3,16 +3,13 @@ #ifndef NOTES_LOADER_KSF_H #define NOTES_LOADER_KSF_H -#include "NotesLoader.h" - class Song; -class KSFLoader: public NotesLoader +namespace KSFLoader { -public: - static void GetApplicableFiles( const RString &sPath, vector &out ); + void GetApplicableFiles( const RString &sPath, vector &out ); bool LoadFromDir( const RString &sDir, Song &out ); -}; +} #endif diff --git a/stepmania/src/NotesLoaderSM.h b/stepmania/src/NotesLoaderSM.h index fccec7fb48..93558681cd 100644 --- a/stepmania/src/NotesLoaderSM.h +++ b/stepmania/src/NotesLoaderSM.h @@ -3,7 +3,6 @@ #ifndef NotesLoaderSM_H #define NotesLoaderSM_H -#include "NotesLoader.h" #include "GameConstantsAndTypes.h" class MsdFile; @@ -11,21 +10,19 @@ class Song; class Steps; class TimingData; -class SMLoader: public NotesLoader +namespace SMLoader { -public: - SMLoader() {} - virtual bool LoadFromDir( const RString &sPath, Song &out ); - virtual void TidyUpData( Song &song, bool bFromCache ); + bool LoadFromDir( const RString &sPath, Song &out ); + void TidyUpData( Song &song, bool bFromCache ); - static bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); - static void GetApplicableFiles( const RString &sPath, vector &out ); - static bool LoadTimingFromFile( const RString &fn, TimingData &out ); - static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); - static bool LoadEditFromFile( RString sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); - static bool LoadEditFromBuffer( const RString &sBuffer, const RString &sEditFilePath, ProfileSlot slot ); - static bool LoadEditFromMsd( const MsdFile &msd, const RString &sEditFilePath, ProfileSlot slot, bool bAddStepsToSong ); -}; + bool LoadFromSMFile( const RString &sPath, Song &out, bool bFromCache = false ); + void GetApplicableFiles( const RString &sPath, vector &out ); + bool LoadTimingFromFile( const RString &fn, TimingData &out ); + void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); + 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 ); +} #endif diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index d4bf4dc524..df8d5e9eff 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -22,7 +22,7 @@ #include "Foreach.h" #include "BackgroundUtil.h" #include "SpecialFiles.h" - +#include "NotesLoader.h" #include "NotesLoaderSM.h" #include "NotesWriterDWI.h" #include "NotesWriterSM.h" @@ -208,8 +208,7 @@ bool Song::LoadFromSongDir( RString sDir ) { // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); SMLoader::LoadFromSMFile( GetCacheFilePath(), *this, true ); - // XXX: This shouldn't really be a non-static member function. - SMLoader().TidyUpData( *this, true ); + SMLoader::TidyUpData( *this, true ); } else { @@ -218,24 +217,7 @@ bool Song::LoadFromSongDir( RString sDir ) // Let's load it from a file, then write a cache entry. // - NotesLoader *ld = NotesLoader::MakeLoader( sDir ); - if( ld ) - { - bool success = ld->LoadFromDir( sDir, *this ); - BlacklistedImages = ld->GetBlacklistedImages(); - - if(!success) - { - delete ld; - return false; - } - - TidyUpData(); - ld->TidyUpData( *this, false ); - - delete ld; - } - else + if( !NotesLoader::LoadFromDir(sDir, *this, BlacklistedImages) ) { LOG->UserLog( "Song", sDir, "has no SM, DWI, BMS, or KSF files." ); @@ -251,9 +233,8 @@ bool Song::LoadFromSongDir( RString sDir ) } // Continue on with a blank Song so that people can make adjustments using the editor. - TidyUpData(); } - + TidyUpData(); // save a cache file so we don't have to parse it all over again next time SaveToCacheFile(); }