Random background movie support

This commit is contained in:
Chris Danford
2002-07-31 22:37:58 +00:00
parent 4ec08edf2d
commit 4f732aaa5b
11 changed files with 127 additions and 40 deletions
+71 -7
View File
@@ -21,6 +21,7 @@
const CString BG_ANIMS_DIR = "BGAnimations\\";
const CString VISUALIZATIONS_DIR = "Visualizations\\";
const CString RANDOMMOVIES_DIR = "RandomMovies\\";
int CompareAnimSegs(const void *arg1, const void *arg2)
@@ -65,6 +66,9 @@ Background::Background()
m_quadBGBrightness.StretchTo( CRect(SCREEN_LEFT, SCREEN_TOP, SCREEN_RIGHT, SCREEN_BOTTOM) );
m_quadBGBrightness.SetDiffuseColor( D3DXCOLOR(0,0,0,1-0.5f) );
m_pCurBGA = NULL;
m_iCurAnimSegment = -1;
}
Background::~Background()
@@ -90,6 +94,8 @@ bool Background::LoadFromSong( Song* pSong, bool bDisableVisualizations )
m_BackgroundMode = MODE_MOVIE_BG;
else if( PREFSMAN->m_BackgroundMode == PrefsManager::BGMODE_MOVIEVIS )
m_BackgroundMode = MODE_MOVIE_VIS;
else if( PREFSMAN->m_BackgroundMode == PrefsManager::BGMODE_RANDOMMOVIES )
m_BackgroundMode = MODE_RANDOMMOVIES;
else
m_BackgroundMode = MODE_ANIMATIONS;
@@ -197,6 +203,33 @@ bool Background::LoadFromSong( Song* pSong, bool bDisableVisualizations )
}
}
break;
case MODE_RANDOMMOVIES:
{
CStringArray asMovieNames;
GetDirListing( RANDOMMOVIES_DIR + "*.avi", asMovieNames );
GetDirListing( RANDOMMOVIES_DIR + "*.mpg", asMovieNames );
GetDirListing( RANDOMMOVIES_DIR + "*.mpeg", asMovieNames );
for( int i=0; i<min(asMovieNames.GetSize(),8); i++ ) // only load up to 8 background because they take a long time to load
{
CString sMovieName = asMovieNames[rand()%asMovieNames.GetSize()];
m_BackgroundAnimations.Add( new BackgroundAnimation(RANDOMMOVIES_DIR+sMovieName, NULL) );
}
if( m_BackgroundAnimations.GetSize() == 0 )
break;
// Generate a plan.
for( int i=0; i<pSong->m_fLastBeat; i+=16 )
m_aAnimSegs.Add( AnimSeg((float)i,rand()%m_BackgroundAnimations.GetSize()) ); // change BG every 4 bars
for( i=0; i<pSong->m_BPMSegments.GetSize(); i++ )
{
const BPMSegment& bpmseg = pSong->m_BPMSegments[i];
m_aAnimSegs.Add( AnimSeg(bpmseg.m_fStartBeat,int(bpmseg.m_fBPM)%m_BackgroundAnimations.GetSize()) ); // change BG every BPM change
}
SortAnimSegArray( m_aAnimSegs );
}
break;
default:
ASSERT(0);
}
@@ -234,8 +267,33 @@ void Background::Update( float fDeltaTime )
m_sprMovieVis.Update( fDeltaTime );
break;
case MODE_ANIMATIONS:
if( GetCurBGA() )
GetCurBGA()->Update( fDeltaTime, m_fSongBeat );
case MODE_RANDOMMOVIES:
{
// Find the AnimSeg we're in
for( int i=0; i<m_aAnimSegs.GetSize()-1; i++ )
if( m_aAnimSegs[i+1].m_fStartBeat > m_fSongBeat )
break;
int iNewAnimationSegment = i;
if( iNewAnimationSegment > m_iCurAnimSegment )
{
m_iCurAnimSegment = iNewAnimationSegment;
if( m_pCurBGA )
m_pCurBGA->LosingFocus();
if( i > m_aAnimSegs.GetSize() )
{
m_pCurBGA = NULL;
}
else
{
int iNewAnimIndex = m_aAnimSegs[i].m_iAnimationIndex;
m_pCurBGA = m_BackgroundAnimations[iNewAnimIndex];
m_pCurBGA->GainingFocus();
}
}
if( m_pCurBGA )
m_pCurBGA->Update( fDeltaTime, m_fSongBeat );
}
break;
default:
ASSERT(0);
@@ -258,7 +316,6 @@ void Background::DrawPrimitives()
{
ActorFrame::DrawPrimitives();
if( DangerVisible() )
{
m_sprDangerBackground.Draw();
@@ -273,19 +330,26 @@ void Background::DrawPrimitives()
m_sprSongBackground.Draw();
break;
case MODE_MOVIE_BG:
::Sleep(4); // let the movie decode a frame
::Sleep(2); // let the movie decode a frame
m_sprMovieBackground.Draw();
break;
case MODE_MOVIE_VIS:
m_sprSongBackground.Draw();
::Sleep(4); // let the movie decode a frame
::Sleep(2); // let the movie decode a frame
m_sprMovieVis.Draw();
break;
case MODE_ANIMATIONS:
if( GetCurBGA() )
GetCurBGA()->Draw();
case MODE_RANDOMMOVIES:
if( m_pCurBGA )
{
if( m_pCurBGA->IsAMovie() )
::Sleep(2); // let the movie decode a frame
m_pCurBGA->Draw();
}
else
{
m_sprSongBackground.Draw();
}
break;
default:
ASSERT(0);
+3 -15
View File
@@ -55,7 +55,7 @@ protected:
Song* m_pSong;
enum BackgroundMode { MODE_STATIC_BG, MODE_MOVIE_BG, MODE_ANIMATIONS, MODE_MOVIE_VIS };
enum BackgroundMode { MODE_STATIC_BG, MODE_MOVIE_BG, MODE_ANIMATIONS, MODE_MOVIE_VIS, MODE_RANDOMMOVIES };
BackgroundMode m_BackgroundMode;
Sprite m_sprSongBackground;
@@ -69,20 +69,8 @@ protected:
// for animations
CArray<BackgroundAnimation*,BackgroundAnimation*> m_BackgroundAnimations;
CArray<AnimSeg,AnimSeg&> m_aAnimSegs;
BackgroundAnimation* GetCurBGA()
{
if( m_aAnimSegs.GetSize() == 0 )
return NULL;
if( m_fSongBeat < m_pSong->m_fFirstBeat || m_fSongBeat > m_pSong->m_fLastBeat )
return NULL;
for( int i=0; i<m_aAnimSegs.GetSize()-1; i++ )
if( m_aAnimSegs[i+1].m_fStartBeat > m_fSongBeat )
break;
int iIndex = m_aAnimSegs[i].m_iAnimationIndex;
return m_BackgroundAnimations[iIndex];
};
BackgroundAnimation* m_pCurBGA;
int m_iCurAnimSegment; // this increases as we move into new segments
// for movie vis
+30
View File
@@ -15,6 +15,7 @@
#include "GameManager.h"
#include "RageException.h"
#include "RageTimer.h"
#include "InputMapper.h"
InputQueue* INPUTQUEUE = NULL; // global and accessable from anywhere in our program
@@ -34,6 +35,35 @@ void InputQueue::RememberInput( const GameInput GameI )
m_aQueue[c].Add( GameButtonAndTime(GameI.button,TIMER->GetTimeSinceStart()) );
};
bool InputQueue::MatchesPattern( const GameController c, const MenuButton* button_sequence, const int iNumButtons, float fMaxSecondsBack )
{
if( fMaxSecondsBack == -1 )
fMaxSecondsBack = 0.4f + iNumButtons*0.15f;
float fOldestTimeAllowed = TIMER->GetTimeSinceStart() - fMaxSecondsBack;
int sequence_index = iNumButtons-1; // count down
for( int queue_index=m_aQueue[c].GetSize()-1; queue_index>=0; queue_index-- ) // iterate newest to oldest
{
GameButtonAndTime BandT = m_aQueue[c][queue_index];
GameInput GameI( c, BandT.button );
MenuInput MenuI;
INPUTMAPPER->GameToMenu( GameI, MenuI );
if( MenuI.button != button_sequence[sequence_index] ||
BandT.fTime < fOldestTimeAllowed )
{
return false;
}
if( sequence_index == 0 ) // we matched the whole pattern
{
m_aQueue[c].RemoveAll(); // empty the queue so we don't match on it again
return true;
}
sequence_index--;
}
return false;
}
bool InputQueue::MatchesPattern( const GameController c, const GameButton* button_sequence, const int iNumButtons, float fMaxSecondsBack )
{
if( fMaxSecondsBack == -1 )
+2 -1
View File
@@ -12,6 +12,7 @@
#include "GameConstantsAndTypes.h"
#include "GameInput.h"
#include "MenuInput.h"
const int MAX_INPUT_QUEUE_LENGTH = 8;
@@ -22,7 +23,7 @@ public:
void RememberInput( GameInput );
bool MatchesPattern( const GameController c, const GameButton* button_sequence, const int iNumButtons, float fMaxSecondsBack = -1 );
bool MatchesPattern( const GameController c, const MenuButton* button_sequence, const int iNumButtons, float fMaxSecondsBack = -1 );
protected:
struct GameButtonAndTime
+1 -1
View File
@@ -842,7 +842,7 @@ void MusicWheel::Update( float fDeltaTime )
{
if ( m_bUseRandomExtra )
{
MUSIC->Stop;
MUSIC->Stop();
m_soundExpand.Play();
m_WheelState = STATE_ROULETTE_SPINNING;
m_SortOrder = SORT_GROUP;
+1 -1
View File
@@ -24,7 +24,7 @@ public:
PrefsManager();
~PrefsManager();
enum BackgroundMode { BGMODE_OFF, BGMODE_ANIMATIONS, BGMODE_MOVIEVIS };
enum BackgroundMode { BGMODE_OFF, BGMODE_ANIMATIONS, BGMODE_MOVIEVIS, BGMODE_RANDOMMOVIES };
// GameOptions (ARE saved between sessions)
bool m_bWindowed;
+2
View File
@@ -43,6 +43,8 @@ public:
);
virtual LPDIRECT3DTEXTURE8 GetD3DTexture();
virtual bool IsAMovie() { return true; };
protected:
virtual void Create(
+1
View File
@@ -99,6 +99,7 @@ public:
virtual void Play();
virtual void SetPosition( float fSeconds );
virtual void Pause();
virtual bool IsAMovie() { return true; };
LPDIRECT3DTEXTURE8 m_pd3dTexture[2]; // double buffered
int m_iIndexActiveTexture; // either 0 or 1
+1
View File
@@ -63,6 +63,7 @@ public:
virtual void Play() {};
virtual void SetPosition( float fSeconds ) {};
virtual void Pause() {};
virtual bool IsAMovie() = 0;
int GetSourceWidth() {return m_iSourceWidth;};
int GetSourceHeight() {return m_iSourceHeight;};
+14 -14
View File
@@ -1,11 +1,12 @@
#include "stdafx.h"
/*
-----------------------------------------------------------------------------
File: ScreenOptions.h
Class: ScreenOptions
Desc: Select a song.
Desc: See header.
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
@@ -23,16 +24,15 @@
const float HEADER_X = CENTER_X;
const float HEADER_Y = 50;
const float HELP_X = CENTER_X;
const float HELP_Y = SCREEN_HEIGHT-35;
const float ITEM_GAP_X = 12;
const float LABELS_X = 80;
const float LINE_START_Y= 80;
const float LINE_GAP_Y = 34;
const float HEADER_X = CENTER_X;
const float HEADER_Y = 50;
const float HELP_X = CENTER_X;
const float HELP_Y = SCREEN_HEIGHT-35;
const float ITEM_GAP_X = 14;
const float LABELS_X = 80;
const float LINE_START_Y = 80;
const float LINE_GAP_Y = 34;
const float ITEMS_START_X = 160;
const ScreenMessage SM_PlaySample = ScreenMessage(SM_User-4);
const ScreenMessage SM_GoToPrevState = ScreenMessage(SM_User-5);
@@ -152,7 +152,7 @@ void ScreenOptions::InitOptionsText()
this->AddSubActor( &title );
// init all text in this line and count the width of the line
float fX = 150; // indent 70 pixels
float fX = ITEMS_START_X; // indent 70 pixels
for( int j=0; j<optline.iNumOptions; j++ ) // for each option on this line
{
BitmapText &option = m_textOptions[i][j];
@@ -160,7 +160,7 @@ void ScreenOptions::InitOptionsText()
option.Load( THEME->GetPathTo(FONT_NORMAL) );
option.SetDiffuseColor( D3DXCOLOR(1,1,1,1) );
option.SetText( optline.szOptionsText[j] );
option.SetZoom( 0.65f );
option.SetZoom( 0.5f );
option.SetShadowLength( 2 );
this->AddSubActor( &option );
+1 -1
View File
@@ -65,7 +65,7 @@ const float DIFFICULTY_ARROW_X[NUM_DIFFICULTY_ITEMS][NUM_PLAYERS] = {
const float ARROW_SHADOW_OFFSET = 10;
const float LOCK_INPUT_TIME = 0.75f; // lock input while waiting for tweening to complete
const float LOCK_INPUT_TIME = 0.50f; // lock input while waiting for tweening to complete
const ScreenMessage SM_GoToPrevState = ScreenMessage(SM_User + 1);