Add course support.

This commit is contained in:
Glenn Maynard
2003-07-20 04:22:25 +00:00
parent afe284316f
commit 489e55d35c
2 changed files with 119 additions and 92 deletions
+108 -79
View File
@@ -15,6 +15,8 @@
#include "PrefsManager.h" #include "PrefsManager.h"
#include "GameState.h" #include "GameState.h"
#include "ThemeManager.h" #include "ThemeManager.h"
#include "Course.h"
#include "StyleDef.h"
#define NORMAL_COLOR THEME->GetMetricC("BPMDisplay","NormalColor") #define NORMAL_COLOR THEME->GetMetricC("BPMDisplay","NormalColor")
@@ -24,9 +26,11 @@
BPMDisplay::BPMDisplay() BPMDisplay::BPMDisplay()
{ {
m_fCurrentBPM = m_fLowBPM = m_fHighBPM = 0; m_fBPMFrom = m_fBPMTo = 0;
m_fTimeLeftInState = 0; m_iCurrentBPM = 0;
m_CountingState = holding_down; m_BPMS.push_back(0);
m_fPercentInState = 0;
m_fCycleTime = 1.0f;
m_textBPM.LoadFromNumbers( THEME->GetPathToN("BPMDisplay") ); m_textBPM.LoadFromNumbers( THEME->GetPathToN("BPMDisplay") );
m_textBPM.EnableShadow( false ); m_textBPM.EnableShadow( false );
@@ -44,88 +48,66 @@ BPMDisplay::BPMDisplay()
this->AddChild( &m_sprLabel ); this->AddChild( &m_sprLabel );
} }
float BPMDisplay::GetActiveBPM() const
{
return m_fBPMTo + (m_fBPMFrom-m_fBPMTo)*m_fPercentInState;
}
void BPMDisplay::Update( float fDeltaTime ) void BPMDisplay::Update( float fDeltaTime )
{ {
ActorFrame::Update( fDeltaTime ); ActorFrame::Update( fDeltaTime );
m_fTimeLeftInState -= fDeltaTime; if( m_BPMS.size() == 0 )
if( m_fTimeLeftInState < 0 ) return; /* no bpm */
m_fPercentInState -= fDeltaTime / m_fCycleTime;
if( m_fPercentInState < 0 )
{ {
// go to next state // go to next state
switch( m_CountingState ) 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)
{ {
case counting_up: m_fBPMFrom = -1;
m_CountingState = holding_up;
m_fTimeLeftInState = 1; // reset timer
break;
case holding_up:
m_CountingState = counting_down;
m_fTimeLeftInState = 1; // reset timer
break;
case counting_down:
m_CountingState = holding_down;
m_fTimeLeftInState = 1; // reset timer
break;
case holding_down:
m_CountingState = counting_up;
m_fTimeLeftInState = 1; // reset timer
break;
case cycle_randomly:
m_textBPM.SetText( (RandomFloat(0,1)>0.90) ? "xxx" : ssprintf("%03.0f",RandomFloat(0,600)) ); m_textBPM.SetText( (RandomFloat(0,1)>0.90) ? "xxx" : ssprintf("%03.0f",RandomFloat(0,600)) );
m_fTimeLeftInState = 0.2f; // reset timer } else if(m_fBPMFrom == -1)
break; m_fBPMFrom = m_fBPMTo;
case no_bpm:
m_fTimeLeftInState = 0;
break;
default:
ASSERT(0);
}
} }
// update m_fCurrentBPM // update m_textBPM
// int iLastCurBPM = (int)m_fCurrentBPM; if( m_fBPMTo != -1)
switch( m_CountingState )
{ {
case counting_down: m_fCurrentBPM = m_fLowBPM + (m_fHighBPM-m_fLowBPM)*m_fTimeLeftInState; break; const float fActualBPM = GetActiveBPM();
case counting_up: m_fCurrentBPM = m_fHighBPM + (m_fLowBPM-m_fHighBPM)*m_fTimeLeftInState; break; m_textBPM.SetText( ssprintf("%03.0f", fActualBPM) );
case holding_up: m_fCurrentBPM = m_fHighBPM; break; }
case holding_down: m_fCurrentBPM = m_fLowBPM; break;
case cycle_randomly: break;
case no_bpm: break;
default:
ASSERT(0);
} }
// update text
switch( m_CountingState ) void BPMDisplay::SetBPMRange( const vector<float> &BPMS )
{ {
case counting_down: ASSERT( m_BPMS.size() );
case counting_up:
case holding_up:
case holding_down:
//if( (int)m_fCurrentBPM != iLastCurBPM )
// m_textBPM.SetText( ssprintf("%03.0f", m_fCurrentBPM) );
/* BUG FIXED:: Just set the BPM.. This was causing an error that would not change m_BPMS.clear();
the BPM to what it should be, if you changed the selection from a Group unsigned i;
to a song. There's no great reason to check if it is higher or lower bool AllIdentical = true;
than the previous BPM -- Miryokuteki */ for( i = 0; i < BPMS.size(); ++i )
m_textBPM.SetText( ssprintf("%03.0f", m_fCurrentBPM) );
break;
}
}
void BPMDisplay::SetBPMRange( float fLowBPM, float fHighBPM )
{ {
m_fLowBPM = fLowBPM; if( i > 0 && m_BPMS[i] != m_BPMS[i-1] )
m_fHighBPM = fHighBPM; AllIdentical = false;
if( m_fCurrentBPM > m_fHighBPM )
m_CountingState = counting_down; m_BPMS.push_back(BPMS[i]);
else if( BPMS[i] != -1 )
m_CountingState = counting_up; m_BPMS.push_back(BPMS[i]); /* hold */
m_fTimeLeftInState = 1; }
m_iCurrentBPM = min(1u, sizeof(m_BPMS)); /* start on the first hold */
m_fBPMFrom = BPMS[0];
m_fBPMTo = BPMS[0];
m_fPercentInState = 1;
m_textBPM.StopTweening(); m_textBPM.StopTweening();
m_sprLabel.StopTweening(); m_sprLabel.StopTweening();
@@ -137,7 +119,7 @@ void BPMDisplay::SetBPMRange( float fLowBPM, float fHighBPM )
m_textBPM.SetDiffuse( EXTRA_COLOR ); m_textBPM.SetDiffuse( EXTRA_COLOR );
m_sprLabel.SetDiffuse( EXTRA_COLOR ); m_sprLabel.SetDiffuse( EXTRA_COLOR );
} }
else if( m_fLowBPM != m_fHighBPM ) else if( !AllIdentical )
{ {
m_textBPM.SetDiffuse( CHANGE_COLOR ); m_textBPM.SetDiffuse( CHANGE_COLOR );
m_sprLabel.SetDiffuse( CHANGE_COLOR ); m_sprLabel.SetDiffuse( CHANGE_COLOR );
@@ -152,16 +134,16 @@ void BPMDisplay::SetBPMRange( float fLowBPM, float fHighBPM )
void BPMDisplay::CycleRandomly() void BPMDisplay::CycleRandomly()
{ {
m_CountingState = cycle_randomly; vector<float> BPMS;
m_fTimeLeftInState = 0; BPMS.push_back(-1);
SetBPMRange( BPMS );
m_textBPM.SetDiffuse( NORMAL_COLOR ); m_fCycleTime = 0.2f;
m_sprLabel.SetDiffuse( NORMAL_COLOR );
} }
void BPMDisplay::NoBPM() void BPMDisplay::NoBPM()
{ {
m_CountingState = no_bpm; m_BPMS.clear();
m_textBPM.SetText( "..." ); m_textBPM.SetText( "..." );
m_textBPM.SetDiffuse( NORMAL_COLOR ); m_textBPM.SetDiffuse( NORMAL_COLOR );
@@ -174,21 +156,68 @@ void BPMDisplay::SetBPM( const Song* pSong )
switch( pSong->m_DisplayBPMType ) switch( pSong->m_DisplayBPMType )
{ {
case Song::DISPLAY_ACTUAL: case Song::DISPLAY_ACTUAL:
case Song::DISPLAY_SPECIFIED:
{ {
float fMinBPM, fMaxBPM; float fMinBPM, fMaxBPM;
pSong->GetActualBPM( fMinBPM, fMaxBPM ); pSong->GetDisplayBPM( fMinBPM, fMaxBPM );
SetBPMRange( fMinBPM, fMaxBPM ); vector<float> BPMS;
BPMS.push_back(fMinBPM);
BPMS.push_back(fMaxBPM);
SetBPMRange( BPMS );
} }
break; break;
case Song::DISPLAY_SPECIFIED:
SetBPMRange( pSong->m_fSpecifiedBPMMin, pSong->m_fSpecifiedBPMMax );
break;
case Song::DISPLAY_RANDOM: case Song::DISPLAY_RANDOM:
CycleRandomly(); CycleRandomly();
break; break;
default: default:
ASSERT(0); ASSERT(0);
} }
m_fCycleTime = 1.0f;
}
void BPMDisplay::SetBPM( const Course* pCourse )
{
vector<Song*> vSongs;
vector<Notes*> vNotes;
vector<CString> vsModifiers;
pCourse->GetStageInfo( vSongs, vNotes, vsModifiers, GAMESTATE->GetCurrentStyleDef()->m_NotesType );
ASSERT( vSongs.size() );
vector<float> BPMS;
for( unsigned i = 0; i < vSongs.size(); ++i )
{
if( pCourse->IsMysterySong(i) )
{
BPMS.push_back( -1 );
continue;
}
Song *pSong = vSongs[i];
ASSERT( pSong );
switch( pSong->m_DisplayBPMType )
{
case Song::DISPLAY_ACTUAL:
case Song::DISPLAY_SPECIFIED:
{
float fMinBPM, fMaxBPM;
pSong->GetDisplayBPM( fMinBPM, fMaxBPM );
BPMS.push_back( fMinBPM );
if( fMinBPM != fMaxBPM )
BPMS.push_back( fMaxBPM );
}
break;
case Song::DISPLAY_RANDOM:
BPMS.push_back( -1 );
break;
default:
ASSERT(0);
}
}
SetBPMRange( BPMS );
m_fCycleTime = 0.2f;
} }
void BPMDisplay::DrawPrimitives() void BPMDisplay::DrawPrimitives()
+10 -12
View File
@@ -17,6 +17,7 @@
#include "BitmapText.h" #include "BitmapText.h"
#include "Quad.h" #include "Quad.h"
class Song; class Song;
class Course;
class BPMDisplay : public ActorFrame class BPMDisplay : public ActorFrame
{ {
@@ -24,26 +25,23 @@ public:
BPMDisplay(); BPMDisplay();
virtual void Update( float fDeltaTime ); virtual void Update( float fDeltaTime );
virtual void DrawPrimitives(); virtual void DrawPrimitives();
void SetBPMRange( float fLowBPM, float fHighBPM );
void SetBPM( const Song* pSong ); void SetBPM( const Song* pSong );
void SetBPM( const Course* pCourse );
void CycleRandomly(); void CycleRandomly();
void NoBPM(); void NoBPM();
protected: protected:
float GetActiveBPM() const;
void SetBPMRange( const vector<float> &m_BPMS );
BitmapText m_textBPM; BitmapText m_textBPM;
Sprite m_sprLabel; Sprite m_sprLabel;
float m_fCurrentBPM; float m_fBPMFrom, m_fBPMTo;
float m_fLowBPM, m_fHighBPM; int m_iCurrentBPM;
enum CountingState { vector<float> m_BPMS;
counting_up, float m_fPercentInState;
holding_up, float m_fCycleTime;
counting_down,
holding_down,
cycle_randomly,
no_bpm // show dashes
} m_CountingState;
float m_fTimeLeftInState;
}; };
#endif #endif