diff --git a/stepmania/src/ActorFrame.cpp b/stepmania/src/ActorFrame.cpp index e6af2abfb4..0d037dbae4 100644 --- a/stepmania/src/ActorFrame.cpp +++ b/stepmania/src/ActorFrame.cpp @@ -6,6 +6,13 @@ ActorFrame::ActorFrame() { m_bPropagateCommands = false; + m_bDeleteChildren = false; +} + +ActorFrame::~ActorFrame() +{ + if( m_bDeleteChildren ) + DeleteAllChildren(); } void ActorFrame::AddChild( Actor* pActor ) diff --git a/stepmania/src/ActorFrame.h b/stepmania/src/ActorFrame.h index 70b49b93d7..9329151764 100644 --- a/stepmania/src/ActorFrame.h +++ b/stepmania/src/ActorFrame.h @@ -9,14 +9,14 @@ class ActorFrame : public Actor { public: ActorFrame(); + virtual ~ActorFrame(); virtual void AddChild( Actor* pActor ); virtual void RemoveChild( Actor* pActor ); virtual void MoveToTail( Actor* pActor ); virtual void MoveToHead( Actor* pActor ); virtual void SortByDrawOrder(); - virtual ~ActorFrame() { } - + void DeleteChildrenWhenDone( bool bDelete=true ) { m_bDeleteChildren = bDelete; } void DeleteAllChildren(); virtual void RunCommandOnChildren( const Commands &cmds ); /* but not on self */ @@ -44,6 +44,7 @@ public: protected: vector m_SubActors; bool m_bPropagateCommands; + bool m_bDeleteChildren; }; #endif diff --git a/stepmania/src/BGAnimation.cpp b/stepmania/src/BGAnimation.cpp index 0ac1f16e6f..079ff26a63 100644 --- a/stepmania/src/BGAnimation.cpp +++ b/stepmania/src/BGAnimation.cpp @@ -187,23 +187,6 @@ void BGAnimation::LoadFromMovie( const CString &sMoviePath ) AddChild( pLayer ); } -void BGAnimation::LoadFromVisualization( const CString &sVisPath ) -{ - Unload(); - BGAnimationLayer* pLayer; - - const Song* pSong = GAMESTATE->m_pCurSong; - CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background"); - - pLayer = new BGAnimationLayer( m_bGeneric ); - pLayer->LoadFromStaticGraphic( sSongBGPath ); - AddChild( pLayer ); - - pLayer = new BGAnimationLayer( m_bGeneric ); - pLayer->LoadFromVisualization( sVisPath ); - AddChild( pLayer ); -} - void BGAnimation::LoadFromNode( const CString &sDir, const XNode& node ) { DEBUG_ASSERT( node.m_sName == "BGAnimation" ); diff --git a/stepmania/src/BGAnimation.h b/stepmania/src/BGAnimation.h index 26e28eb1b0..89a08d119c 100644 --- a/stepmania/src/BGAnimation.h +++ b/stepmania/src/BGAnimation.h @@ -20,7 +20,6 @@ public: void LoadFromStaticGraphic( const CString &sPath ); void LoadFromAniDir( const CString &sAniDir ); void LoadFromMovie( const CString &sMoviePath ); - void LoadFromVisualization( const CString &sMoviePath ); void LoadFromNode( const CString &sDir, const XNode& node ); protected: diff --git a/stepmania/src/BGAnimationLayer.cpp b/stepmania/src/BGAnimationLayer.cpp index babbe0e3c9..5899761181 100644 --- a/stepmania/src/BGAnimationLayer.cpp +++ b/stepmania/src/BGAnimationLayer.cpp @@ -108,16 +108,6 @@ void BGAnimationLayer::LoadFromMovie( const CString& sMoviePath ) this->AddChild( pSprite ); } -void BGAnimationLayer::LoadFromVisualization( const CString& sMoviePath ) -{ - Init(); - Sprite* pSprite = new Sprite; - this->AddChild( pSprite ); - pSprite->LoadBG( sMoviePath ); - pSprite->StretchTo( FullScreenRectF ); - pSprite->SetBlendMode( BLEND_ADD ); -} - void BGAnimationLayer::LoadFromAniLayerFile( const CString& sPath ) { @@ -751,23 +741,6 @@ void BGAnimationLayer::GainFocus( float fRate, bool bRewindMovie, bool bLoop ) { m_fUpdateRate = fRate; - if( !m_SubActors.size() ) - return; - - // - // The order of these actions is important. - // At this point, the movie is probably paused (by LoseFocus()). - // Play the movie, then set the playback rate (which can - // potentially pause the movie again). - // - // TODO: Don't special case subActor[0]. The movie layer should be set up with - // a LoseFocusCommand that pauses, and a GainFocusCommand that plays. - if( bRewindMovie ) - RunCommandOnChildren( ParseCommands("position,0") ); - RunCommandOnChildren( ParseCommands(ssprintf("loop,%i",bLoop)) ); - RunCommandOnChildren( ParseCommands("play") ); - RunCommandOnChildren( ParseCommands(ssprintf("rate,%f",fRate)) ); - if( m_fRepeatCommandEverySeconds == -1 ) // if not repeating { /* Yuck. We send OnCommand on load, since that's what's wanted for @@ -779,19 +752,12 @@ void BGAnimationLayer::GainFocus( float fRate, bool bRewindMovie, bool bLoop ) PlayCommand( "On" ); } - PlayCommand( "GainFocus" ); - ActorFrame::GainFocus( fRate, bRewindMovie, bLoop ); } void BGAnimationLayer::LoseFocus() { - if( !m_SubActors.size() ) - return; - - RunCommandOnChildren( ParseCommands("pause") ); - - PlayCommand( "LoseFocus" ); + ActorFrame::LoseFocus(); } void BGAnimationLayer::PlayCommand( const CString &sCommandName ) diff --git a/stepmania/src/BGAnimationLayer.h b/stepmania/src/BGAnimationLayer.h index 2911717266..5888d1dbb2 100644 --- a/stepmania/src/BGAnimationLayer.h +++ b/stepmania/src/BGAnimationLayer.h @@ -20,7 +20,6 @@ public: void LoadFromStaticGraphic( const CString& sPath ); void LoadFromAniLayerFile( const CString& sPath ); void LoadFromMovie( const CString& sMoviePath ); - void LoadFromVisualization( const CString& sMoviePath ); void LoadFromNode( const CString& sAniDir, const XNode& layer ); void Update( float fDeltaTime ); diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index 92ce718ae1..2aad3fd934 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -98,7 +98,7 @@ Background::~Background() void Background::Unload() { - for( map::iterator iter = m_BGAnimations.begin(); + for( map::iterator iter = m_BGAnimations.begin(); iter != m_BGAnimations.end(); iter++ ) delete iter->second; @@ -114,7 +114,29 @@ void Background::Unload() m_fLastMusicSeconds = -9999; } -BGAnimation *Background::CreateSongBGA( CString sBGName ) const +Actor *MakeVisualization( const CString &sVisPath ) +{ + ActorFrame *pFrame = new ActorFrame; + pFrame->DeleteChildrenWhenDone(); + + const Song* pSong = GAMESTATE->m_pCurSong; + CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background"); + + Sprite* pSprite = new Sprite; + pSprite->LoadBG( sSongBGPath ); + pSprite->StretchTo( FullScreenRectF ); + pFrame->AddChild( pSprite ); + + pSprite = new Sprite; + pSprite->LoadBG( sVisPath ); + pSprite->StretchTo( FullScreenRectF ); + pSprite->SetBlendMode( BLEND_ADD ); + pFrame->AddChild( pSprite ); + + return pFrame; +} + +Actor *Background::CreateSongBGA( CString sBGName ) const { BGAnimation *pTempBGA; @@ -166,11 +188,7 @@ BGAnimation *Background::CreateSongBGA( CString sBGName ) const // Look for BGAnims in the BGAnims dir GetDirListing( VISUALIZATIONS_DIR+sBGName, asFiles, false, true ); if( !asFiles.empty() ) - { - pTempBGA = new BGAnimation; - pTempBGA->LoadFromVisualization( asFiles[0] ); - return pTempBGA; - } + return MakeVisualization( asFiles[0] ); // There is no background by this name. return NULL; @@ -243,12 +261,25 @@ CString Background::CreateRandomBGA() file = arrayPaths[i]; } - BGAnimation *ret = new BGAnimation; + Actor *ret; switch( PREFSMAN->m_iBackgroundMode ) { - case PrefsManager::BGMODE_ANIMATIONS: ret->LoadFromAniDir( file ); break; - case PrefsManager::BGMODE_MOVIEVIS: ret->LoadFromVisualization( file ); break; - case PrefsManager::BGMODE_RANDOMMOVIES: ret->LoadFromMovie( file ); break; + case PrefsManager::BGMODE_ANIMATIONS: + { + BGAnimation *p = new BGAnimation; + p->LoadFromAniDir( file ); + ret = p; + break; + } + case PrefsManager::BGMODE_MOVIEVIS: ret = MakeVisualization( file ); break; + case PrefsManager::BGMODE_RANDOMMOVIES: + { + BGAnimation *p = new BGAnimation; + p->LoadFromMovie( file ); + ret = p; + break; + } + default: FAIL_M( ssprintf("%i", PREFSMAN->m_iBackgroundMode) ); } ret->PlayCommand( "On" ); @@ -325,7 +356,7 @@ void Background::LoadFromSong( const Song* pSong ) if( sBGName.CompareNoCase("-random-") && !bIsAlreadyLoaded ) { - BGAnimation *pTempBGA = CreateSongBGA( sBGName ); + Actor *pTempBGA = CreateSongBGA( sBGName ); if( pTempBGA ) { pTempBGA->PlayCommand( "On" ); @@ -398,7 +429,7 @@ void Background::LoadFromSong( const Song* pSong ) // Re-sort. SortBackgroundChangesArray( m_aBGChanges ); - for( map::iterator iter = m_BGAnimations.begin(); + for( map::iterator iter = m_BGAnimations.begin(); iter != m_BGAnimations.end(); iter++ ) { @@ -433,10 +464,10 @@ void Background::LoadFromSong( const Song* pSong ) * which sync from the regular clock by default. If you don't want this, set * the clock back with "effectclock,timer" in your OnCommand. Note that at this * point, we havn't run the OnCommand yet, so it'll override correctly. */ - map::iterator it; + map::iterator it; for( it = m_BGAnimations.begin(); it != m_BGAnimations.end(); ++it ) { - BGAnimation *pBGA = it->second; + Actor *pBGA = it->second; /* Be sure that we run this command recursively on all children; the tree * may look something like "BGAnimation, BGAnimationLayer, Sprite" or it @@ -492,7 +523,7 @@ void Background::UpdateCurBGChange( float fCurrentTime ) const BackgroundChange& change = m_aBGChanges[i]; - BGAnimation* pOld = m_pCurrentBGA; + Actor *pOld = m_pCurrentBGA; if( change.m_bFadeLast ) m_pFadingBGA = m_pCurrentBGA; diff --git a/stepmania/src/Background.h b/stepmania/src/Background.h index bcdcb96a31..008ef77232 100644 --- a/stepmania/src/Background.h +++ b/stepmania/src/Background.h @@ -64,15 +64,15 @@ protected: BGAnimation m_DeadPlayer[NUM_PLAYERS]; - BGAnimation* CreateSongBGA( CString sBGName ) const; + Actor *CreateSongBGA( CString sBGName ) const; CString CreateRandomBGA(); - map m_BGAnimations; + map m_BGAnimations; deque m_RandomBGAnimations; vector m_aBGChanges; int m_iCurBGChangeIndex; - BGAnimation* m_pCurrentBGA; - BGAnimation* m_pFadingBGA; + Actor *m_pCurrentBGA; + Actor *m_pFadingBGA; float m_fSecsLeftInFade; float m_fLastMusicSeconds; Quad m_quadBorder[4]; // l, t, r, b - cover up the edge of animations that might hang outside of the background rectangle diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index db3591fc82..b28ddfe886 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -934,6 +934,34 @@ void Sprite::HandleCommand( const Command &command ) EndHandleArgs; } +void Sprite::GainFocus( float fRate, bool bRewindMovie, bool bLoop ) +{ + // + // The order of these actions is important. + // At this point, the movie is probably paused (by LoseFocus()). + // Play the movie, then set the playback rate (which can + // potentially pause the movie again). + // + RageTexture *pTexture = GetTexture(); + if( pTexture != NULL ) + { + if( bRewindMovie ) + pTexture->SetPosition( 0 ); + pTexture->SetLooping( bLoop ); + pTexture->SetPlaybackRate( fRate ); + } + EnableAnimation( true ); + + Actor::GainFocus( fRate, bRewindMovie, bLoop ); +} + +void Sprite::LoseFocus() +{ + EnableAnimation( false ); + + Actor::LoseFocus(); +} + /* * (c) 2001-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/Sprite.h b/stepmania/src/Sprite.h index ad91ef8ef2..a350dabf41 100644 --- a/stepmania/src/Sprite.h +++ b/stepmania/src/Sprite.h @@ -18,6 +18,9 @@ public: virtual void DrawPrimitives(); virtual void Update( float fDeltaTime ); + virtual void GainFocus( float fRate, bool bRewindMovie, bool bLoop ); + virtual void LoseFocus(); + void UpdateAnimationState(); // take m_fSecondsIntoState, and move to a new state /* Adjust texture properties for song backgrounds. */