#include "global.h" /* ----------------------------------------------------------------------------- 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 "BGAnimationLayer.h" #include "PrefsManager.h" #include "GameState.h" #include "IniFile.h" #include "RageMath.h" #include "SDL_utils.h" #include #include "RageTimer.h" #include "RageLog.h" #include "song.h" #include "ThemeManager.h" inline float GetOffScreenLeft( Actor* pActor ) { return SCREEN_LEFT - pActor->GetZoomedWidth()/2; } inline float GetOffScreenRight( Actor* pActor ) { return SCREEN_RIGHT + pActor->GetZoomedWidth()/2; } inline float GetOffScreenTop( Actor* pActor ) { return SCREEN_TOP - pActor->GetZoomedHeight()/2; } inline float GetOffScreenBottom(Actor* pActor ) { return SCREEN_BOTTOM+ pActor->GetZoomedHeight()/2; } inline bool IsOffScreenLeft( Actor* pActor ) { return pActor->GetX() < GetOffScreenLeft(pActor); } inline bool IsOffScreenRight( Actor* pActor ) { return pActor->GetX() > GetOffScreenRight(pActor); } inline bool IsOffScreenTop( Actor* pActor ) { return pActor->GetY() < GetOffScreenTop(pActor); } inline bool IsOffScreenBottom(Actor* pActor ) { return pActor->GetY() > GetOffScreenBottom(pActor); } // guard rail is the area that keeps particles from going off screen inline float GetGuardRailLeft( Actor* pActor ) { return SCREEN_LEFT + pActor->GetZoomedWidth()/2; } inline float GetGuardRailRight( Actor* pActor ) { return SCREEN_RIGHT - pActor->GetZoomedWidth()/2; } inline float GetGuardRailTop( Actor* pActor ) { return SCREEN_TOP + pActor->GetZoomedHeight()/2; } inline float GetGuardRailBottom(Actor* pActor ) { return SCREEN_BOTTOM- pActor->GetZoomedHeight()/2; } inline bool HitGuardRailLeft( Actor* pActor ) { return pActor->GetX() < GetGuardRailLeft(pActor); } inline bool HitGuardRailRight( Actor* pActor ) { return pActor->GetX() > GetGuardRailRight(pActor); } inline bool HitGuardRailTop( Actor* pActor ) { return pActor->GetY() < GetGuardRailTop(pActor); } inline bool HitGuardRailBottom(Actor* pActor ) { return pActor->GetY() > GetGuardRailBottom(pActor); } const float PARTICLE_SPEED = 300; const float SPIRAL_MAX_ZOOM = 2; const float SPIRAL_MIN_ZOOM = 0.3f; BGAnimationLayer::BGAnimationLayer() { Init(); } void BGAnimationLayer::Init() { // m_bCycleColor = false; // m_bCycleAlpha = false; // m_Effect = EFFECT_STRETCH_STILL; for( int i=0; iPlay(); SDL_Delay( 50 ); // decode a frame so we don't see a black flash at the beginning m_Sprites[0].GetTexture()->Pause(); m_bRewindMovie = bRewind; if( !bLoop ) m_Sprites[0].GetTexture()->SetLooping(false); } void BGAnimationLayer::LoadFromVisualization( CString sMoviePath ) { Init(); m_iNumSprites = 1; m_Sprites[0].LoadBG( sMoviePath ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].EnableAdditiveBlend( true ); } void BGAnimationLayer::LoadFromAniLayerFile( CString sPath ) { Song* pSong = GAMESTATE->m_pCurSong; CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathTo("Graphics","Common fallback background"); Init(); CString lcPath = sPath; lcPath.MakeLower(); if( lcPath.Find("usesongbg") != -1 ) { LoadFromStaticGraphic( sSongBGPath ); return; // this will ignore other effects in the file name } const CString EFFECT_STRING[NUM_EFFECTS] = { "center", "stretchstill", "stretchscrollleft", "stretchscrollright", "stretchscrollup", "stretchscrolldown", "stretchwater", "stretchbubble", "stretchtwist", "stretchspin", "particlesspiralout", "particlesspiralin", "particlesfloatup", "particlesfloatdown", "particlesfloatleft", "particlesfloatright", "particlesbounce", "tilestill", "tilescrollleft", "tilescrollright", "tilescrollup", "tilescrolldown", "tileflipx", "tileflipy", "tilepulse", }; Effect effect = EFFECT_CENTER; for( int i=0; im_pCurSong; CString sSongBGPath = pSong && pSong->HasBackground() ? pSong->GetBackgroundPath() : THEME->GetPathTo("Graphics","Common fallback background"); Init(); if( sAniDir.Right(1) != "/" ) sAniDir += "/"; ASSERT( IsADirectory(sAniDir) ); CString sPathToIni = sAniDir + "BGAnimation.ini"; IniFile ini(sPathToIni); ini.ReadFile(); CString sFile; ini.GetValue( sLayer, "File", sFile ); bool bUseSongBG = false; ini.GetValueB( sLayer, "UseSongBG", bUseSongBG ); if( bUseSongBG ) sFile = sSongBGPath; if( sFile == "" ) RageException::Throw( "In the ini file for BGAnimation '%s', '%s' is missing a the line 'File='.", sAniDir.GetString(), sLayer.GetString() ); CString sPath = sAniDir+sFile; if( !DoesFileExist(sPath) ) RageException::Throw( "In the ini file for BGAnimation '%s', the specified File '%s' does not exist.", sAniDir.GetString(), sFile.GetString() ); ini.GetValueI( sLayer, "Type", (int&)m_Type ); 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 ); ini.GetValueF( sLayer, "VelocityXMax", m_fVelocityXMax ); ini.GetValueF( sLayer, "VelocityYMin", m_fVelocityYMin ); ini.GetValueF( sLayer, "VelocityYMax", m_fVelocityYMax ); ini.GetValueF( sLayer, "VelocityZMin", m_fVelocityZMin ); ini.GetValueF( sLayer, "VelocityZMax", m_fVelocityZMax ); ini.GetValueF( sLayer, "OverrideSpeed", m_fOverrideSpeed ); ini.GetValueI( sLayer, "NumParticles", m_iNumParticles ); ini.GetValueB( sLayer, "ParticlesBounce", m_bParticlesBounce ); // ini.GetValueI( sLayer, "NumTilesWide", m_iNumTilesWide ); // infer from spacing (or else the Update logic breaks) // ini.GetValueI( sLayer, "NumTilesHigh", m_iNumTilesHigh ); // infer from spacing (or else the Update logic breaks) ini.GetValueF( sLayer, "TilesStartX", m_fTilesStartX ); ini.GetValueF( sLayer, "TilesStartY", m_fTilesStartY ); ini.GetValueF( sLayer, "TilesSpacingX", m_fTilesSpacingX ); ini.GetValueF( sLayer, "TilesSpacingY", m_fTilesSpacingY ); ini.GetValueF( sLayer, "TileVelocityX", m_fTileVelocityX ); ini.GetValueF( sLayer, "TileVelocityY", m_fTileVelocityY ); switch( m_Type ) { case TYPE_SPRITE: m_iNumSprites = 1; m_Sprites[0].Load( sPath ); m_Sprites[0].SetXY( CENTER_X, CENTER_Y ); break; case TYPE_STRETCH: { m_iNumSprites = 1; RageTextureID ID(sPath); ID.bStretch = true; m_Sprites[0].LoadBG( ID ); m_Sprites[0].StretchTo( RectI(SCREEN_LEFT,SCREEN_TOP,SCREEN_RIGHT,SCREEN_BOTTOM) ); m_Sprites[0].SetCustomTextureRect( RectF(0,0,1,1) ); } break; case TYPE_PARTICLES: { m_iNumSprites = m_iNumParticles; for( unsigned i=0; im_fSongBeat; unsigned i; for( i=0; i SPIRAL_MAX_ZOOM ) m_Sprites[i].SetZoom( SPIRAL_MIN_ZOOM ); m_Sprites[i].SetRotationZ( m_Sprites[i].GetRotationZ() + fDeltaTime ); float fRadius = (m_Sprites[i].GetZoom()-SPIRAL_MIN_ZOOM); fRadius *= fRadius; fRadius *= 200; m_Sprites[i].SetX( CENTER_X + cosf(m_Sprites[i].GetRotationZ())*fRadius ); m_Sprites[i].SetY( CENTER_Y + sinf(m_Sprites[i].GetRotationZ())*fRadius ); } break; case EFFECT_PARTICLES_SPIRAL_IN: for( i=0; i0 && IsOffScreenRight(&m_Sprites[i]) ) m_Sprites[i].SetX( GetOffScreenLeft(&m_Sprites[i]) ); if( m_vParticleVelocity[i].y<0 && IsOffScreenTop(&m_Sprites[i]) ) m_Sprites[i].SetY( GetOffScreenBottom(&m_Sprites[i]) ); if( m_vParticleVelocity[i].y>0 && IsOffScreenBottom(&m_Sprites[i]) ) m_Sprites[i].SetY( GetOffScreenTop(&m_Sprites[i]) ); } } break; case TYPE_TILES: { float fSecs = RageTimer::GetTimeSinceStart(); float fTotalWidth = m_iNumTilesWide * m_fTilesSpacingX; float fTotalHeight = m_iNumTilesHigh * m_fTilesSpacingY; ASSERT( int(m_iNumSprites) == m_iNumTilesWide * m_iNumTilesHigh ); for( int x=0; x m_TweenY) // passed the location we wanna go to? { m_Sprites[0].SetY(m_TweenY); // set it to the exact location we want m_TweenPassedY = 1; // say we passed it. } } else // travelling up { m_Sprites[0].SetY(m_Sprites[0].GetY() - ((m_TweenY + m_PosY)/(m_TweenSpeed*60))); if(m_Sprites[0].GetY() < m_TweenY) { m_Sprites[0].SetY(m_TweenY); m_TweenPassedY = 1; } } } if(m_TweenPassedX != 1) // Check to see if we still need to Tween Along the X Axis { if(m_Sprites[0].GetX() < m_TweenX) // it needs to travel right { m_Sprites[0].SetX(m_Sprites[0].GetX() + ((m_TweenX - m_PosX)/(m_TweenSpeed*60))); if(m_Sprites[0].GetX() > m_TweenX) { m_Sprites[0].SetX(m_TweenX); m_TweenPassedX = 1; } } else // travelling left { m_Sprites[0].SetX(m_Sprites[0].GetX() - ((m_TweenX + m_PosX)/(m_TweenSpeed*60))); if(m_Sprites[0].GetX() < m_TweenX) { m_Sprites[0].SetX(m_TweenX); m_TweenPassedX = 1; } } } if(m_TweenPassedY == 1 && m_TweenPassedX == 1) // totally passed both X and Y? Stop tweening. { m_TweenState = 0; } } if(m_ShowTime != 0 && !(m_ShowTime < 0)) { m_ShowTime -= fDeltaTime; if(m_ShowTime <= 0) // if we've gone past the magic point... show the beast.... { m_Sprites[0].SetDiffuse( RageColor(1,1,1,1) ); } } if(m_HideTime != 0 && !(m_HideTime < 0)) // make sure it's not 0 or less than 0... { m_HideTime -= fDeltaTime; if(m_HideTime <= 0) // if we've gone past the magic point... hide the beast.... { m_Sprites[0].SetDiffuse( RageColor(0,0,0,0) ); } } */ } void BGAnimationLayer::Draw() { for( unsigned i=0; iSetPosition( 0 ); // 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(); for( unsigned i=0; iPause(); }