From 19109e2d01d7bcbde51ba84f71fee1cfc751ec24 Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sat, 4 Oct 2014 15:12:15 -0400 Subject: [PATCH] Migrate global init stuff into UICommon. This avoids code duplication in a bunch of places . I also moved the NVIDIA Optimus export into VideoCommon. --- Source/Core/CMakeLists.txt | 1 + Source/Core/DolphinWX/CMakeLists.txt | 1 + Source/Core/DolphinWX/DolphinWX.vcxproj | 3 + Source/Core/DolphinWX/Main.cpp | 46 ++------------ Source/Core/DolphinWX/MainAndroid.cpp | 13 ++-- Source/Core/DolphinWX/MainNoGUI.cpp | 14 ++--- Source/Core/UICommon/CMakeLists.txt | 5 ++ Source/Core/UICommon/UICommon.cpp | 64 ++++++++++++++++++++ Source/Core/UICommon/UICommon.h | 15 +++++ Source/Core/UICommon/UICommon.vcxproj | 54 +++++++++++++++++ Source/Core/VideoCommon/VideoBackendBase.cpp | 7 +++ Source/dolphin-emu.sln | 7 +++ 12 files changed, 170 insertions(+), 60 deletions(-) create mode 100644 Source/Core/UICommon/CMakeLists.txt create mode 100644 Source/Core/UICommon/UICommon.cpp create mode 100644 Source/Core/UICommon/UICommon.h create mode 100644 Source/Core/UICommon/UICommon.vcxproj diff --git a/Source/Core/CMakeLists.txt b/Source/Core/CMakeLists.txt index 7b4042b604..b478a10100 100644 --- a/Source/Core/CMakeLists.txt +++ b/Source/Core/CMakeLists.txt @@ -4,5 +4,6 @@ add_subdirectory(Core) add_subdirectory(DiscIO) add_subdirectory(DolphinWX) add_subdirectory(InputCommon) +add_subdirectory(UICommon) add_subdirectory(VideoCommon) add_subdirectory(VideoBackends) diff --git a/Source/Core/DolphinWX/CMakeLists.txt b/Source/Core/DolphinWX/CMakeLists.txt index 4b60118b48..8a007d0593 100644 --- a/Source/Core/DolphinWX/CMakeLists.txt +++ b/Source/Core/DolphinWX/CMakeLists.txt @@ -3,6 +3,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") endif() set(LIBS core + uicommon ${LZO} ${GTK2_LIBRARIES}) diff --git a/Source/Core/DolphinWX/DolphinWX.vcxproj b/Source/Core/DolphinWX/DolphinWX.vcxproj index 90b6c8ce7b..69fa015d15 100644 --- a/Source/Core/DolphinWX/DolphinWX.vcxproj +++ b/Source/Core/DolphinWX/DolphinWX.vcxproj @@ -188,6 +188,9 @@ {6bbd47cf-91fd-4077-b676-8b76980178a9} + + + {604C8368-F34A-4D55-82C8-CC92A0C13254} {96020103-4ba5-4fd2-b4aa-5b6d24492d4e} diff --git a/Source/Core/DolphinWX/Main.cpp b/Source/Core/DolphinWX/Main.cpp index 082a7544c4..c25b911de3 100644 --- a/Source/Core/DolphinWX/Main.cpp +++ b/Source/Core/DolphinWX/Main.cpp @@ -52,6 +52,8 @@ #include "DolphinWX/Debugger/CodeWindow.h" #include "DolphinWX/Debugger/JitWindow.h" +#include "UICommon/UICommon.h" + #include "VideoCommon/VideoBackendBase.h" #if defined HAVE_X11 && HAVE_X11 @@ -83,15 +85,6 @@ class wxFrame; -// Nvidia drivers >= v302 will check if the application exports a global -// variable named NvOptimusEnablement to know if it should run the app in high -// performance graphics mode or using the IGP. -#ifdef WIN32 -extern "C" { - __declspec(dllexport) DWORD NvOptimusEnablement = 1; -} -#endif - // ------------ // Main window @@ -257,32 +250,8 @@ bool DolphinApp::OnInit() } #endif - // Copy initial Wii NAND data from Sys to User. - File::CopyDir(File::GetSysDirectory() + WII_USER_DIR DIR_SEP, - File::GetUserPath(D_WIIUSER_IDX)); - - File::CreateFullPath(File::GetUserPath(D_USER_IDX)); - File::CreateFullPath(File::GetUserPath(D_CACHE_IDX)); - File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); - File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX)); - File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX)); - File::CreateFullPath(File::GetUserPath(D_GAMESETTINGS_IDX)); - File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX)); - File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP); - File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP); - File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP); - File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX)); - File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX)); - File::CreateFullPath(File::GetUserPath(D_MAPS_IDX)); - File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); - File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); - File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); - File::CreateFullPath(File::GetUserPath(D_THEMES_IDX)); - - LogManager::Init(); - SConfig::Init(); - VideoBackend::PopulateList(); - WiimoteReal::LoadSettings(); + UICommon::CreateDirectories(); + UICommon::Init(); if (selectVideoBackend && videoBackendName != wxEmptyString) SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend = @@ -301,8 +270,6 @@ bool DolphinApp::OnInit() // Enable the PNG image handler for screenshots wxImage::AddHandler(new wxPNGHandler); - SetEnableAlert(SConfig::GetInstance().m_LocalCoreStartupParameter.bUsePanicHandlers); - int x = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosX; int y = SConfig::GetInstance().m_LocalCoreStartupParameter.iPosY; int w = SConfig::GetInstance().m_LocalCoreStartupParameter.iWidth; @@ -445,10 +412,7 @@ void DolphinApp::OnEndSession(wxCloseEvent& event) int DolphinApp::OnExit() { Core::Shutdown(); - WiimoteReal::Shutdown(); - VideoBackend::ClearList(); - SConfig::Shutdown(); - LogManager::Shutdown(); + UICommon::Shutdown(); delete m_locale; diff --git a/Source/Core/DolphinWX/MainAndroid.cpp b/Source/Core/DolphinWX/MainAndroid.cpp index 0f2c5eddce..3d226d5eef 100644 --- a/Source/Core/DolphinWX/MainAndroid.cpp +++ b/Source/Core/DolphinWX/MainAndroid.cpp @@ -43,6 +43,8 @@ #include "DiscIO/Filesystem.h" #include "DiscIO/VolumeCreator.h" +#include "UICommon/UICommon.h" + #include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/VideoBackendBase.h" @@ -359,21 +361,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_Run(JNIEnv * OSD::AddCallback(OSD::OSD_INIT, ButtonManager::Init); OSD::AddCallback(OSD::OSD_SHUTDOWN, ButtonManager::Shutdown); - LogManager::Init(); - SConfig::Init(); - VideoBackend::PopulateList(); - VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend); - WiimoteReal::LoadSettings(); + UICommon::Init(); // No use running the loop when booting fails if ( BootManager::BootCore( g_filename.c_str() ) ) while (PowerPC::GetState() != PowerPC::CPU_POWERDOWN) updateMainFrameEvent.Wait(); - WiimoteReal::Shutdown(); - VideoBackend::ClearList(); - SConfig::Shutdown(); - LogManager::Shutdown(); + UICommon::Shutdown(); ANativeWindow_release(surf); } diff --git a/Source/Core/DolphinWX/MainNoGUI.cpp b/Source/Core/DolphinWX/MainNoGUI.cpp index e000a5a9de..ebe1d97c30 100644 --- a/Source/Core/DolphinWX/MainNoGUI.cpp +++ b/Source/Core/DolphinWX/MainNoGUI.cpp @@ -22,6 +22,8 @@ #include "Core/HW/Wiimote.h" #include "Core/PowerPC/PowerPC.h" +#include "UICommon/UICommon.h" + #include "VideoCommon/VideoBackendBase.h" static bool rendererHasFocus = true; @@ -347,12 +349,7 @@ int main(int argc, char* argv[]) return 1; } - LogManager::Init(); - SConfig::Init(); - VideoBackend::PopulateList(); - VideoBackend::ActivateBackend(SConfig::GetInstance(). - m_LocalCoreStartupParameter.m_strVideoBackend); - WiimoteReal::LoadSettings(); + UICommon::Init(); platform->Init(); @@ -372,10 +369,7 @@ int main(int argc, char* argv[]) platform->Shutdown(); Core::Shutdown(); - WiimoteReal::Shutdown(); - VideoBackend::ClearList(); - SConfig::Shutdown(); - LogManager::Shutdown(); + UICommon::Shutdown(); delete platform; diff --git a/Source/Core/UICommon/CMakeLists.txt b/Source/Core/UICommon/CMakeLists.txt new file mode 100644 index 0000000000..59e9443da7 --- /dev/null +++ b/Source/Core/UICommon/CMakeLists.txt @@ -0,0 +1,5 @@ +set(SRCS UICommon.cpp) + +set(LIBS common) + +add_dolphin_library(uicommon "${SRCS}" "${LIBS}") diff --git a/Source/Core/UICommon/UICommon.cpp b/Source/Core/UICommon/UICommon.cpp new file mode 100644 index 0000000000..f54b1a9c76 --- /dev/null +++ b/Source/Core/UICommon/UICommon.cpp @@ -0,0 +1,64 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#include "Common/CommonPaths.h" +#include "Common/FileUtil.h" +#include "Common/Logging/LogManager.h" + +#include "Core/ConfigManager.h" +#include "Core/HW/Wiimote.h" + +#include "UICommon/UICommon.h" + +#include "VideoCommon/VideoBackendBase.h" + +namespace UICommon +{ + +void Init() +{ + LogManager::Init(); + SConfig::Init(); + VideoBackend::PopulateList(); + WiimoteReal::LoadSettings(); + + VideoBackend::ActivateBackend(SConfig::GetInstance().m_LocalCoreStartupParameter.m_strVideoBackend); + + SetEnableAlert(SConfig::GetInstance().m_LocalCoreStartupParameter.bUsePanicHandlers); +} + +void Shutdown() +{ + WiimoteReal::Shutdown(); + VideoBackend::ClearList(); + SConfig::Shutdown(); + LogManager::Shutdown(); +} + +void CreateDirectories() +{ + // Copy initial Wii NAND data from Sys to User. + File::CopyDir(File::GetSysDirectory() + WII_USER_DIR DIR_SEP, + File::GetUserPath(D_WIIUSER_IDX)); + + File::CreateFullPath(File::GetUserPath(D_USER_IDX)); + File::CreateFullPath(File::GetUserPath(D_CACHE_IDX)); + File::CreateFullPath(File::GetUserPath(D_CONFIG_IDX)); + File::CreateFullPath(File::GetUserPath(D_DUMPDSP_IDX)); + File::CreateFullPath(File::GetUserPath(D_DUMPTEXTURES_IDX)); + File::CreateFullPath(File::GetUserPath(D_GAMESETTINGS_IDX)); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX)); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + USA_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + EUR_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_GCUSER_IDX) + JAP_DIR DIR_SEP); + File::CreateFullPath(File::GetUserPath(D_HIRESTEXTURES_IDX)); + File::CreateFullPath(File::GetUserPath(D_MAILLOGS_IDX)); + File::CreateFullPath(File::GetUserPath(D_MAPS_IDX)); + File::CreateFullPath(File::GetUserPath(D_SCREENSHOTS_IDX)); + File::CreateFullPath(File::GetUserPath(D_SHADERS_IDX)); + File::CreateFullPath(File::GetUserPath(D_STATESAVES_IDX)); + File::CreateFullPath(File::GetUserPath(D_THEMES_IDX)); +} + +} // namespace UICommon diff --git a/Source/Core/UICommon/UICommon.h b/Source/Core/UICommon/UICommon.h new file mode 100644 index 0000000000..d177727986 --- /dev/null +++ b/Source/Core/UICommon/UICommon.h @@ -0,0 +1,15 @@ +// Copyright 2014 Dolphin Emulator Project +// Licensed under GPLv2 +// Refer to the license.txt file included. + +#pragma once + +namespace UICommon +{ + +void Init(); +void Shutdown(); + +void CreateDirectories(); + +} // namespace UICommon diff --git a/Source/Core/UICommon/UICommon.vcxproj b/Source/Core/UICommon/UICommon.vcxproj new file mode 100644 index 0000000000..ca9a9e4dbc --- /dev/null +++ b/Source/Core/UICommon/UICommon.vcxproj @@ -0,0 +1,54 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {604C8368-F34A-4D55-82C8-CC92A0C13254} + + + + StaticLibrary + v120 + Unicode + + + true + + + false + + + + + + + + + + + + + + + + {E54CF649-140E-4255-81A5-30A673C1FB36} + + + + + + + + + + + + \ No newline at end of file diff --git a/Source/Core/VideoCommon/VideoBackendBase.cpp b/Source/Core/VideoCommon/VideoBackendBase.cpp index a2d6d19845..817d917114 100644 --- a/Source/Core/VideoCommon/VideoBackendBase.cpp +++ b/Source/Core/VideoCommon/VideoBackendBase.cpp @@ -32,6 +32,13 @@ static bool IsGteVista() return VerifyVersionInfo(&osvi, VER_MAJORVERSION, dwlConditionMask) != FALSE; } + +// Nvidia drivers >= v302 will check if the application exports a global +// variable named NvOptimusEnablement to know if it should run the app in high +// performance graphics mode or using the IGP. +extern "C" { +__declspec(dllexport) DWORD NvOptimusEnablement = 1; +} #endif void VideoBackend::PopulateList() diff --git a/Source/dolphin-emu.sln b/Source/dolphin-emu.sln index 141580ca87..ceb40afacf 100644 --- a/Source/dolphin-emu.sln +++ b/Source/dolphin-emu.sln @@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DiscIO", "Core\DiscIO\DiscI EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InputCommon", "Core\InputCommon\InputCommon.vcxproj", "{6BBD47CF-91FD-4077-B676-8B76980178A9}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UICommon", "Core\UICommon\UICommon.vcxproj", "{604C8368-F34A-4D55-82C8-CC92A0C13254}" +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VideoCommon", "Core\VideoCommon\VideoCommon.vcxproj", "{3DE9EE35-3E91-4F27-A014-2866AD8C3FE3}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Externals", "Externals", "{87ADDFF9-5768-4DA2-A33B-2477593D6677}" @@ -93,6 +95,10 @@ Global {6BBD47CF-91FD-4077-B676-8B76980178A9}.Debug|x64.Build.0 = Debug|x64 {6BBD47CF-91FD-4077-B676-8B76980178A9}.Release|x64.ActiveCfg = Release|x64 {6BBD47CF-91FD-4077-B676-8B76980178A9}.Release|x64.Build.0 = Release|x64 + {604C8368-F34A-4D55-82C8-CC92A0C13254}.Debug|x64.ActiveCfg = Debug|x64 + {604C8368-F34A-4D55-82C8-CC92A0C13254}.Debug|x64.Build.0 = Debug|x64 + {604C8368-F34A-4D55-82C8-CC92A0C13254}.Release|x64.ActiveCfg = Release|x64 + {604C8368-F34A-4D55-82C8-CC92A0C13254}.Release|x64.Build.0 = Release|x64 {3DE9EE35-3E91-4F27-A014-2866AD8C3FE3}.Debug|x64.ActiveCfg = Debug|x64 {3DE9EE35-3E91-4F27-A014-2866AD8C3FE3}.Debug|x64.Build.0 = Debug|x64 {3DE9EE35-3E91-4F27-A014-2866AD8C3FE3}.Release|x64.ActiveCfg = Release|x64 @@ -187,6 +193,7 @@ Global {2E6C348C-C75C-4D94-8D1E-9C1FCBF3EFE4} = {15670B2E-CED6-4ED5-94CE-A00B1B2B5BA6} {160BDC25-5626-4B0D-BDD8-2953D9777FB5} = {15670B2E-CED6-4ED5-94CE-A00B1B2B5BA6} {6BBD47CF-91FD-4077-B676-8B76980178A9} = {15670B2E-CED6-4ED5-94CE-A00B1B2B5BA6} + {604C8368-F34A-4D55-82C8-CC92A0C13254} = {15670B2E-CED6-4ED5-94CE-A00B1B2B5BA6} {3DE9EE35-3E91-4F27-A014-2866AD8C3FE3} = {15670B2E-CED6-4ED5-94CE-A00B1B2B5BA6} {8ADA04D7-6DB1-4DA4-AB55-64FB12A0997B} = {87ADDFF9-5768-4DA2-A33B-2477593D6677} {AB993F38-C31D-4897-B139-A620C42BC565} = {87ADDFF9-5768-4DA2-A33B-2477593D6677}