diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index f3c2138951..2005e62d31 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -10,75 +10,81 @@ */ #include "BitmapText.h" -#include #include "IniFile.h" +#include BitmapText::BitmapText() { - m_pFont = NULL; - m_colorTop = D3DXCOLOR(1,1,1,1); - m_colorBottom = D3DXCOLOR(1,1,1,1); +// m_colorTop = D3DXCOLOR(1,1,1,1); +// m_colorBottom = D3DXCOLOR(1,1,1,1); -} - -BitmapText::~BitmapText() -{ - delete m_pFont; + for( int i=0; iGetD3D(), SCREEN->GetDevice() ); - m_pFont->Load( BL_BITMAP, ssprintf("Fonts/%s.png",sFontName) ); - m_pFont->Load( BL_SIZES, ssprintf("Fonts/%s.dat",sFontName) ); + Sprite::LoadFromTexture( ssprintf("Fonts/%s 16x16.png",sFontName) ); + LoadCharWidths( ssprintf("Fonts/%s.widths",sFontName) ); return TRUE; } -void BitmapText::Draw() +// returns the font height in the case of a bitmap load. note does not use the real bitmap height but rather +// the height of the bitmap / 16. generally returns > 0 for success. +bool BitmapText::LoadCharWidths( CString sWidthFilePath ) { - RECT rect = m_pFont->GetTextRect(m_sText, 0, 0); - float text_width = RECTWIDTH( rect ); - float text_height = RECTHEIGHT( rect ); - - - LPDIRECT3DDEVICE8 pd3dDevice = SCREEN->GetDevice(); - - // calculate transforms - D3DXMATRIX matWorld, matTemp; - D3DXMatrixIdentity( &matWorld ); // initialize world - //D3DXMatrixScaling( &matTemp, m_size.x, m_size.y, 1 ); // scale to the native height and width - //matWorld *= matTemp; - D3DXMatrixScaling( &matTemp, m_scale.x, m_scale.y, 1 ); // add in the zoom - matWorld *= matTemp; - D3DXMatrixRotationYawPitchRoll( &matTemp, m_rotation.y, m_rotation.x, m_rotation.z ); // add in the rotation - matWorld *= matTemp; - D3DXMatrixTranslation( &matTemp, m_pos.x, m_pos.y, 0 ); // add in the translation - matWorld *= matTemp; - pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld ); - - D3DXMATRIX matView; - D3DXMatrixIdentity( &matView ); - pd3dDevice->SetTransform( D3DTS_VIEW, &matView ); - - D3DXMATRIX matProj; - D3DXMatrixOrthoOffCenterLH( &matProj, 0, 640, 480, 0, -100, 100 ); - pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj ); - - m_pFont->BeginDraw(); - m_pFont->DrawTextEx(m_sText, -text_width/2, -text_height/2, m_colorTop, m_colorBottom, 1.0f); - //m_pFont->DrawTextEx("Cool Effects!", 50, 80, 0xffffff00, 0xffff0000, 2.0f); - //m_pFont->DrawTextEx("Cool Effects!", 50, 120, 0x1100ffff, 0x8800ffff, 2.0f); - m_pFont->EndDraw(); - /////////////////////////////////////////////////////////////////////////////// - + FILE *file; + file = fopen( sWidthFilePath, "rb" ); + for( int i=0; i<256; i++ ) { + BYTE widthSourcePixels; + if( fread(&widthSourcePixels, 1, 1, file) != 1 ) + return false; + m_fCharWidthsInSourcePixels[i] = widthSourcePixels; + } + fclose(file); + return true; } + +// get a rectangle for the text, considering a possible text scaling. +// useful to know if some text is visible or not +float BitmapText::GetTextWidthInSourcePixels() +{ + float fTextWidth = 0; + + for( int i=0; i new_seg.m_iStartBeat ) + break; + m_BPMSegments.InsertAt( i, new_seg ); + RageLog( "Inserting new BPM change at beat %d, BPM %f, index %d", new_seg.m_iStartBeat, new_seg.m_fBPM, i ); + } else if( value_name == "#BackBMP" || value_name == "#backBMP") m_sBackground = data_array[0]; else if( value_name == "#WAV99" ) @@ -129,7 +139,29 @@ bool Song::LoadSongInfoFromBMSFile( CString sPath ) else if( value_name.GetLength() == 6 ) // this is probably step or offset data. Looks like "#00705" { int iMeasureNo = atoi( value_name.Mid(1,3) ); - int iNoteNum = atoi( value_name.Mid(4,2) ); + int iTrackNum = atoi( value_name.Mid(4,2) ); + + if( m_sTitle.Find("era") > 0 ) + m_sTitle = m_sTitle; + switch( iTrackNum ) + { + case 03: // bpm + { + int iNewBPM; + sscanf( data_array[0], "%x", &iNewBPM ); // data is in hexadecimal + BPMSegment new_seg; + new_seg.m_iStartBeat = iMeasureNo * 4; + new_seg.m_fBPM = (float)iNewBPM; + // find insertion point + for( int i=0; i new_seg.m_iStartBeat ) + break; + m_BPMSegments.InsertAt( i, new_seg ); + RageLog( "Inserting new BPM change at beat %d, BPM %f, index %d", new_seg.m_iStartBeat, new_seg.m_fBPM, i ); + } + break; + } + CString sNoteData = data_array[0]; CArray arrayNotes; @@ -141,23 +173,38 @@ bool Song::LoadSongInfoFromBMSFile( CString sPath ) } const int iNumNotesInThisMeasure = arrayNotes.GetSize(); - //RageLog( "%s:%s: iMeasureNo = %d, iNoteNum = %d, iNumNotesInThisMeasure = %d", - // valuename, sNoteData, iMeasureNo, iNoteNum, iNumNotesInThisMeasure ); + //RageLog( "%s:%s: iMeasureNo = %d, iTrackNum = %d, iNumNotesInThisMeasure = %d", + // valuename, sNoteData, iMeasureNo, iTrackNum, iNumNotesInThisMeasure ); for( int j=0; j @@ -287,6 +287,11 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) //----------------------------------------------------------------------------- HRESULT CreateObjects( HWND hWnd ) { + + srand( (unsigned)time(NULL) ); // seed number generator + + RageLogStart(); + SCREEN = new RageScreen( hWnd ); TM = new RageTextureManager( SCREEN ); SOUND = new RageSound( hWnd ); @@ -296,15 +301,12 @@ HRESULT CreateObjects( HWND hWnd ) GAMEINFO = new GameInfo; WM = new WindowManager; - RageLogStart(); + + DXUtil_Timer( TIMER_START ); // Start the accurate timer //WM->SetNewWindow( new WindowSandbox ); - WM->SetNewWindow( new WindowIntroCovers ); + WM->SetNewWindow( new WindowTitleMenu ); - srand( (unsigned)time(NULL) ); - - // Start the accurate timer - DXUtil_Timer( TIMER_START ); return S_OK; } diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index b868c02c9c..6e46c45d5e 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -284,14 +284,6 @@ SOURCE=.\Banner.h # End Source File # Begin Source File -SOURCE=.\BitmapFont.cpp -# End Source File -# Begin Source File - -SOURCE=.\BitmapFont.h -# End Source File -# Begin Source File - SOURCE=.\BitmapText.cpp # End Source File # Begin Source File diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 5268cca20a..72465c4a81 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -48,9 +48,41 @@ public: CString GetTitle() {return m_sTitle; }; CString GetArtist() {return m_sArtist; }; CString GetCreator() {return m_sCreator; }; - float GetBeatOffset() {return m_fBeatOffset; }; - float GetBPM() {return m_fBPM; }; - float GetBeatsPerSecond() {return m_fBPM / 60.0f; }; +// float GetBeatOffset() {return m_fBeatOffset; }; + void GetMinMaxBPM( int &iMinBPM, int &iMaxBPM ) + { + iMaxBPM = 0; + iMinBPM = 100000; // inf + for( int i=0; i iMaxBPM ) + iMaxBPM = (int)m_BPMSegments[i].m_fBPM; + if( m_BPMSegments[i].m_fBPM < iMinBPM ) + iMinBPM = (int)m_BPMSegments[i].m_fBPM; + } + }; + void GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut ) + { + if( fElapsedTime > 50 ) + fElapsedTime = fElapsedTime; + fElapsedTime += m_fOffsetInSeconds; + + for( int i=0; i fSecondsInThisSegment ) + fElapsedTime -= fSecondsInThisSegment; + else { + fBeatOut = iStartBeatThisSegment + fElapsedTime*fBPS; + fBPSOut = fBPS; + return; + } + } + }; public: @@ -59,16 +91,20 @@ private: CString m_sSongFile; CString m_sSongDir; + bool m_bChangedSinceSave; CString m_sTitle; CString m_sArtist; CString m_sCreator; - float m_fBPM; - float m_fBeatOffset; +// float m_fBPM; + float m_fOffsetInSeconds; CString m_sMusic; CString m_sBanner; CString m_sBackground; + struct BPMSegment{ int m_iStartBeat; float m_fBPM; }; + CArray m_BPMSegments; + public: CArray arraySteps; };