From 83fb83d1b4c755ff2ca17f0e743f2fa03eaf8fa2 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Fri, 23 Apr 2004 00:53:29 +0000 Subject: [PATCH] store hash value in Steps for finding equivalent edits --- stepmania/src/Steps.cpp | 10 +++++++--- stepmania/src/Steps.h | 2 ++ stepmania/src/StepsUtil.cpp | 8 +++++++- stepmania/src/StepsUtil.h | 3 ++- stepmania/src/XmlFile.cpp | 6 ++++++ stepmania/src/XmlFile.h | 6 ++++++ 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/stepmania/src/Steps.cpp b/stepmania/src/Steps.cpp index 1d1d43e485..36933f07b1 100644 --- a/stepmania/src/Steps.cpp +++ b/stepmania/src/Steps.cpp @@ -31,6 +31,7 @@ Steps::Steps() { m_StepsType = STEPS_TYPE_INVALID; m_LoadedFromProfile = PROFILE_SLOT_INVALID; + m_uHash = 0; m_Difficulty = DIFFICULTY_INVALID; m_iMeter = 0; @@ -51,11 +52,13 @@ void Steps::SetNoteData( const NoteData* pNewNoteData ) DeAutogen(); - delete notes_comp; - notes_comp = NULL; - delete notes; notes = new NoteData(*pNewNoteData); + + delete notes_comp; + notes_comp = new CompressedNoteData; + NoteDataUtil::GetSMNoteDataString( *notes, notes_comp->notes, notes_comp->attacks ); + m_uHash = GetHashForString( notes_comp->notes ); } void Steps::GetNoteData( NoteData* pNoteDataOut ) const @@ -84,6 +87,7 @@ void Steps::SetSMNoteData( const CString ¬es_comp_, const CString &attacks_co notes_comp->notes = notes_comp_; notes_comp->attacks = attacks_comp_; + m_uHash = GetHashForString( notes_comp->notes ); } void Steps::GetSMNoteData( CString ¬es_comp_out, CString &attacks_comp_out ) const diff --git a/stepmania/src/Steps.h b/stepmania/src/Steps.h index 1e44fa8ede..ae18776215 100644 --- a/stepmania/src/Steps.h +++ b/stepmania/src/Steps.h @@ -38,6 +38,7 @@ public: bool IsAnEdit() const { return m_Difficulty == DIFFICULTY_EDIT; } bool WasLoadedFromProfile() const { return m_LoadedFromProfile != PROFILE_SLOT_INVALID; } ProfileSlot GetLoadedFromProfileSlot() const { return m_LoadedFromProfile; } + unsigned GetHash() const { return Real()->m_uHash; } CString GetDescription() const { return Real()->m_sDescription; } Difficulty GetDifficulty() const { return Real()->m_Difficulty; } ProfileSlot GetLoadedFromProfile() const { return m_LoadedFromProfile; } @@ -80,6 +81,7 @@ protected: /* These values are pulled from the autogen source first, if there is one. */ ProfileSlot m_LoadedFromProfile; // PROFILE_SLOT_INVALID if wasn't loaded from a profile + unsigned m_uHash; // only used if m_Difficulty == DIFFICULTY_EDIT CString m_sDescription; // Step author, edit name, or something meaningful Difficulty m_Difficulty; // difficulty classification int m_iMeter; // difficulty rating from MIN_METER to MAX_METER diff --git a/stepmania/src/StepsUtil.cpp b/stepmania/src/StepsUtil.cpp index c805d0b158..de2564f3d8 100644 --- a/stepmania/src/StepsUtil.cpp +++ b/stepmania/src/StepsUtil.cpp @@ -168,7 +168,10 @@ XNode* StepsID::CreateNode() const pNode->AppendAttr( "StepsType", GameManager::NotesTypeToString(st) ); pNode->AppendAttr( "Difficulty", DifficultyToString(dc) ); if( dc == DIFFICULTY_EDIT ) + { pNode->AppendAttr( "Description", sDescription ); + pNode->AppendAttr( "Hash", uHash ); + } return pNode; } @@ -186,7 +189,10 @@ void StepsID::LoadFromNode( const XNode* pNode ) dc = StringToDifficulty( sTemp ); if( dc == DIFFICULTY_EDIT ) - pNode->GetChildValue("Description", sDescription); + { + pNode->GetAttrValue("Description", sDescription); + pNode->GetAttrValue("Hash", uHash); + } } bool StepsID::IsValid() const diff --git a/stepmania/src/StepsUtil.h b/stepmania/src/StepsUtil.h index 9eb1147e9a..ecd0ad6a9c 100644 --- a/stepmania/src/StepsUtil.h +++ b/stepmania/src/StepsUtil.h @@ -37,6 +37,7 @@ class StepsID StepsType st; Difficulty dc; CString sDescription; + unsigned uHash; public: StepsID() { Unset(); } @@ -45,7 +46,7 @@ public: Steps *ToSteps( const Song *p, bool bAllowNull ) const; bool operator<( const StepsID &other ) const { - return st < other.st || dc < other.dc || sDescription < other.sDescription; + return st < other.st || dc < other.dc || sDescription < other.sDescription || uHash < other.uHash; } XNode* CreateNode() const; diff --git a/stepmania/src/XmlFile.cpp b/stepmania/src/XmlFile.cpp index b3afeb2c86..b83f0dfff7 100644 --- a/stepmania/src/XmlFile.cpp +++ b/stepmania/src/XmlFile.cpp @@ -886,6 +886,11 @@ LPXNode XNode::AppendChild( const char* name /*= NULL*/, int value /*= NULL*/ ) return AppendChild( name, ssprintf("%d",value) ); } +LPXNode XNode::AppendChild( const char* name /*= NULL*/, unsigned value /*= NULL*/ ) +{ + return AppendChild( name, ssprintf("%u",value) ); +} + //======================================================== // Name : AppendChild // Desc : add node @@ -1046,6 +1051,7 @@ LPXAttr XNode::AppendAttr( const char* name /*= NULL*/, const char* value /*= NU LPXAttr XNode::AppendAttr( const char* name, float value ){ return AppendAttr(name,ssprintf("%f",value)); } LPXAttr XNode::AppendAttr( const char* name, int value ) { return AppendAttr(name,ssprintf("%d",value)); } +LPXAttr XNode::AppendAttr( const char* name, unsigned value ) { return AppendAttr(name,ssprintf("%u",value)); } //======================================================== // Name : DetachChild diff --git a/stepmania/src/XmlFile.h b/stepmania/src/XmlFile.h index cda91a1009..190a3db651 100644 --- a/stepmania/src/XmlFile.h +++ b/stepmania/src/XmlFile.h @@ -106,6 +106,7 @@ struct XAttr void GetValue(int &out) const { out = atoi(value); } void GetValue(float &out) const { out = (float) atof(value); } void GetValue(bool &out) const { out = atoi(value) != 0; } + void GetValue(unsigned &out) const { sscanf(value,"%u",&out); } XNode* parent; @@ -123,6 +124,7 @@ struct XNode void GetValue(int &out) const { out = atoi(value); } 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; } // internal variables LPXNode parent; // parent node @@ -145,6 +147,7 @@ struct XNode bool GetAttrValue(const char* name,int &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue(const char* name,float &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } bool GetAttrValue(const char* name,bool &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } + bool GetAttrValue(const char* name,unsigned &out) const { const XAttr* pAttr=GetAttr(name); if(pAttr==NULL) return false; pAttr->GetValue(out); return true; } XAttrs GetAttrs( const char* name ); // in one level child nodes @@ -155,6 +158,7 @@ struct XNode bool GetChildValue(const char* name,int &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue(const char* name,float &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } bool GetChildValue(const char* name,bool &out) const { const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } + bool GetChildValue(const char* name,unsigned &out) const{ const XNode* pChild=GetChild(name); if(pChild==NULL) return false; pChild->GetValue(out); return true; } XNodes GetChilds( const char* name ); XNodes GetChilds(); @@ -169,6 +173,7 @@ struct XNode LPXNode AppendChild( const char* name = NULL, const char* value = NULL ); LPXNode AppendChild( const char* name, float value ); LPXNode AppendChild( const char* name, int value ); + LPXNode AppendChild( const char* name, unsigned value ); LPXNode AppendChild( LPXNode node ); bool RemoveChild( LPXNode node ); LPXNode DetachChild( LPXNode node ); @@ -180,6 +185,7 @@ struct XNode LPXAttr AppendAttr( const char* name = NULL, const char* value = NULL ); LPXAttr AppendAttr( const char* name, float value ); LPXAttr AppendAttr( const char* name, int value ); + LPXAttr AppendAttr( const char* name, unsigned value ); LPXAttr AppendAttr( LPXAttr attr ); bool RemoveAttr( LPXAttr attr ); LPXAttr DetachAttr( LPXAttr attr );