From afaa382b8499c5a4c544f16cadf73d93f19ca797 Mon Sep 17 00:00:00 2001 From: "Devin J. Pohly" Date: Sun, 20 Jan 2013 19:23:28 -0500 Subject: [PATCH] Steps: set Song pointer to associated song when constructing --- src/JsonUtil.h | 14 ++++++++++++++ src/NotesLoaderJson.cpp | 2 +- src/NotesLoaderSMA.cpp | 2 +- src/Song.cpp | 6 +++--- src/Steps.cpp | 3 ++- src/Steps.h | 2 +- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/JsonUtil.h b/src/JsonUtil.h index 22c33ae4ec..3cb1bdf673 100644 --- a/src/JsonUtil.h +++ b/src/JsonUtil.h @@ -181,6 +181,20 @@ namespace JsonUtil } } + /* For classes with one-parameter constructors, such as Steps */ + template + static void DeserializeVectorPointersParam(vector &v, void fn(T &, const Json::Value &), const Json::Value &root, const P param) + { + for(unsigned i=0; i static void DeserializeArrayValues(vector &v, const Json::Value &root) { diff --git a/src/NotesLoaderJson.cpp b/src/NotesLoaderJson.cpp index 1195ea413f..b09d564454 100644 --- a/src/NotesLoaderJson.cpp +++ b/src/NotesLoaderJson.cpp @@ -218,7 +218,7 @@ static void Deserialize( Song &out, const Json::Value &root ) { vector vpSteps; - JsonUtil::DeserializeVectorPointers( vpSteps, Deserialize, root["Charts"] ); + JsonUtil::DeserializeVectorPointersParam( vpSteps, Deserialize, root["Charts"], &out ); FOREACH( Steps*, vpSteps, iter ) out.AddSteps( *iter ); } diff --git a/src/NotesLoaderSMA.cpp b/src/NotesLoaderSMA.cpp index bb1bf09c46..43d5d08b50 100644 --- a/src/NotesLoaderSMA.cpp +++ b/src/NotesLoaderSMA.cpp @@ -301,7 +301,7 @@ bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach else { state = SMA_GETTING_STEP_INFO; - pNewNotes = new Steps; + pNewNotes = new Steps(&out); } } diff --git a/src/Song.cpp b/src/Song.cpp index c5da1cb5f0..5404507ad0 100644 --- a/src/Song.cpp +++ b/src/Song.cpp @@ -191,7 +191,7 @@ void Song::AddLyricSegment( LyricSegment seg ) Steps *Song::CreateSteps() { - Steps *pSteps = new Steps; + Steps *pSteps = new Steps(this); InitSteps( pSteps ); return pSteps; } @@ -415,7 +415,7 @@ bool Song::ReloadFromSongDir( RString sDir ) // The leftovers in the map are steps that didn't exist before we reverted for( map::const_iterator it = mNewSteps.begin(); it != mNewSteps.end(); ++it ) { - Steps *NewSteps = new Steps(); + Steps *NewSteps = new Steps(this); *NewSteps = *(it->second); AddSteps( NewSteps ); } @@ -1136,7 +1136,7 @@ void Song::AutoGen( StepsType ntTo, StepsType ntFrom ) const Steps* pOriginalNotes = m_vpSteps[j]; if( pOriginalNotes->m_StepsType == ntFrom ) { - Steps* pNewNotes = new Steps; + Steps* pNewNotes = new Steps(this); pNewNotes->AutogenFrom( pOriginalNotes, ntTo ); this->AddSteps( pNewNotes ); } diff --git a/src/Steps.cpp b/src/Steps.cpp index 9e53aed9a7..e1c0d9d31a 100644 --- a/src/Steps.cpp +++ b/src/Steps.cpp @@ -42,7 +42,7 @@ static const char *DisplayBPMNames[] = XToString( DisplayBPM ); LuaXType( DisplayBPM ); -Steps::Steps(): m_StepsType(StepsType_Invalid), m_pSong(NULL), +Steps::Steps(Song *song): m_StepsType(StepsType_Invalid), m_pSong(song), parent(NULL), m_pNoteData(new NoteData), m_bNoteDataIsFilled(false), m_sNoteDataCompressed(""), m_sFilename(""), m_bSavedToDisk(false), m_LoadedFromProfile(ProfileSlot_Invalid), m_iHash(0), @@ -465,6 +465,7 @@ void Steps::CopyFrom( Steps* pSource, StepsType ntTo, float fMusicLengthSeconds noteData.SetNumTracks( GAMEMAN->GetStepsTypeInfo(ntTo).iNumTracks ); parent = NULL; m_Timing = pSource->m_Timing; + this->m_pSong = pSource->m_pSong; this->m_Attacks = pSource->m_Attacks; this->m_sAttackString = pSource->m_sAttackString; this->SetNoteData( noteData ); diff --git a/src/Steps.h b/src/Steps.h index 6838ed55ed..95b179bcd1 100644 --- a/src/Steps.h +++ b/src/Steps.h @@ -42,7 +42,7 @@ class Steps { public: /** @brief Set up the Steps with initial values. */ - Steps(); + Steps( Song* song ); /** @brief Destroy the Steps that are no longer needed. */ ~Steps();