Files
itgmania212121/stepmania/src/BPMDisplay.cpp
T

279 lines
6.1 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2001-12-28 10:15:59 +00:00
#include "BPMDisplay.h"
#include "RageUtil.h"
2002-05-01 19:14:55 +00:00
#include "GameConstantsAndTypes.h"
2002-08-28 22:42:40 +00:00
#include "GameState.h"
2003-07-20 04:22:25 +00:00
#include "Course.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
2005-02-09 05:27:51 +00:00
#include "ActorUtil.h"
#include "CommonMetrics.h"
2005-09-03 06:13:30 +00:00
#include "song.h"
2001-12-28 10:15:59 +00:00
#include <limits.h>
2006-08-16 07:02:46 +00:00
REGISTER_ACTOR_CLASS( BPMDisplay )
BPMDisplay::BPMDisplay()
2001-12-28 10:15:59 +00:00
{
2003-07-20 04:22:25 +00:00
m_fBPMFrom = m_fBPMTo = 0;
m_iCurrentBPM = 0;
m_BPMS.push_back(0);
m_fPercentInState = 0;
m_fCycleTime = 1.0f;
}
2001-12-28 10:15:59 +00:00
void BPMDisplay::Load()
{
NORMAL_COLOR.Load( m_sName, "NormalColor");
CHANGE_COLOR.Load( m_sName, "ChangeColor" );
EXTRA_COLOR.Load( m_sName, "ExtraColor" );
CYCLE.Load( m_sName, "Cycle" );
SEPARATOR.Load( m_sName, "Separator" );
NO_BPM_TEXT.Load( m_sName, "NoBPMText" );
2006-08-16 07:20:45 +00:00
SetDiffuse( NORMAL_COLOR );
2001-12-28 10:15:59 +00:00
}
2006-08-16 07:02:46 +00:00
void BPMDisplay::LoadFromNode( const RString &sDir, const XNode *pNode )
{
2006-08-16 07:20:45 +00:00
BitmapText::LoadFromNode( sDir, pNode );
2006-08-16 07:02:46 +00:00
Load();
}
2003-07-20 04:22:25 +00:00
float BPMDisplay::GetActiveBPM() const
{
return m_fBPMTo + (m_fBPMFrom-m_fBPMTo)*m_fPercentInState;
}
2001-12-28 10:15:59 +00:00
void BPMDisplay::Update( float fDeltaTime )
{
2006-08-16 07:20:45 +00:00
BitmapText::Update( fDeltaTime );
2003-07-20 04:22:25 +00:00
2005-02-02 05:25:43 +00:00
if( !(bool)CYCLE )
return;
2003-07-20 04:22:25 +00:00
if( m_BPMS.size() == 0 )
return; /* no bpm */
m_fPercentInState -= fDeltaTime / m_fCycleTime;
if( m_fPercentInState < 0 )
2001-12-28 10:15:59 +00:00
{
2003-03-30 19:30:54 +00:00
// go to next state
2003-07-20 04:22:25 +00:00
m_fPercentInState = 1; // reset timer
m_iCurrentBPM = (m_iCurrentBPM + 1) % m_BPMS.size();
m_fBPMFrom = m_fBPMTo;
m_fBPMTo = m_BPMS[m_iCurrentBPM];
if(m_fBPMTo == -1)
2001-12-28 10:15:59 +00:00
{
2003-07-20 04:22:25 +00:00
m_fBPMFrom = -1;
2006-08-16 07:20:45 +00:00
SetText( (RandomFloat(0,1)>0.90f) ? RString("xxx") : ssprintf("%03.0f",RandomFloat(0,600)) );
}
else if(m_fBPMFrom == -1)
{
2003-07-20 04:22:25 +00:00
m_fBPMFrom = m_fBPMTo;
}
2001-12-28 10:15:59 +00:00
}
2003-03-30 19:30:54 +00:00
2003-07-20 04:22:25 +00:00
if( m_fBPMTo != -1)
2001-12-28 10:15:59 +00:00
{
2003-07-20 04:22:25 +00:00
const float fActualBPM = GetActiveBPM();
2006-08-16 07:20:45 +00:00
SetText( ssprintf("%03.0f", fActualBPM) );
2001-12-28 10:15:59 +00:00
}
}
void BPMDisplay::SetBPMRange( const DisplayBpms &bpms )
2001-12-28 10:15:59 +00:00
{
ASSERT( !bpms.vfBpms.empty() );
m_BPMS.clear();
const vector<float> &BPMS = bpms.vfBpms;
2003-07-20 04:22:25 +00:00
bool AllIdentical = true;
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < BPMS.size(); ++i )
2003-07-20 04:22:25 +00:00
{
2003-07-21 20:11:13 +00:00
if( i > 0 && BPMS[i] != BPMS[i-1] )
2003-07-20 04:22:25 +00:00
AllIdentical = false;
}
2005-02-02 05:25:43 +00:00
if( !(bool)CYCLE )
{
int MinBPM = INT_MAX;
int MaxBPM = INT_MIN;
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < BPMS.size(); ++i )
{
MinBPM = min( MinBPM, (int) roundf(BPMS[i]) );
MaxBPM = max( MaxBPM, (int) roundf(BPMS[i]) );
}
if( MinBPM == MaxBPM )
2003-11-17 01:41:21 +00:00
{
if( MinBPM == -1 )
2006-08-16 07:20:45 +00:00
SetText( "..." ); // random
2003-11-17 01:41:21 +00:00
else
2006-08-16 07:20:45 +00:00
SetText( ssprintf("%i", MinBPM) );
2003-11-17 01:41:21 +00:00
}
else
{
2006-08-16 07:20:45 +00:00
SetText( ssprintf("%i%s%i", MinBPM, SEPARATOR.GetValue().c_str(), MaxBPM) );
}
}
else
{
2004-09-21 07:53:39 +00:00
for( unsigned i = 0; i < BPMS.size(); ++i )
{
m_BPMS.push_back(BPMS[i]);
if( BPMS[i] != -1 )
m_BPMS.push_back(BPMS[i]); /* hold */
}
m_iCurrentBPM = min(1u, m_BPMS.size()); /* start on the first hold */
m_fBPMFrom = BPMS[0];
m_fBPMTo = BPMS[0];
m_fPercentInState = 1;
}
2001-12-28 10:15:59 +00:00
2006-08-06 02:37:42 +00:00
if( GAMESTATE->IsAnExtraStage() )
2006-08-16 07:20:45 +00:00
SetDiffuse( EXTRA_COLOR );
2003-07-20 04:22:25 +00:00
else if( !AllIdentical )
2006-08-16 07:20:45 +00:00
SetDiffuse( CHANGE_COLOR );
2001-12-28 10:15:59 +00:00
else
2006-08-16 07:20:45 +00:00
SetDiffuse( NORMAL_COLOR );
2003-02-16 04:56:36 +00:00
}
2003-03-30 19:30:54 +00:00
void BPMDisplay::CycleRandomly()
{
DisplayBpms bpms;
bpms.Add(-1);
SetBPMRange( bpms );
2003-03-30 21:02:15 +00:00
2003-07-20 04:22:25 +00:00
m_fCycleTime = 0.2f;
2003-03-30 19:30:54 +00:00
}
void BPMDisplay::NoBPM()
{
2003-07-20 04:22:25 +00:00
m_BPMS.clear();
2006-08-16 07:20:45 +00:00
SetText( NO_BPM_TEXT );
SetDiffuse( NORMAL_COLOR );
2003-03-30 19:30:54 +00:00
}
void BPMDisplay::SetBpmFromSong( const Song* pSong )
{
ASSERT( pSong );
switch( pSong->m_DisplayBPMType )
{
case Song::DISPLAY_ACTUAL:
2003-07-20 04:22:25 +00:00
case Song::DISPLAY_SPECIFIED:
{
DisplayBpms bpms;
pSong->GetDisplayBpms( bpms );
SetBPMRange( bpms );
2003-07-20 05:08:32 +00:00
m_fCycleTime = 1.0f;
}
break;
case Song::DISPLAY_RANDOM:
2003-06-12 20:10:08 +00:00
CycleRandomly();
break;
default:
ASSERT(0);
}
2003-07-20 04:22:25 +00:00
}
void BPMDisplay::SetBpmFromCourse( const Course* pCourse )
2003-07-20 04:22:25 +00:00
{
2003-07-21 20:11:13 +00:00
ASSERT( pCourse );
2003-07-20 04:22:25 +00:00
2004-06-28 07:26:00 +00:00
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
Trail *pTrail = pCourse->GetTrail( st );
2004-06-03 21:34:11 +00:00
ASSERT( pTrail );
2003-07-20 04:22:25 +00:00
2006-08-16 07:02:46 +00:00
m_fCycleTime = 0.2f;
if( (int)pTrail->m_vEntries.size() > CommonMetrics::MAX_COURSE_ENTRIES_BEFORE_VARIOUS )
{
SetVarious();
return;
}
DisplayBpms bpms;
pTrail->GetDisplayBpms( bpms );
SetBPMRange( bpms );
}
void BPMDisplay::SetConstantBpm( float fBPM )
2004-12-18 08:15:19 +00:00
{
DisplayBpms bpms;
bpms.Add( fBPM );
SetBPMRange( bpms );
}
void BPMDisplay::SetVarious()
{
m_BPMS.clear();
m_BPMS.push_back( -1 );
2006-08-16 07:20:45 +00:00
SetText( "Various" );
}
2006-08-16 07:02:46 +00:00
void BPMDisplay::SetFromGameState()
{
if( GAMESTATE->m_pCurSong.Get() )
{
if( GAMESTATE->IsAnExtraStage() )
CycleRandomly();
else
SetBpmFromSong( GAMESTATE->m_pCurSong );
return;
}
if( GAMESTATE->m_pCurCourse.Get() )
{
SetBpmFromCourse( GAMESTATE->m_pCurCourse );
return;
}
NoBPM();
}
#include "LuaBinding.h"
class LunaBPMDisplay: public Luna<BPMDisplay>
{
public:
LunaBPMDisplay() { LUA->Register( Register ); }
static int SetFromGameState( T* p, lua_State *L ) { p->SetFromGameState(); return 0; }
static void Register(lua_State *L)
{
ADD_METHOD( SetFromGameState );
Luna<T>::Register( L );
}
};
2006-08-16 07:20:45 +00:00
LUA_REGISTER_DERIVED_CLASS( BPMDisplay, BitmapText )
2006-08-16 07:02:46 +00:00
2004-06-07 21:14:03 +00:00
/*
* (c) 2001-2002 Chris Danford
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/