From 4f1455d30e38078e67d308f79aa3cea9c60645fc Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 14 Jan 2003 22:44:30 +0000 Subject: [PATCH] fix up MsdFile; get rid of arbitrary limits --- stepmania/src/Course.cpp | 13 ++++------ stepmania/src/MsdFile.cpp | 32 +++++++++--------------- stepmania/src/MsdFile.h | 43 ++++++++++++++++---------------- stepmania/src/NotesLoaderDWI.cpp | 40 ++++++++++++++++------------- stepmania/src/NotesLoaderDWI.h | 2 +- stepmania/src/NotesLoaderKSF.cpp | 4 +-- stepmania/src/NotesLoaderSM.cpp | 4 +-- 7 files changed, 67 insertions(+), 71 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 1a6a67f3cc..6f1a8ca5ff 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -50,8 +50,8 @@ void Course::LoadFromCRSFile( CString sPath, vector &apSongs ) for( unsigned i=0; i &apSongs ) else if( 0 == stricmp(sValueName, "REPEAT") ) { - sParams[1].MakeLower(); - if( sParams[1].Find("yes") != -1 ) + CString str = sParams[1]; + str.MakeLower(); + if( str.Find("yes") != -1 ) m_bRepeat = true; } else if( 0 == stricmp(sValueName, "LIVES") ) - { m_iLives = atoi( sParams[1] ); - } else if( 0 == stricmp(sValueName, "EXTRA") ) - { m_iExtra = atoi( sParams[1] ); - } else if( 0 == stricmp(sValueName, "SONG") ) { diff --git a/stepmania/src/MsdFile.cpp b/stepmania/src/MsdFile.cpp index 3daec18071..80f69320b2 100644 --- a/stepmania/src/MsdFile.cpp +++ b/stepmania/src/MsdFile.cpp @@ -7,6 +7,7 @@ Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford + Glenn Maynard ----------------------------------------------------------------------------- */ @@ -40,37 +41,21 @@ #include "RageLog.h" #include "io.h" #include "fcntl.h" - - -MsdFile::MsdFile() -{ - m_iNumValues = 0; -} - -MsdFile::~MsdFile() -{ -} +#include "RageUtil.h" void MsdFile::AddParam( char *buf, int len ) { - int valueno = m_iNumValues-1; - int paramno = m_iNumParams[valueno]; - ASSERT( paramno < MAX_PARAMS_PER_VALUE ); - m_iNumParams[valueno]++; - m_sParams[valueno][paramno] = CString(buf, len); + values.back().params.push_back(CString(buf, len)); } void MsdFile::AddValue() /* (no extra charge) */ { - m_iNumValues++; - ASSERT( m_iNumValues < MAX_VALUES ); + values.push_back(value_t()); } void MsdFile::ReadBuf( char *buf, int len ) { int value_start = -1; - memset(m_iNumParams, 0, sizeof(m_iNumParams)); - m_iNumValues = 0; bool ReadingValue=false; int i = 0; @@ -163,7 +148,7 @@ bool MsdFile::ReadFile( CString sNewPath ) if( (fd = open(sNewPath, _O_RDONLY, 0)) == -1 ) return false; - int iBufferSize = _filelength( fd ) + 1000; // +1000 because sometimes the bytes read is > filelength. Why? + int iBufferSize = GetFileSizeInBytes(sNewPath) + 1000; // +1000 because sometimes the bytes read is > filelength. Why? // allocate a string to hold the file char* szFileString = new char[iBufferSize]; @@ -181,3 +166,10 @@ bool MsdFile::ReadFile( CString sNewPath ) return true; } +CString MsdFile::GetParam(unsigned val, unsigned par) const +{ + if(val >= GetNumValues()) return 0; + if(par >= GetNumParams(val)) return 0; + + return values[val].params[par]; +} diff --git a/stepmania/src/MsdFile.h b/stepmania/src/MsdFile.h index 319440d1e5..313867b815 100644 --- a/stepmania/src/MsdFile.h +++ b/stepmania/src/MsdFile.h @@ -8,37 +8,38 @@ Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford + Glenn Maynard ----------------------------------------------------------------------------- */ -const unsigned MAX_VALUES = 200; -const unsigned MAX_PARAMS_PER_VALUE = 10; - class MsdFile { +public: + /* #param:param:param:param; <- one whole value */ + struct value_t + { + vector params; + + CString operator[](unsigned i) const { if(i >= params.size()) return ""; return params[i]; } + }; + + virtual ~MsdFile() { } + + //returns true if successful, false otherwise + bool ReadFile( CString sFilePath ); + + unsigned GetNumValues() const { return values.size(); } + unsigned GetNumParams(unsigned val) const { if(val >= GetNumValues()) return 0; return values[val].params.size(); } + const value_t &GetValue(unsigned val) const { ASSERT(val < GetNumValues()); return values[val]; } + CString GetParam(unsigned val, unsigned par) const; + +private: void ReadBuf( char *buf, int len ); void AddParam( char *buf, int len ); void AddValue(); - unsigned m_iNumValues; // tells how many values are valid - -public: - MsdFile(); - - //default destructor - virtual ~MsdFile(); - - //reads ini file specified using MsdFile::SetPath() - //returns true if successful, false otherwise - bool ReadFile( CString sFilePath ); - - CString m_sParams[MAX_VALUES][MAX_PARAMS_PER_VALUE]; - - /* #param:param:param:param; <- one whole value */ - unsigned m_iNumParams[MAX_VALUES]; // tells how many params this value has - - unsigned GetNumValues() const { return m_iNumValues; } + vector values; }; #endif diff --git a/stepmania/src/NotesLoaderDWI.cpp b/stepmania/src/NotesLoaderDWI.cpp index 86f9fac296..f3c9f31f9e 100644 --- a/stepmania/src/NotesLoaderDWI.cpp +++ b/stepmania/src/NotesLoaderDWI.cpp @@ -247,20 +247,26 @@ bool DWILoader::LoadFromDWITokens( * or milliseconds. * What's even more dumb is that the value can contain a ':'. Colon is supposed to be a parameter separator! */ -float DWILoader::ParseBrokenDWITimestamp(const CString *sParams, int iNumParams) +float DWILoader::ParseBrokenDWITimestamp(const CString &arg1, const CString &arg2, const CString &arg3) { - if( iNumParams == 4 ) - return TimeToSeconds( sParams[1]+":"+sParams[2]+":"+sParams[3] ); - - if( iNumParams == 3 ) - return TimeToSeconds( sParams[1]+":"+sParams[2] ); - - // iNumParams == 2 - /* If the value contains a period, treat it as seconds; otherwise ms. */ - if(sParams[1].find_first_of(".") != sParams[1].npos) - return (float)atof(sParams[1].GetString()); - else - return float(atof(sParams[1].GetString())) / 1000.f; + if(arg1.empty()) return 0; + + /* 1+ args */ + if(arg2.empty()) + { + /* If the value contains a period, treat it as seconds; otherwise ms. */ + if(arg1.find_first_of(".") != arg1.npos) + return (float)atof(arg1.GetString()); + else + return float(atof(arg1.GetString())) / 1000.f; + } + + /* 2+ args */ + if(arg3.empty()) + return TimeToSeconds( arg1+":"+arg2 ); + + /* 3+ args */ + return TimeToSeconds( arg1+":"+arg2+":"+arg3 ); } bool DWILoader::LoadFromDWIFile( CString sPath, Song &out ) @@ -275,8 +281,8 @@ bool DWILoader::LoadFromDWIFile( CString sPath, Song &out ) for( unsigned i=0; i