#include "global.h" #include "PrefsManager.h" #include "IniFile.h" #include "GameState.h" #include "RageDisplay.h" #include "RageUtil.h" #include "arch/arch.h" /* for default driver specs */ #include "RageSoundReader_Resample.h" /* for ResampleQuality */ #include "RageFile.h" #include "ProductInfo.h" #include "GameConstantsAndTypes.h" #include "Foreach.h" #include "Preference.h" #define DEFAULTS_INI_PATH "Data/Defaults.ini" // these can be overridden #define STEPMANIA_INI_PATH "Data/StepMania.ini" // overlay on Defaults.ini, contains the user's choices #define STATIC_INI_PATH "Data/Static.ini" // overlay on the 2 above, can't be overridden PrefsManager* PREFSMAN = NULL; // global and accessable from anywhere in our program const float DEFAULT_SOUND_VOLUME = 1.00f; const CString DEFAULT_LIGHTS_DRIVER = "Null"; // // For self-registering prefs // static vector *g_pvpSubscribers = NULL; void PrefsManager::Subscribe( IPreference *p ) { // TRICKY: If we make this a global vector instead of a global pointer, // then we'd have to be careful that the static constructors of all // Preferences are called before the vector constructor. It's // too tricky to enfore that, so we'll allocate the vector ourself // so that the compiler can't possibly call the vector constructor // after we've already added to the vector. if( g_pvpSubscribers == NULL ) g_pvpSubscribers = new vector; g_pvpSubscribers->push_back( p ); } bool g_bAutoRestart = false; PrefsManager::PrefsManager() { Init(); ReadGlobalPrefsFromDisk(); } void PrefsManager::Init() { #ifdef DEBUG m_bWindowed = true; #else m_bWindowed = false; #endif m_iDisplayWidth = 640; m_iDisplayHeight = 480; m_iDisplayColorDepth = 16; m_iTextureColorDepth = 16; // default to 16 for better preformance on slower cards m_iMovieColorDepth = 16; m_iMaxTextureResolution = 2048; m_iRefreshRate = REFRESH_DEFAULT; m_bOnlyDedicatedMenuButtons = false; m_bCelShadeModels = false; // Work-In-Progress.. disable by default. m_fConstantUpdateDeltaSeconds = 0; #ifdef DEBUG m_bShowStats = true; #else m_bShowStats = false; #endif m_bShowBanners = true ; m_BackgroundMode = BGMODE_ANIMATIONS; m_iNumBackgrounds = 8; m_bShowDanger = true; m_fBGBrightness = 0.8f; m_bMenuTimer = true; m_iNumArcadeStages = 3; m_bEventMode = false; m_bAutoPlay = false; m_fJudgeWindowScale = 1.0f; m_fJudgeWindowAdd = 0; m_fLifeDifficultyScale = 1.0f; m_fJudgeWindowSecondsMarvelous = 0.0225f; m_fJudgeWindowSecondsPerfect = 0.045f; m_fJudgeWindowSecondsGreat = 0.090f; m_fJudgeWindowSecondsGood = 0.135f; m_fJudgeWindowSecondsBoo = 0.180f; m_fJudgeWindowSecondsOK = 0.250f; // allow enough time to take foot off and put back on m_fJudgeWindowSecondsMine = 0.090f; // same as great m_fJudgeWindowSecondsAttack = 0.135f; m_fLifeDeltaPercentChangeMarvelous = +0.008f; m_fLifeDeltaPercentChangePerfect = +0.008f; m_fLifeDeltaPercentChangeGreat = +0.004f; m_fLifeDeltaPercentChangeGood = +0.000f; m_fLifeDeltaPercentChangeBoo = -0.040f; m_fLifeDeltaPercentChangeMiss = -0.080f; m_fLifeDeltaPercentChangeHitMine = -0.160f; m_fLifeDeltaPercentChangeOK = +0.008f; m_fLifeDeltaPercentChangeNG = -0.080f; m_fTugMeterPercentChangeMarvelous = +0.010f; m_fTugMeterPercentChangePerfect = +0.008f; m_fTugMeterPercentChangeGreat = +0.004f; m_fTugMeterPercentChangeGood = +0.000f; m_fTugMeterPercentChangeBoo = -0.010f; m_fTugMeterPercentChangeMiss = -0.020f; m_fTugMeterPercentChangeHitMine = -0.040f; m_fTugMeterPercentChangeOK = +0.008f; m_fTugMeterPercentChangeNG = -0.020f; m_iRegenComboAfterFail = 10; // cumulative m_iRegenComboAfterMiss = 5; // cumulative m_iMaxRegenComboAfterFail = 10; m_iMaxRegenComboAfterMiss = 10; m_bTwoPlayerRecovery = true; m_bMercifulDrain = true; m_bMinimum1FullSongInCourses = false; m_iPercentScoreWeightMarvelous = 3; m_iPercentScoreWeightPerfect = 2; m_iPercentScoreWeightGreat = 1; m_iPercentScoreWeightGood = 0; m_iPercentScoreWeightBoo = 0; m_iPercentScoreWeightMiss = 0; m_iPercentScoreWeightOK = 3; m_iPercentScoreWeightNG = 0; m_iPercentScoreWeightHitMine = -2; m_iGradeWeightMarvelous = 2; m_iGradeWeightPerfect = 2; m_iGradeWeightGreat = 1; m_iGradeWeightGood = 0; m_iGradeWeightBoo = -4; m_iGradeWeightMiss = -8; m_iGradeWeightHitMine = -8; m_iGradeWeightOK = 6; m_iGradeWeightNG = 0; m_iNumGradeTiersUsed = 7; for( int i=0; iLoadDefault(); } PrefsManager::~PrefsManager() { } void PrefsManager::ReadGlobalPrefsFromDisk() { ReadPrefsFromFile( DEFAULTS_INI_PATH ); ReadPrefsFromFile( STEPMANIA_INI_PATH ); ReadPrefsFromFile( STATIC_INI_PATH ); } void PrefsManager::ResetToFactoryDefaults() { // clobber the users prefs by initing then applying defaults Init(); m_bFirstRun = false; ReadPrefsFromFile( DEFAULTS_INI_PATH ); ReadPrefsFromFile( STATIC_INI_PATH ); SaveGlobalPrefsToDisk(); } void PrefsManager::ReadPrefsFromFile( CString sIni ) { IniFile ini; if( !ini.ReadFile(sIni) ) return; ini.GetValue( "Options", "Windowed", m_bWindowed ); ini.GetValue( "Options", "Interlaced", m_bInterlaced ); ini.GetValue( "Options", "PAL", m_bPAL ); ini.GetValue( "Options", "CelShadeModels", m_bCelShadeModels ); ini.GetValue( "Options", "ConstantUpdateDeltaSeconds", m_fConstantUpdateDeltaSeconds ); ini.GetValue( "Options", "DisplayWidth", m_iDisplayWidth ); ini.GetValue( "Options", "DisplayHeight", m_iDisplayHeight ); ini.GetValue( "Options", "DisplayColorDepth", m_iDisplayColorDepth ); ini.GetValue( "Options", "TextureColorDepth", m_iTextureColorDepth ); ini.GetValue( "Options", "MovieColorDepth", m_iMovieColorDepth ); ini.GetValue( "Options", "MaxTextureResolution", m_iMaxTextureResolution ); ini.GetValue( "Options", "RefreshRate", m_iRefreshRate ); ini.GetValue( "Options", "UseDedicatedMenuButtons", m_bOnlyDedicatedMenuButtons ); ini.GetValue( "Options", "ShowStats", m_bShowStats ); ini.GetValue( "Options", "ShowBanners", m_bShowBanners ); ini.GetValue( "Options", "BackgroundMode", (int&)m_BackgroundMode ); ini.GetValue( "Options", "NumBackgrounds", m_iNumBackgrounds); ini.GetValue( "Options", "ShowDanger", m_bShowDanger ); ini.GetValue( "Options", "BGBrightness", m_fBGBrightness ); ini.GetValue( "Options", "MenuTimer", m_bMenuTimer ); ini.GetValue( "Options", "NumArcadeStages", m_iNumArcadeStages ); ini.GetValue( "Options", "EventMode", m_bEventMode ); ini.GetValue( "Options", "AutoPlay", m_bAutoPlay ); ini.GetValue( "Options", "JudgeWindowScale", m_fJudgeWindowScale ); ini.GetValue( "Options", "JudgeWindowAdd", m_fJudgeWindowAdd ); ini.GetValue( "Options", "JudgeWindowSecondsMarvelous", m_fJudgeWindowSecondsMarvelous ); ini.GetValue( "Options", "JudgeWindowSecondsPerfect", m_fJudgeWindowSecondsPerfect ); ini.GetValue( "Options", "JudgeWindowSecondsGreat", m_fJudgeWindowSecondsGreat ); ini.GetValue( "Options", "JudgeWindowSecondsGood", m_fJudgeWindowSecondsGood ); ini.GetValue( "Options", "JudgeWindowSecondsBoo", m_fJudgeWindowSecondsBoo ); ini.GetValue( "Options", "JudgeWindowSecondsOK", m_fJudgeWindowSecondsOK ); ini.GetValue( "Options", "JudgeWindowSecondsMine", m_fJudgeWindowSecondsMine ); ini.GetValue( "Options", "JudgeWindowSecondsAttack", m_fJudgeWindowSecondsAttack ); ini.GetValue( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale ); ini.GetValue( "Options", "LifeDeltaPercentChangeMarvelous", m_fLifeDeltaPercentChangeMarvelous ); ini.GetValue( "Options", "LifeDeltaPercentChangePerfect", m_fLifeDeltaPercentChangePerfect ); ini.GetValue( "Options", "LifeDeltaPercentChangeGreat", m_fLifeDeltaPercentChangeGreat ); ini.GetValue( "Options", "LifeDeltaPercentChangeGood", m_fLifeDeltaPercentChangeGood ); ini.GetValue( "Options", "LifeDeltaPercentChangeBoo", m_fLifeDeltaPercentChangeBoo ); ini.GetValue( "Options", "LifeDeltaPercentChangeMiss", m_fLifeDeltaPercentChangeMiss ); ini.GetValue( "Options", "LifeDeltaPercentChangeHitMine", m_fLifeDeltaPercentChangeHitMine ); ini.GetValue( "Options", "LifeDeltaPercentChangeOK", m_fLifeDeltaPercentChangeOK ); ini.GetValue( "Options", "LifeDeltaPercentChangeNG", m_fLifeDeltaPercentChangeNG ); ini.GetValue( "Options", "TugMeterPercentChangeMarvelous", m_fTugMeterPercentChangeMarvelous ); ini.GetValue( "Options", "TugMeterPercentChangePerfect", m_fTugMeterPercentChangePerfect ); ini.GetValue( "Options", "TugMeterPercentChangeGreat", m_fTugMeterPercentChangeGreat ); ini.GetValue( "Options", "TugMeterPercentChangeGood", m_fTugMeterPercentChangeGood ); ini.GetValue( "Options", "TugMeterPercentChangeBoo", m_fTugMeterPercentChangeBoo ); ini.GetValue( "Options", "TugMeterPercentChangeMiss", m_fTugMeterPercentChangeMiss ); ini.GetValue( "Options", "TugMeterPercentChangeHitMine", m_fTugMeterPercentChangeHitMine ); ini.GetValue( "Options", "TugMeterPercentChangeOK", m_fTugMeterPercentChangeOK ); ini.GetValue( "Options", "TugMeterPercentChangeNG", m_fTugMeterPercentChangeNG ); ini.GetValue( "Options", "RegenComboAfterFail", m_iRegenComboAfterFail ); ini.GetValue( "Options", "RegenComboAfterMiss", m_iRegenComboAfterMiss ); ini.GetValue( "Options", "MaxRegenComboAfterFail", m_iMaxRegenComboAfterFail ); ini.GetValue( "Options", "MaxRegenComboAfterMiss", m_iMaxRegenComboAfterMiss ); ini.GetValue( "Options", "TwoPlayerRecovery", m_bTwoPlayerRecovery ); ini.GetValue( "Options", "MercifulDrain", m_bMercifulDrain ); ini.GetValue( "Options", "Minimum1FullSongInCourses", m_bMinimum1FullSongInCourses ); ini.GetValue( "Options", "PercentScoreWeightMarvelous", m_iPercentScoreWeightMarvelous ); ini.GetValue( "Options", "PercentScoreWeightPerfect", m_iPercentScoreWeightPerfect ); ini.GetValue( "Options", "PercentScoreWeightGreat", m_iPercentScoreWeightGreat ); ini.GetValue( "Options", "PercentScoreWeightGood", m_iPercentScoreWeightGood ); ini.GetValue( "Options", "PercentScoreWeightBoo", m_iPercentScoreWeightBoo ); ini.GetValue( "Options", "PercentScoreWeightMiss", m_iPercentScoreWeightMiss ); ini.GetValue( "Options", "PercentScoreWeightOK", m_iPercentScoreWeightOK ); ini.GetValue( "Options", "PercentScoreWeightNG", m_iPercentScoreWeightNG ); ini.GetValue( "Options", "PercentScoreWeightHitMine", m_iPercentScoreWeightHitMine ); ini.GetValue( "Options", "GradeWeightMarvelous", m_iGradeWeightMarvelous ); ini.GetValue( "Options", "GradeWeightPerfect", m_iGradeWeightPerfect ); ini.GetValue( "Options", "GradeWeightGreat", m_iGradeWeightGreat ); ini.GetValue( "Options", "GradeWeightGood", m_iGradeWeightGood ); ini.GetValue( "Options", "GradeWeightBoo", m_iGradeWeightBoo ); ini.GetValue( "Options", "GradeWeightMiss", m_iGradeWeightMiss ); ini.GetValue( "Options", "GradeWeightHitMine", m_iGradeWeightHitMine ); ini.GetValue( "Options", "GradeWeightOK", m_iGradeWeightOK ); ini.GetValue( "Options", "GradeWeightNG", m_iGradeWeightNG ); ini.GetValue( "Options", "NumGradeTiersUsed", m_iNumGradeTiersUsed ); for( int g=0; gReadFrom( ini ); } void PrefsManager::SaveGlobalPrefsToDisk() const { IniFile ini; ini.SetValue( "Options", "Windowed", m_bWindowed ); ini.SetValue( "Options", "CelShadeModels", m_bCelShadeModels ); ini.SetValue( "Options", "ConstantUpdateDeltaSeconds", m_fConstantUpdateDeltaSeconds ); ini.SetValue( "Options", "DisplayWidth", m_iDisplayWidth ); ini.SetValue( "Options", "DisplayHeight", m_iDisplayHeight ); ini.SetValue( "Options", "DisplayColorDepth", m_iDisplayColorDepth ); ini.SetValue( "Options", "TextureColorDepth", m_iTextureColorDepth ); ini.SetValue( "Options", "MovieColorDepth", m_iMovieColorDepth ); ini.SetValue( "Options", "MaxTextureResolution", m_iMaxTextureResolution ); ini.SetValue( "Options", "RefreshRate", m_iRefreshRate ); ini.SetValue( "Options", "UseDedicatedMenuButtons", m_bOnlyDedicatedMenuButtons ); ini.SetValue( "Options", "ShowStats", m_bShowStats ); ini.SetValue( "Options", "ShowBanners", m_bShowBanners ); ini.SetValue( "Options", "BackgroundMode", m_BackgroundMode); ini.SetValue( "Options", "NumBackgrounds", m_iNumBackgrounds); ini.SetValue( "Options", "ShowDanger", m_bShowDanger ); ini.SetValue( "Options", "BGBrightness", m_fBGBrightness ); ini.SetValue( "Options", "MenuTimer", m_bMenuTimer ); ini.SetValue( "Options", "NumArcadeStages", m_iNumArcadeStages ); ini.SetValue( "Options", "EventMode", m_bEventMode ); ini.SetValue( "Options", "AutoPlay", m_bAutoPlay ); ini.SetValue( "Options", "JudgeWindowScale", m_fJudgeWindowScale ); ini.SetValue( "Options", "JudgeWindowAdd", m_fJudgeWindowAdd ); ini.SetValue( "Options", "JudgeWindowSecondsMarvelous", m_fJudgeWindowSecondsMarvelous ); ini.SetValue( "Options", "JudgeWindowSecondsPerfect", m_fJudgeWindowSecondsPerfect ); ini.SetValue( "Options", "JudgeWindowSecondsGreat", m_fJudgeWindowSecondsGreat ); ini.SetValue( "Options", "JudgeWindowSecondsGood", m_fJudgeWindowSecondsGood ); ini.SetValue( "Options", "JudgeWindowSecondsBoo", m_fJudgeWindowSecondsBoo ); ini.SetValue( "Options", "JudgeWindowSecondsOK", m_fJudgeWindowSecondsOK ); ini.SetValue( "Options", "JudgeWindowSecondsMine", m_fJudgeWindowSecondsMine ); ini.SetValue( "Options", "JudgeWindowSecondsAttack", m_fJudgeWindowSecondsAttack ); ini.SetValue( "Options", "LifeDifficultyScale", m_fLifeDifficultyScale ); ini.SetValue( "Options", "LifeDeltaPercentChangeMarvelous", m_fLifeDeltaPercentChangeMarvelous ); ini.SetValue( "Options", "LifeDeltaPercentChangePerfect", m_fLifeDeltaPercentChangePerfect ); ini.SetValue( "Options", "LifeDeltaPercentChangeGreat", m_fLifeDeltaPercentChangeGreat ); ini.SetValue( "Options", "LifeDeltaPercentChangeGood", m_fLifeDeltaPercentChangeGood ); ini.SetValue( "Options", "LifeDeltaPercentChangeBoo", m_fLifeDeltaPercentChangeBoo ); ini.SetValue( "Options", "LifeDeltaPercentChangeMiss", m_fLifeDeltaPercentChangeMiss ); ini.SetValue( "Options", "LifeDeltaPercentChangeHitMine", m_fLifeDeltaPercentChangeHitMine ); ini.SetValue( "Options", "LifeDeltaPercentChangeOK", m_fLifeDeltaPercentChangeOK ); ini.SetValue( "Options", "LifeDeltaPercentChangeNG", m_fLifeDeltaPercentChangeNG ); ini.SetValue( "Options", "TugMeterPercentChangeMarvelous", m_fTugMeterPercentChangeMarvelous ); ini.SetValue( "Options", "TugMeterPercentChangePerfect", m_fTugMeterPercentChangePerfect ); ini.SetValue( "Options", "TugMeterPercentChangeGreat", m_fTugMeterPercentChangeGreat ); ini.SetValue( "Options", "TugMeterPercentChangeGood", m_fTugMeterPercentChangeGood ); ini.SetValue( "Options", "TugMeterPercentChangeBoo", m_fTugMeterPercentChangeBoo ); ini.SetValue( "Options", "TugMeterPercentChangeMiss", m_fTugMeterPercentChangeMiss ); ini.SetValue( "Options", "TugMeterPercentChangeHitMine", m_fTugMeterPercentChangeHitMine ); ini.SetValue( "Options", "TugMeterPercentChangeOK", m_fTugMeterPercentChangeOK ); ini.SetValue( "Options", "TugMeterPercentChangeNG", m_fTugMeterPercentChangeNG ); ini.SetValue( "Options", "RegenComboAfterFail", m_iRegenComboAfterFail ); ini.SetValue( "Options", "RegenComboAfterMiss", m_iRegenComboAfterMiss ); ini.SetValue( "Options", "MaxRegenComboAfterFail", m_iMaxRegenComboAfterFail ); ini.SetValue( "Options", "MaxRegenComboAfterMiss", m_iMaxRegenComboAfterMiss ); ini.SetValue( "Options", "TwoPlayerRecovery", m_bTwoPlayerRecovery ); ini.SetValue( "Options", "MercifulDrain", m_bMercifulDrain ); ini.SetValue( "Options", "Minimum1FullSongInCourses", m_bMinimum1FullSongInCourses ); ini.SetValue( "Options", "PercentScoreWeightMarvelous", m_iPercentScoreWeightMarvelous ); ini.SetValue( "Options", "PercentScoreWeightPerfect", m_iPercentScoreWeightPerfect ); ini.SetValue( "Options", "PercentScoreWeightGreat", m_iPercentScoreWeightGreat ); ini.SetValue( "Options", "PercentScoreWeightGood", m_iPercentScoreWeightGood ); ini.SetValue( "Options", "PercentScoreWeightBoo", m_iPercentScoreWeightBoo ); ini.SetValue( "Options", "PercentScoreWeightMiss", m_iPercentScoreWeightMiss ); ini.SetValue( "Options", "PercentScoreWeightOK", m_iPercentScoreWeightOK ); ini.SetValue( "Options", "PercentScoreWeightNG", m_iPercentScoreWeightNG ); ini.SetValue( "Options", "PercentScoreWeightHitMine", m_iPercentScoreWeightHitMine ); ini.SetValue( "Options", "GradeWeightMarvelous", m_iGradeWeightMarvelous ); ini.SetValue( "Options", "GradeWeightPerfect", m_iGradeWeightPerfect ); ini.SetValue( "Options", "GradeWeightGreat", m_iGradeWeightGreat ); ini.SetValue( "Options", "GradeWeightGood", m_iGradeWeightGood ); ini.SetValue( "Options", "GradeWeightBoo", m_iGradeWeightBoo ); ini.SetValue( "Options", "GradeWeightMiss", m_iGradeWeightMiss ); ini.SetValue( "Options", "GradeWeightHitMine", m_iGradeWeightHitMine ); ini.SetValue( "Options", "GradeWeightOK", m_iGradeWeightOK ); ini.SetValue( "Options", "GradeWeightNG", m_iGradeWeightNG ); ini.SetValue( "Options", "NumGradeTiersUsed", m_iNumGradeTiersUsed ); for( int g=0; gWriteTo( ini ); ini.WriteFile( STEPMANIA_INI_PATH ); } int PrefsManager::GetCoinMode() { if( m_bEventMode && m_iCoinMode == COIN_PAY ) return COIN_FREE; else return m_iCoinMode; } PrefsManager::Premium PrefsManager::GetPremium() { if(m_bEventMode) return NO_PREMIUM; else return m_Premium; } /* * (c) 2001-2004 Chris Danford, Chris Gomez * 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. */