Steps: set Song pointer to associated song when constructing
This commit is contained in:
@@ -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>
|
||||
static void DeserializeArrayValues(vector<T> &v, const Json::Value &root)
|
||||
{
|
||||
|
||||
@@ -218,7 +218,7 @@ static void Deserialize( Song &out, const Json::Value &root )
|
||||
|
||||
{
|
||||
vector<Steps*> vpSteps;
|
||||
JsonUtil::DeserializeVectorPointers<Steps>( vpSteps, Deserialize, root["Charts"] );
|
||||
JsonUtil::DeserializeVectorPointersParam<Steps,Song*>( vpSteps, Deserialize, root["Charts"], &out );
|
||||
FOREACH( Steps*, vpSteps, iter )
|
||||
out.AddSteps( *iter );
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -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<StepsID, Steps*>::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 );
|
||||
}
|
||||
|
||||
+2
-1
@@ -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 );
|
||||
|
||||
+1
-1
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user