From 14fc4e888268fd6dbfc731989437b80ebde4f524 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 28 Feb 2005 20:12:07 +0000 Subject: [PATCH] cleanup, convert EditSourceSteps pointer too --- stepmania/src/SongManager.cpp | 44 ++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 3da0af1f0a..ca5ea8dd49 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -742,6 +742,24 @@ void SongManager::Invalidate( Song *pStaleSong ) * reverting out of the editor. If false, this is unexpected and will assert. * This is used when reverting out of gameplay, in which case we may have StageStats, * etc. which may cause hard-to-trace crashes down the line if we set them to NULL. */ +void CONVERT_STEPS_POINTER( Steps *&pSteps, const map &mapOldStepsToStepsID, const Song *pSong, bool bAllowNotesLoss ) +{ + if( pSteps == NULL ) + return; + + map::const_iterator it = mapOldStepsToStepsID.find(pSteps); + if( it != mapOldStepsToStepsID.end() ) + pSteps = it->second.ToSteps(pSong, bAllowNotesLoss); +} +void CONVERT_STEPS_POINTER( BroadcastOnChangePtr &pSteps, const map &mapOldStepsToStepsID, const Song *pSong, bool bAllowNotesLoss ) +{ + if( pSteps == NULL ) + return; + + map::const_iterator it = mapOldStepsToStepsID.find(pSteps); + if( it != mapOldStepsToStepsID.end() ) + pSteps.Set( it->second.ToSteps(pSong, bAllowNotesLoss) ); +} void SongManager::RevertFromDisk( Song *pSong, bool bAllowNotesLoss ) { /* Reverting from disk is brittle, and touches a lot of tricky and rarely- @@ -790,35 +808,19 @@ void SongManager::RevertFromDisk( Song *pSong, bool bAllowNotesLoss ) StepsID::ClearCache(); - -#define CONVERT_STEPS_POINTER( pSteps ) do { \ - if( pSteps != NULL ) { \ - map::iterator it = mapOldStepsToStepsID.find(pSteps); \ - if( it != mapOldStepsToStepsID.end() ) \ - pSteps = it->second.ToSteps(pSong, bAllowNotesLoss); \ - } \ -} while(false) - -#define CONVERT_STEPS_POINTER2( pSteps ) do { \ - if( pSteps != NULL ) { \ - map::iterator it = mapOldStepsToStepsID.find(pSteps); \ - if( it != mapOldStepsToStepsID.end() ) \ - pSteps.Set( it->second.ToSteps(pSong, bAllowNotesLoss) ); \ - } \ -} while(false) - - FOREACH_PlayerNumber( p ) { - CONVERT_STEPS_POINTER2( GAMESTATE->m_pCurSteps[p] ); + CONVERT_STEPS_POINTER( GAMESTATE->m_pCurSteps[p], mapOldStepsToStepsID, pSong, bAllowNotesLoss ); FOREACH( Steps*, STATSMAN->m_CurStageStats.m_player[p].vpSteps, pSteps ) - CONVERT_STEPS_POINTER( *pSteps ); + CONVERT_STEPS_POINTER( *pSteps, mapOldStepsToStepsID, pSong, bAllowNotesLoss ); FOREACH( StageStats, STATSMAN->m_vPlayedStageStats, ss ) FOREACH( Steps*, ss->m_player[p].vpSteps, pSteps ) - CONVERT_STEPS_POINTER( *pSteps ); + CONVERT_STEPS_POINTER( *pSteps, mapOldStepsToStepsID, pSong, bAllowNotesLoss ); } + + CONVERT_STEPS_POINTER( GAMESTATE->m_pEditSourceSteps, mapOldStepsToStepsID, pSong, bAllowNotesLoss ); } void SongManager::RegenerateNonFixedCourses()