From f082368325bd6872d6d2f1e572f58e3267d9ddc1 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 13 Jan 2005 17:38:18 +0000 Subject: [PATCH] fix up Song::GetClosestNotes: search all difficulties; if not looking for an edit, don't return one --- stepmania/src/Song.cpp | 44 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 2836934bce..c4389e2b79 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -922,30 +922,26 @@ Steps* Song::GetStepsByDescription( StepsType st, CString sDescription ) const Steps* Song::GetClosestNotes( StepsType st, Difficulty dc ) const { - Difficulty newDC = dc; - Steps* pSteps; - pSteps = GetStepsByDifficulty( st, newDC ); - if( pSteps ) - return pSteps; - newDC = (Difficulty)(dc-1); - CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 ); - pSteps = GetStepsByDifficulty( st, newDC ); - if( pSteps ) - return pSteps; - newDC = (Difficulty)(dc+1); - CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 ); - pSteps = GetStepsByDifficulty( st, newDC ); - if( pSteps ) - return pSteps; - newDC = (Difficulty)(dc-2); - CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 ); - pSteps = GetStepsByDifficulty( st, newDC ); - if( pSteps ) - return pSteps; - newDC = (Difficulty)(dc+2); - CLAMP( (int&)newDC, 0, NUM_DIFFICULTIES-1 ); - pSteps = GetStepsByDifficulty( st, newDC ); - return pSteps; + ASSERT( dc != DIFFICULTY_INVALID ); + + const vector& vpSteps = GetAllSteps(st); + Steps *pClosest = NULL; + int iClosestDistance = 999; + for( unsigned i=0; iGetDifficulty() == DIFFICULTY_EDIT && dc != DIFFICULTY_EDIT ) + continue; + int iDistance = abs(dc - pSteps->GetDifficulty()); + if( iDistance < iClosestDistance ) + { + pClosest = pSteps; + iClosestDistance = iDistance; + } + } + + return pClosest; } /* Return whether the song is playable in the given style. */