diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index 638ac7f68d..3f8ef526ca 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -23,6 +23,7 @@ #include "XmlFile.h" #include "BackgroundUtil.h" #include "song.h" +#include "RageFileDriverMemory.h" ThemeMetric LEFT_EDGE ("Background","LeftEdge"); ThemeMetric TOP_EDGE ("Background","TopEdge"); @@ -250,9 +251,7 @@ void BackgroundImpl::Unload() void BackgroundImpl::Layer::Unload() { - for( map::iterator iter = m_BGAnimations.begin(); - iter != m_BGAnimations.end(); - iter++ ) + FOREACHM( BackgroundDef, Actor*, m_BGAnimations, iter ) delete iter->second; m_BGAnimations.clear(); m_aBGChanges.clear(); @@ -766,7 +765,16 @@ void BackgroundImpl::Layer::UpdateCurBGChange( const Song *pSong, float fLastMus m_pFadingBGA = m_pCurrentBGA; map::const_iterator iter = m_BGAnimations.find( change.m_def ); - ASSERT( iter != m_BGAnimations.end() ); + if( iter == m_BGAnimations.end() ) + { + XNode *pNode = change.m_def.CreateNode(); + RageFileObjMem f; + pNode->GetXML( f, NULL ); + LOG->Warn( "Tried to switch to a background that was never loaded\n" + f.GetString() ); + SAFE_DELETE( pNode ); + return; + } + m_pCurrentBGA = iter->second; if( m_pFadingBGA == m_pCurrentBGA ) diff --git a/stepmania/src/BackgroundUtil.cpp b/stepmania/src/BackgroundUtil.cpp index 31f741314d..8dc832b108 100644 --- a/stepmania/src/BackgroundUtil.cpp +++ b/stepmania/src/BackgroundUtil.cpp @@ -7,6 +7,48 @@ #include "RageLog.h" #include + +bool BackgroundDef::operator<( const BackgroundDef &other ) const +{ +#define COMPARE(x) if( x < other.x ) return true; else if( x > other.x ) return false; + COMPARE( m_sEffect ); + COMPARE( m_sFile1 ); + COMPARE( m_sFile2 ); + COMPARE( m_sColor1 ); + COMPARE( m_sColor2 ); +#undef COMPARE + return false; +} + +bool BackgroundDef::operator==( const BackgroundDef &other ) const +{ + return + m_sEffect == other.m_sEffect && + m_sFile1 == other.m_sFile1 && + m_sFile2 == other.m_sFile2 && + m_sColor1 == other.m_sColor1 && + m_sColor2 == other.m_sColor2; +} + +XNode *BackgroundDef::CreateNode() const +{ + XNode* pNode = new XNode; + pNode->m_sName = "BackgroundDef"; + + if( !m_sEffect.empty() ) + pNode->AppendAttr( "Effect", m_sEffect ); + if( !m_sFile1.empty() ) + pNode->AppendAttr( "File1", m_sFile1 ); + if( !m_sFile2.empty() ) + pNode->AppendAttr( "File2", m_sFile2 ); + if( !m_sColor1.empty() ) + pNode->AppendAttr( "Color1", m_sColor1 ); + if( !m_sColor2.empty() ) + pNode->AppendAttr( "Color2", m_sColor2 ); + + return pNode; +} + const CString BACKGROUND_EFFECTS_DIR = "BackgroundEffects/"; const CString BACKGROUND_TRANSITIONS_DIR = "BackgroundTransitions/"; const CString BG_ANIMS_DIR = "BGAnimations/"; diff --git a/stepmania/src/BackgroundUtil.h b/stepmania/src/BackgroundUtil.h index 2884d3911d..10624a1ed2 100644 --- a/stepmania/src/BackgroundUtil.h +++ b/stepmania/src/BackgroundUtil.h @@ -4,6 +4,7 @@ #define BackgroundUtil_H class Song; +struct XNode; extern const CString RANDOM_BACKGROUND_FILE; extern const CString NO_SONG_BG_FILE; @@ -18,35 +19,16 @@ extern const CString SBT_CrossFade; struct BackgroundDef { - BackgroundDef() - { - } - bool operator<( const BackgroundDef &other ) const - { -#define COMPARE(x) if( x < other.x ) return true; else if( x > other.x ) return false; - COMPARE( m_sEffect ); - COMPARE( m_sFile1 ); - COMPARE( m_sFile2 ); - COMPARE( m_sColor1 ); - COMPARE( m_sColor2 ); -#undef COMPARE - return false; - } - bool operator==( const BackgroundDef &other ) const - { - return - m_sEffect == other.m_sEffect && - m_sFile1 == other.m_sFile1 && - m_sFile2 == other.m_sFile2 && - m_sColor1 == other.m_sColor1 && - m_sColor2 == other.m_sColor2; - } - bool IsEmpty() { return m_sFile1.empty() && m_sFile2.empty(); } + bool operator<( const BackgroundDef &other ) const; + bool operator==( const BackgroundDef &other ) const; + bool IsEmpty() const { return m_sFile1.empty() && m_sFile2.empty(); } CString m_sEffect; // "" == automatically choose CString m_sFile1; // must not be "" CString m_sFile2; // may be "" CString m_sColor1; // "" == use default CString m_sColor2; // "" == use default + + XNode *CreateNode() const; }; struct BackgroundChange diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index 24da169905..5443ade327 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -515,7 +515,7 @@ char* XNode::Load( const char* pszXml, PARSEINFO *pi /*= &piDefault*/ ) //======================================================== bool XAttr::GetXML( RageFileBasic &f, DISP_OPT *opt ) const { - return f.Write(m_sName + "='" + (opt->reference_value&&opt->entitys?opt->entitys->Entity2Ref(m_sValue):m_sValue) + "' ") != -1; + return f.Write(m_sName + "='" + (opt && opt->reference_value && opt->entitys ? opt->entitys->Entity2Ref(m_sValue) : m_sValue) + "' ") != -1; } //========================================================