Files
itgmania212121/stepmania/src/BGAnimation.cpp
T

285 lines
7.4 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-09-29 05:06:18 +00:00
/*
-----------------------------------------------------------------------------
Class: BGAnimation
Desc: Particles used initially for background effects
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Ben Nordstrom
Chris Danford
-----------------------------------------------------------------------------
*/
#include "BGAnimation.h"
#include "PrefsManager.h"
#include "GameState.h"
#include "IniFile.h"
#include "BGAnimationLayer.h"
2003-03-05 02:52:40 +00:00
#include "RageUtil.h"
2003-03-10 05:07:00 +00:00
#include "song.h"
#include "ThemeManager.h"
2003-10-14 17:05:10 +00:00
#include "RageFile.h"
2003-10-31 01:55:17 +00:00
#include "ActorUtil.h"
2002-09-29 05:06:18 +00:00
2003-10-24 07:24:12 +00:00
const int MAX_LAYERS = 1000;
2002-09-29 05:06:18 +00:00
BGAnimation::BGAnimation( bool Generic )
2002-09-29 05:06:18 +00:00
{
/* See BGAnimationLayer::BGAnimationLayer for explanation. */
m_bGeneric = Generic;
2003-03-05 02:52:40 +00:00
m_fLengthSeconds = 10;
2002-09-29 05:06:18 +00:00
}
BGAnimation::~BGAnimation()
{
Unload();
}
void BGAnimation::Unload()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
delete m_Layers[i];
2002-10-24 20:15:24 +00:00
m_Layers.clear();
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LoadFromStaticGraphic( CString sPath )
{
Unload();
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
2002-09-29 05:06:18 +00:00
pLayer->LoadFromStaticGraphic( sPath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
}
void AddLayersFromAniDir( CString sAniDir, vector<BGAnimationLayer*> &layersAddTo, bool Generic )
2002-09-29 05:06:18 +00:00
{
2003-10-14 17:05:10 +00:00
if( sAniDir.empty() )
return;
2002-09-29 05:06:18 +00:00
2003-12-10 09:44:16 +00:00
if( sAniDir.Right(1) != "/" )
sAniDir += "/";
2002-09-29 05:06:18 +00:00
2003-09-03 18:10:26 +00:00
RAGE_ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
2002-09-29 05:06:18 +00:00
2003-03-05 02:52:40 +00:00
CString sPathToIni = sAniDir + "BGAnimation.ini";
2002-09-29 05:06:18 +00:00
2003-10-14 17:05:10 +00:00
IniFile ini(sPathToIni);
ini.ReadFile();
int i;
for( i=0; i<MAX_LAYERS; i++ )
2002-09-29 05:06:18 +00:00
{
2003-10-14 17:05:10 +00:00
CString sLayer = ssprintf("Layer%d",i+1);
const IniFile::key* pKey = ini.GetKey( sLayer );
if( pKey == NULL )
continue; // skip
2003-03-05 02:52:40 +00:00
2003-10-14 17:05:10 +00:00
CString sImportDir;
if( ini.GetValue(sLayer, "Import", sImportDir) )
2003-03-05 02:52:40 +00:00
{
2003-10-14 17:05:10 +00:00
// import a whole BGAnimation
sImportDir = sAniDir + sImportDir;
CollapsePath( sImportDir );
AddLayersFromAniDir( sImportDir, layersAddTo, Generic );
2003-10-14 17:05:10 +00:00
}
else
{
2004-01-26 02:32:09 +00:00
// import as a single layer
BGAnimationLayer* pLayer = new BGAnimationLayer( Generic );
pLayer->LoadFromIni( sAniDir, sLayer );
2003-10-14 17:05:10 +00:00
layersAddTo.push_back( pLayer );
2003-03-05 02:52:40 +00:00
}
2003-10-14 17:05:10 +00:00
}
}
2003-10-14 17:05:10 +00:00
void BGAnimation::LoadFromAniDir( CString sAniDir )
{
Unload();
if( sAniDir.empty() )
return;
2003-12-10 09:44:16 +00:00
if( sAniDir.Right(1) != "/" )
sAniDir += "/";
2003-10-14 17:05:10 +00:00
RAGE_ASSERT_M( IsADirectory(sAniDir), sAniDir + " isn't a directory" );
CString sPathToIni = sAniDir + "BGAnimation.ini";
if( DoesFileExist(sPathToIni) )
{
// This is a new style BGAnimation (using .ini)
AddLayersFromAniDir( sAniDir, m_Layers, m_bGeneric ); // TODO: Check for circular load
2003-10-14 17:05:10 +00:00
IniFile ini(sPathToIni);
ini.ReadFile();
2003-10-02 02:03:29 +00:00
if( !ini.GetValue( "BGAnimation", "LengthSeconds", m_fLengthSeconds ) )
{
m_fLengthSeconds = 0;
2003-10-14 17:05:10 +00:00
for( int i=0; (unsigned)i < m_Layers.size(); i++ )
m_fLengthSeconds = max(m_fLengthSeconds, m_Layers[i]->GetMaxTweenTimeLeft());
}
2004-01-07 00:13:59 +00:00
2004-01-25 22:22:40 +00:00
bool bUseScroller;
if( ini.GetValue( "BGAnimation", "UseScroller", bUseScroller ) && bUseScroller )
{
#define REQUIRED_GET_VALUE( szName, valueOut ) \
if( !ini.GetValue( "BGAnimation", szName, valueOut ) ) \
RageException::Throw( "File '%s' is missing the value BGAnimation::%s", sPathToIni.c_str(), szName );
2004-01-26 02:32:09 +00:00
float fScrollSecondsPerItem, fSpacingX, fSpacingY, fItemPaddingStart, fItemPaddingEnd;
2004-01-25 22:22:40 +00:00
REQUIRED_GET_VALUE( "ScrollSecondsPerItem", fScrollSecondsPerItem );
REQUIRED_GET_VALUE( "ScrollSpacingX", fSpacingX );
REQUIRED_GET_VALUE( "ScrollSpacingY", fSpacingY );
2004-01-26 02:32:09 +00:00
REQUIRED_GET_VALUE( "ItemPaddingStart", fItemPaddingStart );
REQUIRED_GET_VALUE( "ItemPaddingEnd", fItemPaddingEnd );
2004-01-25 22:22:40 +00:00
#undef REQUIRED_GET_VALUE
m_Scroller.Load( fScrollSecondsPerItem, fSpacingX, fSpacingY );
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Scroller.AddChild( m_Layers[i] );
2004-01-26 02:32:09 +00:00
m_Scroller.SetCurrentAndDestinationItem( -fItemPaddingStart );
m_Scroller.SetDestinationItem( m_Layers.size()-1+fItemPaddingEnd );
2004-01-25 22:22:40 +00:00
this->AddChild( &m_Scroller );
}
2004-01-07 00:13:59 +00:00
CString InitCommand;
if( ini.GetValue( "BGAnimation", "InitCommand", InitCommand ) )
{
/* There's an InitCommand. Run it now. This can be used to eg. change Z to
* modify draw order between BGAs in a Foreground. Most things should be done
* in metrics.ini commands, not here. */
this->Command( InitCommand );
}
2003-03-05 02:52:40 +00:00
}
else
{
// This is an old style BGAnimation (not using .ini)
// loading a directory of layers
CStringArray asImagePaths;
ASSERT( sAniDir != "" );
GetDirListing( sAniDir+"*.png", asImagePaths, false, true );
GetDirListing( sAniDir+"*.jpg", asImagePaths, false, true );
GetDirListing( sAniDir+"*.gif", asImagePaths, false, true );
GetDirListing( sAniDir+"*.avi", asImagePaths, false, true );
GetDirListing( sAniDir+"*.mpg", asImagePaths, false, true );
GetDirListing( sAniDir+"*.mpeg", asImagePaths, false, true );
GetDirListing( sAniDir+"*.sprite", asImagePaths, false, true );
SortCStringArray( asImagePaths );
for( unsigned i=0; i<asImagePaths.size(); i++ )
{
const CString sPath = asImagePaths[i];
2003-10-29 20:32:29 +00:00
if( Basename(sPath).Left(1) == "_" )
2003-03-05 02:52:40 +00:00
continue; // don't directly load files starting with an underscore
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
pLayer->LoadFromAniLayerFile( asImagePaths[i] );
2003-03-05 02:52:40 +00:00
m_Layers.push_back( pLayer );
}
2002-09-29 05:06:18 +00:00
}
}
void BGAnimation::LoadFromMovie( CString sMoviePath )
2002-09-29 05:06:18 +00:00
{
Unload();
BGAnimationLayer* pLayer = new BGAnimationLayer( m_bGeneric );
pLayer->LoadFromMovie( sMoviePath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LoadFromVisualization( CString sVisPath )
2002-09-29 05:06:18 +00:00
{
Unload();
BGAnimationLayer* pLayer;
2003-10-30 20:50:31 +00:00
const Song* pSong = GAMESTATE->m_pCurSong;
CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathToG("Common fallback background");
pLayer = new BGAnimationLayer( m_bGeneric );
2002-09-29 05:06:18 +00:00
pLayer->LoadFromStaticGraphic( sSongBGPath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
pLayer = new BGAnimationLayer( m_bGeneric );
2002-09-29 05:06:18 +00:00
pLayer->LoadFromVisualization( sVisPath );
2002-10-31 04:23:39 +00:00
m_Layers.push_back( pLayer );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::Update( float fDeltaTime )
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->Update( fDeltaTime );
ActorFrame::Update( fDeltaTime );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::DrawPrimitives()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->Draw();
}
void BGAnimation::GainingFocus( float fRate, bool bRewindMovie, bool bLoop )
2002-09-29 05:06:18 +00:00
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->GainingFocus( fRate, bRewindMovie, bLoop );
SetDiffuse( RageColor(1,1,1,1) );
2002-09-29 05:06:18 +00:00
}
void BGAnimation::LosingFocus()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2002-09-29 05:06:18 +00:00
m_Layers[i]->LosingFocus();
}
void BGAnimation::SetDiffuse( const RageColor &c )
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->SetDiffuse(c);
ActorFrame::SetDiffuse( c );
2003-07-10 03:37:13 +00:00
}
2003-10-31 01:55:17 +00:00
float BGAnimation::GetTweenTimeLeft() const
{
float ret = 0;
2003-10-31 01:55:17 +00:00
2003-10-31 03:53:48 +00:00
for( unsigned i=0; i<m_Layers.size(); ++i )
ret = max( ret, m_Layers[i]->GetMaxTweenTimeLeft() );
2003-10-31 01:55:17 +00:00
return max( ret, Actor::GetTweenTimeLeft() );
2003-10-31 01:55:17 +00:00
}
2003-11-05 02:23:21 +00:00
void BGAnimation::FinishTweening()
{
for( unsigned i=0; i<m_Layers.size(); i++ )
m_Layers[i]->FinishTweening();
ActorFrame::FinishTweening();
2003-11-05 02:23:21 +00:00
}
2003-10-31 01:55:17 +00:00
void BGAnimation::PlayCommand( const CString &cmd )
2003-07-10 03:37:13 +00:00
{
for( unsigned i=0; i<m_Layers.size(); i++ )
2003-10-31 01:55:17 +00:00
m_Layers[i]->PlayCommand( cmd );
2003-07-10 03:37:13 +00:00
}
2003-10-31 01:55:17 +00:00
void BGAnimation::HandleCommand( const ParsedCommand &command )
2003-10-31 01:55:17 +00:00
{
HandleParams;
if( sParam(0)=="playcommand" ) PlayCommand( sParam(1) );
2003-10-31 01:55:17 +00:00
else
{
Actor::HandleCommand( command );
2003-10-31 01:55:17 +00:00
return;
}
CheckHandledParams;
}