2004-04-18 08:05:18 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "StepsUtil.h"
|
|
|
|
|
#include "Steps.h"
|
|
|
|
|
#include "ProfileManager.h"
|
|
|
|
|
#include "song.h"
|
2004-04-18 18:42:42 +00:00
|
|
|
#include "SongManager.h"
|
|
|
|
|
#include "GameManager.h"
|
2004-05-22 01:37:00 +00:00
|
|
|
#include "XmlFile.h"
|
2004-04-18 08:05:18 +00:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Sorting stuff
|
|
|
|
|
//
|
|
|
|
|
map<const Steps*, CString> steps_sort_val;
|
|
|
|
|
|
|
|
|
|
bool CompareStepsPointersBySortValueAscending(const Steps *pSteps1, const Steps *pSteps2)
|
|
|
|
|
{
|
|
|
|
|
return steps_sort_val[pSteps1] < steps_sort_val[pSteps2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool CompareStepsPointersBySortValueDescending(const Steps *pSteps1, const Steps *pSteps2)
|
|
|
|
|
{
|
|
|
|
|
return steps_sort_val[pSteps1] > steps_sort_val[pSteps2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StepsUtil::SortStepsPointerArrayByNumPlays( vector<Steps*> &vStepsPointers, ProfileSlot slot, bool bDescending )
|
|
|
|
|
{
|
|
|
|
|
Profile* pProfile = PROFILEMAN->GetProfile(slot);
|
|
|
|
|
if( pProfile == NULL )
|
|
|
|
|
return; // nothing to do since we don't have data
|
|
|
|
|
SortStepsPointerArrayByNumPlays( vStepsPointers, pProfile, bDescending );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StepsUtil::SortStepsPointerArrayByNumPlays( vector<Steps*> &vStepsPointers, const Profile* pProfile, bool bDecending )
|
|
|
|
|
{
|
2004-04-18 18:42:42 +00:00
|
|
|
// ugly...
|
|
|
|
|
vector<Song*> vpSongs = SONGMAN->GetAllSongs();
|
|
|
|
|
vector<Steps*> vpAllSteps;
|
|
|
|
|
map<Steps*,Song*> mapStepsToSong;
|
|
|
|
|
{
|
|
|
|
|
for( unsigned i=0; i<vpSongs.size(); i++ )
|
|
|
|
|
{
|
|
|
|
|
Song* pSong = vpSongs[i];
|
|
|
|
|
vector<Steps*> vpSteps = pSong->GetAllSteps();
|
|
|
|
|
for( unsigned j=0; j<vpSteps.size(); j++ )
|
|
|
|
|
{
|
|
|
|
|
Steps* pSteps = vpSteps[j];
|
|
|
|
|
if( pSteps->IsAutogen() )
|
|
|
|
|
continue; // skip
|
|
|
|
|
vpAllSteps.push_back( pSteps );
|
|
|
|
|
mapStepsToSong[pSteps] = pSong;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-04-18 08:05:18 +00:00
|
|
|
ASSERT( pProfile );
|
|
|
|
|
for(unsigned i = 0; i < vStepsPointers.size(); ++i)
|
2004-04-18 18:42:42 +00:00
|
|
|
{
|
|
|
|
|
Steps* pSteps = vStepsPointers[i];
|
|
|
|
|
Song* pSong = mapStepsToSong[pSteps];
|
|
|
|
|
steps_sort_val[vStepsPointers[i]] = ssprintf("%9i", pProfile->GetStepsNumTimesPlayed(pSong,pSteps));
|
|
|
|
|
}
|
2004-04-18 08:05:18 +00:00
|
|
|
stable_sort( vStepsPointers.begin(), vStepsPointers.end(), bDecending ? CompareStepsPointersBySortValueDescending : CompareStepsPointersBySortValueAscending );
|
|
|
|
|
steps_sort_val.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
bool StepsUtil::CompareNotesPointersByRadarValues(const Steps* pSteps1, const Steps* pSteps2)
|
2004-04-18 08:05:18 +00:00
|
|
|
{
|
|
|
|
|
float fScore1 = 0;
|
|
|
|
|
float fScore2 = 0;
|
|
|
|
|
|
|
|
|
|
for( int r=0; r<NUM_RADAR_CATEGORIES; r++ )
|
|
|
|
|
{
|
2004-05-24 03:41:39 +00:00
|
|
|
fScore1 += pSteps1->GetRadarValues()[r];
|
|
|
|
|
fScore2 += pSteps2->GetRadarValues()[r];
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return fScore1 < fScore2;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
bool StepsUtil::CompareNotesPointersByMeter(const Steps *pSteps1, const Steps* pSteps2)
|
2004-04-18 08:05:18 +00:00
|
|
|
{
|
2004-05-24 03:41:39 +00:00
|
|
|
return pSteps1->GetMeter() < pSteps2->GetMeter();
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-24 03:41:39 +00:00
|
|
|
bool StepsUtil::CompareNotesPointersByDifficulty(const Steps *pSteps1, const Steps *pSteps2)
|
2004-04-18 08:05:18 +00:00
|
|
|
{
|
2004-05-24 03:41:39 +00:00
|
|
|
return pSteps1->GetDifficulty() < pSteps2->GetDifficulty();
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StepsUtil::SortNotesArrayByDifficulty( vector<Steps*> &arraySteps )
|
|
|
|
|
{
|
|
|
|
|
/* Sort in reverse order of priority. */
|
|
|
|
|
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByRadarValues );
|
|
|
|
|
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByMeter );
|
|
|
|
|
stable_sort( arraySteps.begin(), arraySteps.end(), CompareNotesPointersByDifficulty );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool StepsUtil::CompareStepsPointersByTypeAndDifficulty(const Steps *pStep1, const Steps *pStep2)
|
|
|
|
|
{
|
|
|
|
|
if( pStep1->m_StepsType < pStep2->m_StepsType )
|
|
|
|
|
return true;
|
|
|
|
|
if( pStep1->m_StepsType > pStep2->m_StepsType )
|
|
|
|
|
return false;
|
|
|
|
|
return pStep1->GetDifficulty() < pStep2->GetDifficulty();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StepsUtil::SortStepsByTypeAndDifficulty( vector<Steps*> &arraySongPointers )
|
|
|
|
|
{
|
|
|
|
|
sort( arraySongPointers.begin(), arraySongPointers.end(), CompareStepsPointersByTypeAndDifficulty );
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-23 09:17:10 +00:00
|
|
|
|
2004-04-18 08:05:18 +00:00
|
|
|
void StepsID::FromSteps( const Steps *p )
|
|
|
|
|
{
|
|
|
|
|
if( p == NULL )
|
|
|
|
|
{
|
|
|
|
|
st = STEPS_TYPE_INVALID;
|
|
|
|
|
dc = DIFFICULTY_INVALID;
|
|
|
|
|
sDescription = "";
|
2004-04-23 02:19:45 +00:00
|
|
|
uHash = 0;
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
st = p->m_StepsType;
|
|
|
|
|
dc = p->GetDifficulty();
|
2004-05-01 21:53:28 +00:00
|
|
|
if( dc == DIFFICULTY_EDIT )
|
|
|
|
|
{
|
|
|
|
|
sDescription = p->GetDescription();
|
|
|
|
|
uHash = p->GetHash();
|
|
|
|
|
} else {
|
|
|
|
|
sDescription = "";
|
|
|
|
|
uHash = 0;
|
|
|
|
|
}
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* XXX: Don't allow duplicate edit descriptions, and don't allow edit descriptions
|
|
|
|
|
* to be difficulty names (eg. "Hard"). If we do that, this will be completely unambiguous.
|
|
|
|
|
*
|
|
|
|
|
* XXX: Unless two memcards are inserted and there's overlap in the names. In that
|
|
|
|
|
* case, maybe both edits should be renamed to "Pn: foo"; as long as we don't write
|
|
|
|
|
* them back out (which we don't do except in the editor), it won't be permanent.
|
|
|
|
|
* We could do this during the actual Steps::GetID() call, instead, but then it'd have
|
|
|
|
|
* to have access to Song::m_LoadedFromProfile. */
|
2004-05-21 05:08:04 +00:00
|
|
|
|
|
|
|
|
static map<StepsID,Steps *> g_StepsIDCache;
|
2004-04-18 08:05:18 +00:00
|
|
|
Steps *StepsID::ToSteps( const Song *p, bool bAllowNull ) const
|
|
|
|
|
{
|
2004-04-24 21:01:32 +00:00
|
|
|
if( st == STEPS_TYPE_INVALID || dc == DIFFICULTY_INVALID )
|
2004-04-18 08:05:18 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
2004-05-21 05:08:04 +00:00
|
|
|
map<StepsID,Steps *>::iterator it = g_StepsIDCache.find( *this );
|
|
|
|
|
if( it != g_StepsIDCache.end() )
|
|
|
|
|
return it->second;
|
|
|
|
|
|
2004-04-18 08:05:18 +00:00
|
|
|
vector<Steps*> vNotes;
|
2004-04-24 21:01:32 +00:00
|
|
|
if( dc == DIFFICULTY_EDIT )
|
2004-05-21 05:08:04 +00:00
|
|
|
p->GetSteps( vNotes, st, dc, -1, -1, sDescription, true, 1 );
|
2004-04-24 21:01:32 +00:00
|
|
|
else
|
2004-05-21 05:08:04 +00:00
|
|
|
p->GetSteps( vNotes, st, dc, -1, -1, "", true, 1 );
|
|
|
|
|
|
|
|
|
|
Steps *ret = NULL;
|
2004-04-18 08:05:18 +00:00
|
|
|
if( !vNotes.empty() )
|
2004-05-21 05:08:04 +00:00
|
|
|
ret = vNotes[0];
|
|
|
|
|
else if( !bAllowNull )
|
|
|
|
|
RageException::Throw( "%i, %i, \"%s\"", st, dc, sDescription.c_str() );
|
|
|
|
|
|
|
|
|
|
g_StepsIDCache[*this] = ret;
|
|
|
|
|
return ret;
|
2004-04-18 08:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2004-04-18 18:42:42 +00:00
|
|
|
XNode* StepsID::CreateNode() const
|
|
|
|
|
{
|
|
|
|
|
XNode* pNode = new XNode;
|
|
|
|
|
pNode->name = "Steps";
|
|
|
|
|
|
|
|
|
|
pNode->AppendAttr( "StepsType", GameManager::NotesTypeToString(st) );
|
|
|
|
|
pNode->AppendAttr( "Difficulty", DifficultyToString(dc) );
|
|
|
|
|
if( dc == DIFFICULTY_EDIT )
|
2004-04-23 00:53:29 +00:00
|
|
|
{
|
2004-04-18 18:42:42 +00:00
|
|
|
pNode->AppendAttr( "Description", sDescription );
|
2004-04-23 00:53:29 +00:00
|
|
|
pNode->AppendAttr( "Hash", uHash );
|
|
|
|
|
}
|
2004-04-18 18:42:42 +00:00
|
|
|
|
|
|
|
|
return pNode;
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-21 05:08:04 +00:00
|
|
|
|
|
|
|
|
void StepsID::FlushCache()
|
|
|
|
|
{
|
|
|
|
|
g_StepsIDCache.clear();
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-18 18:42:42 +00:00
|
|
|
void StepsID::LoadFromNode( const XNode* pNode )
|
|
|
|
|
{
|
|
|
|
|
ASSERT( pNode->name == "Steps" );
|
|
|
|
|
|
|
|
|
|
CString sTemp;
|
|
|
|
|
|
|
|
|
|
pNode->GetAttrValue("StepsType", sTemp);
|
|
|
|
|
st = GameManager::StringToNotesType( sTemp );
|
|
|
|
|
|
|
|
|
|
pNode->GetAttrValue("Difficulty", sTemp);
|
|
|
|
|
dc = StringToDifficulty( sTemp );
|
|
|
|
|
|
|
|
|
|
if( dc == DIFFICULTY_EDIT )
|
2004-04-23 00:53:29 +00:00
|
|
|
{
|
|
|
|
|
pNode->GetAttrValue("Description", sDescription);
|
|
|
|
|
pNode->GetAttrValue("Hash", uHash);
|
2004-05-01 21:53:28 +00:00
|
|
|
} else {
|
|
|
|
|
sDescription = "";
|
|
|
|
|
uHash = 0;
|
2004-04-23 00:53:29 +00:00
|
|
|
}
|
2004-04-18 18:42:42 +00:00
|
|
|
}
|
|
|
|
|
|
2004-05-08 10:12:10 +00:00
|
|
|
CString StepsID::ToString() const
|
|
|
|
|
{
|
|
|
|
|
CString s = GameManager::NotesTypeToString(st);
|
|
|
|
|
s += " " + DifficultyToString(dc);
|
|
|
|
|
if( dc == DIFFICULTY_EDIT )
|
|
|
|
|
{
|
|
|
|
|
s += " " + sDescription;
|
|
|
|
|
s += ssprintf(" %u", uHash );
|
|
|
|
|
}
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
2004-04-18 18:42:42 +00:00
|
|
|
bool StepsID::IsValid() const
|
|
|
|
|
{
|
|
|
|
|
return st != STEPS_TYPE_INVALID && dc != DIFFICULTY_INVALID;
|
|
|
|
|
}
|
2004-04-18 08:05:18 +00:00
|
|
|
|
2004-04-26 00:08:51 +00:00
|
|
|
bool StepsID::operator<( const StepsID &rhs ) const
|
|
|
|
|
{
|
|
|
|
|
#define COMP(a) if(a<rhs.a) return true; if(a>rhs.a) return false;
|
|
|
|
|
COMP(st);
|
|
|
|
|
COMP(dc);
|
|
|
|
|
COMP(sDescription);
|
|
|
|
|
COMP(uHash);
|
|
|
|
|
#undef COMP
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-05-31 21:35:31 +00:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* (c) 2001-2004 Chris Danford, Glenn Maynard
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
|
|
|
|
* whom the Software is furnished to do so, provided that the above
|
|
|
|
|
* copyright notice(s) and this permission notice appear in all copies of
|
|
|
|
|
* the Software and that both the above copyright notice(s) and this
|
|
|
|
|
* permission notice appear in supporting documentation.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
|
|
|
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
|
|
|
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
|
|
|
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
|
|
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
|
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
|
|
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|