pull out some repetitive code

This commit is contained in:
Glenn Maynard
2002-10-25 07:35:07 +00:00
parent 9a45291805
commit 6fc73af64b
+28 -41
View File
@@ -105,28 +105,33 @@ void Background::LoadFromSong( Song* pSong )
//
// Load the static background that will before notes start and after notes end
//
BGAnimation* pTempBGA;
// Tricky! The song background looks terrible unless its loaded with no alpha
// and dithered. Create a dummy sprite that loads the texture with the proper
// hints so we don't have to hack up BGAnimation to handle this special
// case.
// XXX: This assumes the TextureManager doesn't track hints. Also, BGA
// backgrounds (bottom layer) should do this, too, for the same reason.
// We can probably handle this intelligently in the texture loader and get
// rid of bDither completely, but only if there aren't some weird BGAs out
// there that actually use the alpha channel. (In that case, the texture
// loader would have no way of knowing that the image, seeming to use the
// alpha layer, actually doesn't since it's the back-most image. Hmm.)
Sprite sprDummy;
sprDummy.Load( sSongBackgroundPath, true, 4, 0, true, false );
pTempBGA = new BGAnimation;
pTempBGA->LoadFromStaticGraphic( sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
{
BGAnimation *pTempBGA = new BGAnimation;
pTempBGA->LoadFromStaticGraphic( sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
}
if( pSong->HasBGChanges() )
{
// start off showing the static song background
m_aBGSegments.Add( BGSegment(-10000,0,false) );
// Load the animations used by the song's pre-defined animation plan.
// the song has a plan. Use it.
for( int i=0; i<pSong->m_BackgroundChanges.GetSize(); i++ )
@@ -134,6 +139,8 @@ void Background::LoadFromSong( Song* pSong )
const BackgroundChange& aniseg = pSong->m_BackgroundChanges[i];
bool bFade = i==0;
BGAnimation *pTempBGA = NULL;
// Using aniseg.m_sBGName, search for the corresponding animation.
// Look in this order: movies in song dir, BGAnims in song dir
// movies in RandomMovies dir, BGAnims in BGAnimsDir.
@@ -141,69 +148,49 @@ void Background::LoadFromSong( Song* pSong )
// Look for BG movies in the song dir
GetDirListing( pSong->m_sSongDir+aniseg.m_sBGName, asFiles, false, true );
GetDirListing( pSong->m_sSongDir+aniseg.m_sBGName, asFiles, false, true );
GetDirListing( pSong->m_sSongDir+aniseg.m_sBGName, asFiles, false, true );
if( asFiles.GetSize() > 0 )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromMovie( asFiles[0], true, true );
m_BGAnimations.Add( pTempBGA );
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) ); // add to the plan
continue; // stop looking for this background
}
// Look for BGAnims in the song dir
GetDirListing( pSong->m_sSongDir+aniseg.m_sBGName, asFiles, true, true );
if( asFiles.empty() ) GetDirListing( pSong->m_sSongDir+aniseg.m_sBGName, asFiles, true, true );
if( asFiles.GetSize() > 0 )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromAniDir( asFiles[0], sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) ); // add to the plan
continue; // stop looking for this background
}
// Look for movies in the RandomMovies dir
GetDirListing( RANDOMMOVIES_DIR+aniseg.m_sBGName, asFiles, false, true );
GetDirListing( RANDOMMOVIES_DIR+aniseg.m_sBGName, asFiles, false, true );
GetDirListing( RANDOMMOVIES_DIR+aniseg.m_sBGName, asFiles, false, true );
if( asFiles.empty() ) GetDirListing( RANDOMMOVIES_DIR+aniseg.m_sBGName, asFiles, false, true );
if( asFiles.GetSize() > 0 )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromMovie( asFiles[0], true, false );
m_BGAnimations.Add( pTempBGA );
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) ); // add to the plan
continue; // stop looking for this background
}
// Look for BGAnims in the BGAnims dir
GetDirListing( BG_ANIMS_DIR+aniseg.m_sBGName, asFiles, true, true );
if( asFiles.empty() ) GetDirListing( BG_ANIMS_DIR+aniseg.m_sBGName, asFiles, true, true );
if( asFiles.GetSize() > 0 )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromAniDir( asFiles[0], sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) ); // add to the plan
continue; // stop looking for this background
}
// Look for BGAnims in the BGAnims dir
GetDirListing( VISUALIZATIONS_DIR+aniseg.m_sBGName, asFiles, false, true );
if( asFiles.empty() ) GetDirListing( VISUALIZATIONS_DIR+aniseg.m_sBGName, asFiles, false, true );
if( asFiles.GetSize() > 0 )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromVisualization( asFiles[0], sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) ); // add to the plan
continue; // stop looking for this background
}
// if we make it here, ignore the background change
if(pTempBGA != NULL)
{
m_BGAnimations.Add( pTempBGA );
// add to the plan
m_aBGSegments.Add( BGSegment(aniseg.m_fStartBeat, m_BGAnimations.GetSize()-1, bFade) );
}
}
// end showing the static song background
@@ -244,19 +231,19 @@ void Background::LoadFromSong( Song* pSong )
GetDirListing( VISUALIZATIONS_DIR + "*.mpg", arrayPossibleMovies, false, true );
GetDirListing( VISUALIZATIONS_DIR + "*.mpeg", arrayPossibleMovies, false, true );
BGAnimation *pTempBGA = NULL;
if( arrayPossibleMovies.GetSize() > 0 )
{
int index = rand() % arrayPossibleMovies.GetSize();
pTempBGA = new BGAnimation;
pTempBGA->LoadFromVisualization( arrayPossibleMovies[index], sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
}
else
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromStaticGraphic( sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
}
m_BGAnimations.Add( pTempBGA );
}
break;
case MODE_ANIMATIONS:
@@ -270,7 +257,7 @@ void Background::LoadFromSong( Song* pSong )
for( i=0; i<4 && arrayPossibleAnims.GetSize()>0; i++ )
{
int index = rand() % arrayPossibleAnims.GetSize();
pTempBGA = new BGAnimation;
BGAnimation *pTempBGA = new BGAnimation;
pTempBGA->LoadFromAniDir( arrayPossibleAnims[index], sSongBackgroundPath );
m_BGAnimations.Add( pTempBGA );
arrayPossibleAnims.RemoveAt( index );
@@ -286,7 +273,7 @@ void Background::LoadFromSong( Song* pSong )
for( int i=0; i<4 && arrayPossibleMovies.GetSize()>0; i++ )
{
int index = rand() % arrayPossibleMovies.GetSize();
pTempBGA = new BGAnimation;
BGAnimation *pTempBGA = new BGAnimation;
pTempBGA->LoadFromMovie( arrayPossibleMovies[index], true, false );
m_BGAnimations.Add( pTempBGA );
arrayPossibleMovies.RemoveAt( index );