Add ActorFrame::DeleteChildrenWhenDone, to call DeleteAllChildren automatically.
Move movie GainFocus/LoseFocus handling to Sprite. Visualizations are part of Background, not BGAnimation; move them there. Remove BGAnimation::LoadFromVisualization and BGAnimationLayer::LoadFromVisualization.
This commit is contained in:
@@ -6,6 +6,13 @@
|
||||
ActorFrame::ActorFrame()
|
||||
{
|
||||
m_bPropagateCommands = false;
|
||||
m_bDeleteChildren = false;
|
||||
}
|
||||
|
||||
ActorFrame::~ActorFrame()
|
||||
{
|
||||
if( m_bDeleteChildren )
|
||||
DeleteAllChildren();
|
||||
}
|
||||
|
||||
void ActorFrame::AddChild( Actor* pActor )
|
||||
|
||||
@@ -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<Actor*> m_SubActors;
|
||||
bool m_bPropagateCommands;
|
||||
bool m_bDeleteChildren;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -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" );
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 )
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -98,7 +98,7 @@ Background::~Background()
|
||||
|
||||
void Background::Unload()
|
||||
{
|
||||
for( map<CString,BGAnimation*>::iterator iter = m_BGAnimations.begin();
|
||||
for( map<CString,Actor*>::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<CString,BGAnimation*>::iterator iter = m_BGAnimations.begin();
|
||||
for( map<CString,Actor*>::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<CString,BGAnimation*>::iterator it;
|
||||
map<CString,Actor*>::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;
|
||||
|
||||
@@ -64,15 +64,15 @@ protected:
|
||||
|
||||
BGAnimation m_DeadPlayer[NUM_PLAYERS];
|
||||
|
||||
BGAnimation* CreateSongBGA( CString sBGName ) const;
|
||||
Actor *CreateSongBGA( CString sBGName ) const;
|
||||
CString CreateRandomBGA();
|
||||
|
||||
map<CString,BGAnimation*> m_BGAnimations;
|
||||
map<CString,Actor*> m_BGAnimations;
|
||||
deque<CString> m_RandomBGAnimations;
|
||||
vector<BackgroundChange> 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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user