diff --git a/stepmania/src/Background.cpp b/stepmania/src/Background.cpp index cb5c679860..09a740976e 100644 --- a/stepmania/src/Background.cpp +++ b/stepmania/src/Background.cpp @@ -54,7 +54,7 @@ bool Background::LoadFromSong( Song* pSong, bool bDisableVisualizations ) this->AddActor( &m_sprSongBackground ); - if( GAMEINFO->m_GameOptions.m_bRandomVis && !bDisableVisualizations ) + if( PREFS->m_GameOptions.m_bUseRandomVis && !bDisableVisualizations ) { // load a random visualization CStringArray sVisualizationPaths; diff --git a/stepmania/src/GhostArrow.cpp b/stepmania/src/GhostArrow.cpp index 5d68536197..8a0bbe4d10 100644 --- a/stepmania/src/GhostArrow.cpp +++ b/stepmania/src/GhostArrow.cpp @@ -28,7 +28,7 @@ void GhostArrow::Update( float fDeltaTime ) void GhostArrow::SetBeat( const float fSongBeat ) { - //SetState( fmod(fSongBeat,1)<0.25 ? 1 : 0 ); + //SetState( fmodf(fSongBeat,1)<0.25 ? 1 : 0 ); } void GhostArrow::Step( TapStepScore score ) diff --git a/stepmania/src/GhostArrowBright.cpp b/stepmania/src/GhostArrowBright.cpp index 3964ce6df3..ff7d222f4c 100644 --- a/stepmania/src/GhostArrowBright.cpp +++ b/stepmania/src/GhostArrowBright.cpp @@ -24,7 +24,7 @@ GhostArrowBright::GhostArrowBright() void GhostArrowBright::SetBeat( const float fSongBeat ) { - //SetState( fmod(fSongBeat,1)<0.25 ? 1 : 0 ); + //SetState( fmodf(fSongBeat,1)<0.25 ? 1 : 0 ); } void GhostArrowBright::Step( TapStepScore score ) diff --git a/stepmania/src/GrayArrow.cpp b/stepmania/src/GrayArrow.cpp index dc84cc5fff..6ca10ff3af 100644 --- a/stepmania/src/GrayArrow.cpp +++ b/stepmania/src/GrayArrow.cpp @@ -1,8 +1,15 @@ #include "stdafx.h" -// -// GrayArrow.cpp: implementation of the GrayArrow class. -// -////////////////////////////////////////////////////////////////////// +/* +----------------------------------------------------------------------------- + Class: GrayArrow + + Desc: A gray arrow that "receives" ColorArrows. + + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Ben Nordstrom + Chris Danford +----------------------------------------------------------------------------- +*/ #include "GrayArrow.h" #include "ThemeManager.h" @@ -10,10 +17,6 @@ const float GRAY_ARROW_POP_UP_TIME = 0.3f; -////////////////////////////////////////////////////////////////////// -// Construction/Destruction -////////////////////////////////////////////////////////////////////// - GrayArrow::GrayArrow() { Load( THEME->GetPathTo(GRAPHIC_GRAY_ARROW) ); diff --git a/stepmania/src/GrayArrow.h b/stepmania/src/GrayArrow.h index cc0afea77e..d65adb3ea1 100644 --- a/stepmania/src/GrayArrow.h +++ b/stepmania/src/GrayArrow.h @@ -1,10 +1,12 @@ /* ----------------------------------------------------------------------------- - File: GrayArrow.h + Class: GrayArrow - Desc: Class used to represent a color arrow on the screen. + Desc: A gray arrow that "receives" ColorArrows. - Copyright (c) 2001 Ben Norstrom. All rights reserved. + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Ben Nordstrom + Chris Danford ----------------------------------------------------------------------------- */ diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index ce0b2a366c..e1dbe2f9c7 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -11,6 +11,7 @@ #include "MusicWheel.h" #include "RageUtil.h" +#include "SongManager.h" #include "ScreenDimensions.h" #include "ThemeManager.h" #include "RageMusic.h" @@ -216,7 +217,7 @@ MusicWheel::MusicWheel() // init m_mapGroupNameToBannerColor CArray arraySongs; - arraySongs.Copy( GAMEINFO->m_pSongs ); + arraySongs.Copy( SONGS->m_pSongs ); SortSongPointerArrayByGroup( arraySongs ); int iNextGroupBannerColor = 0; @@ -236,7 +237,7 @@ MusicWheel::MusicWheel() } - m_SortOrder = GAMEINFO->m_SongSortOrder; + m_SortOrder = PREFS->m_SongSortOrder; m_MusicSortDisplay.Set( m_SortOrder ); m_MusicSortDisplay.SetXY( SORT_ICON_ON_SCREEN_X, SORT_ICON_ON_SCREEN_Y ); @@ -256,10 +257,10 @@ MusicWheel::MusicWheel() BuildWheelItemDatas( m_WheelItemDatas[so], SongSortOrder(so) ); - if( GAMEINFO->m_pCurSong == NULL // if there is no currently selected song - && GAMEINFO->m_pSongs.GetSize() > 0 ) // and there is at least one song + if( SONGS->m_pCurSong == NULL && // if there is no currently selected song + SONGS->m_pSongs.GetSize() > 0 ) // and there is at least one song { - GAMEINFO->m_pCurSong = GAMEINFO->m_pSongs[0]; // select the first song + SONGS->m_pCurSong = SONGS->m_pSongs[0]; // select the first song } @@ -268,7 +269,7 @@ MusicWheel::MusicWheel() for( i=0; im_pCurSong ) + && GetCurWheelItemDatas()[i].m_pSong == SONGS->m_pCurSong ) { m_iSelection = i; // select it m_sExpandedSectionName = GetCurWheelItemDatas()[m_iSelection].m_sSectionName; // make its group the currently expanded group @@ -283,7 +284,7 @@ MusicWheel::MusicWheel() MusicWheel::~MusicWheel() { - GAMEINFO->m_SongSortOrder = m_SortOrder; + PREFS->m_SongSortOrder = m_SortOrder; } void MusicWheel::BuildWheelItemDatas( CArray &arrayWheelItemDatas, SongSortOrder so ) @@ -295,12 +296,12 @@ void MusicWheel::BuildWheelItemDatas( CArray &arr CArray arraySongs; // copy only song that have at least one Steps for the current GameMode - for( int i=0; im_pSongs.GetSize(); i++ ) + for( int i=0; im_pSongs.GetSize(); i++ ) { - Song* pSong = GAMEINFO->m_pSongs[i]; + Song* pSong = SONGS->m_pSongs[i]; CArray arraySteps; - pSong->GetStepsThatMatchGameMode( GAMEINFO->m_GameMode, arraySteps ); + pSong->GetStepsThatMatchGameMode( PREFS->m_GameMode, arraySteps ); if( arraySteps.GetSize() > 0 ) arraySongs.Add( pSong ); diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index ad221ae2f8..97aac9ec43 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -86,14 +86,14 @@ void Player::Load( const Style& style, PlayerNumber player_no, const Steps& step // load step elements for( int i=0; iIsButtonDown( PlayerI ); + PlayerInput PlayerI( m_PlayerNumber, hs.m_TapStep ); + bool bIsHoldingButton = PREFS->IsButtonDown( PlayerI ); if( bIsHoldingButton ) { hss.m_fLife += fDeltaTime/HOLD_ARROW_NG_TIME; @@ -201,7 +201,7 @@ void Player::RenderPrimitives() { D3DXMATRIX matOldView, matOldProj; - if( m_PlayerOptions.m_EffectType == PlayerOptions::EFFECT_STARS ) + if( m_PlayerOptions.m_EffectType == PlayerOptions::EFFECT_SPACE ) { // turn off Z Buffering SCREEN->GetDevice()->SetRenderState( D3DRS_ZENABLE, FALSE ); @@ -229,7 +229,7 @@ void Player::RenderPrimitives() m_ColorArrowField.Draw(); m_GhostArrows.Draw(); - if( m_PlayerOptions.m_EffectType == PlayerOptions::EFFECT_STARS ) + if( m_PlayerOptions.m_EffectType == PlayerOptions::EFFECT_SPACE ) { // restire old view and projection SCREEN->GetDevice()->SetTransform( D3DTS_VIEW, &matOldView ); diff --git a/stepmania/src/Player.h b/stepmania/src/Player.h index 3a053ff92d..6372a82dfb 100644 --- a/stepmania/src/Player.h +++ b/stepmania/src/Player.h @@ -12,7 +12,7 @@ #ifndef _PLAYER_H_ #define _PLAYER_H_ -#include "GameInfo.h" // for ScoreSummary +#include "PrefsManager.h" // for ScoreSummary #include "Steps.h" #include "Sprite.h" #include "BitmapText.h" diff --git a/stepmania/src/PrefsManager.cpp b/stepmania/src/PrefsManager.cpp new file mode 100644 index 0000000000..8aba1dd808 --- /dev/null +++ b/stepmania/src/PrefsManager.cpp @@ -0,0 +1,407 @@ +#include "stdafx.h" +/* +----------------------------------------------------------------------------- + Class: PrefsManager + + Desc: See Header. + + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "PrefsManager.h" +#include "IniFile.h" + + +PrefsManager* PREFS = NULL; // global and accessable from anywhere in our program + + + + +PrefsManager::PrefsManager() +{ + m_GameMode = MODE_SINGLE; + m_SongSortOrder = SORT_GROUP; + m_iCurrentStage = 1; + m_ThemeName = "default"; + + ReadPrefsFromDisk(); + SetHardCodedButtons(); +} + + +PrefsManager::~PrefsManager() +{ + // don't worry about releasing the Song array. Let the OS do it :-) + SavePrefsToDisk(); +} + + +void PrefsManager::ReadPrefsFromDisk() +{ + IniFile ini; + ini.SetPath( "StepMania.ini" ); + if( !ini.ReadFile() ) { + return; // load nothing + //RageError( "could not read config file" ); + } + + CMapStringToString* pKey = ini.GetKeyPointer("Input"); + CString name_string, value_string; + + if( pKey != NULL ) + { + for( POSITION pos = pKey->GetStartPosition(); pos != NULL; ) + { + pKey->GetNextAssoc( pos, name_string, value_string ); + + PadInput pi; + pi.fromString(name_string); + + CStringArray sDeviceInputStrings; + split( value_string, ",", sDeviceInputStrings, false ); + + for( int i=0; iSetHardCodedButtons(); + + + pKey = ini.GetKeyPointer( "GameOptions" ); + if( pKey ) + { + for( POSITION pos = pKey->GetStartPosition(); pos != NULL; ) + { + pKey->GetNextAssoc( pos, name_string, value_string ); + + if( name_string == "Windowed" ) m_GameOptions.m_bWindowed = ( value_string == "1" ); + if( name_string == "Resolution" ) m_GameOptions.m_iResolution = atoi( value_string ); + if( name_string == "DisplayColor" ) m_GameOptions.m_iDisplayColor = atoi( value_string ); + if( name_string == "TextureColor" ) m_GameOptions.m_iTextureColor = atoi( value_string ); + if( name_string == "FilterTextures" ) m_GameOptions.m_bFilterTextures = ( value_string == "1" ); + if( name_string == "Shadows" ) m_GameOptions.m_bShadows = ( value_string == "1" ); + if( name_string == "IgnoreJoyDirs" ) m_GameOptions.m_bIgnoreJoyDirs = ( value_string == "1" ); + if( name_string == "ShowFPS" ) m_GameOptions.m_bShowFPS = ( value_string == "1" ); + if( name_string == "UseRandomVis" ) m_GameOptions.m_bUseRandomVis = ( value_string == "1" ); + if( name_string == "ShowCaution" ) m_GameOptions.m_bShowCaution = ( value_string == "1" ); + if( name_string == "Announcer" ) m_GameOptions.m_bAnnouncer = ( value_string == "1" ); + } + } + +} + + +void PrefsManager::SavePrefsToDisk() +{ + IniFile ini; + ini.SetPath( "StepMania.ini" ); +// ini.ReadFile(); // don't read the file so that we overwrite everything there + + + // iterate over our input map and write all mappings to the ini file + for( int i=0; iIsBeingPressed( di ) ) + return true; + } + } + + return false; +} + +bool PrefsManager::IsButtonDown( PlayerInput PlayerI ) +{ + PadInput PadI; + PlayerToPad( PlayerI, PadI ); + return IsButtonDown( PadI ); +} + + + diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h new file mode 100644 index 0000000000..5da16590ad --- /dev/null +++ b/stepmania/src/PrefsManager.h @@ -0,0 +1,114 @@ +/* +----------------------------------------------------------------------------- + Class: PrefsManager + + Desc: Manages input mapping, saves preferences, and holds data that is passed + between Windows. + + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#ifndef _PrefsManager_H_ +#define _PrefsManager_H_ + + +#include "RageInput.h" +#include "PadInput.h" +#include "PlayerInput.h" +#include "GameTypes.h" + + + +const int NUM_PAD_TO_DEVICE_SLOTS = 3; // three device inputs may map to one pad input + + +class Song; + +class PrefsManager +{ +public: + PrefsManager(); + ~PrefsManager(); + + GameMode m_GameMode; + + ScoreSummary scoreSummaryPlayer[NUM_PLAYERS]; + + SongSortOrder m_SongSortOrder; + + int m_iCurrentStage; + + GameOptions m_GameOptions; + PlayerOptions m_PlayerOptions[NUM_PLAYERS]; + SongOptions m_SongOptions; + + bool IsPlayerEnabled( PlayerNumber PlayerNo ) + { + switch( m_GameMode ) + { + case MODE_VERSUS: + case MODE_COUPLE: + if( PlayerNo == PLAYER_1 ) + return true; + if( PlayerNo == PLAYER_2 ) + return true; + break; + case MODE_SINGLE: + case MODE_SOLO: + case MODE_DOUBLE: + if( PlayerNo == PLAYER_1 ) + return true; + if( PlayerNo == PLAYER_2 ) + return false; + break; + default: + ASSERT( false ); // invalid game mode + } + return false; + }; + + // prefs file stuff + void ReadPrefsFromDisk(); + void SavePrefsToDisk(); + + + // input mapping stuff + void SetInputMap( DeviceInput di, PadInput pi, int iSlotIndex, bool bOverrideHardCoded = false ); + void ClearFromInputMap( DeviceInput di ); + void ClearFromInputMap( PadInput pi, int iSlotIndex ); + + void SetHardCodedButtons(); + bool IsAHardCodedDeviceInput( DeviceInput di ); + + bool DeviceToPad( DeviceInput di, PadInput& pi ); // return true if there is a mapping from device to pad + bool PadToDevice( PadInput pi, int iSoltNum, DeviceInput& di ); // return true if there is a mapping from pad to device + + void PadToPlayer( PadInput PadI, PlayerInput &PlayerI ); + void PlayerToPad( PlayerInput PlayerI, PadInput &PadI ); + + bool IsButtonDown( PadInput pi ); + bool IsButtonDown( PlayerInput PlayerI ); + + // theme stuff + CString m_ThemeName; + + + + +protected: + + DeviceInput m_PItoDI[NUM_PADS][NUM_PAD_BUTTONS][NUM_PAD_TO_DEVICE_SLOTS]; // all the DeviceInputs that map to a PadInput + + // lookup for efficiency from a DeviceInput to a PadInput + // This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI(). + PadInput m_tempDItoPI[NUM_INPUT_DEVICES][NUM_DEVICE_BUTTONS]; + void UpdateTempDItoPI(); +}; + + +extern PrefsManager* PREFS; // global and accessable from anywhere in our program + + +#endif \ No newline at end of file diff --git a/stepmania/src/RageBitmapTexture.cpp b/stepmania/src/RageBitmapTexture.cpp index 11e1caaae2..08a61c1ed7 100644 --- a/stepmania/src/RageBitmapTexture.cpp +++ b/stepmania/src/RageBitmapTexture.cpp @@ -23,7 +23,7 @@ #include "dxerr8.h" #include "DXUtil.h" #include "RageUtil.h" -#include "GameInfo.h" +#include "PrefsManager.h" //#include #include @@ -92,9 +92,9 @@ void RageBitmapTexture::Create( DWORD dwHints ) // if the user has requested high color textures, use the higher color - if( GAMEINFO != NULL - && GAMEINFO->m_GameOptions.m_iDisplayColor == 32 - && GAMEINFO->m_GameOptions.m_iTextureColor == 32 ) + if( PREFS != NULL + && PREFS->m_GameOptions.m_iDisplayColor == 32 + && PREFS->m_GameOptions.m_iTextureColor == 32 ) { fmtTexture = D3DFMT_A8R8G8B8; } diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index 898d00f9d6..6f9150b48f 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -12,36 +12,10 @@ #include "RageUtil.h" -//----------------------------------------------------------------------------- -// UTIL globals -//----------------------------------------------------------------------------- const CString g_sLogFileName = "log.txt"; const CString g_sErrorFileName = "error.txt"; FILE* g_fileLog = NULL; -//----------------------------------------------------------------------------- -// Name: randomf() -// Desc: -//----------------------------------------------------------------------------- -float randomf( float low, float high ) -{ - return low + ( high - low ) * ( (FLOAT)rand() ) / RAND_MAX; -} - -//----------------------------------------------------------------------------- -// Name: roundf() -// Desc: -//----------------------------------------------------------------------------- -int roundf( float f ) -{ - return (int)((f)+0.5f); -} - -int roundf( double f ) -{ - return (int)((f)+0.5); -} - bool IsAnInt( CString s ) diff --git a/stepmania/src/RageUtil.h b/stepmania/src/RageUtil.h index 1a96c759b9..a4d1ed12d7 100644 --- a/stepmania/src/RageUtil.h +++ b/stepmania/src/RageUtil.h @@ -46,12 +46,17 @@ //----------------------------------------------------------------------------- // Simple function for generating random numbers -float randomf( float low=-1.0f, float high=1.0f ); -int roundf( FLOAT f ); -int roundf( double f ); +inline float randomf( float low=-1.0f, float high=1.0f ) +{ + return low + ( high - low ) * ( (FLOAT)rand() ) / RAND_MAX; +} +inline int roundf( float f ) { return (int)((f)+0.5f); }; +inline int roundf( double f ) { return (int)((f)+0.5); }; + bool IsAnInt( CString s ); + CString ssprintf( LPCTSTR fmt, ...); CString vssprintf( LPCTSTR fmt, va_list argList ); diff --git a/stepmania/src/ScreenDimensions.h b/stepmania/src/ScreenDimensions.h index 109c6a3387..3cae135bce 100644 --- a/stepmania/src/ScreenDimensions.h +++ b/stepmania/src/ScreenDimensions.h @@ -12,16 +12,16 @@ #define _SCREENDIMENSIONS_H_ -const int SCREEN_WIDTH = 640; -const int SCREEN_HEIGHT = 480; +#define SCREEN_WIDTH (640) +#define SCREEN_HEIGHT (480) -const float SCREEN_LEFT = 0; -const float SCREEN_RIGHT = SCREEN_WIDTH; -const float SCREEN_TOP = 0; -const float SCREEN_BOTTOM = SCREEN_HEIGHT; +#define SCREEN_LEFT (0) +#define SCREEN_RIGHT (SCREEN_WIDTH) +#define SCREEN_TOP (0) +#define SCREEN_BOTTOM (SCREEN_HEIGHT) -const float CENTER_X = SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT)/2.0f; -const float CENTER_Y = SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP)/2.0f; +#define CENTER_X (SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT)/2.0f) +#define CENTER_Y (SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP)/2.0f) #endif \ No newline at end of file diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 44f5fc535e..80da9a7ef3 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -16,6 +16,7 @@ #include "Song.h" #include +#include // for fmod @@ -77,6 +78,9 @@ Song::Song() void Song::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut ) { + RageLog( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime ); + // This function is a nightmare. Don't even try to understand it. :-) + fElapsedTime += m_fOffsetInSeconds; @@ -186,6 +190,8 @@ bool Song::LoadFromSongDir( CString sDir ) RageError( ssprintf("Couldn't find any BMS or MSD files in '%s'", sDir) ); } + RageLog( "m_fOffsetInSeconds is %f", m_fOffsetInSeconds ); + return TRUE; @@ -485,7 +491,7 @@ bool Song::LoadSongInfoFromDWIFile( CString sPath ) { CStringArray arrayFreezeValues; split( arrayFreezeExpressions[f], "=", arrayFreezeValues ); - int fIndex = atoi( arrayFreezeValues[0] ) * 2; + float fIndex = atoi( arrayFreezeValues[0] ) * ELEMENTS_PER_BEAT / 4.0f; float fFreezeBeat = StepIndexToBeat( fIndex ); float fFreezeSeconds = (float)atof( arrayFreezeValues[1] ) / 1000.0f; @@ -510,7 +516,7 @@ bool Song::LoadSongInfoFromDWIFile( CString sPath ) { CStringArray arrayBPMChangeValues; split( arrayBPMChangeExpressions[b], "=", arrayBPMChangeValues ); - int fIndex = atoi( arrayBPMChangeValues[0] ) * 2; + float fIndex = atoi( arrayBPMChangeValues[0] ) * ELEMENTS_PER_BEAT / 4.0f; float fBeat = StepIndexToBeat( fIndex ); float fNewBPM = (float)atoi( arrayBPMChangeValues[1] ); diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp new file mode 100644 index 0000000000..feb329a106 --- /dev/null +++ b/stepmania/src/SongManager.cpp @@ -0,0 +1,256 @@ +#include "stdafx.h" +/* +----------------------------------------------------------------------------- + Class: SongManager + + Desc: See header. + + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "SongManager.h" +#include "IniFile.h" + + +SongManager* SONGS = NULL; // global and accessable from anywhere in our program + + +const CString g_sStatisticsFileName = "statistics.ini"; + + +SongManager::SongManager() +{ + m_pCurSong = NULL; + for( int p=0; pLoadSongInfoFromDWIFile( ssprintf("DWI Support\\DWIs\\%s\\%s", sDirName, sDWIFileName) ); + m_pSongs.Add( pNewSong ); + } + } + + + ///////////////////////////// + // Load songs from StepMania's directory structure in Songs + ///////////////////////////// + + // Find all group directories in "Songs" folder + CStringArray arrayGroupDirs; + GetDirListing( "Songs\\*.*", arrayGroupDirs, true ); + SortCStringArray( arrayGroupDirs ); + + for( i=0; i< arrayGroupDirs.GetSize(); i++ ) // for each dir in /Songs/ + { + CString sGroupDirName = arrayGroupDirs[i]; + sGroupDirName.MakeLower(); + + if( sGroupDirName == "cvs" ) // ignore the directory called "CVS" + continue; + + // Find all Song folders in this group directory + CStringArray arraySongDirs; + GetDirListing( ssprintf("Songs\\%s\\*.*", sGroupDirName, true), arraySongDirs ); + SortCStringArray( arraySongDirs ); + + for( int j=0; j< arraySongDirs.GetSize(); j++ ) // for each song dir + { + CString sSongDirName = arraySongDirs[j]; + sSongDirName.MakeLower(); + + if( sSongDirName == "cvs" ) // ignore the directory called "CVS" + continue; + + // load DWIs from the sub dirs + Song* pNewSong = new Song; + pNewSong->LoadFromSongDir( ssprintf("Songs\\%s\\%s", sGroupDirName, sSongDirName) ); + m_pSongs.Add( pNewSong ); + } + } + + + + RageLog( "Found %d Songs.", m_pSongs.GetSize() ); +} + + +void SongManager::CleanUpSongArray() +{ + for( int i=0; iGetStartPosition(); pos != NULL; ) + { + CString name_string, value_string; + + pKey->GetNextAssoc( pos, name_string, value_string ); + + // Each value has the format "SongName::StepsName=TimesPlayed::TopGrade::TopScore::MaxCombo". + + char szSongName[256]; + char szStepsName[256]; + int iRetVal; + int i; + + // Parse for Song name and Steps name + iRetVal = sscanf( name_string, "%[^:]::%[^\n]", szSongName, szStepsName ); + if( iRetVal != 2 ) + continue; // this line doesn't match what is expected + + + // Search for the corresponding Song pointer. + Song* pSong = NULL; + for( i=0; iGetTitle() == szSongName ) // match! + { + pSong = m_pSongs[i]; + break; + } + } + if( pSong == NULL ) // didn't find a match + continue; // skip this entry + + + // Search for the corresponding Steps pointer. + Steps* pSteps = NULL; + for( i=0; iarraySteps.GetSize(); i++ ) + { + if( pSong->arraySteps[i].m_sDescription == szStepsName ) // match! + { + pSteps = &pSong->arraySteps[i]; + break; + } + } + if( pSteps == NULL ) // didn't find a match + continue; // skip this entry + + + // Parse the Steps statistics. + char szGradeLetters[10]; // longest possible string is "AAA" + + iRetVal = sscanf( + value_string, + "%d::%[^:]::%d::%d", + &pSteps->m_iNumTimesPlayed, + szGradeLetters, + &pSteps->m_iTopScore, + &pSteps->m_iMaxCombo + ); + if( iRetVal != 4 ) + continue; + + pSteps->m_TopGrade = StringToGrade( szGradeLetters ); + } + } +} + +void SongManager::SaveStatisticsToDisk() +{ + IniFile ini; + ini.SetPath( g_sStatisticsFileName ); + if( !ini.ReadFile() ) { + return; // load nothing + //RageError( "could not read config file" ); + } + + // save song statistics + for( int i=0; iarraySteps.GetSize(); j++ ) // for each Steps + { + Steps* pSteps = &pSong->arraySteps[j]; + + if( pSteps->m_TopGrade == GRADE_NO_DATA ) + continue; + + // Each value has the format "SongName::StepsName=TimesPlayed::TopGrade::TopScore::MaxCombo". + + CString sName = ssprintf( "%s::%s", pSong->GetTitle(), pSteps->m_sDescription ); + CString sValue = ssprintf( + "%d::%s::%d::%d", + pSteps->m_iNumTimesPlayed, + GradeToString( pSteps->m_TopGrade ), + pSteps->m_iTopScore, + pSteps->m_iMaxCombo + ); + + ini.SetValue( "Statistics", sName, sValue ); + } + } + + ini.WriteFile(); +} \ No newline at end of file diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h new file mode 100644 index 0000000000..6997ad3853 --- /dev/null +++ b/stepmania/src/SongManager.h @@ -0,0 +1,46 @@ +/* +----------------------------------------------------------------------------- + Class: SongManager + + Desc: Holder for all Songs and Steps. Also keeps track of the current + Song and Steps, and loads/saves statistics. + + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#ifndef _SongManager_H_ +#define _SongManager_H_ + + +#include "Song.h" + + + +class SongManager +{ +public: + SongManager(); + ~SongManager(); + + CArray m_pSongs; + Song* m_pCurSong; + Steps* m_pStepsPlayer[NUM_PLAYERS]; + + void InitSongArrayFromDisk(); + void CleanUpSongArray(); + void ReloadSongArray(); + + void ReadStatisticsFromDisk(); + void SaveStatisticsToDisk(); + +protected: + +}; + + +extern SongManager* SONGS; // global and accessable from anywhere in our program + + +#endif \ No newline at end of file diff --git a/stepmania/src/Sprite.cpp b/stepmania/src/Sprite.cpp index b1b5a73e03..47881911e2 100644 --- a/stepmania/src/Sprite.cpp +++ b/stepmania/src/Sprite.cpp @@ -12,7 +12,7 @@ #include "Sprite.h" #include "RageTextureManager.h" -#include "GameInfo.h" +#include "PrefsManager.h" #include "IniFile.h" #include #include @@ -40,8 +40,8 @@ Sprite::Sprite() m_VertAlign = align_middle; - if( GAMEINFO ) - m_bHasShadow = GAMEINFO->m_GameOptions.m_bShadows; + if( PREFS ) + m_bHasShadow = PREFS->m_GameOptions.m_bShadows; else m_bHasShadow = true; diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 39bd22ce6f..1840bec92e 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -20,7 +20,8 @@ #include "RageMusic.h" #include "RageInput.h" -#include "GameInfo.h" +#include "PrefsManager.h" +#include "SongManager.h" #include "ThemeManager.h" #include "WindowManager.h" @@ -377,7 +378,7 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) case WM_COMMAND: { - GameOptions &go = GAMEINFO->m_GameOptions; + GameOptions &go = PREFS->m_GameOptions; switch( LOWORD(wParam) ) { @@ -472,7 +473,8 @@ HRESULT CreateObjects( HWND hWnd ) SOUND = new RageSound( hWnd ); MUSIC = new RageSoundStream; INPUT = new RageInput( hWnd ); - GAMEINFO= new GameInfo; + PREFS = new PrefsManager; + SONGS = new SongManager; SCREEN = new RageScreen( hWnd ); BringWindowToTop( hWnd ); @@ -499,7 +501,7 @@ HRESULT CreateObjects( HWND hWnd ) // go.m_iDisplayColor // ); - WM->SystemMessage( ssprintf("Found %d songs.", GAMEINFO->m_pSongs.GetSize()) ); + WM->SystemMessage( ssprintf("Found %d songs.", SONGS->m_pSongs.GetSize()) ); //WM->SetNewWindow( new WindowLoading ); @@ -524,7 +526,8 @@ void DestroyObjects() DXUtil_Timer( TIMER_STOP ); SAFE_DELETE( WM ); - SAFE_DELETE( GAMEINFO ); + SAFE_DELETE( PREFS ); + SAFE_DELETE( SONGS ); SAFE_DELETE( INPUT ); SAFE_DELETE( MUSIC ); @@ -619,8 +622,8 @@ void Update() { DeviceI = diArray[i]; - GAMEINFO->DeviceToPad( DeviceI, PadI ); - GAMEINFO->PadToPlayer( PadI, PlayerI ); + PREFS->DeviceToPad( DeviceI, PadI ); + PREFS->PadToPlayer( PadI, PlayerI ); WM->Input( DeviceI, PadI, PlayerI ); } @@ -708,7 +711,7 @@ BOOL SwitchDisplayMode()//( BOOL bWindowed, DWORD dwWidth, DWORD dwHeight, DWORD // use GameOptions to get the display settings - GameOptions &go = GAMEINFO->m_GameOptions; + GameOptions &go = PREFS->m_GameOptions; bool bWindowed = go.m_bWindowed; DWORD dwWidth = go.m_iResolution; DWORD dwHeight = go.m_iResolution==640 ? 480 : 240; @@ -748,12 +751,12 @@ BOOL SwitchDisplayMode()//( BOOL bWindowed, DWORD dwWidth, DWORD dwHeight, DWORD RestoreObjects(); - if( GAMEINFO ) + if( PREFS ) { - GAMEINFO->m_GameOptions.m_bWindowed = bWindowed; - GAMEINFO->m_GameOptions.m_iDisplayColor = dwBPP; - GAMEINFO->m_GameOptions.m_iResolution = dwWidth; - GAMEINFO->SaveConfigToDisk(); + PREFS->m_GameOptions.m_bWindowed = bWindowed; + PREFS->m_GameOptions.m_iDisplayColor = dwBPP; + PREFS->m_GameOptions.m_iResolution = dwWidth; + PREFS->SavePrefsToDisk(); } if( WM ) diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 03ee49f74b..992282c9db 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -384,11 +384,7 @@ SOURCE=.\WindowTitleMenu.h # PROP Default_Filter "" # Begin Source File -SOURCE=.\GameInfo.cpp -# End Source File -# Begin Source File - -SOURCE=.\GameInfo.h +SOURCE=.\GameConstants.h # End Source File # Begin Source File @@ -420,6 +416,14 @@ SOURCE=.\PlayerInput.h # End Source File # Begin Source File +SOURCE=.\PrefsManager.cpp +# End Source File +# Begin Source File + +SOURCE=.\PrefsManager.h +# End Source File +# Begin Source File + SOURCE=.\Song.cpp # End Source File # Begin Source File @@ -428,6 +432,14 @@ SOURCE=.\song.h # End Source File # Begin Source File +SOURCE=.\SongManager.cpp +# End Source File +# Begin Source File + +SOURCE=.\SongManager.h +# End Source File +# Begin Source File + SOURCE=.\SoundSet.cpp # End Source File # Begin Source File @@ -470,6 +482,14 @@ SOURCE=.\IniFile.cpp SOURCE=.\IniFile.h # End Source File +# Begin Source File + +SOURCE=.\XMLMarkup.cpp +# End Source File +# Begin Source File + +SOURCE=.\XMLMarkup.h +# End Source File # End Group # Begin Group "System" @@ -668,6 +688,14 @@ SOURCE=.\GradeDisplay.h # End Source File # Begin Source File +SOURCE=.\GranularityIndicator.cpp +# End Source File +# Begin Source File + +SOURCE=.\GranularityIndicator.h +# End Source File +# Begin Source File + SOURCE=.\MusicSortDisplay.cpp # End Source File # Begin Source File @@ -792,14 +820,6 @@ SOURCE=.\GhostArrows.h # End Source File # Begin Source File -SOURCE=.\GranularityIndicator.cpp -# End Source File -# Begin Source File - -SOURCE=.\GranularityIndicator.h -# End Source File -# Begin Source File - SOURCE=.\GrayArrow.cpp # End Source File # Begin Source File diff --git a/stepmania/src/ThemeManager.cpp b/stepmania/src/ThemeManager.cpp index 7294815234..9d0dc2cfc7 100644 --- a/stepmania/src/ThemeManager.cpp +++ b/stepmania/src/ThemeManager.cpp @@ -1,11 +1,12 @@ #include "stdafx.h" /* ----------------------------------------------------------------------------- - File: ThemeManager.h + Class: ThemeManager - Desc: . + Desc: See header. - Copyright (c) 2001 Chris Danford. All rights reserved. + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford ----------------------------------------------------------------------------- */ @@ -73,6 +74,7 @@ CString ThemeManager::ElementToAssetPath( ThemeElement te ) case GRAPHIC_ARROWS_LEFT: sAssetPath = "Graphics\\arrows left 1x4"; break; case GRAPHIC_ARROWS_RIGHT: sAssetPath = "Graphics\\arrows right 1x4"; break; case GRAPHIC_EDIT_BACKGROUND: sAssetPath = "Graphics\\edit background"; break; + case GRAPHIC_EDIT_SNAP_INDICATOR: sAssetPath = "Graphics\\edit snap indicator"; break; case SOUND_FAILED: sAssetPath = "Sounds\\failed"; break; case SOUND_ASSIST: sAssetPath = "Sounds\\Assist"; break; @@ -87,6 +89,8 @@ CString ThemeManager::ElementToAssetPath( ThemeElement te ) case SOUND_MENU_BACK: sAssetPath = "Sounds\\menu back"; break; case SOUND_TRAINING_MUSIC: sAssetPath = "Sounds\\training music"; break; case SOUND_INVALID: sAssetPath = "Sounds\\invalid"; break; + case SOUND_EDIT_CHANGE_LINE: sAssetPath = "Sounds\\edit change line"; break; + case SOUND_EDIT_CHANGE_SNAP: sAssetPath = "Sounds\\edit change snap"; break; case FONT_OUTLINE: sAssetPath = "Fonts\\Outline"; break; case FONT_NORMAL: sAssetPath = "Fonts\\Normal"; break; diff --git a/stepmania/src/ThemeManager.h b/stepmania/src/ThemeManager.h index e01dbca45a..d0a1f533b4 100644 --- a/stepmania/src/ThemeManager.h +++ b/stepmania/src/ThemeManager.h @@ -1,10 +1,12 @@ /* ----------------------------------------------------------------------------- - File: ThemeManager.h + Class: ThemeManager - Desc: . + Desc: Manages which graphics and sounds are chosed to load. Every time + a sound or graphic is loaded, it gets the path from the ThemeManager. - Copyright (c) 2001 Chris Danford. All rights reserved. + Copyright (c) 2001-2002 by the names listed below. All rights reserved. + Chris Danford ----------------------------------------------------------------------------- */ @@ -67,6 +69,7 @@ enum ThemeElement { GRAPHIC_ARROWS_LEFT, GRAPHIC_ARROWS_RIGHT, GRAPHIC_EDIT_BACKGROUND, + GRAPHIC_EDIT_SNAP_INDICATOR, SOUND_FAILED, SOUND_ASSIST, @@ -81,6 +84,8 @@ enum ThemeElement { SOUND_MENU_BACK, SOUND_TRAINING_MUSIC, SOUND_INVALID, + SOUND_EDIT_CHANGE_LINE, + SOUND_EDIT_CHANGE_SNAP, FONT_OUTLINE, FONT_NORMAL, diff --git a/stepmania/src/smpackage/smpackage.clw b/stepmania/src/smpackage/smpackage.clw index bcea9e3272..9f78f5fc63 100644 --- a/stepmania/src/smpackage/smpackage.clw +++ b/stepmania/src/smpackage/smpackage.clw @@ -13,9 +13,9 @@ Class2=CSmpackageDlg ResourceCount=3 Resource1=IDR_MAINFRAME -Resource2=IDD_MANAGER +Resource2=IDD_INSTALL Class3=CSMPackageInstallDlg -Resource3=IDD_INSTALL +Resource3=IDD_MANAGER [CLS:CSmpackageApp] Type=0 diff --git a/stepmania/src/song.h b/stepmania/src/song.h index f510072d6d..048ee38421 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -14,7 +14,7 @@ #include "Steps.h" -#include "GameInfo.h" // for definition of GameMode +#include "PrefsManager.h" // for definition of GameMode enum GameMode; // why is this needed?