Steps: set Song pointer to associated song when constructing

This commit is contained in:
Devin J. Pohly
2013-01-20 19:23:28 -05:00
parent 1327fa6356
commit afaa382b84
6 changed files with 22 additions and 7 deletions
+14
View File
@@ -181,6 +181,20 @@ namespace JsonUtil
} }
} }
/* For classes with one-parameter constructors, such as Steps */
template<class T, class P>
static void DeserializeVectorPointersParam(vector<T*> &v, void fn(T &, const Json::Value &), const Json::Value &root, const P param)
{
for(unsigned i=0; i<v.size(); i++)
SAFE_DELETE(v[i]);
v.resize(root.size());
for(unsigned i=0; i<v.size(); i++)
{
v[i] = new T(param);
fn(*v[i], root[i]);
}
}
template<class T> template<class T>
static void DeserializeArrayValues(vector<T> &v, const Json::Value &root) static void DeserializeArrayValues(vector<T> &v, const Json::Value &root)
{ {
+1 -1
View File
@@ -218,7 +218,7 @@ static void Deserialize( Song &out, const Json::Value &root )
{ {
vector<Steps*> vpSteps; vector<Steps*> vpSteps;
JsonUtil::DeserializeVectorPointers<Steps>( vpSteps, Deserialize, root["Charts"] ); JsonUtil::DeserializeVectorPointersParam<Steps,Song*>( vpSteps, Deserialize, root["Charts"], &out );
FOREACH( Steps*, vpSteps, iter ) FOREACH( Steps*, vpSteps, iter )
out.AddSteps( *iter ); out.AddSteps( *iter );
} }
+1 -1
View File
@@ -301,7 +301,7 @@ bool SMALoader::LoadFromSimfile( const RString &sPath, Song &out, bool bFromCach
else else
{ {
state = SMA_GETTING_STEP_INFO; state = SMA_GETTING_STEP_INFO;
pNewNotes = new Steps; pNewNotes = new Steps(&out);
} }
} }
+3 -3
View File
@@ -191,7 +191,7 @@ void Song::AddLyricSegment( LyricSegment seg )
Steps *Song::CreateSteps() Steps *Song::CreateSteps()
{ {
Steps *pSteps = new Steps; Steps *pSteps = new Steps(this);
InitSteps( pSteps ); InitSteps( pSteps );
return 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 // The leftovers in the map are steps that didn't exist before we reverted
for( map<StepsID, Steps*>::const_iterator it = mNewSteps.begin(); it != mNewSteps.end(); ++it ) for( map<StepsID, Steps*>::const_iterator it = mNewSteps.begin(); it != mNewSteps.end(); ++it )
{ {
Steps *NewSteps = new Steps(); Steps *NewSteps = new Steps(this);
*NewSteps = *(it->second); *NewSteps = *(it->second);
AddSteps( NewSteps ); AddSteps( NewSteps );
} }
@@ -1136,7 +1136,7 @@ void Song::AutoGen( StepsType ntTo, StepsType ntFrom )
const Steps* pOriginalNotes = m_vpSteps[j]; const Steps* pOriginalNotes = m_vpSteps[j];
if( pOriginalNotes->m_StepsType == ntFrom ) if( pOriginalNotes->m_StepsType == ntFrom )
{ {
Steps* pNewNotes = new Steps; Steps* pNewNotes = new Steps(this);
pNewNotes->AutogenFrom( pOriginalNotes, ntTo ); pNewNotes->AutogenFrom( pOriginalNotes, ntTo );
this->AddSteps( pNewNotes ); this->AddSteps( pNewNotes );
} }
+2 -1
View File
@@ -42,7 +42,7 @@ static const char *DisplayBPMNames[] =
XToString( DisplayBPM ); XToString( DisplayBPM );
LuaXType( 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), parent(NULL), m_pNoteData(new NoteData), m_bNoteDataIsFilled(false),
m_sNoteDataCompressed(""), m_sFilename(""), m_bSavedToDisk(false), m_sNoteDataCompressed(""), m_sFilename(""), m_bSavedToDisk(false),
m_LoadedFromProfile(ProfileSlot_Invalid), m_iHash(0), 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 ); noteData.SetNumTracks( GAMEMAN->GetStepsTypeInfo(ntTo).iNumTracks );
parent = NULL; parent = NULL;
m_Timing = pSource->m_Timing; m_Timing = pSource->m_Timing;
this->m_pSong = pSource->m_pSong;
this->m_Attacks = pSource->m_Attacks; this->m_Attacks = pSource->m_Attacks;
this->m_sAttackString = pSource->m_sAttackString; this->m_sAttackString = pSource->m_sAttackString;
this->SetNoteData( noteData ); this->SetNoteData( noteData );
+1 -1
View File
@@ -42,7 +42,7 @@ class Steps
{ {
public: public:
/** @brief Set up the Steps with initial values. */ /** @brief Set up the Steps with initial values. */
Steps(); Steps( Song* song );
/** @brief Destroy the Steps that are no longer needed. */ /** @brief Destroy the Steps that are no longer needed. */
~Steps(); ~Steps();