Files
itgmania212121/stepmania/src/RadarValues.cpp
T

116 lines
3.2 KiB
C++
Raw Normal View History

2004-07-12 06:36:10 +00:00
#include "global.h"
#include "RadarValues.h"
#include "ThemeManager.h"
#include "RageUtil.h"
#include "XmlFile.h"
#include "ThemeManager.h"
2004-07-12 06:36:10 +00:00
#define WRITE_COMPLEX_VALUES THEME->GetMetricB("RadarValues","WriteComplexValues")
#define WRITE_SIMPLE_VALUES THEME->GetMetricB("RadarValues","WriteSimpleValues")
2004-07-12 06:36:10 +00:00
RadarValues::RadarValues()
{
2004-08-22 17:23:08 +00:00
MakeUnknown();
2004-07-12 06:36:10 +00:00
}
2004-08-22 17:23:08 +00:00
void RadarValues::MakeUnknown()
2004-07-12 06:36:10 +00:00
{
FOREACH_RadarCategory( rc )
2005-04-11 07:28:09 +00:00
m_Values.f[rc] = RADAR_VAL_UNKNOWN;
2004-07-12 06:36:10 +00:00
}
2004-08-22 17:23:08 +00:00
void RadarValues::Zero()
{
FOREACH_RadarCategory( rc )
2005-04-11 07:28:09 +00:00
m_Values.f[rc] = 0;
2004-08-22 17:23:08 +00:00
}
2004-07-12 06:36:10 +00:00
XNode* RadarValues::CreateNode() const
{
XNode* pNode = new XNode;
2005-01-07 14:28:00 +00:00
pNode->m_sName = "RadarValues";
2004-07-12 06:36:10 +00:00
// TRICKY: Don't print a remainder for the integer values.
FOREACH_RadarCategory( rc )
{
if( rc >= RadarCategory_TapsAndHolds )
{
if( WRITE_SIMPLE_VALUES )
2005-04-11 07:28:09 +00:00
pNode->AppendChild( RadarCategoryToString(rc), (int)m_Values.f[rc] );
}
2004-07-12 06:36:10 +00:00
else
{
if( WRITE_COMPLEX_VALUES )
2005-04-11 07:28:09 +00:00
pNode->AppendChild( RadarCategoryToString(rc), m_Values.f[rc] );
}
2004-07-12 06:36:10 +00:00
}
return pNode;
}
void RadarValues::LoadFromNode( const XNode* pNode )
{
2005-01-07 14:28:00 +00:00
ASSERT( pNode->m_sName == "RadarValues" );
2004-07-12 06:36:10 +00:00
Zero();
2004-07-12 06:36:10 +00:00
FOREACH_RadarCategory( rc )
2005-04-11 07:28:09 +00:00
pNode->GetChildValue( RadarCategoryToString(rc), m_Values.f[rc] );
2004-07-12 06:36:10 +00:00
}
2005-03-07 22:30:39 +00:00
/* iMaxValues is only used for writing compatibility fields in non-cache
* SM files; they're never actually read. */
2006-01-22 01:00:06 +00:00
RString RadarValues::ToString( int iMaxValues ) const
2005-03-07 22:30:39 +00:00
{
if( iMaxValues == -1 )
2006-01-07 04:11:29 +00:00
iMaxValues = NUM_RadarCategory;
iMaxValues = min( iMaxValues, (int)NUM_RadarCategory );
2005-03-07 22:30:39 +00:00
2006-01-22 01:00:06 +00:00
vector<RString> asRadarValues;
2005-03-07 22:30:39 +00:00
for( int r=0; r < iMaxValues; r++ )
2005-04-11 07:28:09 +00:00
asRadarValues.push_back( ssprintf("%.3f", m_Values.f[r]) );
2005-03-07 22:30:39 +00:00
return join( ",",asRadarValues );
}
2006-01-22 01:00:06 +00:00
void RadarValues::FromString( RString sRadarValues )
2005-03-07 22:30:39 +00:00
{
2006-01-22 01:00:06 +00:00
vector<RString> saValues;
2005-03-07 22:30:39 +00:00
split( sRadarValues, ",", saValues, true );
2006-01-07 04:11:29 +00:00
if( saValues.size() != NUM_RadarCategory )
2005-03-07 22:30:39 +00:00
{
MakeUnknown();
return;
}
FOREACH_RadarCategory(rc)
2005-04-11 07:28:09 +00:00
m_Values.f[rc] = strtof( saValues[rc], NULL );
2005-03-07 22:30:39 +00:00
}
2004-07-12 06:36:10 +00:00
/*
* (c) 2001-2004 Chris Danford
* 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.
*/