move song finding to SongUtil

This commit is contained in:
Chris Danford
2006-06-13 03:51:18 +00:00
parent af3e1c571c
commit c7124728e0
4 changed files with 32 additions and 28 deletions
+19 -17
View File
@@ -69,14 +69,16 @@ RString CourseEntry::GetTextDescription() const
vsEntryDescription.push_back( pSong->GetTranslitFullTitle() ); vsEntryDescription.push_back( pSong->GetTranslitFullTitle() );
else else
vsEntryDescription.push_back( "Random" ); vsEntryDescription.push_back( "Random" );
if( !sSongGroup.empty() ) if( !songCriteria.m_sGroupName.empty() )
vsEntryDescription.push_back( sSongGroup ); vsEntryDescription.push_back( songCriteria.m_sGroupName );
if( baseDifficulty != DIFFICULTY_INVALID && baseDifficulty != DIFFICULTY_MEDIUM ) if( !songCriteria.m_sGenre.empty() )
vsEntryDescription.push_back( DifficultyToLocalizedString(baseDifficulty) ); vsEntryDescription.push_back( songCriteria.m_sGenre );
if( iLowMeter != -1 ) if( stepsCriteria.m_difficulty != DIFFICULTY_INVALID && stepsCriteria.m_difficulty != DIFFICULTY_MEDIUM )
vsEntryDescription.push_back( ssprintf("Low meter: %d", iLowMeter) ); vsEntryDescription.push_back( DifficultyToLocalizedString(stepsCriteria.m_difficulty) );
if( iHighMeter != -1 ) if( stepsCriteria.m_iLowMeter != -1 )
vsEntryDescription.push_back( ssprintf("High meter: %d", iHighMeter) ); vsEntryDescription.push_back( ssprintf("Low meter: %d", stepsCriteria.m_iLowMeter) );
if( stepsCriteria.m_iHighMeter != -1 )
vsEntryDescription.push_back( ssprintf("High meter: %d", stepsCriteria.m_iHighMeter) );
if( songSort != SongSort_Randomize ) if( songSort != SongSort_Randomize )
vsEntryDescription.push_back( "Sort: %d" + SongSortToLocalizedString(songSort) ); vsEntryDescription.push_back( "Sort: %d" + SongSortToLocalizedString(songSort) );
if( songSort != SongSort_Randomize && iChooseIndex != 0 ) if( songSort != SongSort_Randomize && iChooseIndex != 0 )
@@ -487,7 +489,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
if( IsAnEdit() && UNLOCKMAN->SongIsLocked(e->pSong) ) if( IsAnEdit() && UNLOCKMAN->SongIsLocked(e->pSong) )
continue; continue;
// Choose an exact song, if we have matching steps and all // Choose an exact song, if we have matching steps and all
e->pSong->GetSteps( vpPossibleSteps, st, e->baseDifficulty, e->iLowMeter, e->iHighMeter ); SongUtil::GetSteps( e->pSong, vpPossibleSteps, st, e->stepsCriteria.m_difficulty, e->stepsCriteria.m_iLowMeter, e->stepsCriteria.m_iHighMeter );
// Remove all locked steps. // Remove all locked steps.
if( IsAnEdit() ) if( IsAnEdit() )
RemoveIf( vpPossibleSteps, bind1st(ptr_fun(StepsIsLocked), e->pSong) ); RemoveIf( vpPossibleSteps, bind1st(ptr_fun(StepsIsLocked), e->pSong) );
@@ -510,11 +512,11 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
vector<Song*> vpPossibleSongs; vector<Song*> vpPossibleSongs;
FOREACH( Song*, vpAllPossibleSongs, song ) FOREACH( Song*, vpAllPossibleSongs, song )
{ {
if( !e->sSongGroup.empty() && (*song)->m_sGroupName != e->sSongGroup ) if( !e->songCriteria.Matches( *song ) )
continue; continue;
vector<Steps*> vpMatchingSteps; vector<Steps*> vpMatchingSteps;
(*song)->GetSteps( vpMatchingSteps, st, e->baseDifficulty, e->iLowMeter, e->iHighMeter ); SongUtil::GetSteps( *song, vpMatchingSteps, st, e->stepsCriteria.m_difficulty, e->stepsCriteria.m_iLowMeter, e->stepsCriteria.m_iHighMeter );
StepsUtil::RemoveLockedSteps( *song, vpMatchingSteps ); StepsUtil::RemoveLockedSteps( *song, vpMatchingSteps );
if( vpMatchingSteps.empty() ) if( vpMatchingSteps.empty() )
@@ -534,7 +536,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
pResolvedSong = vpPossibleSongs[e->iChooseIndex]; pResolvedSong = vpPossibleSongs[e->iChooseIndex];
else else
continue; continue;
pResolvedSong->GetSteps( vpPossibleSteps, st, e->baseDifficulty, e->iLowMeter, e->iHighMeter ); SongUtil::GetSteps( pResolvedSong, vpPossibleSteps, st, e->stepsCriteria.m_difficulty, e->stepsCriteria.m_iLowMeter, e->stepsCriteria.m_iHighMeter );
StepsUtil::RemoveLockedSteps( pResolvedSong, vpPossibleSteps ); StepsUtil::RemoveLockedSteps( pResolvedSong, vpPossibleSteps );
} }
@@ -550,8 +552,8 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
* either easier or harder than the base difficulty. If no such steps exist, then * either easier or harder than the base difficulty. If no such steps exist, then
* just use the one we already have. */ * just use the one we already have. */
Difficulty dc = pResolvedSteps->GetDifficulty(); Difficulty dc = pResolvedSteps->GetDifficulty();
int iLowMeter = e->iLowMeter; int iLowMeter = e->stepsCriteria.m_iLowMeter;
int iHighMeter = e->iHighMeter; int iHighMeter = e->stepsCriteria.m_iHighMeter;
if( cd != DIFFICULTY_MEDIUM && !e->bNoDifficult ) if( cd != DIFFICULTY_MEDIUM && !e->bNoDifficult )
{ {
Difficulty new_dc = (Difficulty)(dc + cd - DIFFICULTY_MEDIUM); Difficulty new_dc = (Difficulty)(dc + cd - DIFFICULTY_MEDIUM);
@@ -560,7 +562,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
bool bChangedDifficulty = false; bool bChangedDifficulty = false;
if( new_dc != dc ) if( new_dc != dc )
{ {
Steps* pNewSteps = pResolvedSong->GetStepsByDifficulty( st, new_dc ); Steps* pNewSteps = SongUtil::GetStepsByDifficulty( pResolvedSong, st, new_dc );
if( pNewSteps ) if( pNewSteps )
{ {
dc = new_dc; dc = new_dc;
@@ -577,7 +579,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
* on the original range, bump the steps based on course difficulty, and * on the original range, bump the steps based on course difficulty, and
* then retroactively tweak the low_meter/high_meter so course displays * then retroactively tweak the low_meter/high_meter so course displays
* line up. */ * line up. */
if( e->baseDifficulty == DIFFICULTY_INVALID && bChangedDifficulty ) if( e->stepsCriteria.m_difficulty == DIFFICULTY_INVALID && bChangedDifficulty )
{ {
/* Minimum and maximum to add to make the meter range contain the actual /* Minimum and maximum to add to make the meter range contain the actual
* meter: */ * meter: */
@@ -610,7 +612,7 @@ bool Course::GetTrailUnsorted( StepsType st, CourseDifficulty cd, Trail &trail )
/* If we chose based on meter (not difficulty), then store DIFFICULTY_INVALID, so /* If we chose based on meter (not difficulty), then store DIFFICULTY_INVALID, so
* other classes can tell that we used meter. */ * other classes can tell that we used meter. */
if( e->baseDifficulty == DIFFICULTY_INVALID ) if( e->stepsCriteria.m_difficulty == DIFFICULTY_INVALID )
{ {
te.dc = DIFFICULTY_INVALID; te.dc = DIFFICULTY_INVALID;
} }
+9 -9
View File
@@ -165,7 +165,7 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou
split( sSong, "/", bits ); split( sSong, "/", bits );
if( bits.size() == 2 ) if( bits.size() == 2 )
{ {
new_entry.sSongGroup = bits[0]; new_entry.songCriteria.m_sGroupName = bits[0];
} }
else else
{ {
@@ -174,7 +174,7 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou
sPath.c_str(), sSong.c_str() ); sPath.c_str(), sSong.c_str() );
} }
if( !SONGMAN->DoesSongGroupExist(new_entry.sSongGroup) ) if( !SONGMAN->DoesSongGroupExist(new_entry.songCriteria.m_sGroupName) )
{ {
/* XXX: We need a place to put "user warnings". This is too loud for info.txt-- /* XXX: We need a place to put "user warnings". This is too loud for info.txt--
* it obscures important warnings--and regular users never look there, anyway. */ * it obscures important warnings--and regular users never look there, anyway. */
@@ -193,7 +193,7 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou
if( bits.size() == 2 ) if( bits.size() == 2 )
{ {
new_entry.sSongGroup = bits[0]; new_entry.songCriteria.m_sGroupName = bits[0];
new_entry.pSong = SONGMAN->FindSong( bits[0], bits[1] ); new_entry.pSong = SONGMAN->FindSong( bits[0], bits[1] );
} }
else if( bits.size() == 1 ) else if( bits.size() == 1 )
@@ -212,18 +212,18 @@ bool CourseLoaderCRS::LoadFromMsd( const RString &sPath, const MsdFile &msd, Cou
} }
} }
new_entry.baseDifficulty = StringToDifficulty( sParams[2] ); new_entry.stepsCriteria.m_difficulty = StringToDifficulty( sParams[2] );
if( new_entry.baseDifficulty == DIFFICULTY_INVALID ) if( new_entry.stepsCriteria.m_difficulty == DIFFICULTY_INVALID )
{ {
int retval = sscanf( sParams[2], "%d..%d", &new_entry.iLowMeter, &new_entry.iHighMeter ); int retval = sscanf( sParams[2], "%d..%d", &new_entry.stepsCriteria.m_iLowMeter, &new_entry.stepsCriteria.m_iHighMeter );
if( retval == 1 ) if( retval == 1 )
new_entry.iHighMeter = new_entry.iLowMeter; new_entry.stepsCriteria.m_iHighMeter = new_entry.stepsCriteria.m_iLowMeter;
else if( retval != 2 ) else if( retval != 2 )
{ {
LOG->Warn( "Course file '%s' contains an invalid difficulty setting: \"%s\", 3..6 used instead", LOG->Warn( "Course file '%s' contains an invalid difficulty setting: \"%s\", 3..6 used instead",
sPath.c_str(), sParams[2].c_str() ); sPath.c_str(), sParams[2].c_str() );
new_entry.iLowMeter = 3; new_entry.stepsCriteria.m_iLowMeter = 3;
new_entry.iHighMeter = 6; new_entry.stepsCriteria.m_iHighMeter = 6;
} }
} }
+1
View File
@@ -13,6 +13,7 @@
#include <map> #include <map>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <float.h>
int randseed = time(NULL); int randseed = time(NULL);
+3 -2
View File
@@ -22,6 +22,7 @@
#include "RageLog.h" #include "RageLog.h"
#include "song.h" #include "song.h"
#include "InputEventPlus.h" #include "InputEventPlus.h"
#include "SongUtil.h"
#include "RageInput.h" #include "RageInput.h"
AutoScreenMessage( SM_NoSongs ) AutoScreenMessage( SM_NoSongs )
@@ -472,7 +473,7 @@ void ScreenNetSelectMusic::StartSelectedSong()
FOREACH_EnabledPlayer (pn) FOREACH_EnabledPlayer (pn)
{ {
GAMESTATE->m_PreferredDifficulty[pn].Set( m_DC[pn] ); GAMESTATE->m_PreferredDifficulty[pn].Set( m_DC[pn] );
Steps * pSteps = pSong->GetStepsByDifficulty(st,m_DC[pn]); Steps *pSteps = SongUtil::GetStepsByDifficulty(pSong, st, m_DC[pn]);
GAMESTATE->m_pCurSteps[pn].Set( pSteps ); GAMESTATE->m_pCurSteps[pn].Set( pSteps );
} }
@@ -501,7 +502,7 @@ void ScreenNetSelectMusic::UpdateDifficulties( PlayerNumber pn )
StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType; StepsType st = GAMESTATE->GetCurrentStyle()->m_StepsType;
Steps * pSteps = GAMESTATE->m_pCurSong->GetStepsByDifficulty( st, m_DC[pn] ); Steps * pSteps = SongUtil::GetStepsByDifficulty( GAMESTATE->m_pCurSong, st, m_DC[pn] );
GAMESTATE->m_pCurSteps[pn].Set( pSteps ); GAMESTATE->m_pCurSteps[pn].Set( pSteps );
if ( ( m_DC[pn] < NUM_Difficulty ) && ( m_DC[pn] >= DIFFICULTY_BEGINNER ) ) if ( ( m_DC[pn] < NUM_Difficulty ) && ( m_DC[pn] >= DIFFICULTY_BEGINNER ) )