From a6b5da320777d16c288bff648067a39574b9270e Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 17 Jul 2004 21:49:32 +0000 Subject: [PATCH] move Style XML saving/loading into StyleID --- stepmania/src/GameState.cpp | 4 +- stepmania/src/Makefile.am | 2 +- stepmania/src/Profile.cpp | 27 ++++------ stepmania/src/Profile.h | 3 +- stepmania/src/StepMania.dsp | 12 ++++- stepmania/src/StepMania.vcproj | 6 +++ stepmania/src/StyleUtil.cpp | 90 ++++++++++++++++++++++++++++++++++ stepmania/src/StyleUtil.h | 51 +++++++++++++++++++ stepmania/src/XmlFile.cpp | 25 ++++++++++ stepmania/src/XmlFile.h | 4 ++ 10 files changed, 201 insertions(+), 23 deletions(-) create mode 100644 stepmania/src/StyleUtil.cpp create mode 100644 stepmania/src/StyleUtil.h diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 8c8fa950d2..53199b28c9 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -287,7 +287,9 @@ void AddPlayerStatsToProfile( Profile *pProfile, const StageStats &ss, PlayerNum const int iMeter = clamp( ss.iMeter[p], 0, MAX_METER ); pProfile->m_iNumSongsPlayedByPlayMode[ss.playMode]++; - pProfile->m_iNumSongsPlayedByStyle[ss.pStyle]++; + StyleID sID; + sID.FromStyle( ss.pStyle ); + pProfile->m_iNumSongsPlayedByStyle[sID]++; pProfile->m_iNumSongsPlayedByDifficulty[ss.pSteps[p]->GetDifficulty()]++; pProfile->m_iNumSongsPlayedByMeter[iMeter]++; pProfile->m_iTotalDancePoints += ss.iActualDancePoints[p]; diff --git a/stepmania/src/Makefile.am b/stepmania/src/Makefile.am index cea1fa312a..0ac360b2b0 100644 --- a/stepmania/src/Makefile.am +++ b/stepmania/src/Makefile.am @@ -68,7 +68,7 @@ RandomSample.cpp RandomSample.h RadarValues.cpp RadarValues.h \ ScoreKeeper.h ScoreKeeperMAX2.cpp ScoreKeeperMAX2.h \ ScoreKeeperRave.cpp ScoreKeeperRave.h Song.cpp song.h SongCacheIndex.cpp SongCacheIndex.h \ SongOptions.cpp SongOptions.h SongUtil.cpp SongUtil.h StageStats.cpp StageStats.h Steps.cpp Steps.h \ -StepsUtil.cpp StepsUtil.h Style.cpp Style.h \ +StepsUtil.cpp StepsUtil.h Style.cpp Style.h StyleUtil.cpp StyleUtil.h \ StyleInput.h TimingData.cpp TimingData.h \ Trail.cpp Trail.h TrailUtil.cpp TrailUtil.h TitleSubstitution.cpp TitleSubstitution.h diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 445ab5cab2..bb758e07a2 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -769,18 +769,17 @@ XNode* Profile::SaveGeneralDataCreateNode() const { XNode* pNumSongsPlayedByStyle = pGeneralDataNode->AppendChild("NumSongsPlayedByStyle"); - for( map::const_iterator iter = m_iNumSongsPlayedByStyle.begin(); + for( map::const_iterator iter = m_iNumSongsPlayedByStyle.begin(); iter != m_iNumSongsPlayedByStyle.end(); iter++ ) { - const Style *s = iter->first; - const GameDef *g = GAMEMAN->GetGameDefForGame( s->m_Game ); - ASSERT( g ); + const StyleID &s = iter->first; int iNumPlays = iter->second; - XNode *pStyleNode = pNumSongsPlayedByStyle->AppendChild( "Style", iNumPlays ); - pStyleNode->AppendAttr( "Game", g->m_szName ); - pStyleNode->AppendAttr( "Style", s->m_szName ); + XNode *pStyleNode = s.CreateNode(); + pStyleNode->SetValue( iNumPlays ); + + pNumSongsPlayedByStyle->AppendChild( pStyleNode ); } } @@ -919,18 +918,10 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) if( style->name != "Style" ) continue; - CString sGame; - if( !style->GetAttrValue( "Game", sGame ) ) - WARN_AND_CONTINUE; - Game g = GAMEMAN->StringToGameType( sGame ); - if( g == GAME_INVALID ) - WARN_AND_CONTINUE; + StyleID s; + s.LoadFromNode( style ); - CString sStyle; - if( !style->GetAttrValue( "Style", sStyle ) ) - WARN_AND_CONTINUE; - const Style* s = GAMEMAN->GameAndStringToStyle( g, sStyle ); - if( s == NULL ) + if( !s.IsValid() ) WARN_AND_CONTINUE; style->GetValue( m_iNumSongsPlayedByStyle[s] ); diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 46d6722817..4550974103 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -13,6 +13,7 @@ #include "StepsUtil.h" // for StepsID #include "CourseUtil.h" // for CourseID #include "TrailUtil.h" // for TrailID +#include "StyleUtil.h" // for StyleID struct XNode; @@ -107,7 +108,7 @@ public: set m_UnlockedSongs; mutable CString m_sLastPlayedMachineGuid; // mutable because we overwrite this on save, and I don't want to remove const from the whole save chain. -Chris int m_iNumSongsPlayedByPlayMode[NUM_PLAY_MODES]; - map m_iNumSongsPlayedByStyle; + map m_iNumSongsPlayedByStyle; int m_iNumSongsPlayedByDifficulty[NUM_DIFFICULTIES]; int m_iNumSongsPlayedByMeter[MAX_METER+1]; int m_iNumSongsPassedByPlayMode[NUM_PLAY_MODES]; diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 6d5a56ffd2..7b7948e2c4 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -62,7 +62,7 @@ IntDir=.\../Debug6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -99,7 +99,7 @@ IntDir=.\../Release6 TargetDir=\stepmania\stepmania\Program TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool @@ -996,6 +996,14 @@ SOURCE=.\StyleInput.h # End Source File # Begin Source File +SOURCE=.\StyleUtil.cpp +# End Source File +# Begin Source File + +SOURCE=.\StyleUtil.h +# End Source File +# Begin Source File + SOURCE=.\TimingData.cpp # End Source File # Begin Source File diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index 6e86fe99bf..f87e02942e 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -878,6 +878,12 @@ cl /Zl /nologo /c verstub.cpp /Fo"$(IntDir)"\ + + + + diff --git a/stepmania/src/StyleUtil.cpp b/stepmania/src/StyleUtil.cpp new file mode 100644 index 0000000000..b9dc1a22ec --- /dev/null +++ b/stepmania/src/StyleUtil.cpp @@ -0,0 +1,90 @@ +#include "global.h" +#include "StyleUtil.h" +#include "GameManager.h" +#include "XmlFile.h" + + +void StyleID::FromStyle( const Style *p ) +{ + if( p ) + { + sGame = GAMEMAN->GetGameDefForGame(p->m_Game)->m_szName; + sStyle = p->m_szName; + } + else + { + sGame = ""; + sStyle = ""; + } +} + +const Style *StyleID::ToStyle() const +{ + Game game = GameManager::StringToGameType( sGame ); + if( game == GAME_INVALID ) + return NULL; + + return GAMEMAN->GameAndStringToStyle( game, sStyle ); +} + +XNode* StyleID::CreateNode() const +{ + XNode* pNode = new XNode; + pNode->name = "Style"; + + pNode->AppendAttr( "Game", sGame ); + pNode->AppendAttr( "Style", sStyle ); + + return pNode; +} + +void StyleID::LoadFromNode( const XNode* pNode ) +{ + Unset(); + ASSERT( pNode->name == "Style" ); + + sGame = ""; + pNode->GetAttrValue("Game", sGame); + + sStyle = ""; + pNode->GetAttrValue("Style", sStyle); +} + +bool StyleID::IsValid() const +{ + return !sGame.empty() && !sStyle.empty(); +} + +bool StyleID::operator<( const StyleID &rhs ) const +{ +#define COMP(a) if(arhs.a) return false; + COMP(sGame); + COMP(sStyle); +#undef COMP + return false; +} + +/* + * (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. + */ diff --git a/stepmania/src/StyleUtil.h b/stepmania/src/StyleUtil.h new file mode 100644 index 0000000000..a6016d37c5 --- /dev/null +++ b/stepmania/src/StyleUtil.h @@ -0,0 +1,51 @@ +#ifndef STYLEUTIL_H +#define STYLEUTIL_H + +#include "Style.h" + +struct XNode; + +class StyleID +{ + CString sGame; + CString sStyle; + +public: + StyleID() { Unset(); } + void Unset() { FromStyle(NULL); } + void FromStyle( const Style *p ); + const Style *ToStyle() const; + bool operator<( const StyleID &rhs ) const; + + XNode* CreateNode() const; + void LoadFromNode( const XNode* pNode ); + bool IsValid() const; + static void FlushCache(); +}; + +#endif + +/* + * (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. + */ diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index d488ab800f..830aa74902 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -625,6 +625,31 @@ bool XNode::GetXML( RageFile &f, LPDISP_OPT opt /*= &optDefault*/ ) return true; } +//======================================================== +// Name : GetValue +// Desc : +// Param : +// Return : +//-------------------------------------------------------- +// Coder Date Desc +//======================================================== +void XNode::SetValue(int v) +{ + value = ssprintf("%d",v); +} +void XNode::SetValue(float v) +{ + value = ssprintf("%f",v); +} +void XNode::SetValue(bool v) +{ + value = ssprintf("%d",v); +} +void XNode::SetValue(unsigned v) +{ + value = ssprintf("%u",v); +} + //======================================================== // Name : GetAttr // Desc : get attribute with attribute name diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index 3f99c6bf90..76e5810b3f 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -127,6 +127,10 @@ struct XNode void GetValue(float &out) const { out = (float) atof(value); } void GetValue(bool &out) const { out = atoi(value) != 0; } void GetValue(unsigned &out) const { out = (unsigned)atoi(value) != 0; } + void SetValue(int v); + void SetValue(float v); + void SetValue(bool v); + void SetValue(unsigned v); // internal variables LPXNode parent; // parent node