diff --git a/stepmania/src/Preference.cpp b/stepmania/src/Preference.cpp index a0870a27d5..ad2c74348d 100644 --- a/stepmania/src/Preference.cpp +++ b/stepmania/src/Preference.cpp @@ -33,44 +33,28 @@ void IPreference::SetFromStack( lua_State *L ) lua_pop( L, 1 ); } - -#define READFROM_AND_WRITETO( type, cast ) \ - template<> void Preference::FromString( const CString &s ) \ +#define READFROM_AND_WRITETO( type ) \ + template<> CString PrefToString( const type &v ) \ { \ - ::FromString( s, (cast)m_currentValue ); \ + return ::ToString( v ); \ } \ - template<> CString Preference::ToString() const \ + template<> void PrefFromString( const CString &s, type &v ) \ { \ - return ::ToString( (cast)m_currentValue ); \ + ::FromString( s, v ); \ } \ - template<> void Preference::PushValue( lua_State *L ) const \ + template<> void PrefSetFromStack( lua_State *L, type &v ) \ { \ - LuaHelpers::PushStack( (cast)m_currentValue, L ); \ + LuaHelpers::PopStack( v, L ); \ } \ - template<> void Preference::SetFromStack( lua_State *L ) \ + template<> void PrefPushValue( lua_State *L, const type &v ) \ { \ - LuaHelpers::PopStack( (cast)m_currentValue, L ); \ + LuaHelpers::PushStack( v, L ); \ } -READFROM_AND_WRITETO( int, int& ) -READFROM_AND_WRITETO( float, float& ) -READFROM_AND_WRITETO( bool, bool& ) -READFROM_AND_WRITETO( CString, CString& ) -READFROM_AND_WRITETO( PrefsManager::BackgroundMode, int& ) -READFROM_AND_WRITETO( PrefsManager::BannerCache, int& ) -READFROM_AND_WRITETO( PrefsManager::MusicWheelUsesSections, int& ) -READFROM_AND_WRITETO( PrefsManager::AllowW1, int& ) -READFROM_AND_WRITETO( CoinMode, int& ) -READFROM_AND_WRITETO( Premium, int& ) -READFROM_AND_WRITETO( PrefsManager::Maybe, int& ) -READFROM_AND_WRITETO( PrefsManager::ShowDancingCharacters, int& ) -READFROM_AND_WRITETO( PrefsManager::CourseSortOrders, int& ) -READFROM_AND_WRITETO( PrefsManager::GetRankingName, int& ) -READFROM_AND_WRITETO( PrefsManager::ScoringType, int& ) -READFROM_AND_WRITETO( PrefsManager::BoostAppPriority, int& ) -READFROM_AND_WRITETO( PrefsManager::AttractSoundFrequency, int& ) -READFROM_AND_WRITETO( PlayerController, int& ) -READFROM_AND_WRITETO( RageSoundReader_Resample::ResampleQuality, int& ) +READFROM_AND_WRITETO( int ) +READFROM_AND_WRITETO( float ) +READFROM_AND_WRITETO( bool ) +READFROM_AND_WRITETO( CString ) void IPreference::ReadFrom( const IniFile &ini ) { diff --git a/stepmania/src/Preference.h b/stepmania/src/Preference.h index 60a188dc77..6b8d8db5ac 100644 --- a/stepmania/src/Preference.h +++ b/stepmania/src/Preference.h @@ -31,15 +31,14 @@ protected: void BroadcastPreferenceChanged( const CString& sPreferenceName ); -template +template CString PrefToString( const BasicType &v ); +template void PrefFromString( const CString &s, BasicType &v ); +template void PrefSetFromStack( lua_State *L, BasicType &v ); +template void PrefPushValue( lua_State *L, const BasicType &v ); + +template class Preference : public IPreference { -private: - // Make currentValue first in the list so that we can pass this object - // as an argument in a var_arg function as in printf. - T m_currentValue; - T m_defaultValue; - public: Preference( const CString& sName, const T& defaultValue ): IPreference( sName ), @@ -49,10 +48,10 @@ public: LoadDefault(); } - CString ToString() const; - void FromString( const CString &s ); - void SetFromStack( lua_State *L ); - void PushValue( lua_State *L ) const; + CString ToString() const { return PrefToString( (const BasicType &) m_currentValue ); } + void FromString( const CString &s ) { PrefFromString( s, (BasicType &)m_currentValue ); } + void SetFromStack( lua_State *L ) { PrefSetFromStack( L, (BasicType &)m_currentValue ); } + void PushValue( lua_State *L ) const { PrefPushValue( L, (BasicType &)m_currentValue ); } void LoadDefault() { @@ -74,6 +73,10 @@ public: m_currentValue = other; BroadcastPreferenceChanged( m_sName ); } + +private: + T m_currentValue; + T m_defaultValue; }; template diff --git a/stepmania/src/PrefsManager.h b/stepmania/src/PrefsManager.h index 8d783a101f..fa541e619d 100644 --- a/stepmania/src/PrefsManager.h +++ b/stepmania/src/PrefsManager.h @@ -35,7 +35,7 @@ public: Preference m_bShowBanners; enum BackgroundMode { BGMODE_OFF, BGMODE_ANIMATIONS, BGMODE_RANDOMMOVIES, NUM_BackgroundMode }; - Preference m_BackgroundMode; + Preference m_BackgroundMode; Preference m_iNumBackgrounds; Preference m_fBGBrightness; Preference m_bHiddenSongs; @@ -50,7 +50,7 @@ public: BNCACHE_LOW_RES_PRELOAD, // preload low-res on start BNCACHE_LOW_RES_LOAD_ON_DEMAND, // preload low-res on screen load BNCACHE_FULL }; - Preference m_BannerCache; + Preference m_BannerCache; Preference m_bPalettedBannerCache; Preference m_bFastLoad; @@ -94,7 +94,7 @@ public: // time meter used in survival Preference1D m_fTimeMeterSecondsChange; - Preference m_AutoPlay; + Preference m_AutoPlay; Preference m_bDelayedBack; Preference m_bShowInstructions; Preference m_bShowSelectGroup; @@ -102,19 +102,19 @@ public: Preference m_bShowNativeLanguage; Preference m_bArcadeOptionsNavigation; enum MusicWheelUsesSections { NEVER, ALWAYS, ABC_ONLY }; - Preference m_MusicWheelUsesSections; + Preference m_MusicWheelUsesSections; Preference m_iMusicWheelSwitchSpeed; Preference m_bEasterEggs; enum AllowW1 { ALLOW_W1_NEVER, ALLOW_W1_COURSES_ONLY, ALLOW_W1_EVERYWHERE }; - Preference m_AllowW1; + Preference m_AllowW1; Preference m_bEventMode; Preference m_iCoinsPerCredit; Preference m_iSongsPerPlay; // These options have weird interactions depending on m_bEventMode, // so wrap them in GameState. - Preference m_CoinMode; - Preference m_Premium; + Preference m_CoinMode; + Preference m_Premium; Preference m_bDelayedCreditsReconcile; Preference m_bPickExtraStage; @@ -122,7 +122,7 @@ public: Preference m_fLongVerSongSeconds; Preference m_fMarathonVerSongSeconds; enum Maybe { ASK = -1, NO = 0, YES = 1 }; - Preference m_ShowSongOptions; + Preference m_ShowSongOptions; Preference m_bSoloSingle; Preference m_bDancePointsForOni; Preference m_bPercentageScoring; @@ -135,7 +135,7 @@ public: Preference m_bBreakComboToGetItem; Preference m_bLockCourseDifficulties; enum ShowDancingCharacters { SDC_Off = 0, SDC_Random = 1, SDC_Select = 2}; - Preference m_ShowDancingCharacters; + Preference m_ShowDancingCharacters; Preference m_bUseUnlockSystem; Preference m_bAutoMapOnJoyChange; Preference m_fGlobalOffsetSeconds; @@ -159,7 +159,7 @@ public: Preference m_fCenterImageAddHeight; Preference m_fBrightnessAdd; enum AttractSoundFrequency { ASF_NEVER, ASF_EVERY_TIME, ASF_EVERY_2_TIMES, ASF_EVERY_3_TIMES, ASF_EVERY_4_TIMES, ASF_EVERY_5_TIMES }; - Preference m_AttractSoundFrequency; + Preference m_AttractSoundFrequency; Preference m_bAllowExtraStage; Preference m_bHideDefaultNoteSkin; Preference m_iMaxHighScoresPerListForMachine; @@ -195,17 +195,17 @@ public: // course ranking enum CourseSortOrders { COURSE_SORT_SONGS, COURSE_SORT_METER, COURSE_SORT_METER_SUM, COURSE_SORT_RANK }; - Preference m_CourseSortOrder; + Preference m_CourseSortOrder; Preference m_bMoveRandomToEnd; Preference m_bSubSortByNumSteps; enum GetRankingName { RANKING_OFF, RANKING_ON, RANKING_LIST }; - Preference m_GetRankingName; + Preference m_GetRankingName; enum ScoringType { SCORING_NEW, SCORING_OLD }; - Preference m_ScoringType; + Preference m_ScoringType; enum BoostAppPriority { BOOST_NO, BOOST_YES, BOOST_AUTO }; /* auto = do whatever is appropriate for the arch. */ - Preference m_BoostAppPriority; + Preference m_BoostAppPriority; Preference m_sAdditionalSongFolders; Preference m_sAdditionalFolders; @@ -224,7 +224,7 @@ public: Preference m_iSoundWriteAhead; Preference m_iSoundDevice; Preference m_iSoundPreferredSampleRate; - Preference m_SoundResampleQuality; + Preference m_SoundResampleQuality; private: Preference m_sInputDrivers; // "" == default Preference m_sLightsDriver; // "" == default