Files
itgmania212121/stepmania/src/RadarValues.cpp
T

132 lines
3.6 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
ThemeMetric<bool> RadarValues::WRITE_SIMPLE_VALIES( "RadarValues", "WriteSimpleValues" );
ThemeMetric<bool> RadarValues::WRITE_COMPLEX_VALIES( "RadarValues", "WriteComplexValues" );
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_ENUM( 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_ENUM( RadarCategory, rc )
2005-04-11 07:28:09 +00:00
m_Values.f[rc] = 0;
2004-08-22 17:23:08 +00:00
}
XNode* RadarValues::CreateNode( bool bIncludeSimpleValues, bool bIncludeComplexValues ) const
2004-07-12 06:36:10 +00:00
{
2006-10-01 14:51:50 +00:00
XNode* pNode = new XNode( "RadarValues" );
2004-07-12 06:36:10 +00:00
// TRICKY: Don't print a remainder for the integer values.
FOREACH_ENUM( RadarCategory, rc )
2004-07-12 06:36:10 +00:00
{
if( rc >= RadarCategory_TapsAndHolds )
{
if( bIncludeSimpleValues )
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( bIncludeComplexValues )
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 )
{
2006-10-02 06:12:42 +00:00
ASSERT( pNode->GetName() == "RadarValues" );
2004-07-12 06:36:10 +00:00
Zero();
FOREACH_ENUM( 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_ENUM( RadarCategory, rc )
2006-06-12 06:42:25 +00:00
m_Values.f[rc] = StringToFloat( saValues[rc] );
2005-03-07 22:30:39 +00:00
}
2006-08-16 05:11:01 +00:00
// lua start
#include "LuaBinding.h"
class LunaRadarValues: public Luna<RadarValues>
{
public:
static int GetValue( T* p, lua_State *L ) { lua_pushnumber( L, (*p)[IArg(1)] ); return 1; }
2006-09-27 19:53:05 +00:00
LunaRadarValues()
2006-08-16 05:11:01 +00:00
{
2006-09-27 19:53:05 +00:00
ADD_METHOD( GetValue );
2006-08-16 05:11:01 +00:00
}
};
LUA_REGISTER_CLASS( RadarValues )
// lua end
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.
*/