use union in RadarValues for readability

This commit is contained in:
Chris Danford
2005-04-11 07:28:09 +00:00
parent 064fc27c7c
commit d7f4346cb7
3 changed files with 29 additions and 13 deletions
+1 -1
View File
@@ -603,7 +603,7 @@ static HighScore MakeRandomHighScore( float fPercentDP )
FOREACH_HoldNoteScore( hns ) FOREACH_HoldNoteScore( hns )
hs.iHoldNoteScores[hns] = rand() % 100; hs.iHoldNoteScores[hns] = rand() % 100;
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
hs.radarValues.m_fValues[rc] = randomf( 0, 1 ); hs.radarValues.m_Values.f[rc] = randomf( 0, 1 );
return hs; return hs;
} }
+7 -7
View File
@@ -16,13 +16,13 @@ RadarValues::RadarValues()
void RadarValues::MakeUnknown() void RadarValues::MakeUnknown()
{ {
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
m_fValues[rc] = RADAR_VAL_UNKNOWN; m_Values.f[rc] = RADAR_VAL_UNKNOWN;
} }
void RadarValues::Zero() void RadarValues::Zero()
{ {
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
m_fValues[rc] = 0; m_Values.f[rc] = 0;
} }
XNode* RadarValues::CreateNode() const XNode* RadarValues::CreateNode() const
@@ -36,12 +36,12 @@ XNode* RadarValues::CreateNode() const
if( rc >= RADAR_NUM_TAPS_AND_HOLDS ) if( rc >= RADAR_NUM_TAPS_AND_HOLDS )
{ {
if( WRITE_SIMPLE_VALUES ) if( WRITE_SIMPLE_VALUES )
pNode->AppendChild( RadarCategoryToString(rc), (int)m_fValues[rc] ); pNode->AppendChild( RadarCategoryToString(rc), (int)m_Values.f[rc] );
} }
else else
{ {
if( WRITE_COMPLEX_VALUES ) if( WRITE_COMPLEX_VALUES )
pNode->AppendChild( RadarCategoryToString(rc), m_fValues[rc] ); pNode->AppendChild( RadarCategoryToString(rc), m_Values.f[rc] );
} }
} }
@@ -55,7 +55,7 @@ void RadarValues::LoadFromNode( const XNode* pNode )
Zero(); Zero();
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
pNode->GetChildValue( RadarCategoryToString(rc), m_fValues[rc] ); pNode->GetChildValue( RadarCategoryToString(rc), m_Values.f[rc] );
} }
/* iMaxValues is only used for writing compatibility fields in non-cache /* iMaxValues is only used for writing compatibility fields in non-cache
@@ -68,7 +68,7 @@ CString RadarValues::ToString( int iMaxValues ) const
CStringArray asRadarValues; CStringArray asRadarValues;
for( int r=0; r < iMaxValues; r++ ) for( int r=0; r < iMaxValues; r++ )
asRadarValues.push_back( ssprintf("%.3f", m_fValues[r]) ); asRadarValues.push_back( ssprintf("%.3f", m_Values.f[r]) );
return join( ",",asRadarValues ); return join( ",",asRadarValues );
} }
@@ -85,7 +85,7 @@ void RadarValues::FromString( CString sRadarValues )
} }
FOREACH_RadarCategory(rc) FOREACH_RadarCategory(rc)
m_fValues[rc] = strtof( saValues[rc], NULL ); m_Values.f[rc] = strtof( saValues[rc], NULL );
} }
+21 -5
View File
@@ -11,10 +11,26 @@ struct XNode;
struct RadarValues struct RadarValues
{ {
float m_fValues[NUM_RADAR_CATEGORIES]; union Values
{
struct
{
float fStream;
float fVoltage;
float fAir;
float fFreeze;
float fChaos;
float fNumTapsAndHolds;
float fNumJumps;
float fNumHolds;
float fNumMines;
float fNumHands;
} v;
float f[NUM_RADAR_CATEGORIES];
} m_Values;
operator const float* () const { return m_fValues; }; operator const float* () const { return m_Values.f; };
operator float* () { return m_fValues; }; operator float* () { return m_Values.f; };
RadarValues(); RadarValues();
void MakeUnknown(); void MakeUnknown();
@@ -24,14 +40,14 @@ struct RadarValues
RadarValues& operator+=( const RadarValues& other ) RadarValues& operator+=( const RadarValues& other )
{ {
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
m_fValues[rc] += other.m_fValues[rc]; m_Values.f[rc] += other.m_Values.f[rc];
return *this; return *this;
} }
bool operator==( const RadarValues& other ) const bool operator==( const RadarValues& other ) const
{ {
FOREACH_RadarCategory( rc ) FOREACH_RadarCategory( rc )
{ {
if( m_fValues[rc] != other.m_fValues[rc] ) if( m_Values.f[rc] != other.m_Values.f[rc] )
return false; return false;
} }
return true; return true;