From 66b17e5ef2df76d26256e3835151cee5a487b3f6 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Mon, 13 Sep 2004 08:00:34 +0000 Subject: [PATCH] fix legacy songs not showing background at end, but still allow new songs to not have it --- stepmania/src/NotesLoader.h | 1 + stepmania/src/NotesLoaderSM.cpp | 43 +++++++++++++++++++++++++++++++++ stepmania/src/NotesLoaderSM.h | 1 + stepmania/src/NotesWriterSM.cpp | 10 +++++--- stepmania/src/Song.cpp | 8 +++++- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/stepmania/src/NotesLoader.h b/stepmania/src/NotesLoader.h index 7fc9c2a5f6..16572d33c8 100644 --- a/stepmania/src/NotesLoader.h +++ b/stepmania/src/NotesLoader.h @@ -18,6 +18,7 @@ public: const set &GetBlacklistedImages() const { return BlacklistedImages; } static void GetMainAndSubTitlesFromFullTitle( const CString sFullTitle, CString &sMainTitleOut, CString &sSubTitleOut ); virtual bool LoadFromDir( CString sPath, Song &out ) = 0; + virtual void TidyUpData( Song &song, bool cache ) { } bool Loadable( CString sPath ); }; diff --git a/stepmania/src/NotesLoaderSM.cpp b/stepmania/src/NotesLoaderSM.cpp index 20c1473276..e40133b159 100644 --- a/stepmania/src/NotesLoaderSM.cpp +++ b/stepmania/src/NotesLoaderSM.cpp @@ -470,6 +470,49 @@ bool SMLoader::LoadEdit( CString sEditFilePath, ProfileSlot slot ) } +void SMLoader::TidyUpData( Song &song, bool cache ) +{ + /* + * Hack: if the song has any changes at all (so it won't use a random BGA) + * and doesn't end with "-nosongbg-", add a song background BGC. Remove + * "-nosongbg-" if it exists. + * + * This way, songs that were created earlier, when we added the song BG + * at the end by default, will still behave as expected; all new songs will + * have to add an explicit song BG tag if they want it. This is really a + * formatting hack only; nothing outside of SMLoader ever sees "-nosongbg-". + */ + vector &bg = song.m_BackgroundChanges; + if( !bg.empty() ) + { + /* BGChanges have been sorted. On the odd chance that a BGChange exists + * with a very high beat, search the whole list. */ + bool bHasNoSongBgTag = false; + + for( unsigned i = 0; !bHasNoSongBgTag && i < bg.size(); ++i ) + { + if( !bg[i].m_sBGName.CompareNoCase("-nosongbg-") ) + { + bg.erase( bg.begin()+i ); + bHasNoSongBgTag = true; + } + } + + /* + * If we're loading cache, -nosongbg- should always be in there. We must + * not call IsAFile(song.GetBackgroundPath()) when loading cache. + * + * If BGChanges already exist after the last beat, don't add the background + * in the middle. + */ + if( !cache && + bg.back().m_fStartBeat-0.0001f < song.m_fLastBeat && + !bHasNoSongBgTag && + IsAFile( song.GetBackgroundPath() ) ) + bg.push_back( BackgroundChange(song.m_fLastBeat,song.m_sBackgroundFile) ); + } +} + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/NotesLoaderSM.h b/stepmania/src/NotesLoaderSM.h index c3df452fcd..8242a721cf 100644 --- a/stepmania/src/NotesLoaderSM.h +++ b/stepmania/src/NotesLoaderSM.h @@ -34,6 +34,7 @@ public: void GetApplicableFiles( CString sPath, CStringArray &out ); bool LoadFromDir( CString sPath, Song &out ); + void TidyUpData( Song &song, bool cache ); static bool LoadTimingFromFile( const CString &fn, TimingData &out ); static void LoadTimingFromSMFile( const MsdFile &msd, TimingData &out ); static bool LoadEdit( CString sEditFilePath, ProfileSlot slot ); diff --git a/stepmania/src/NotesWriterSM.cpp b/stepmania/src/NotesWriterSM.cpp index b5be5d6d78..e83e3a457d 100644 --- a/stepmania/src/NotesWriterSM.cpp +++ b/stepmania/src/NotesWriterSM.cpp @@ -85,10 +85,14 @@ void NotesWriterSM::WriteGlobalTags( RageFile &f, const Song &out ) { const BackgroundChange &seg = out.m_BackgroundChanges[i]; - f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) ); - if( i != out.m_BackgroundChanges.size()-1 ) - f.Write( "," ); + f.PutLine( ssprintf( "%.3f=%s=%.3f=%d=%d=%d,", seg.m_fStartBeat, seg.m_sBGName.c_str(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop ) ); } + /* If there's an animation plan at all, add a dummy "-nosongbg-" tag to indicate that + * this file doesn't want a song BG entry added at the end. See SMLoader::TidyUpData. + * This tag will be removed on load. Add it at a very high beat, so it won't cause + * problems if loaded in older versions. */ + if( !out.m_BackgroundChanges.empty() ) + f.PutLine( "99999=-nosongbg-=1.000=0=0=0 // don't automatically add -songbackground-" ); f.PutLine( ";" ); if( out.m_ForegroundChanges.size() ) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 300532d144..4586f2be99 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -229,6 +229,7 @@ bool Song::LoadFromSongDir( CString sDir ) // LOG->Trace( "Loading '%s' from cache file '%s'.", m_sSongDir.c_str(), GetCacheFilePath().c_str() ); SMLoader ld; ld.LoadFromSMFile( GetCacheFilePath(), *this, true ); + ld.TidyUpData( *this, true ); } else { @@ -246,12 +247,17 @@ bool Song::LoadFromSongDir( CString sDir ) bool success = ld->LoadFromDir( sDir, *this ); BlacklistedImages = ld->GetBlacklistedImages(); - delete ld; if(!success) + { + delete ld; return false; + } TidyUpData(); + ld->TidyUpData( *this, false ); + + delete ld; // save a cache file so we don't have to parse it all over again next time SaveToCacheFile();