From aa0055cea72d1478c560cee4a44ac43f6ffcad42 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 5 Jan 2016 22:37:28 -0800 Subject: [PATCH 1/4] Track the running GPU backend separate from config. This way we can change the config directly when we want to save a new setting, rather than having hacks to use a temp var. --- Core/Config.cpp | 5 ----- Core/Config.h | 11 ++++++----- Core/Screenshot.cpp | 4 ++-- Core/System.cpp | 10 ++++++++++ Core/System.h | 4 ++++ GPU/Common/FramebufferCommon.cpp | 8 +++----- UI/DevScreens.cpp | 4 ++-- UI/EmuScreen.cpp | 6 +++--- UI/GameSettingsScreen.cpp | 13 +++++++++---- UI/NativeApp.cpp | 11 ++++++----- Windows/MainWindowMenu.cpp | 6 ++++-- Windows/main.cpp | 10 ---------- 12 files changed, 49 insertions(+), 43 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index c909ab7620..38d807bbd0 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -442,7 +442,6 @@ static ConfigSetting graphicsSettings[] = { ReportedConfigSetting("FrameRate", &g_Config.iFpsLimit, 0, true, true), #ifdef _WIN32 ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, false, true, true), - ConfigSetting("TemporaryGPUBackend", &g_Config.iTempGPUBackend, -1, false), ConfigSetting("RestartRequired", &g_Config.bRestartRequired, false, false), #else ConfigSetting("FrameSkipUnthrottle", &g_Config.bFrameSkipUnthrottle, true), @@ -943,10 +942,6 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { CleanRecent(); -#ifdef _WIN32 - iTempGPUBackend = iGPUBackend; -#endif - // Fix Wrong MAC address by old version by "Change MAC address" if (sMACAddress.length() != 17) sMACAddress = CreateRandMAC(); diff --git a/Core/Config.h b/Core/Config.h index 318fa89d07..6d9e2b2b9b 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -45,9 +45,13 @@ enum BufferFilter { }; // Software is not among these because it will have one of these perform the blit to display. +enum class GPUBackend { + OPENGL = 0, + DIRECT3D9 = 1, +}; enum { - GPU_BACKEND_OPENGL = 0, - GPU_BACKEND_DIRECT3D9 = 1, + GPU_BACKEND_OPENGL = GPUBackend::OPENGL, + GPU_BACKEND_DIRECT3D9 = GPUBackend::DIRECT3D9, }; enum AudioBackendType { @@ -96,9 +100,6 @@ public: bool bTopMost; std::string sFont; bool bIgnoreWindowsKey; - // Used for switching the GPU backend in GameSettingsScreen. - // Without this, PPSSPP instantly crashes if we edit iGPUBackend directly... - int iTempGPUBackend; bool bRestartRequired; #endif diff --git a/Core/Screenshot.cpp b/Core/Screenshot.cpp index b758c30ad2..c2d95ac3cc 100644 --- a/Core/Screenshot.cpp +++ b/Core/Screenshot.cpp @@ -221,10 +221,10 @@ bool TakeGameScreenshot(const char *filename, ScreenshotFormat fmt, ScreenshotTy success = gpuDebug->GetCurrentFramebuffer(buf); } } else { - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { success = GLES_GPU::GetDisplayFramebuffer(buf); #ifdef _WIN32 - } else if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + } else if (GetGPUBackend() == GPUBackend::DIRECT3D9) { success = DX9::DIRECTX9_GPU::GetDisplayFramebuffer(buf); #endif } diff --git a/Core/System.cpp b/Core/System.cpp index a228b9308e..06246507d6 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -90,6 +90,8 @@ volatile CoreState coreState = CORE_STEPPING; volatile bool coreStatePending = false; static volatile CPUThreadState cpuThreadState = CPU_THREAD_NOT_RUNNING; +static GPUBackend gpuBackend; + void UpdateUIState(GlobalUIState newState) { // Never leave the EXIT state. if (globalUIState != newState && globalUIState != UISTATE_EXIT) { @@ -102,6 +104,14 @@ GlobalUIState GetUIState() { return globalUIState; } +void SetGPUBackend(GPUBackend type) { + gpuBackend = type; +} + +GPUBackend GetGPUBackend() { + return gpuBackend; +} + bool IsAudioInitialised() { return audioInitialized; } diff --git a/Core/System.h b/Core/System.h index b32a14b26a..9a11b5241f 100644 --- a/Core/System.h +++ b/Core/System.h @@ -48,10 +48,14 @@ enum PSPDirectories { }; class GraphicsContext; +enum class GPUBackend; void UpdateUIState(GlobalUIState newState); GlobalUIState GetUIState(); +void SetGPUBackend(GPUBackend type); +GPUBackend GetGPUBackend(); + bool PSP_Init(const CoreParameter &coreParam, std::string *error_string); bool PSP_InitStart(const CoreParameter &coreParam, std::string *error_string); bool PSP_InitUpdate(std::string *error_string); diff --git a/GPU/Common/FramebufferCommon.cpp b/GPU/Common/FramebufferCommon.cpp index 0f56e743da..37018a0f62 100644 --- a/GPU/Common/FramebufferCommon.cpp +++ b/GPU/Common/FramebufferCommon.cpp @@ -50,11 +50,9 @@ void CenterDisplayOutputRect(float *x, float *y, float *w, float *h, float origW float offsetX = (g_Config.fSmallDisplayOffsetX - 0.5f) * 2.0f * frameW; float offsetY = (g_Config.fSmallDisplayOffsetY - 0.5f) * 2.0f * frameH; // Have to invert Y for GL -#ifdef _WIN32 - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { offsetY = offsetY * -1.0f; } -#else - offsetY = offsetY * -1.0f; -#endif + if (GetGPUBackend() == GPUBackend::OPENGL) { + offsetY = offsetY * -1.0f; + } float customZoom = g_Config.fSmallDisplayCustomZoom / 8.0f; float smallDisplayW = origW * customZoom; float smallDisplayH = origH * customZoom; diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index f6e530edc2..fc3bdd52df 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -356,7 +356,7 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new InfoItem("Model", thin3d->GetInfoString(T3DInfo::RENDERER))); #ifdef _WIN32 deviceSpecs->Add(new InfoItem("Driver Version", System_GetProperty(SYSPROP_GPUDRIVER_VERSION))); - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { deviceSpecs->Add(new InfoItem("D3DX Version", StringFromFormat("%d", GetD3DXVersion()))); } #endif @@ -378,7 +378,7 @@ void SystemInfoScreen::CreateViews() { deviceSpecs->Add(new ItemHeader("Version Information")); std::string apiVersion; - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { if (gl_extensions.IsGLES) { apiVersion = StringFromFormat("v%d.%d.%d ES", gl_extensions.ver[0], gl_extensions.ver[1], gl_extensions.ver[2]); } else { diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index fd2a5f25e6..3b785c2d7b 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -98,7 +98,7 @@ void EmuScreen::bootGame(const std::string &filename) { CoreParameter coreParam; coreParam.cpuCore = g_Config.bJit ? CPU_JIT : CPU_INTERPRETER; coreParam.gpuCore = g_Config.bSoftwareRendering ? GPU_SOFTWARE : GPU_GLES; - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { coreParam.gpuCore = GPU_DIRECTX9; } // Preserve the existing graphics context. @@ -152,7 +152,7 @@ void EmuScreen::bootComplete() { #endif memset(virtKeys, 0, sizeof(virtKeys)); - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { const char *renderer = (const char*)glGetString(GL_RENDERER); if (strstr(renderer, "Chainfire3D") != 0) { osm.Show(sc->T("Chainfire3DWarning", "WARNING: Chainfire3D detected, may cause problems"), 10.0f, 0xFF30a0FF, -1, true); @@ -901,7 +901,7 @@ void EmuScreen::render() { if (invalid_) return; - if (useBufferedRendering && g_Config.iGPUBackend == GPU_BACKEND_OPENGL) + if (useBufferedRendering && GetGPUBackend() == GPUBackend::OPENGL) fbo_unbind(); if (!osm.IsEmpty() || g_Config.bShowDebugStats || g_Config.iShowFPSCounter || g_Config.bShowTouchControls || g_Config.bShowDeveloperMenu || g_Config.bShowAudioDebug || saveStatePreview_->GetVisibility() != UI::V_GONE || g_Config.bShowFrameProfiler) { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index fdf7278623..7de23b92b3 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -135,7 +135,7 @@ void GameSettingsScreen::CreateViews() { graphicsSettings->Add(new ItemHeader(gr->T("Rendering Mode"))); #if defined(_WIN32) static const char *renderingBackend[] = { "OpenGL", "Direct3D9" }; - PopupMultiChoice *renderingBackendChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iTempGPUBackend, gr->T("Backend"), renderingBackend, GPU_BACKEND_OPENGL, ARRAY_SIZE(renderingBackend), gr->GetName(), screenManager())); + PopupMultiChoice *renderingBackendChoice = graphicsSettings->Add(new PopupMultiChoice(&g_Config.iGPUBackend, gr->T("Backend"), renderingBackend, GPU_BACKEND_OPENGL, ARRAY_SIZE(renderingBackend), gr->GetName(), screenManager())); renderingBackendChoice->OnChoice.Handle(this, &GameSettingsScreen::OnRenderingBackend); #endif static const char *renderingMode[] = { "Non-Buffered Rendering", "Buffered Rendering", "Read Framebuffers To Memory (CPU)", "Read Framebuffers To Memory (GPU)"}; @@ -871,13 +871,18 @@ void GlobalSettingsScreen::CreateViews() { void GameSettingsScreen::CallbackRenderingBackend(bool yes) { #if defined(_WIN32) - // If the user ends up deciding not to restart, set the temporary variable back to the current backend + // If the user ends up deciding not to restart, set the config back to the current backend // so it doesn't get switched by accident. if (yes) { + if (g_Config.iGPUBackend == (int)GPUBackend::DIRECT3D9) { + // TODO: Remove once software renderer supports D3D9. + g_Config.bSoftwareRendering = false; + } + g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); } else { - g_Config.iTempGPUBackend = g_Config.iGPUBackend; + g_Config.iGPUBackend = (int)GetGPUBackend(); } #endif } @@ -887,7 +892,7 @@ UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) { I18NCategory *di = GetI18NCategory("Dialog"); // It only makes sense to show the restart prompt if the backend was actually changed. - if (g_Config.iTempGPUBackend != g_Config.iGPUBackend) { + if (g_Config.iGPUBackend != (int)GetGPUBackend()) { screenManager()->push(new PromptScreen(di->T("ChangingGPUBackends", "Changing GPU backends requires PPSSPP to restart. Restart now?"), di->T("Yes"), di->T("No"), std::bind(&GameSettingsScreen::CallbackRenderingBackend, this, placeholder::_1))); } diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index adf7da59e9..0c5b26ab5a 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -501,7 +501,8 @@ void NativeInit(int argc, const char *argv[], // We do this here, instead of in NativeInitGraphics, because the display may be reset. // When it's reset we don't want to forget all our managed things. - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + SetGPUBackend((GPUBackend) g_Config.iGPUBackend); + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_init(); } } @@ -689,7 +690,7 @@ void NativeRender(GraphicsContext *graphicsContext) { // Apply the UIContext bounds as a 2D transformation matrix. Matrix4x4 ortho; - if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { + if (GetGPUBackend() == GPUBackend::DIRECT3D9) { ortho.setOrthoD3D(0.0f, xres, yres, 0.0f, -1.0f, 1.0f); Matrix4x4 translation; translation.setTranslation(Vec3(-0.5f, -0.5f, 0.0f)); @@ -718,7 +719,7 @@ void NativeRender(GraphicsContext *graphicsContext) { graphicsContext->Resize(); // TODO: Move this to new GraphicsContext objects for each backend. #ifndef _WIN32 - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { PSP_CoreParameter().pixelWidth = pixel_xres; PSP_CoreParameter().pixelHeight = pixel_yres; NativeMessageReceived("gpu resized", ""); @@ -757,7 +758,7 @@ void NativeDeviceLost() { g_gameInfoCache.Clear(); screenManager->deviceLost(); - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost(); } // Should dirty EVERYTHING @@ -915,7 +916,7 @@ void NativeResized() { } void NativeShutdown() { - if (g_Config.iGPUBackend == GPU_BACKEND_OPENGL) { + if (GetGPUBackend() == GPUBackend::OPENGL) { gl_lost_manager_shutdown(); } diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index e7ed9dea07..9e87c9d83d 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -666,13 +666,15 @@ namespace MainWindow { break; case ID_OPTIONS_DIRECTX: - g_Config.iTempGPUBackend = GPU_BACKEND_DIRECT3D9; + g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D9; + // TODO: Remove once software renderer supports D3D9. + g_Config.bSoftwareRendering = false; g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); break; case ID_OPTIONS_OPENGL: - g_Config.iTempGPUBackend = GPU_BACKEND_OPENGL; + g_Config.iGPUBackend = GPU_BACKEND_OPENGL; g_Config.bRestartRequired = true; PostMessage(MainWindow::GetHWND(), WM_CLOSE, 0, 0); break; diff --git a/Windows/main.cpp b/Windows/main.cpp index 6cbe20f783..375a8a12ee 100644 --- a/Windows/main.cpp +++ b/Windows/main.cpp @@ -600,16 +600,6 @@ int WINAPI WinMain(HINSTANCE _hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLin timeEndPeriod(1); delete host; - // Is there a safer place to do this? - // Doing this in Config::Save requires knowing if the UI state is UISTATE_EXIT, - // but that causes UnitTest to fail linking with 400 errors if System.h is included.. - if (g_Config.iTempGPUBackend != g_Config.iGPUBackend) { - g_Config.iGPUBackend = g_Config.iTempGPUBackend; - - // For now, turn off software rendering too, similar to the command-line. - g_Config.bSoftwareRendering = false; - } - g_Config.Save(); g_gameInfoCache.Clear(); g_gameInfoCache.Shutdown(); From 02f6b3dec70866f2bf15db90f584e5d23c29ad5d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 5 Jan 2016 23:01:49 -0800 Subject: [PATCH 2/4] Refactor config setting iteration. Cleaner. --- Core/Config.cpp | 118 +++++++++++++++++++++--------------------------- Core/Config.h | 3 ++ 2 files changed, 55 insertions(+), 66 deletions(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 38d807bbd0..407b8b12c9 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -20,6 +20,7 @@ #include #include "base/display.h" +#include "base/functional.h" #include "base/NativeApp.h" #include "ext/vjson/json.h" #include "file/ini_file.h" @@ -753,6 +754,15 @@ static ConfigSectionSettings sections[] = { {"Upgrade", upgradeSettings}, }; +static void IterateSettings(IniFile &iniFile, std::function func) { + for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { + IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); + for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { + func(section, setting); + } + } +} + Config::Config() : bGameSpecific(false) { } Config::~Config() { } @@ -812,12 +822,9 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { // Continue anyway to initialize the config. } - for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { - IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); - for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { - setting->Get(section); - } - } + IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + setting->Get(section); + }); iRunCount++; if (!File::Exists(currentDirectory)) @@ -923,14 +930,7 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) { INFO_LOG(LOADER, "Loading controller config: %s", controllerIniFilename_.c_str()); bSaveSettings = true; - IniFile controllerIniFile; - if (!controllerIniFile.Load(controllerIniFilename_)) { - ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename_.c_str()); - KeyMap::RestoreDefault(); - } else { - // Continue anyway to initialize the config. It will just restore the defaults. - KeyMap::LoadFromIni(controllerIniFile); - } + LoadStandardControllerIni(); //so this is all the way down here to overwrite the controller settings //sadly it won't benefit from all the "version conversion" going on up-above @@ -975,14 +975,11 @@ void Config::Save() { // Need to do this somewhere... bFirstRun = false; - for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { - IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); - for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { - if (!bGameSpecific || !setting->perGame_){ - setting->Set(section); - } + IterateSettings(iniFile, [&](IniFile::Section *section, ConfigSetting *setting) { + if (!bGameSpecific || !setting->perGame_) { + setting->Set(section); } - } + }); IniFile::Section *recent = iniFile.GetOrCreateSection("Recent"); recent->Set("MaxRecent", iMaxRecent); @@ -1168,13 +1165,10 @@ const std::string Config::FindConfigFile(const std::string &baseFilename) { } void Config::RestoreDefaults() { - if (bGameSpecific) - { + if (bGameSpecific) { deleteGameConfig(gameId_); createGameConfig(gameId_); - } - else - { + } else { if (File::Exists(iniFilename_)) File::Delete(iniFilename_); recentIsos.clear(); @@ -1183,25 +1177,21 @@ void Config::RestoreDefaults() { Load(); } -bool Config::hasGameConfig(const std::string &pGameId) -{ +bool Config::hasGameConfig(const std::string &pGameId) { std::string fullIniFilePath = getGameConfigFile(pGameId); return File::Exists(fullIniFilePath); } -void Config::changeGameSpecific(const std::string &pGameId) -{ +void Config::changeGameSpecific(const std::string &pGameId) { Save(); gameId_ = pGameId; bGameSpecific = !pGameId.empty(); } -bool Config::createGameConfig(const std::string &pGameId) -{ +bool Config::createGameConfig(const std::string &pGameId) { std::string fullIniFilePath = getGameConfigFile(pGameId); - if (hasGameConfig(pGameId)) - { + if (hasGameConfig(pGameId)) { return false; } @@ -1210,26 +1200,22 @@ bool Config::createGameConfig(const std::string &pGameId) return true; } -bool Config::deleteGameConfig(const std::string& pGameId) -{ +bool Config::deleteGameConfig(const std::string& pGameId) { std::string fullIniFilePath = getGameConfigFile(pGameId); File::Delete(fullIniFilePath); return true; } -std::string Config::getGameConfigFile(const std::string &pGameId) -{ +std::string Config::getGameConfigFile(const std::string &pGameId) { std::string iniFileName = pGameId + "_ppsspp.ini"; std::string iniFileNameFull = FindConfigFile(iniFileName); return iniFileNameFull; } -bool Config::saveGameConfig(const std::string &pGameId) -{ - if (pGameId.empty()) - { +bool Config::saveGameConfig(const std::string &pGameId) { + if (pGameId.empty()) { return false; } @@ -1237,14 +1223,11 @@ bool Config::saveGameConfig(const std::string &pGameId) IniFile iniFile; - for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { - IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); - for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { - if (setting->perGame_){ - setting->Set(section); - } + IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + if (setting->perGame_) { + setting->Set(section); } - } + }); KeyMap::SaveToIni(iniFile); iniFile.Save(fullIniFilePath); @@ -1252,12 +1235,10 @@ bool Config::saveGameConfig(const std::string &pGameId) return true; } -bool Config::loadGameConfig(const std::string &pGameId) -{ +bool Config::loadGameConfig(const std::string &pGameId) { std::string iniFileNameFull = getGameConfigFile(pGameId); - if (!hasGameConfig(pGameId)) - { + if (!hasGameConfig(pGameId)) { INFO_LOG(LOADER, "Failed to read %s. No game-specific settings found, using global defaults.", iniFileNameFull.c_str()); return false; } @@ -1266,29 +1247,34 @@ bool Config::loadGameConfig(const std::string &pGameId) IniFile iniFile; iniFile.Load(iniFileNameFull); - - for (size_t i = 0; i < ARRAY_SIZE(sections); ++i) { - IniFile::Section *section = iniFile.GetOrCreateSection(sections[i].section); - for (auto setting = sections[i].settings; setting->HasMore(); ++setting) { - if (setting->perGame_){ - setting->Get(section); - } + IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + if (setting->perGame_) { + setting->Get(section); } - } + }); + KeyMap::LoadFromIni(iniFile); return true; } - -void Config::unloadGameConfig() -{ - if (bGameSpecific) - { +void Config::unloadGameConfig() { + if (bGameSpecific){ changeGameSpecific(); Load(iniFilename_.c_str(), controllerIniFilename_.c_str()); } } +void Config::LoadStandardControllerIni() { + IniFile controllerIniFile; + if (!controllerIniFile.Load(controllerIniFilename_)) { + ERROR_LOG(LOADER, "Failed to read %s. Setting controller config to default.", controllerIniFilename_.c_str()); + KeyMap::RestoreDefault(); + } else { + // Continue anyway to initialize the config. It will just restore the defaults. + KeyMap::LoadFromIni(controllerIniFile); + } +} + void Config::ResetControlLayout() { g_Config.fActionButtonScale = defaultControlScale; g_Config.fActionButtonSpacing = 1.0f; diff --git a/Core/Config.h b/Core/Config.h index 6d9e2b2b9b..4fab14bc48 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -451,6 +451,9 @@ public: bool IsPortrait() const { return (iInternalScreenRotation == ROTATION_LOCKED_VERTICAL || iInternalScreenRotation == ROTATION_LOCKED_VERTICAL180) && iRenderingMode != 0; } + +protected: + void LoadStandardControllerIni(); private: std::string gameId_; From b1e10894a4c5441925a04c20246de373880a94a1 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 5 Jan 2016 23:02:19 -0800 Subject: [PATCH 3/4] Don't forget global setting when switching configs. Fixes #8393. --- Core/Config.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Core/Config.cpp b/Core/Config.cpp index 407b8b12c9..5d5c6355b2 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1260,7 +1260,18 @@ bool Config::loadGameConfig(const std::string &pGameId) { void Config::unloadGameConfig() { if (bGameSpecific){ changeGameSpecific(); - Load(iniFilename_.c_str(), controllerIniFilename_.c_str()); + + IniFile iniFile; + iniFile.Load(iniFilename_); + + // Reload game specific settings back to standard. + IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) { + if (setting->perGame_) { + setting->Get(section); + } + }); + + LoadStandardControllerIni(); } } From 48ef1ae8ca7cd133bc35bc1b81027f4d44508311 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Tue, 5 Jan 2016 23:08:20 -0800 Subject: [PATCH 4/4] Change Win UI constants to use D3D9 not DX. --- Windows/MainWindowMenu.cpp | 10 +++++----- Windows/ppsspp.rc | 2 +- Windows/resource.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Windows/MainWindowMenu.cpp b/Windows/MainWindowMenu.cpp index 9e87c9d83d..d628ad048b 100644 --- a/Windows/MainWindowMenu.cpp +++ b/Windows/MainWindowMenu.cpp @@ -270,7 +270,7 @@ namespace MainWindow { TranslateSubMenu(menu, "Window Size", MENU_OPTIONS, SUBMENU_WINDOW_SIZE); // Skip window size 1x-4x.. TranslateSubMenu(menu, "Backend", MENU_OPTIONS, SUBMENU_RENDERING_BACKEND); - TranslateMenuItem(menu, ID_OPTIONS_DIRECTX); + TranslateMenuItem(menu, ID_OPTIONS_DIRECT3D9); TranslateMenuItem(menu, ID_OPTIONS_OPENGL); TranslateSubMenu(menu, "Rendering Mode", MENU_OPTIONS, SUBMENU_RENDERING_MODE); TranslateMenuItem(menu, ID_OPTIONS_NONBUFFEREDRENDERING); @@ -665,7 +665,7 @@ namespace MainWindow { NativeMessageReceived("gpu clear cache", ""); break; - case ID_OPTIONS_DIRECTX: + case ID_OPTIONS_DIRECT3D9: g_Config.iGPUBackend = GPU_BACKEND_DIRECT3D9; // TODO: Remove once software renderer supports D3D9. g_Config.bSoftwareRendering = false; @@ -1108,13 +1108,13 @@ namespace MainWindow { } if (g_Config.iGPUBackend == GPU_BACKEND_DIRECT3D9) { - EnableMenuItem(menu, ID_OPTIONS_DIRECTX, MF_GRAYED); - CheckMenuItem(menu, ID_OPTIONS_DIRECTX, MF_CHECKED); + EnableMenuItem(menu, ID_OPTIONS_DIRECT3D9, MF_GRAYED); + CheckMenuItem(menu, ID_OPTIONS_DIRECT3D9, MF_CHECKED); EnableMenuItem(menu, ID_OPTIONS_OPENGL, MF_ENABLED); } else { EnableMenuItem(menu, ID_OPTIONS_OPENGL, MF_GRAYED); CheckMenuItem(menu, ID_OPTIONS_OPENGL, MF_CHECKED); - EnableMenuItem(menu, ID_OPTIONS_DIRECTX, MF_ENABLED); + EnableMenuItem(menu, ID_OPTIONS_DIRECT3D9, MF_ENABLED); } UpdateDynamicMenuCheckmarks(menu); diff --git a/Windows/ppsspp.rc b/Windows/ppsspp.rc index 0fa59884a4..40928a86e8 100644 --- a/Windows/ppsspp.rc +++ b/Windows/ppsspp.rc @@ -471,7 +471,7 @@ BEGIN POPUP "Backend" BEGIN - MENUITEM "Direct3D9" ID_OPTIONS_DIRECTX + MENUITEM "Direct3D9" ID_OPTIONS_DIRECT3D9 MENUITEM "OpenGL" ID_OPTIONS_OPENGL END diff --git a/Windows/resource.h b/Windows/resource.h index fdd01bde79..e097d0327c 100644 --- a/Windows/resource.h +++ b/Windows/resource.h @@ -316,7 +316,7 @@ #define ID_DEBUG_SAVESYMFILE 40151 #define ID_OPTIONS_BUFLINEARFILTER 40152 #define ID_OPTIONS_BUFNEARESTFILTER 40153 -#define ID_OPTIONS_DIRECTX 40154 +#define ID_OPTIONS_DIRECT3D9 40154 #define ID_OPTIONS_OPENGL 40155 // Dummy option to let the buffered rendering hotkey cycle through all the options.