From 267b3bd90dc2727c973be06ed7e768c697c4001b Mon Sep 17 00:00:00 2001 From: "Jake.Stine" Date: Tue, 4 Jan 2011 22:49:58 +0000 Subject: [PATCH] API change: Simplified handling of app/emu config defaults handling. Got rid of the mandatory "defaults" override -- LoadSave APIs for Pcsx2Config and EmuConfig now use the current settings of the class instead. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@4177 96395faa-99c1-11dd-bbfe-3dabce05a288 --- common/include/Utilities/IniInterface.h | 53 +++++++++++++------------ common/src/Utilities/IniInterface.cpp | 28 ++++++------- pcsx2/Pcsx2Config.cpp | 10 +---- pcsx2/gui/AppConfig.cpp | 31 ++++++--------- pcsx2/gui/AppCorePlugins.cpp | 4 +- 5 files changed, 57 insertions(+), 69 deletions(-) diff --git a/common/include/Utilities/IniInterface.h b/common/include/Utilities/IniInterface.h index da820b62da..957015510c 100644 --- a/common/include/Utilities/IniInterface.h +++ b/common/include/Utilities/IniInterface.h @@ -18,6 +18,7 @@ #include "Path.h" #include "FixedPointTypes.h" #include +#include // -------------------------------------------------------------------------------------- // IniInterface (abstract base class) @@ -48,9 +49,9 @@ public: virtual bool IsLoading() const=0; bool IsSaving() const { return !IsLoading(); } - virtual void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() )=0; - virtual void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() )=0; - virtual void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() )=0; + virtual void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() )=0; + virtual void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName() )=0; + virtual void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName() )=0; virtual void Entry( const wxString& var, int& value, const int defvalue=0 )=0; virtual void Entry( const wxString& var, uint& value, const uint defvalue=0 )=0; virtual void Entry( const wxString& var, bool& value, const bool defvalue=false )=0; @@ -59,11 +60,11 @@ public: virtual bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false )=0; virtual int EntryBitfield( const wxString& var, int value, const int defvalue=0 )=0; - virtual void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() )=0; + virtual void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() )=0; - virtual void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition )=0; - virtual void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize )=0; - virtual void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect )=0; + virtual void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition )=0; + virtual void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize )=0; + virtual void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect )=0; template< typename T > void EnumEntry( const wxString& var, T& value, const wxChar* const* enumArray=NULL, const T defvalue=(T)0 ) @@ -111,9 +112,9 @@ public: bool IsLoading() const { return true; } - void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxEmptyString ); - void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() ); - void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() ); + void Entry( const wxString& var, wxString& value, const wxString defvalue=wxEmptyString ); + void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName() ); + void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName() ); void Entry( const wxString& var, int& value, const int defvalue=0 ); void Entry( const wxString& var, uint& value, const uint defvalue=0 ); void Entry( const wxString& var, bool& value, const bool defvalue=false ); @@ -121,11 +122,11 @@ public: bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false ); int EntryBitfield( const wxString& var, int value, const int defvalue=0 ); - void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() ); + void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() ); - void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition ); - void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize ); - void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect ); + void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition ); + void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); + void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect ); protected: void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ); @@ -149,9 +150,9 @@ public: bool IsLoading() const { return false; } - void Entry( const wxString& var, wxString& value, const wxString& defvalue=wxString() ); - void Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue=wxDirName() ); - void Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue=wxFileName() ); + void Entry( const wxString& var, wxString& value, const wxString defvalue=wxString() ); + void Entry( const wxString& var, wxDirName& value, const wxDirName defvalue=wxDirName() ); + void Entry( const wxString& var, wxFileName& value, const wxFileName defvalue=wxFileName() ); void Entry( const wxString& var, int& value, const int defvalue=0 ); void Entry( const wxString& var, uint& value, const uint defvalue=0 ); void Entry( const wxString& var, bool& value, const bool defvalue=false ); @@ -159,11 +160,11 @@ public: bool EntryBitBool( const wxString& var, bool value, const bool defvalue=false ); int EntryBitfield( const wxString& var, int value, const int defvalue=0 ); - void Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue=Fixed100() ); + void Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue=Fixed100() ); - void Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue=wxDefaultPosition ); - void Entry( const wxString& var, wxSize& value, const wxSize& defvalue=wxDefaultSize ); - void Entry( const wxString& var, wxRect& value, const wxRect& defvalue=wxDefaultRect ); + void Entry( const wxString& var, wxPoint& value, const wxPoint defvalue=wxDefaultPosition ); + void Entry( const wxString& var, wxSize& value, const wxSize defvalue=wxDefaultSize ); + void Entry( const wxString& var, wxRect& value, const wxRect defvalue=wxDefaultRect ); protected: void _EnumEntry( const wxString& var, int& value, const wxChar* const* enumArray, int defvalue ); @@ -173,9 +174,9 @@ protected: // GCC Note: wxT() macro is required when using string token pasting. For some reason L generates // syntax errors. >_< // -#define IniEntry( varname ) ini.Entry( wxT(#varname), varname, defaults.varname ) -#define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, defaults.varname ) -#define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, defaults.varname ) +#define IniEntry( varname ) ini.Entry( wxT(#varname), varname, varname ) +#define IniBitfield( varname ) varname = ini.EntryBitfield( wxT(#varname), varname, varname ) +#define IniBitBool( varname ) varname = ini.EntryBitBool( wxT(#varname), !!varname, varname ) -#define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, defaults.varname ) -#define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, defaults.varname ) +#define IniBitfieldEx( varname, textname ) varname = ini.EntryBitfield( wxT(textname), varname, varname ) +#define IniBitBoolEx( varname, textname ) varname = ini.EntryBitBool( wxT(textname), !!varname, varname ) diff --git a/common/src/Utilities/IniInterface.cpp b/common/src/Utilities/IniInterface.cpp index b90d521976..1f6a97a02c 100644 --- a/common/src/Utilities/IniInterface.cpp +++ b/common/src/Utilities/IniInterface.cpp @@ -94,7 +94,7 @@ IniLoader::IniLoader() : IniInterface() {} IniLoader::~IniLoader() throw() {} -void IniLoader::Entry( const wxString& var, wxString& value, const wxString& defvalue ) +void IniLoader::Entry( const wxString& var, wxString& value, const wxString defvalue ) { if( m_Config ) m_Config->Read( var, &value, defvalue ); @@ -102,7 +102,7 @@ void IniLoader::Entry( const wxString& var, wxString& value, const wxString& def value = defvalue; } -void IniLoader::Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue ) +void IniLoader::Entry( const wxString& var, wxDirName& value, const wxDirName defvalue ) { wxString dest; if( m_Config ) m_Config->Read( var, &dest, wxEmptyString ); @@ -113,7 +113,7 @@ void IniLoader::Entry( const wxString& var, wxDirName& value, const wxDirName& d value = dest; } -void IniLoader::Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue ) +void IniLoader::Entry( const wxString& var, wxFileName& value, const wxFileName defvalue ) { wxString dest( defvalue.GetFullPath() ); if( m_Config ) m_Config->Read( var, &dest, defvalue.GetFullPath() ); @@ -159,7 +159,7 @@ int IniLoader::EntryBitfield( const wxString& var, int value, const int defvalue return result; } -void IniLoader::Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue ) +void IniLoader::Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue ) { // Note: the "easy" way would be to convert to double and load/save that, but floating point // has way too much rounding error so we really need to do things out manually.. >_< @@ -169,7 +169,7 @@ void IniLoader::Entry( const wxString& var, Fixed100& value, const Fixed100& def value = Fixed100::FromString( readval, value ); } -void IniLoader::Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue ) +void IniLoader::Entry( const wxString& var, wxPoint& value, const wxPoint defvalue ) { if( !m_Config ) { @@ -178,7 +178,7 @@ void IniLoader::Entry( const wxString& var, wxPoint& value, const wxPoint& defva TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); } -void IniLoader::Entry( const wxString& var, wxSize& value, const wxSize& defvalue ) +void IniLoader::Entry( const wxString& var, wxSize& value, const wxSize defvalue ) { if( !m_Config ) { @@ -187,7 +187,7 @@ void IniLoader::Entry( const wxString& var, wxSize& value, const wxSize& defvalu TryParse( value, m_Config->Read( var, ToString( defvalue ) ), defvalue ); } -void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect& defvalue ) +void IniLoader::Entry( const wxString& var, wxRect& value, const wxRect defvalue ) { if( !m_Config ) { @@ -243,13 +243,13 @@ IniSaver::IniSaver( wxConfigBase* config ) : IniInterface( config ) { } IniSaver::IniSaver() : IniInterface() {} IniSaver::~IniSaver() {} -void IniSaver::Entry( const wxString& var, wxString& value, const wxString& defvalue ) +void IniSaver::Entry( const wxString& var, wxString& value, const wxString defvalue ) { if( !m_Config ) return; m_Config->Write( var, value ); } -void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName& defvalue ) +void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName defvalue ) { if( !m_Config ) return; @@ -259,7 +259,7 @@ void IniSaver::Entry( const wxString& var, wxDirName& value, const wxDirName& de m_Config->Write( var, value.ToString() ); } -void IniSaver::Entry( const wxString& var, wxFileName& value, const wxFileName& defvalue ) +void IniSaver::Entry( const wxString& var, wxFileName& value, const wxFileName defvalue ) { if( !m_Config ) return; m_Config->Write( var, value.GetFullPath() ); @@ -295,7 +295,7 @@ int IniSaver::EntryBitfield( const wxString& var, int value, const int defvalue return value; } -void IniSaver::Entry( const wxString& var, Fixed100& value, const Fixed100& defvalue ) +void IniSaver::Entry( const wxString& var, Fixed100& value, const Fixed100 defvalue ) { if( !m_Config ) return; @@ -305,19 +305,19 @@ void IniSaver::Entry( const wxString& var, Fixed100& value, const Fixed100& defv m_Config->Write( var, value.ToString() ); } -void IniSaver::Entry( const wxString& var, wxPoint& value, const wxPoint& defvalue ) +void IniSaver::Entry( const wxString& var, wxPoint& value, const wxPoint defvalue ) { if( !m_Config ) return; m_Config->Write( var, ToString( value ) ); } -void IniSaver::Entry( const wxString& var, wxSize& value, const wxSize& defvalue ) +void IniSaver::Entry( const wxString& var, wxSize& value, const wxSize defvalue ) { if( !m_Config ) return; m_Config->Write( var, ToString( value ) ); } -void IniSaver::Entry( const wxString& var, wxRect& value, const wxRect& defvalue ) +void IniSaver::Entry( const wxString& var, wxRect& value, const wxRect defvalue ) { if( !m_Config ) return; m_Config->Write( var, ToString( value ) ); diff --git a/pcsx2/Pcsx2Config.cpp b/pcsx2/Pcsx2Config.cpp index 91e4054d37..bf7441482d 100644 --- a/pcsx2/Pcsx2Config.cpp +++ b/pcsx2/Pcsx2Config.cpp @@ -23,7 +23,6 @@ void TraceLogFilters::LoadSave( IniInterface& ini ) { - TraceLogFilters defaults; ScopedIniGroup path( ini, L"TraceLog" ); IniEntry( Enabled ); @@ -56,7 +55,6 @@ Pcsx2Config::SpeedhackOptions& Pcsx2Config::SpeedhackOptions::DisableAll() void Pcsx2Config::SpeedhackOptions::LoadSave( IniInterface& ini ) { - SpeedhackOptions defaults; ScopedIniGroup path( ini, L"Speedhacks" ); IniBitfield( EECycleRate ); @@ -71,7 +69,6 @@ void Pcsx2Config::SpeedhackOptions::LoadSave( IniInterface& ini ) void Pcsx2Config::ProfilerOptions::LoadSave( IniInterface& ini ) { - ProfilerOptions defaults; ScopedIniGroup path( ini, L"Profiler" ); IniBitBool( Enabled ); @@ -144,7 +141,6 @@ void Pcsx2Config::RecompilerOptions::ApplySanityCheck() void Pcsx2Config::RecompilerOptions::LoadSave( IniInterface& ini ) { - RecompilerOptions defaults; ScopedIniGroup path( ini, L"Recompiler" ); IniBitBool( EnableEE ); @@ -185,7 +181,6 @@ void Pcsx2Config::CpuOptions::ApplySanityCheck() void Pcsx2Config::CpuOptions::LoadSave( IniInterface& ini ) { - CpuOptions defaults; ScopedIniGroup path( ini, L"CPU" ); IniBitBoolEx( sseMXCSR.DenormalsAreZero, "FPU.DenormalsAreZero" ); @@ -221,7 +216,6 @@ Pcsx2Config::GSOptions::GSOptions() void Pcsx2Config::GSOptions::LoadSave( IniInterface& ini ) { - GSOptions defaults; ScopedIniGroup path( ini, L"GS" ); IniEntry( SynchronousMTGS ); @@ -237,7 +231,7 @@ void Pcsx2Config::GSOptions::LoadSave( IniInterface& ini ) IniEntry( FrameratePAL ); static const wxChar * const ntsc_pal_str[2] = { L"ntsc", L"pal" }; - ini.EnumEntry( L"DefaultRegionMode", DefaultRegionMode, ntsc_pal_str, defaults.DefaultRegionMode ); + ini.EnumEntry( L"DefaultRegionMode", DefaultRegionMode, ntsc_pal_str, DefaultRegionMode ); IniEntry( FramesToDraw ); IniEntry( FramesToSkip ); @@ -339,7 +333,6 @@ bool Pcsx2Config::GamefixOptions::Get( GamefixId id ) const void Pcsx2Config::GamefixOptions::LoadSave( IniInterface& ini ) { - GamefixOptions defaults; ScopedIniGroup path( ini, L"Gamefixes" ); IniBitBool( VuAddSubHack ); @@ -364,7 +357,6 @@ Pcsx2Config::Pcsx2Config() void Pcsx2Config::LoadSave( IniInterface& ini ) { - Pcsx2Config defaults; ScopedIniGroup path( ini, L"EmuCore" ); IniBitBool( CdvdVerboseReads ); diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index 1d04fa80b2..4453e7d8f9 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -437,15 +437,14 @@ void AppConfig::LoadSaveUserMode( IniInterface& ini, const wxString& cwdhash ) // ------------------------------------------------------------------------ void AppConfig::LoadSaveMemcards( IniInterface& ini ) { - AppConfig defaults; ScopedIniGroup path( ini, L"MemoryCards" ); for( uint slot=0; slot<2; ++slot ) { - ini.Entry( wxsFormat( L"Slot%u_Enable", slot+1 ), - Mcd[slot].Enabled, defaults.Mcd[slot].Enabled ); - ini.Entry( wxsFormat( L"Slot%u_Filename", slot+1 ), - Mcd[slot].Filename, defaults.Mcd[slot].Filename ); + ini.Entry( pxsFmt( L"Slot%u_Enable", slot+1 ), + Mcd[slot].Enabled, Mcd[slot].Enabled ); + ini.Entry( pxsFmt( L"Slot%u_Filename", slot+1 ), + Mcd[slot].Filename, Mcd[slot].Filename ); } for( uint slot=2; slot<8; ++slot ) @@ -453,24 +452,22 @@ void AppConfig::LoadSaveMemcards( IniInterface& ini ) int mtport = FileMcd_GetMtapPort(slot)+1; int mtslot = FileMcd_GetMtapSlot(slot)+1; - ini.Entry( wxsFormat( L"Multitap%u_Slot%u_Enable", mtport, mtslot ), - Mcd[slot].Enabled, defaults.Mcd[slot].Enabled ); - ini.Entry( wxsFormat( L"Multitap%u_Slot%u_Filename", mtport, mtslot ), - Mcd[slot].Filename, defaults.Mcd[slot].Filename ); + ini.Entry( pxsFmt( L"Multitap%u_Slot%u_Enable", mtport, mtslot ), + Mcd[slot].Enabled, Mcd[slot].Enabled ); + ini.Entry( pxsFmt( L"Multitap%u_Slot%u_Filename", mtport, mtslot ), + Mcd[slot].Filename, Mcd[slot].Filename ); } } void AppConfig::LoadSaveRootItems( IniInterface& ini ) { - AppConfig defaults; - IniEntry( MainGuiPosition ); IniEntry( SysSettingsTabName ); IniEntry( McdSettingsTabName ); IniEntry( ComponentsTabName ); IniEntry( AppSettingsTabName ); IniEntry( GameDatabaseTabName ); - ini.EnumEntry( L"LanguageId", LanguageId, NULL, defaults.LanguageId ); + ini.EnumEntry( L"LanguageId", LanguageId, NULL, LanguageId ); IniEntry( LanguageCode ); IniEntry( RecentIsoCount ); IniEntry( DeskTheme ); @@ -488,7 +485,7 @@ void AppConfig::LoadSaveRootItems( IniInterface& ini ) IniEntry( McdCompressNTFS ); #endif - ini.EnumEntry( L"CdvdSource", CdvdSource, CDVD_SourceLabels, defaults.CdvdSource ); + ini.EnumEntry( L"CdvdSource", CdvdSource, CDVD_SourceLabels, CdvdSource ); } // ------------------------------------------------------------------------ @@ -528,7 +525,6 @@ AppConfig::ConsoleLogOptions::ConsoleLogOptions() void AppConfig::ConsoleLogOptions::LoadSave( IniInterface& ini, const wxChar* logger ) { - ConsoleLogOptions defaults; ScopedIniGroup path( ini, logger ); IniEntry( Visible ); @@ -566,7 +562,6 @@ AppConfig::FolderOptions::FolderOptions() void AppConfig::FolderOptions::LoadSave( IniInterface& ini ) { - FolderOptions defaults; ScopedIniGroup path( ini, L"Folders" ); if( ini.IsSaving() ) @@ -662,7 +657,6 @@ void AppConfig::GSWindowOptions::SanityCheck() void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini ) { ScopedIniGroup path( ini, L"GSWindow" ); - GSWindowOptions defaults; IniEntry( CloseOnEsc ); IniEntry( DefaultToFullscreen ); @@ -682,7 +676,7 @@ void AppConfig::GSWindowOptions::LoadSave( IniInterface& ini ) L"16:9", }; - ini.EnumEntry( L"AspectRatio", AspectRatio, AspectRatioNames, defaults.AspectRatio ); + ini.EnumEntry( L"AspectRatio", AspectRatio, AspectRatioNames, AspectRatio ); if( ini.IsLoading() ) SanityCheck(); } @@ -710,7 +704,6 @@ void AppConfig::FramerateOptions::SanityCheck() void AppConfig::FramerateOptions::LoadSave( IniInterface& ini ) { ScopedIniGroup path( ini, L"Framerate" ); - FramerateOptions defaults; IniEntry( NominalScalar ); IniEntry( TurboScalar ); @@ -864,6 +857,8 @@ void AppLoadSettings() AppIniLoader loader; ConLog_LoadSaveSettings( loader ); SysTraceLog_LoadSaveSettings( loader ); + + g_Conf = new AppConfig(); g_Conf->LoadSave( loader ); if( !wxFile::Exists( g_Conf->CurrentIso ) ) diff --git a/pcsx2/gui/AppCorePlugins.cpp b/pcsx2/gui/AppCorePlugins.cpp index ee151560ec..cf1a16e406 100644 --- a/pcsx2/gui/AppCorePlugins.cpp +++ b/pcsx2/gui/AppCorePlugins.cpp @@ -227,9 +227,9 @@ void AppCorePlugins::Load( PluginsEnum_t pid, const wxString& srcfile ) { if( !wxThread::IsMain() ) { + Sleep( 5 ); LoadSinglePluginEvent evt( pid, srcfile ); wxGetApp().ProcessAction( evt); - Sleep( 5 ); return; } @@ -240,9 +240,9 @@ void AppCorePlugins::Unload( PluginsEnum_t pid ) { if( !wxThread::IsMain() ) { + Sleep( 5 ); SinglePluginMethodEvent evt( &AppCorePlugins::Unload, pid ); wxGetApp().ProcessAction( evt ); - Sleep( 5 ); return; }