Esempio n. 1
0
/**
 * distance
 * Calculates the distance from then unknown pattern to sample number 
 * sampleIndex using elastic matching
 **/
int 
distance( int sampleIndex )
{
    currentModel = samples[ sampleIndex ];
    newLookup( unknown->nPoints, currentModel->nPoints );
    return D( unknown->nPoints - 1, currentModel->nPoints - 1 ) 
	/ currentModel->nPoints;
}
Esempio n. 2
0
void RA_RichPresenceInterpretter::ParseRichPresenceFile( const char* sFilename )
{
	m_formats.clear();
	m_lookups.clear();
	m_sDisplay.clear();

	const char EndLine = '\n';

	const char* LookupStr = "Lookup:";
	const char* FormatStr = "Format:";
	const char* FormatTypeStr = "FormatType=";
	const char* DisplayableStr = "Display:";

	FILE* pFile = NULL;
	fopen_s( &pFile, sFilename, "r" );
	if( pFile != NULL )
	{
		DWORD nCharsRead = 0;
		char buffer[4096];

		_ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile );
		while( nCharsRead != 0 )
		{
			if( strncmp( LookupStr, buffer, strlen( LookupStr ) ) == 0 )
			{
				//	Lookup type
				char* pBuf = buffer + ( strlen( LookupStr ) );
				RA_Lookup newLookup( _ReadStringTil( EndLine, pBuf, TRUE ) );
				while( nCharsRead != 0 && ( buffer[0] != EndLine ) )
				{
					_ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile );
					if( nCharsRead > 2 )
					{
						char* pBuf = &buffer[0];
						const char* pValue = _ReadStringTil( '=', pBuf, TRUE );
						const char* pName = _ReadStringTil( EndLine, pBuf, TRUE );

						int nBase = 10;
						if( pValue[0] == '0' && pValue[1] == 'x' )
							nBase = 16;

						DataPos nVal = static_cast<DataPos>( strtol( pValue, NULL, nBase ) );

						newLookup.AddLookupData( nVal, pName );
					}
				}

				RA_LOG( "RP: Adding Lookup %s\n", newLookup.Description().c_str() );
				m_lookups.push_back( newLookup );

			}
			else if( strncmp( FormatStr, buffer, strlen( FormatStr ) ) == 0 )
			{
				//	
				char* pBuf = &buffer[0];
				const char* pUnused = _ReadStringTil( ':', pBuf, TRUE );
				std::string sDesc = _ReadStringTil( EndLine, pBuf, TRUE );

				_ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile );
				if( nCharsRead > 0 && strncmp( FormatTypeStr, buffer, strlen( FormatTypeStr ) ) == 0 )
				{
					char* pBuf = &buffer[0];
					const char* pUnused = _ReadStringTil( '=', pBuf, TRUE );
					const char* pType = _ReadStringTil( EndLine, pBuf, TRUE );
					
					RA_Leaderboard::FormatType nType;

					if( strcmp( pType, "SCORE" ) == 0 || strcmp( pType, "POINTS" ) == 0 )
					{
						nType = RA_Leaderboard::Format_Score;
					}
					else if( strcmp( pType, "TIME" ) == 0 || strcmp( pType, "FRAMES" ) == 0 )
					{
						nType = RA_Leaderboard::Format_TimeFrames;
					}
					else if( strcmp( pType, "SECS" ) == 0 )
					{
						nType = RA_Leaderboard::Format_TimeSecs;
					}
					else if( strcmp( pType, "MILLISECS" ) == 0 )
					{
						nType = RA_Leaderboard::Format_TimeMillisecs;
					}
					else if( strcmp( pType, "VALUE" ) == 0 )
					{
						nType = RA_Leaderboard::Format_Value;
					}
					else
					{
						nType = RA_Leaderboard::Format_Other;
					}

					RA_LOG( "RP: Adding Formatter %s (%s)\n", sDesc.c_str(), pType );
					m_formats.push_back( RA_Formattable( sDesc, nType ) );
				}
			}
			else if( strncmp( DisplayableStr, buffer, strlen( DisplayableStr ) ) == 0 )
			{
				_ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile );
				
				char* pBuf =  &buffer[0];
				m_sDisplay = _ReadStringTil( '\n', pBuf, TRUE );	//	Terminates \n instead
			}

			_ReadTil( EndLine, buffer, 4096, &nCharsRead, pFile );
		}

		fclose( pFile );
	}
}