Discord Rich Presence CMake integration

I have no idea if this works or not. Hopefully the build bot will tell me.
This commit is contained in:
yourWaifu 2018-06-08 15:56:11 -05:00 committed by Sleepy Flower Girl
parent 57bd13a0ce
commit 63f03455f3
19 changed files with 98 additions and 59 deletions

View File

@ -28,6 +28,7 @@ option(ENABLE_HEADLESS "Enables running Dolphin as a headless variant" OFF)
option(ENABLE_ALSA "Enables ALSA sound backend" ON)
option(ENABLE_PULSEAUDIO "Enables PulseAudio sound backend" ON)
option(ENABLE_LLVM "Enables LLVM support, for disassembly" ON)
option(USE_DISCORD_PRESENCE "Enables Discord Rich Presence, show the current game on Discord" ON)
# Maintainers: if you consider blanket disabling this for your users, please
# consider the following points:
@ -366,6 +367,7 @@ if(ANDROID)
set(USE_EGL 1)
set(ENABLE_WX 0)
set(ENABLE_QT2 0)
set(USE_DISCORD_PRESENCE 0)
# We are cross compiling, search only the toolchain for libraries and includes
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
@ -388,6 +390,7 @@ if(ENABLE_HEADLESS)
set(USE_X11 0)
set(ENABLE_WX 0)
set(ENABLE_QT2 0)
set(USE_DISCORD_PRESENCE 0)
add_definitions(-DUSE_HEADLESS)
endif()
@ -717,6 +720,11 @@ if(ENABLE_WX)
endif()
endif()
if(USE_DISCORD_PRESENCE)
message(STATUS "Using static DiscordRPC from Externals")
add_subdirectory(Externals/discord-rpc)
endif()
find_package(Libsystemd)
if(SYSTEMD_FOUND)
message(STATUS "libsystemd found, enabling traversal server watchdog support")

View File

@ -3,11 +3,8 @@ project (DiscordRPC)
include(GNUInstallDirs)
option(BUILD_EXAMPLES "Build example apps" ON)
# format
file(GLOB_RECURSE ALL_SOURCE_FILES
examples/*.cpp examples/*.h examples/*.c
include/*.h
src/*.cpp src/*.h src/*.c
)
@ -26,31 +23,6 @@ if (CLANG_FORMAT_CMD)
)
endif(CLANG_FORMAT_CMD)
# thirdparty stuff
execute_process(
COMMAND mkdir ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty
ERROR_QUIET
)
find_file(RAPIDJSONTEST NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty CMAKE_FIND_ROOT_PATH_BOTH)
if (NOT RAPIDJSONTEST)
message("no rapidjson, download")
set(RJ_TAR_FILE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/v1.1.0.tar.gz)
file(DOWNLOAD https://github.com/miloyip/rapidjson/archive/v1.1.0.tar.gz ${RJ_TAR_FILE})
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xzf ${RJ_TAR_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty
)
file(REMOVE ${RJ_TAR_FILE})
endif(NOT RAPIDJSONTEST)
find_file(RAPIDJSON NAMES rapidjson rapidjson-1.1.0 PATHS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty CMAKE_FIND_ROOT_PATH_BOTH)
add_library(rapidjson STATIC IMPORTED ${RAPIDJSON})
# add subdirs
add_subdirectory(src)
if (BUILD_EXAMPLES)
add_subdirectory(examples/send-presence)
endif(BUILD_EXAMPLES)

View File

@ -1,4 +1,4 @@
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/thirdparty/include)
option(ENABLE_IO_THREAD "Start up a separate I/O thread, otherwise I'd need to call an update function" ON)
option(USE_STATIC_CRT "Use /MT[d] for dynamic library" OFF)

View File

@ -29,6 +29,7 @@ add_library(core
Config/MainSettings.cpp
Config/NetplaySettings.cpp
Config/SYSCONFSettings.cpp
Config/UISettings.cpp
ConfigLoaders/BaseConfigLoader.cpp
ConfigLoaders/GameConfigLoader.cpp
ConfigLoaders/IsSettingSaveable.cpp

View File

@ -0,0 +1,14 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included
#include "Core/Config/UISettings.h"
namespace Config
{
// UI.General
const ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE{{System::Main, "General", "UseDiscordPresence"},
true};
} // namespace Config

View File

@ -0,0 +1,21 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include "Common/Config/Config.h"
// This is a temporary soluation, although they should be in their repected cpp file in UICommon.
// However, in order for IsSettingSaveable to commpile without some issues, this needs to be here.
// Once IsSettingSaveable is removed, then you should able to move these back to UICommon.
namespace Config
{
// Configuration Information
// UI.General
extern const ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE;
} // namespace Config

View File

@ -9,7 +9,7 @@
#include "Common/Config/Config.h"
#include "Core/Config/GraphicsSettings.h"
#include "UICommon/DiscordPresence.h"
#include "Core/Config/UISettings.h"
namespace ConfigLoaders
{
@ -116,9 +116,9 @@ bool IsSettingSaveable(const Config::ConfigLocation& config_location)
Config::GFX_PERF_QUERIES_ENABLE.location,
// Main.General
// UI.General
MAIN_USE_DISCORD_PRESENCE.location,
Config::MAIN_USE_DISCORD_PRESENCE.location,
};

View File

@ -48,6 +48,7 @@
<ClCompile Include="Config\GraphicsSettings.cpp" />
<ClCompile Include="Config\MainSettings.cpp" />
<ClCompile Include="Config\NetplaySettings.cpp" />
<ClCompile Include="Config\UISettings.cpp" />
<ClCompile Include="Config\SYSCONFSettings.cpp" />
<ClCompile Include="ConfigLoaders\BaseConfigLoader.cpp" />
<ClCompile Include="ConfigLoaders\GameConfigLoader.cpp" />
@ -316,6 +317,7 @@
<ClInclude Include="ConfigLoaders\MovieConfigLoader.h" />
<ClInclude Include="ConfigLoaders\NetPlayConfigLoader.h" />
<ClInclude Include="ConfigManager.h" />
<ClInclude Include="Config\UISettings.h" />
<ClInclude Include="Core.h" />
<ClInclude Include="CoreTiming.h" />
<ClInclude Include="Debugger\Debugger_SymbolMap.h" />

View File

@ -898,6 +898,9 @@
<ClCompile Include="IOS\Network\NCD\WiiNetConfig.cpp">
<Filter>IOS\Network\NCD</Filter>
</ClCompile>
<ClCompile Include="Config\UISettings.cpp">
<Filter>Config</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="BootManager.h" />
@ -1580,6 +1583,9 @@
<ClInclude Include="HW\WiimoteCommon\WiimoteReport.h">
<Filter>HW %28Flipper/Hollywood%29\WiimoteCommon</Filter>
</ClInclude>
<ClInclude Include="Config\UISettings.h">
<Filter>Config</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />

View File

@ -15,6 +15,10 @@ PRIVATE
cpp-optparse
)
if(USE_DISCORD_PRESENCE)
target_compile_definitions(dolphin-nogui PRIVATE -DUSE_DISCORD_PRESENCE)
endif()
set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} dolphin-nogui)
install(TARGETS dolphin-nogui RUNTIME DESTINATION ${bindir})

View File

@ -28,6 +28,9 @@
#include "Core/State.h"
#include "UICommon/CommandLineParse.h"
#ifdef USE_DISCORD_PRESENCE
#include "UICommon/DiscordPresence.h"
#endif
#include "UICommon/UICommon.h"
#include "VideoCommon/RenderBase.h"
@ -440,6 +443,10 @@ int main(int argc, char* argv[])
return 1;
}
#ifdef USE_DISCORD_PRESENCE
Discord::UpdateDiscordPresence();
#endif
while (!Core::IsRunning() && s_running.IsSet())
{
Core::HostDispatchJobs();

View File

@ -218,3 +218,7 @@ if(APPLE)
else()
install(TARGETS dolphin-emu RUNTIME DESTINATION ${bindir})
endif()
if(USE_DISCORD_PRESENCE)
target_compile_definitions(dolphin-emu PRIVATE -DUSE_DISCORD_PRESENCE)
endif()

View File

@ -19,10 +19,6 @@
#include "DolphinQt2/Settings.h"
#include "InputCommon/InputConfig.h"
#ifdef USE_DISCORD_PRESENCE
#include "UICommon/DiscordPresence.h"
#endif
Settings::Settings()
{
qRegisterMetaType<Core::State>();

View File

@ -19,6 +19,7 @@
#include <QWidget>
#include "Core/Analytics.h"
#include "Core/Config/UISettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/PowerPC/PowerPC.h"
@ -227,7 +228,7 @@ void GeneralPane::LoadConfig()
m_checkbox_dualcore->setChecked(SConfig::GetInstance().bCPUThread);
m_checkbox_cheats->setChecked(Settings::Instance().GetCheatsEnabled());
#ifdef USE_DISCORD_PRESENCE
m_checkbox_discord_presence->setChecked(Config::Get(MAIN_USE_DISCORD_PRESENCE));
m_checkbox_discord_presence->setChecked(Config::Get(Config::MAIN_USE_DISCORD_PRESENCE));
#endif
int selection = qRound(SConfig::GetInstance().m_EmulationSpeed * 10);
if (selection < m_combobox_speedlimit->count())

View File

@ -187,4 +187,8 @@ else()
install(TARGETS dolphin-emu-wx RUNTIME DESTINATION ${bindir})
endif()
if(USE_DISCORD_PRESENCE)
target_compile_definitions(dolphin-emu-wx PRIVATE -DUSE_DISCORD_PRESENCE)
endif()
set(CPACK_PACKAGE_EXECUTABLES ${CPACK_PACKAGE_EXECUTABLES} dolphin-emu-wx)

View File

@ -20,6 +20,7 @@
#include "Common/Common.h"
#include "Core/Analytics.h"
#include "Core/Config/UISettings.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
#include "Core/PowerPC/PowerPC.h"
@ -161,7 +162,7 @@ void GeneralConfigPane::LoadGUIValues()
m_cheats_checkbox->SetValue(startup_params.bEnableCheats);
#ifdef USE_DISCORD_PRESENCE
m_discord_presence_checkbox->SetValue(Config::Get(MAIN_USE_DISCORD_PRESENCE));
m_discord_presence_checkbox->SetValue(Config::Get(Config::MAIN_USE_DISCORD_PRESENCE));
#endif
#if defined(USE_ANALYTICS) && USE_ANALYTICS

View File

@ -37,3 +37,8 @@ if(ENABLE_LLVM)
target_include_directories(uicommon PRIVATE ${LLVM_INCLUDE_DIRS})
endif()
endif()
if(USE_DISCORD_PRESENCE)
target_compile_definitions(uicommon PRIVATE -DUSE_DISCORD_PRESENCE)
target_link_libraries(uicommon PRIVATE discord-rpc)
endif()

View File

@ -2,31 +2,28 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
#ifdef USE_DISCORD_PRESENCE
#include "UICommon/DiscordPresence.h"
#include "Core/Config/UISettings.h"
#include "Core/ConfigManager.h"
#ifdef USE_DISCORD_PRESENCE
#include <ctime>
#include <discord-rpc/include/discord_rpc.h>
#include "Core/ConfigManager.h"
#endif
const Config::ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE{
{Config::System::Main, "General", "UseDiscordPresence"}, true};
namespace Discord
{
void Init()
{
#ifdef USE_DISCORD_PRESENCE
if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
DiscordEventHandlers handlers = {};
// The number is the client ID for Dolphin, it's used for images and the appication name
Discord_Initialize("450033159212630028", &handlers, 1, nullptr);
Discord_Initialize("455712169795780630", &handlers, 1, nullptr);
UpdateDiscordPresence();
#endif
}
@ -34,7 +31,7 @@ void Init()
void UpdateDiscordPresence()
{
#ifdef USE_DISCORD_PRESENCE
if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
const std::string& title = SConfig::GetInstance().GetTitleDescription();
@ -51,7 +48,7 @@ void UpdateDiscordPresence()
void Shutdown()
{
#ifdef USE_DISCORD_PRESENCE
if (!Config::Get(MAIN_USE_DISCORD_PRESENCE))
if (!Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
return;
Discord_ClearPresence();
@ -61,15 +58,15 @@ void Shutdown()
void SetDiscordPresenceEnabled(bool enabled)
{
if (Config::Get(MAIN_USE_DISCORD_PRESENCE) == enabled)
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE) == enabled)
return;
if (Config::Get(MAIN_USE_DISCORD_PRESENCE))
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
Discord::Shutdown();
Config::SetBase(MAIN_USE_DISCORD_PRESENCE, enabled);
Config::SetBase(Config::MAIN_USE_DISCORD_PRESENCE, enabled);
if (Config::Get(MAIN_USE_DISCORD_PRESENCE))
if (Config::Get(Config::MAIN_USE_DISCORD_PRESENCE))
Discord::Init();
}

View File

@ -4,8 +4,6 @@
#pragma once
#include "Common/Config/Config.h"
namespace Discord
{
void Init();
@ -13,5 +11,3 @@ void UpdateDiscordPresence();
void Shutdown();
void SetDiscordPresenceEnabled(bool enabled);
} // namespace Discord
extern const Config::ConfigInfo<bool> MAIN_USE_DISCORD_PRESENCE;