Add parameters to BackgroundChange: fRate, bFadeLast, bRewindMovie, bLoop.

I don't like how this changes the syntax for the #BGCHANGES tag in an SM file.  I will think more about this - it's important to finalize it quickly.
This commit is contained in:
Chris Danford
2003-04-14 04:10:01 +00:00
parent 5ea408a547
commit cfe1f9ec67
20 changed files with 125 additions and 62 deletions
+4 -4
View File
@@ -119,12 +119,12 @@ void BGAnimation::LoadFromAniDir( CString sAniDir )
}
}
void BGAnimation::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind )
void BGAnimation::LoadFromMovie( CString sMoviePath )
{
Unload();
BGAnimationLayer* pLayer = new BGAnimationLayer;
pLayer->LoadFromMovie( sMoviePath, bLoop, bRewind );
pLayer->LoadFromMovie( sMoviePath );
m_Layers.push_back( pLayer );
}
@@ -158,10 +158,10 @@ void BGAnimation::DrawPrimitives()
m_Layers[i]->Draw();
}
void BGAnimation::GainingFocus()
void BGAnimation::GainingFocus( float fRate, bool bRewindMovie, bool bLoop )
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->GainingFocus();
m_Layers[i]->GainingFocus( fRate, bRewindMovie, bLoop );
SetDiffuse( RageColor(1,1,1,1) );
}
+2 -2
View File
@@ -29,7 +29,7 @@ public:
void LoadFromStaticGraphic( CString sPath );
void LoadFromAniDir( CString sAniDir );
void LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind );
void LoadFromMovie( CString sMoviePath );
void LoadFromVisualization( CString sMoviePath );
virtual void Update( float fDeltaTime );
@@ -37,7 +37,7 @@ public:
virtual void SetDiffuse( const RageColor &c );
void GainingFocus();
void GainingFocus( float fRate, bool bRewindMovie, bool bLoop );
void LosingFocus();
float GetLengthSeconds() { return m_fLengthSeconds; }
+6 -8
View File
@@ -65,7 +65,6 @@ void BGAnimationLayer::Init()
m_fStretchTexCoordVelocityX = 0;
m_fStretchTexCoordVelocityY = 0;
m_bRewindMovie = false;
m_fZoomMin = 1;
m_fZoomMax = 1;
m_fVelocityXMin = 10;
@@ -117,7 +116,7 @@ void BGAnimationLayer::LoadFromStaticGraphic( CString sPath )
m_Sprites.back()->StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) );
}
void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind )
void BGAnimationLayer::LoadFromMovie( CString sMoviePath )
{
Init();
m_Sprites.push_back(new Sprite);
@@ -126,9 +125,6 @@ void BGAnimationLayer::LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewi
m_Sprites.back()->GetTexture()->Play();
SDL_Delay( 50 ); // decode a frame so we don't see a black flash at the beginning
m_Sprites.back()->GetTexture()->Pause();
m_bRewindMovie = bRewind;
if( !bLoop )
m_Sprites.back()->GetTexture()->SetLooping(false);
}
void BGAnimationLayer::LoadFromVisualization( CString sMoviePath )
@@ -486,7 +482,6 @@ void BGAnimationLayer::LoadFromIni( CString sAniDir, CString sLayer )
ini.GetValue ( sLayer, "Command", m_sCommand );
ini.GetValueF( sLayer, "StretchTexCoordVelocityX", m_fStretchTexCoordVelocityX );
ini.GetValueF( sLayer, "StretchTexCoordVelocityY", m_fStretchTexCoordVelocityY );
ini.GetValueB( sLayer, "RewindMovie", m_bRewindMovie );
ini.GetValueF( sLayer, "ZoomMin", m_fZoomMin );
ini.GetValueF( sLayer, "ZoomMax", m_fZoomMax );
ini.GetValueF( sLayer, "VelocityXMin", m_fVelocityXMin );
@@ -872,10 +867,13 @@ void BGAnimationLayer::SetDiffuse( RageColor c )
m_Sprites[i]->SetDiffuse(c);
}
void BGAnimationLayer::GainingFocus()
void BGAnimationLayer::GainingFocus( float fRate, bool bRewindMovie, bool bLoop )
{
if( m_bRewindMovie )
m_Sprites.back()->GetTexture()->SetPlaybackRate(fRate);
if( bRewindMovie )
m_Sprites[0]->GetTexture()->SetPosition( 0 );
m_Sprites.back()->GetTexture()->SetLooping(bLoop);
// if movie texture, pause and play movie so we don't waste CPU cycles decoding frames that won't be shown
m_Sprites[0]->GetTexture()->Play();
+2 -3
View File
@@ -31,7 +31,7 @@ public:
void LoadFromStaticGraphic( CString sPath );
void LoadFromAniLayerFile( CString sPath );
void LoadFromMovie( CString sMoviePath, bool bLoop, bool bRewind );
void LoadFromMovie( CString sMoviePath );
void LoadFromVisualization( CString sMoviePath );
void LoadFromIni( CString sDir, CString sLayer );
@@ -41,7 +41,7 @@ public:
virtual void SetDiffuse( RageColor c );
float GetMaxTweenTimeLeft() const;
void GainingFocus();
void GainingFocus( float fRate, bool bRewindMovie, bool bLoop );
void LosingFocus();
protected:
@@ -102,7 +102,6 @@ protected:
float m_fStretchTexCoordVelocityY;
// particle and tile stuff
bool m_bRewindMovie;
float m_fZoomMin, m_fZoomMax;
float m_fVelocityXMin, m_fVelocityXMax;
float m_fVelocityYMin, m_fVelocityYMax;
+30 -21
View File
@@ -49,6 +49,7 @@ Background::Background()
{
m_bInDanger = false;
m_iCurBGChangeIndex = -1;
m_pCurrentBGA = NULL;
m_pFadingBGA = NULL;
m_fSecsLeftInFade = 0;
@@ -123,7 +124,7 @@ BGAnimation *Background::CreateSongBGA(const Song *pSong, CString sBGName) const
if( sExt.CompareNoCase("avi")==0 ||
sExt.CompareNoCase("mpg")==0 ||
sExt.CompareNoCase("mpeg")==0 )
pTempBGA->LoadFromMovie( asFiles[0], true, true );
pTempBGA->LoadFromMovie( asFiles[0] );
else
pTempBGA->LoadFromStaticGraphic( asFiles[0] );
return pTempBGA;
@@ -133,7 +134,7 @@ BGAnimation *Background::CreateSongBGA(const Song *pSong, CString sBGName) const
if( !asFiles.empty() )
{
pTempBGA = new BGAnimation;
pTempBGA->LoadFromMovie( asFiles[0], true, false );
pTempBGA->LoadFromMovie( asFiles[0] );
return pTempBGA;
}
@@ -212,7 +213,7 @@ BGAnimation* Background::CreateRandomBGA() const
return NULL;
unsigned index = rand() % arrayPossibleMovies.size();
BGAnimation *pTempBGA = new BGAnimation;
pTempBGA->LoadFromMovie( arrayPossibleMovies[index], true, false );
pTempBGA->LoadFromMovie( arrayPossibleMovies[index] );
return pTempBGA;
}
break;
@@ -260,8 +261,8 @@ void Background::LoadFromSong( Song* pSong )
// Load all song-specified backgrounds
for( unsigned i=0; i<pSong->m_BackgroundChanges.size(); i++ )
{
float fStartBeat = pSong->m_BackgroundChanges[i].m_fStartBeat;
CString sBGName = pSong->m_BackgroundChanges[i].m_sBGName;
BackgroundChange change = pSong->m_BackgroundChanges[i];
CString sBGName = change.m_sBGName;
bool bIsAlreadyLoaded = m_BGAnimations.find(sBGName) != m_BGAnimations.end();
@@ -277,7 +278,7 @@ void Background::LoadFromSong( Song* pSong )
sBGName = STATIC_BACKGROUND;
}
m_aBGChanges.push_back( BackgroundChange(fStartBeat, sBGName) );
m_aBGChanges.push_back( change );
}
}
else // pSong doesn't have an animation plan
@@ -366,24 +367,32 @@ void Background::Update( float fDeltaTime )
if( GAMESTATE->m_fSongBeat < m_aBGChanges[i+1].m_fStartBeat )
break;
BGAnimation* pOld = m_pCurrentBGA;
CString sNewBGName = m_aBGChanges[i].m_sBGName;
BGAnimation* pNew = m_BGAnimations[sNewBGName];
if( pOld != pNew )
if( i != m_iCurBGChangeIndex )
{
// LOG->Trace( "new bga %d, %d, %f, %f", m_iCurBGChange, i, m_aBGChanges[i].m_fStartBeat, GAMESTATE->m_fSongBeat );
m_pFadingBGA = pOld;
m_pCurrentBGA = pNew;
LOG->Trace( "old bga %d -> new bga %d, %f, %f", i, m_iCurBGChangeIndex, m_aBGChanges[i].m_fStartBeat, GAMESTATE->m_fSongBeat );
if( pOld )
pOld->LosingFocus();
if( pNew )
pNew->GainingFocus();
m_iCurBGChangeIndex = i;
bool bBGAnimsMode = PREFSMAN->m_BackgroundMode == PrefsManager::BGMODE_ANIMATIONS;
m_fSecsLeftInFade = bBGAnimsMode ? 0 : FADE_SECONDS;
const BackgroundChange& change = m_aBGChanges[i];
BGAnimation* pOld = m_pCurrentBGA;
if( change.m_bFadeLast )
m_pFadingBGA = m_pCurrentBGA;
else
m_pFadingBGA = NULL;
m_pCurrentBGA = m_BGAnimations[ change.m_sBGName ];
if( pOld != m_pCurrentBGA )
{
if( pOld )
pOld->LosingFocus();
if( m_pCurrentBGA )
m_pCurrentBGA->GainingFocus( change.m_fRate, change.m_bRewindMovie, change.m_bLoop );
}
m_fSecsLeftInFade = m_pFadingBGA!=NULL ? FADE_SECONDS : 0;
}
if( m_pCurrentBGA )
+1
View File
@@ -50,6 +50,7 @@ protected:
map<CString,BGAnimation*> m_BGAnimations;
vector<BackgroundChange> m_aBGChanges;
int m_iCurBGChangeIndex;
BGAnimation* m_pCurrentBGA;
BGAnimation* m_pFadingBGA;
float m_fSecsLeftInFade;
+11 -1
View File
@@ -309,7 +309,17 @@ void NoteField::DrawPrimitives()
{
if(aBackgroundChanges[i].m_fStartBeat >= fFirstBeatToDraw &&
aBackgroundChanges[i].m_fStartBeat <= fLastBeatToDraw)
DrawBGChangeText( aBackgroundChanges[i].m_fStartBeat, aBackgroundChanges[i].m_sBGName );
{
const BackgroundChange& change = aBackgroundChanges[i];
CString sChangeText = ssprintf("%s\n%.0f%%%s%s%s",
change.m_sBGName.GetString(),
change.m_fRate*100,
change.m_bFadeLast ? " Fade" : "",
change.m_bRewindMovie ? " Rewind" : "",
change.m_bLoop ? " Loop" : "" );
DrawBGChangeText( change.m_fStartBeat, sChangeText );
}
}
//
+17 -8
View File
@@ -232,17 +232,26 @@ bool SMLoader::LoadFromSMFile( CString sPath, Song &out )
split( aBGChangeExpressions[b], "=", aBGChangeValues );
/* XXX: Once we have a way to display warnings that the user actually
* cares about (unlike most warnings), this should be one of them. */
if(aBGChangeValues.size() != 2)
BackgroundChange change;
switch( aBGChangeValues.size() )
{
LOG->Warn("Invalid #%s value \"%s\" (must have exactly one '='), ignored",
case 6:
change.m_fRate = (float)atof( aBGChangeValues[2] );
change.m_bFadeLast = atoi( aBGChangeValues[3] ) != 0;
change.m_bRewindMovie = atoi( aBGChangeValues[4] ) != 0;
change.m_bLoop = atoi( aBGChangeValues[5] ) != 0;
// fall through
case 2:
change.m_fStartBeat = (float)atof( aBGChangeValues[0] );
change.m_sBGName = aBGChangeValues[1];
out.AddBackgroundChange( change );
break;
default:
LOG->Warn("Invalid #BGCHANGES%s value \"%s\" was ignored",
sValueName.GetString(), aBGChangeExpressions[b].GetString());
continue;
break;
}
float fBeat = (float)atof( aBGChangeValues[0] );
CString sBGName = aBGChangeValues[1];
sBGName.MakeLower();
out.AddBackgroundChange( BackgroundChange(fBeat, sBGName) );
}
}
+1 -1
View File
@@ -65,7 +65,7 @@ void NotesWriterSM::WriteGlobalTags(FILE *fp, const Song &out)
{
const BackgroundChange &seg = out.m_BackgroundChanges[i];
fprintf( fp, "%.3f=%s", seg.m_fStartBeat, seg.m_sBGName.GetString() );
fprintf( fp, "%.3f=%s=%.3f=%d=%d=%d", seg.m_fStartBeat, seg.m_sBGName.GetString(), seg.m_fRate, seg.m_bFadeLast, seg.m_bRewindMovie, seg.m_bLoop );
if( i != out.m_BackgroundChanges.size()-1 )
fprintf( fp, "," );
}
+1
View File
@@ -59,6 +59,7 @@ public:
virtual void Stop() {}
virtual void Pause() {}
virtual void SetPosition( float fSeconds ) {}
virtual void SetPlaybackRate( float fRate ) {}
virtual bool IsAMovie() const { return false; }
virtual bool IsPlaying() const { return false; }
void SetLooping(bool looping) { }
+17 -7
View File
@@ -194,6 +194,10 @@ Menu g_EditSongInfo
Menu g_BGChange
(
"Background Change",
MenuRow( "Rate (applies to new adds)", true, 5, "50%","60%","70%","80%","90%","100%","110%","120%","130%","140%","150%","160%","170%","180%","190%","200%" ),
MenuRow( "Fade Last (applies to new adds)", true, 0, "NO","YES" ),
MenuRow( "Rewind Movie (applies to new adds)", true, 0, "NO","YES" ),
MenuRow( "Loop (applies to new adds)", true, 1, "NO","YES" ),
MenuRow( "Add Change to random", true ),
MenuRow( "Add Change to song BGAnimation", true ),
MenuRow( "Add Change to song Movie", true ),
@@ -1542,12 +1546,13 @@ void ScreenEdit::HandleEditSongInfoChoice( EditSongInfoChoice c, int* iAnswers )
void ScreenEdit::HandleBGChangeChoice( BGChangeChoice c, int* iAnswers )
{
CString sBGName;
BackgroundChange change;
change.m_fStartBeat = GAMESTATE->m_fSongBeat;
switch( c )
{
case add_random:
sBGName = "-random-";
change.m_sBGName = "-random-";
break;
case add_song_bganimation:
case add_song_movie:
@@ -1555,15 +1560,20 @@ void ScreenEdit::HandleBGChangeChoice( BGChangeChoice c, int* iAnswers )
case add_global_random_movie:
case add_global_bganimation:
case add_global_visualization:
sBGName = g_BGChange.rows[c].choices[iAnswers[c]];
change.m_sBGName = g_BGChange.rows[c].choices[iAnswers[c]];
break;
case delete_change:
sBGName = "";
change.m_sBGName = "";
break;
default:
ASSERT(0);
SOUNDMAN->PlayOnce( THEME->GetPathToS("Common invalid") );
};
change.m_fRate = (float)atof( g_BGChange.rows[rate].choices[iAnswers[rate]] )/100.f;
change.m_bFadeLast = !!iAnswers[fade_last];
change.m_bRewindMovie = !!iAnswers[rewind_movie];
change.m_bLoop = !!iAnswers[loop];
unsigned i;
for( i=0; i<m_pSong->m_BackgroundChanges.size(); i++ )
if( m_pSong->m_BackgroundChanges[i].m_fStartBeat == GAMESTATE->m_fSongBeat )
@@ -1574,6 +1584,6 @@ void ScreenEdit::HandleBGChangeChoice( BGChangeChoice c, int* iAnswers )
m_pSong->m_BackgroundChanges.begin()+i+1);
// create a new BGChange
if( sBGName != "" )
m_pSong->AddBackgroundChange( BackgroundChange(GAMESTATE->m_fSongBeat, sBGName) );
if( change.m_sBGName != "" )
m_pSong->AddBackgroundChange( change );
}
+4
View File
@@ -167,6 +167,10 @@ public:
void HandleEditSongInfoChoice( EditSongInfoChoice c, int* iAnswers );
enum BGChangeChoice {
rate,
fade_last,
rewind_movie,
loop,
add_random,
add_song_bganimation,
add_song_movie,
+3 -3
View File
@@ -33,13 +33,13 @@ struct MenuRow
defaultChoice = 0;
}
MenuRow( const char * n, bool e, const char * c0=NULL, const char * c1=NULL, const char * c2=NULL, const char * c3=NULL, const char * c4=NULL, const char * c5=NULL, const char * c6=NULL, const char * c7=NULL, const char * c8=NULL, const char * c9=NULL, const char * c10=NULL, const char * c11=NULL, const char * c12=NULL, const char * c13=NULL, const char * c14=NULL )
MenuRow( const char * n, bool e, int d=0, const char * c0=NULL, const char * c1=NULL, const char * c2=NULL, const char * c3=NULL, const char * c4=NULL, const char * c5=NULL, const char * c6=NULL, const char * c7=NULL, const char * c8=NULL, const char * c9=NULL, const char * c10=NULL, const char * c11=NULL, const char * c12=NULL, const char * c13=NULL, const char * c14=NULL, const char * c15=NULL, const char * c16=NULL, const char * c17=NULL, const char * c18=NULL, const char * c19=NULL )
{
name = n;
enabled = e;
defaultChoice = 0;
defaultChoice = d;
#define PUSH( c ) if(c!=NULL) choices.push_back(c);
PUSH(c0);PUSH(c1);PUSH(c2);PUSH(c3);PUSH(c4);PUSH(c5);PUSH(c6);PUSH(c7);PUSH(c8);PUSH(c9);PUSH(c10);PUSH(c11);PUSH(c12);PUSH(c13);PUSH(c14);
PUSH(c0);PUSH(c1);PUSH(c2);PUSH(c3);PUSH(c4);PUSH(c5);PUSH(c6);PUSH(c7);PUSH(c8);PUSH(c9);PUSH(c10);PUSH(c11);PUSH(c12);PUSH(c13);PUSH(c14);PUSH(c15);PUSH(c16);PUSH(c17);PUSH(c18);PUSH(c19);
#undef PUSH
// printf( "choices.size = %u", choices.size() );
}
+1 -1
View File
@@ -638,7 +638,7 @@ void Song::TidyUpData()
/* Use this->GetBeatFromElapsedTime(0) instead of 0 to start when the
* music starts. */
if( arrayPossibleMovies.size() == 1 )
this->AddBackgroundChange( BackgroundChange(0,arrayPossibleMovies[0]) );
this->AddBackgroundChange( BackgroundChange(0,arrayPossibleMovies[0],1.f,true,true,false) );
}
for( i=0; i<m_apNotes.size(); i++ )
+5
View File
@@ -54,8 +54,13 @@ void Transition::Update( float fDeltaTime )
/* Start the transition on the first update, not in the ctor, so
* we don't play a sound while our parent is still loading. */
if( m_fSecsIntoTransition==0 ) // first update
{
m_sound.PlayRandom();
// stop the sound from playing multiple times on an Update(0)
m_fSecsIntoTransition+=0.000001f;
}
m_BGAnimation.Update( fDeltaTime );
if( m_fSecsIntoTransition > m_BGAnimation.GetLengthSeconds() ) // over
{
@@ -83,7 +83,7 @@ bool LowLevelWindow_SDL::SetVideoMode( bool windowed, int width, int height, int
* in the real branch we can remove this #if. */
#if defined(WIN32)
SDL_Event e;
if(SDL_GetEvent(&e, SDL_OPENGLRESETMASK))
if(SDL_GetEvent(e, SDL_OPENGLRESETMASK))
{
LOG->Trace("New OpenGL context");
@@ -16,6 +16,7 @@ public:
virtual void Pause() = 0;
virtual void Stop() = 0;
virtual void SetPosition( float fSeconds ) = 0;
virtual void SetPlaybackRate( float fRate ) = 0;
virtual bool IsPlaying() const = 0;
virtual void SetLooping(bool looping=true) { }
@@ -378,6 +378,17 @@ void MovieTexture_DShow::SetPosition( float fSeconds )
StopSkippingUpdates();
}
void MovieTexture_DShow::SetPlaybackRate( float fRate )
{
SkipUpdates();
CComPtr<IMediaPosition> pMP;
m_pGB.QueryInterface(&pMP);
pMP->put_Rate(fRate);
StopSkippingUpdates();
}
bool MovieTexture_DShow::IsPlaying() const
{
return m_bPlaying;
@@ -57,6 +57,7 @@ public:
virtual void Pause();
virtual void Stop();
virtual void SetPosition( float fSeconds );
virtual void SetPlaybackRate( float fRate );
virtual bool IsPlaying() const;
void SetLooping(bool looping=true) { m_bLoop = looping; }
+6 -2
View File
@@ -41,10 +41,14 @@ struct StopSegment
struct BackgroundChange
{
BackgroundChange() { m_fStartBeat = -1; };
BackgroundChange( float s, CString sBGName ) { m_fStartBeat = s; m_sBGName = sBGName; };
BackgroundChange() { m_fStartBeat=-1; m_fRate=1; m_bFadeLast=false; m_bRewindMovie=false; m_bLoop=true; };
BackgroundChange( float s, CString n, float r=1.f, bool f=false, bool m=false, bool l=true ) { m_fStartBeat=s; m_sBGName=n; m_fRate=r; m_bFadeLast=f; m_bRewindMovie=m; m_bLoop=l; };
float m_fStartBeat;
CString m_sBGName;
float m_fRate;
bool m_bFadeLast;
bool m_bRewindMovie;
bool m_bLoop;
};
void SortBackgroundChangesArray( vector<BackgroundChange> &arrayBackgroundChanges );