From 2d983d6f90f0d0e59e3f5df141a16169f3af4009 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 3 Oct 2004 13:52:07 +0000 Subject: [PATCH] optimize --- stepmania/src/DifficultyMeter.cpp | 59 ++++++++++++++++--------------- stepmania/src/DifficultyMeter.h | 3 ++ 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/stepmania/src/DifficultyMeter.cpp b/stepmania/src/DifficultyMeter.cpp index bfbde68a47..221e4bd28b 100644 --- a/stepmania/src/DifficultyMeter.cpp +++ b/stepmania/src/DifficultyMeter.cpp @@ -12,17 +12,6 @@ #include "Style.h" -#define NUM_FEET_IN_METER THEME->GetMetricI(m_sName,"NumFeetInMeter") -#define MAX_FEET_IN_METER THEME->GetMetricI(m_sName,"MaxFeetInMeter") -#define GLOW_IF_METER_GREATER_THAN THEME->GetMetricI(m_sName,"GlowIfMeterGreaterThan") -#define SHOW_FEET THEME->GetMetricB(m_sName,"ShowFeet") -/* "easy", "hard" */ -#define SHOW_DIFFICULTY THEME->GetMetricB(m_sName,"ShowDifficulty") -/* 3, 9 */ -#define SHOW_METER THEME->GetMetricB(m_sName,"ShowMeter") -#define FEET_IS_DIFFICULTY_COLOR THEME->GetMetricB(m_sName,"FeetIsDifficultyColor") -#define FEET_PER_DIFFICULTY THEME->GetMetricB(m_sName,"FeetPerDifficulty") - DifficultyMeter::DifficultyMeter() { } @@ -51,11 +40,24 @@ DifficultyMeter::DifficultyMeter() void DifficultyMeter::Load() { - if( SHOW_FEET ) + /* We can't use global CachedThemeMetrics, because we can have multiple + * DifficultyMeters on screen at once, with different names. */ + m_iNumFeetInMeter = THEME->GetMetricI(m_sName,"NumFeetInMeter"); + m_iMaxFeetInMeter = THEME->GetMetricI(m_sName,"MaxFeetInMeter"); + m_iGlowIfMeterGreaterThan = THEME->GetMetricI(m_sName,"GlowIfMeterGreaterThan"); + m_bShowFeet = THEME->GetMetricB(m_sName,"ShowFeet"); + /* "easy", "hard" */ + m_bShowDifficulty = THEME->GetMetricB(m_sName,"ShowDifficulty"); + /* 3, 9 */ + m_bShowMeter = THEME->GetMetricB(m_sName,"ShowMeter"); + m_bFeetIsDifficultyColor = THEME->GetMetricB(m_sName,"FeetIsDifficultyColor"); + m_bFeetPerDifficulty = THEME->GetMetricB(m_sName,"FeetPerDifficulty"); + + if( m_bShowFeet ) { m_textFeet.SetName( "Feet" ); CString Feet; - if( FEET_PER_DIFFICULTY ) + if( m_bFeetPerDifficulty ) { for( unsigned i = 0; i < NUM_DIFFICULTIES; ++i ) Feet += char(i + '0'); // 01234 @@ -68,7 +70,7 @@ void DifficultyMeter::Load() this->AddChild( &m_textFeet ); } - if( SHOW_DIFFICULTY ) + if( m_bShowDifficulty ) { m_Difficulty.Load( THEME->GetPathG(m_sName,"difficulty") ); m_Difficulty->SetName( "Difficulty" ); @@ -76,7 +78,7 @@ void DifficultyMeter::Load() this->AddChild( m_Difficulty ); } - if( SHOW_METER ) + if( m_bShowMeter ) { m_textMeter.SetName( "Meter" ); m_textMeter.LoadFromFont( THEME->GetPathF(m_sName,"meter") ); @@ -151,32 +153,31 @@ void DifficultyMeter::SetFromCourseDifficulty( CourseDifficulty cd ) void DifficultyMeter::SetFromMeterAndDifficulty( int iMeter, Difficulty dc ) { - if( SHOW_FEET ) + if( m_bShowFeet ) { - CString on = "0"; - CString off = "X"; - if( FEET_PER_DIFFICULTY ) + char on = '0'; + char off = 'X'; + if( m_bFeetPerDifficulty ) on = char(dc + '0'); CString sNewText; - int f; - for( f=0; f GLOW_IF_METER_GREATER_THAN ) + if( iMeter > m_iGlowIfMeterGreaterThan ) m_textFeet.SetEffectGlowShift(); else m_textFeet.SetEffectNone(); - if( FEET_IS_DIFFICULTY_COLOR ) + if( m_bFeetIsDifficultyColor ) m_textFeet.SetDiffuse( SONGMAN->GetDifficultyColor( dc ) ); } - if( SHOW_METER ) + if( m_bShowMeter ) { if( iMeter == 0 ) // Unset calls with this { @@ -196,9 +197,9 @@ void DifficultyMeter::SetDifficulty( CString diff ) return; m_CurDifficulty = diff; - if( SHOW_DIFFICULTY ) + if( m_bShowDifficulty ) COMMAND( m_Difficulty, "Set" + Capitalize(diff) ); - if( SHOW_METER ) + if( m_bShowMeter ) COMMAND( m_textMeter, "Set" + Capitalize(diff) ); } diff --git a/stepmania/src/DifficultyMeter.h b/stepmania/src/DifficultyMeter.h index 14fa9de888..6bb634a560 100644 --- a/stepmania/src/DifficultyMeter.h +++ b/stepmania/src/DifficultyMeter.h @@ -36,6 +36,9 @@ private: AutoActor m_Difficulty; BitmapText m_textMeter; + + int m_iNumFeetInMeter, m_iMaxFeetInMeter, m_iGlowIfMeterGreaterThan; + bool m_bShowFeet, m_bShowDifficulty, m_bShowMeter, m_bFeetIsDifficultyColor, m_bFeetPerDifficulty; }; #endif