Files
itgmania212121/stepmania/src/Transition.cpp
T

118 lines
2.6 KiB
C++
Raw Normal View History

2003-03-05 08:48:35 +00:00
#include "global.h"
/*
-----------------------------------------------------------------------------
2003-04-13 02:33:11 +00:00
Class: Transition
2003-03-05 08:48:35 +00:00
Desc: See header
Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved.
Chris Danford
-----------------------------------------------------------------------------
*/
2003-04-13 02:33:11 +00:00
#include "Transition.h"
2003-03-05 08:48:35 +00:00
#include "RageUtil.h"
#include "ScreenManager.h"
#include "IniFile.h"
2003-07-22 07:47:27 +00:00
#include "RageFile.h"
2003-03-05 08:48:35 +00:00
2003-04-13 02:33:11 +00:00
Transition::Transition()
2003-03-05 08:48:35 +00:00
{
2003-04-13 00:44:50 +00:00
m_State = waiting;
2003-03-05 08:48:35 +00:00
m_fSecsIntoTransition = 0.0f;
}
2003-04-13 02:33:11 +00:00
void Transition::Load( CString sBGAniDir )
2003-03-05 08:48:35 +00:00
{
2003-07-22 07:47:27 +00:00
if( !sBGAniDir.empty() && sBGAniDir.Right(1) != SLASH )
sBGAniDir += SLASH;
2003-03-05 08:48:35 +00:00
m_BGAnimation.LoadFromAniDir( sBGAniDir );
2003-03-09 00:55:49 +00:00
2003-04-13 00:44:50 +00:00
m_State = waiting;
m_fSecsIntoTransition = 0.0f;
// load sound from file specified by ini, or use the first sound in the directory
IniFile ini;
ini.SetPath( sBGAniDir+"BGAnimation.ini" );
ini.ReadFile();
CString sSoundFileName;
if( ini.GetValue("BGAnimation","Sound",sSoundFileName) )
2003-07-22 07:47:27 +00:00
{
FixSlashesInPlace( sSoundFileName );
CString sPath = sBGAniDir+sSoundFileName;
CollapsePath( sPath );
m_sound.Load( sPath );
}
else
2003-07-22 07:47:27 +00:00
{
m_sound.Load( sBGAniDir );
2003-07-22 07:47:27 +00:00
}
2003-03-05 08:48:35 +00:00
}
2003-04-13 02:33:11 +00:00
void Transition::Update( float fDeltaTime )
2003-03-05 08:48:35 +00:00
{
Actor::Update( fDeltaTime );
if( m_State == transitioning )
{
/* 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;
}
2003-03-05 08:48:35 +00:00
m_BGAnimation.Update( fDeltaTime );
if( m_fSecsIntoTransition > m_BGAnimation.GetLengthSeconds() ) // over
{
SCREENMAN->SendMessageToTopScreen( m_MessageToSendWhenDone );
2003-03-05 08:48:35 +00:00
m_fSecsIntoTransition = 0.0;
m_State = finished;
}
else
m_fSecsIntoTransition += fDeltaTime;
2003-03-05 08:48:35 +00:00
}
}
2003-04-13 02:33:11 +00:00
void Transition::DrawPrimitives()
2003-03-05 08:48:35 +00:00
{
2003-04-13 00:44:50 +00:00
// Unless we're transitioning, don't draw because we'll waste resources drawing things
// that aren't visible. -Chris
switch( m_State )
{
2003-04-13 21:17:14 +00:00
case waiting:
return;
case finished:
2003-04-13 00:44:50 +00:00
return;
}
2003-04-13 00:44:50 +00:00
m_BGAnimation.Draw();
2003-03-05 08:48:35 +00:00
}
2003-04-13 02:33:11 +00:00
void Transition::StartTransitioning( ScreenMessage send_when_done )
2003-03-05 08:48:35 +00:00
{
2003-04-24 06:16:04 +00:00
if( m_State != waiting )
{
// This assert will trigger in some cases if start is pressed
// right as a transition is ending. We want to know about these
// problems in debug builds, but they're not fatal.
DEBUG_ASSERT( m_State == waiting ); // can't call this more than once
return; // ignore
}
2003-03-05 08:48:35 +00:00
m_MessageToSendWhenDone = send_when_done;
m_State = transitioning;
m_fSecsIntoTransition = 0.0;
}
2003-04-13 02:33:11 +00:00
float Transition::GetLengthSeconds()
2003-03-09 00:55:49 +00:00
{
return m_BGAnimation.GetLengthSeconds();
}