From eddaf9793834dfba80605a04e0455fef93fb21af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Aug 2018 00:05:00 +0200 Subject: [PATCH 1/5] Add submodules, namespace json to prepare for the addition of rapidjson (sigh) --- .gitmodules | 6 ++++++ Core/Config.cpp | 4 ++-- Core/Debugger/WebSocket/WebSocketUtils.h | 2 ++ UI/RemoteISOScreen.cpp | 2 ++ UI/Store.cpp | 5 +++-- UI/Store.h | 7 +++++-- ext/discord-rpc | 1 + ext/native/json/json_reader.cpp | 4 ++++ ext/native/json/json_reader.h | 5 +++++ ext/native/json/json_writer.cpp | 5 +++++ ext/native/json/json_writer.h | 7 ++++++- ext/rapidjson | 1 + 12 files changed, 42 insertions(+), 7 deletions(-) create mode 160000 ext/discord-rpc create mode 160000 ext/rapidjson diff --git a/.gitmodules b/.gitmodules index 57a0d7933e..d39e459a44 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,9 @@ [submodule "ext/SPIRV-Cross"] path = ext/SPIRV-Cross url = https://github.com/KhronosGroup/SPIRV-Cross.git +[submodule "ext/discord-rpc"] + path = ext/discord-rpc + url = https://github.com/discordapp/discord-rpc.git +[submodule "ext/rapidjson"] + path = ext/rapidjson + url = https://github.com/Tencent/rapidjson.git diff --git a/Core/Config.cpp b/Core/Config.cpp index e7c22fe0ad..6b16d7cb3f 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -1162,8 +1162,8 @@ void Config::DownloadCompletedCallback(http::Download &download) { return; } - JsonReader reader(data.c_str(), data.size()); - const JsonGet root = reader.root(); + json::JsonReader reader(data.c_str(), data.size()); + const json::JsonGet root = reader.root(); if (!root) { ERROR_LOG(LOADER, "Failed to parse json"); return; diff --git a/Core/Debugger/WebSocket/WebSocketUtils.h b/Core/Debugger/WebSocket/WebSocketUtils.h index e49647dcf8..70c08828b2 100644 --- a/Core/Debugger/WebSocket/WebSocketUtils.h +++ b/Core/Debugger/WebSocket/WebSocketUtils.h @@ -24,6 +24,8 @@ #include "net/websocket_server.h" #include "Common/Log.h" +using namespace json; + static inline void DebuggerJsonAddTicket(JsonWriter &writer, const JsonGet &data) { const JsonNode *value = data.get("ticket"); if (value) diff --git a/UI/RemoteISOScreen.cpp b/UI/RemoteISOScreen.cpp index 31d8f9f966..7e4238b96c 100644 --- a/UI/RemoteISOScreen.cpp +++ b/UI/RemoteISOScreen.cpp @@ -82,6 +82,8 @@ static bool FindServer(std::string &resultHost, int &resultPort) { std::string json; result.TakeAll(&json); + using namespace json; + JsonReader reader(json.c_str(), json.size()); if (!reader.ok()) { return false; diff --git a/UI/Store.cpp b/UI/Store.cpp index da2d2f1a4f..58e780dbda 100644 --- a/UI/Store.cpp +++ b/UI/Store.cpp @@ -391,6 +391,7 @@ void StoreScreen::update() { } void StoreScreen::ParseListing(std::string json) { + using namespace json; JsonReader reader(json.c_str(), json.size()); if (!reader.ok() || !reader.root()) { ELOG("Error parsing JSON from store"); @@ -540,8 +541,8 @@ std::string StoreScreen::GetStoreJsonURL(std::string storePath) const { return path; } -std::string StoreScreen::GetTranslatedString(const JsonGet json, std::string key, const char *fallback) const { - JsonGet dict = json.getDict("en_US"); +std::string StoreScreen::GetTranslatedString(const json::JsonGet json, std::string key, const char *fallback) const { + json::JsonGet dict = json.getDict("en_US"); if (dict && json.hasChild(lang_.c_str(), JSON_OBJECT)) { if (json.getDict(lang_.c_str()).hasChild(key.c_str(), JSON_STRING)) { dict = json.getDict(lang_.c_str()); diff --git a/UI/Store.h b/UI/Store.h index e7786c7c9c..c935bcb042 100644 --- a/UI/Store.h +++ b/UI/Store.h @@ -29,7 +29,10 @@ // set game specific settings, etc. // Uses GameInfoCache heavily to implement the functionality. -struct JsonGet; +namespace json { + struct JsonGet; +} + class ProductItemView; enum EntryType { @@ -79,7 +82,7 @@ private: std::vector FilterEntries(); std::string GetStoreJsonURL(std::string storePath) const; - std::string GetTranslatedString(const JsonGet json, std::string key, const char *fallback = nullptr) const; + std::string GetTranslatedString(const json::JsonGet json, std::string key, const char *fallback = nullptr) const; std::shared_ptr listing_; std::shared_ptr image_; diff --git a/ext/discord-rpc b/ext/discord-rpc new file mode 160000 index 0000000000..3d3ae7129d --- /dev/null +++ b/ext/discord-rpc @@ -0,0 +1 @@ +Subproject commit 3d3ae7129d17643bc706da0a2eea85aafd10ab3a diff --git a/ext/native/json/json_reader.cpp b/ext/native/json/json_reader.cpp index 83fbe94fa4..eaf9d0ae08 100644 --- a/ext/native/json/json_reader.cpp +++ b/ext/native/json/json_reader.cpp @@ -2,6 +2,8 @@ #include "file/vfs.h" #include "json/json_reader.h" +namespace json { + JsonReader::JsonReader(const std::string &filename) { size_t buf_size; buffer_ = (char *)VFSReadFile(filename.c_str(), &buf_size); @@ -117,3 +119,5 @@ bool JsonGet::getBool(const char *child_name, bool default_value) const { } return default_value; } + +} // namespace json diff --git a/ext/native/json/json_reader.h b/ext/native/json/json_reader.h index b9e8de5e53..a18915f488 100644 --- a/ext/native/json/json_reader.h +++ b/ext/native/json/json_reader.h @@ -1,9 +1,12 @@ #include #include + #include "base/basictypes.h" #include "base/logging.h" #include "ext/gason/gason.h" +namespace json { + struct JsonGet { JsonGet(const JsonValue &value) : value_(value) { } @@ -83,3 +86,5 @@ private: DISALLOW_COPY_AND_ASSIGN(JsonReader); }; + +} // namespace json diff --git a/ext/native/json/json_writer.cpp b/ext/native/json/json_writer.cpp index 7d1c47a620..7440cf731d 100644 --- a/ext/native/json/json_writer.cpp +++ b/ext/native/json/json_writer.cpp @@ -1,9 +1,12 @@ #include #include #include + #include "json/json_reader.h" #include "json/json_writer.h" +namespace json { + JsonWriter::JsonWriter(int flags) { pretty_ = (flags & PRETTY) != 0; str_.imbue(std::locale::classic()); @@ -383,3 +386,5 @@ static void json_stringify_array(JsonWriter &writer, const JsonNode *node) { break; } } + +} // namespace json diff --git a/ext/native/json/json_writer.h b/ext/native/json/json_writer.h index 22c712c856..d82b7151cf 100644 --- a/ext/native/json/json_writer.h +++ b/ext/native/json/json_writer.h @@ -13,6 +13,10 @@ #include #include +struct JsonNode; + +namespace json { + class JsonWriter { public: JsonWriter(int flags = NORMAL); @@ -79,5 +83,6 @@ private: bool pretty_; }; -struct JsonNode; std::string json_stringify(const JsonNode *json); + +} // namespace json diff --git a/ext/rapidjson b/ext/rapidjson new file mode 160000 index 0000000000..73063f5002 --- /dev/null +++ b/ext/rapidjson @@ -0,0 +1 @@ +Subproject commit 73063f5002612c6bf64fe24f851cd5cc0d83eef9 From 785858dbf8238173bfb8d33f74b1fbb85120ae0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Aug 2018 00:08:56 +0200 Subject: [PATCH 2/5] Basic Discord presence integration. --- Core/Config.cpp | 1 + Core/Config.h | 2 + UI/DiscordIntegration.cpp | 114 ++++++++++++ UI/DiscordIntegration.h | 28 +++ UI/EmuScreen.cpp | 6 + UI/GameSettingsScreen.cpp | 1 + UI/NativeApp.cpp | 7 + UI/UI.vcxproj | 10 +- UI/UI.vcxproj.filters | 2 + Windows/MainWindow.cpp | 2 +- Windows/PPSSPP.sln | 19 +- ext/discord-rpc-build/discord-rpc.vcxproj | 176 ++++++++++++++++++ .../discord-rpc.vcxproj.filters | 23 +++ 13 files changed, 385 insertions(+), 6 deletions(-) create mode 100644 UI/DiscordIntegration.cpp create mode 100644 UI/DiscordIntegration.h create mode 100644 ext/discord-rpc-build/discord-rpc.vcxproj create mode 100644 ext/discord-rpc-build/discord-rpc.vcxproj.filters diff --git a/Core/Config.cpp b/Core/Config.cpp index 6b16d7cb3f..5d10bfadb9 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -396,6 +396,7 @@ static ConfigSetting generalSettings[] = { ConfigSetting("CheckForNewVersion", &g_Config.bCheckForNewVersion, true), ConfigSetting("Language", &g_Config.sLanguageIni, &DefaultLangRegion), ConfigSetting("ForceLagSync", &g_Config.bForceLagSync, false, true, true), + ConfigSetting("DiscordPresence", &g_Config.bDiscordPresence, true, true, false), // Or maybe it makes sense to have it per-game? Race conditions abound... ReportedConfigSetting("NumWorkerThreads", &g_Config.iNumWorkerThreads, &DefaultNumWorkers, true, true), ConfigSetting("AutoLoadSaveState", &g_Config.iAutoLoadSaveState, 0, true, true), diff --git a/Core/Config.h b/Core/Config.h index d39957e7fb..110eae6052 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -117,6 +117,8 @@ public: std::vector vPinnedPaths; std::string sLanguageIni; + bool bDiscordPresence; // Enables setting the Discord presence to the current game (or menu) + // GFX int iGPUBackend; // We have separate device parameters for each backend so it doesn't get erased if you switch backends. diff --git a/UI/DiscordIntegration.cpp b/UI/DiscordIntegration.cpp new file mode 100644 index 0000000000..0f7d4e6544 --- /dev/null +++ b/UI/DiscordIntegration.cpp @@ -0,0 +1,114 @@ +#include +#include + +#include "ppsspp_config.h" +#include "Common/Log.h" +#include "Core/Config.h" +#include "DiscordIntegration.h" + +#include "ext/discord-rpc/include/discord_rpc.h" + +// TODO: Enable on more platforms. Make optional. + +#ifdef _WIN32 + +const bool g_DiscordEnabled = true; + +#else + +const bool g_DiscordEnabled = true; + +#endif + + +Discord g_Discord; + +static const char *ppsspp_app_id = "423397985041383434"; + +// No context argument? What? +static void handleDiscordError(int errCode, const char *message) { + ERROR_LOG(SYSTEM, "Discord error code %d: '%s'", message); +} + +Discord::~Discord() { + assert(!initialized_); +} + +bool Discord::IsEnabled() const { + return g_DiscordEnabled && g_Config.bDiscordPresence; +} + +void Discord::Init() { + assert(IsEnabled()); + assert(!initialized_); + + DiscordEventHandlers eventHandlers{}; + eventHandlers.errored = &handleDiscordError; + Discord_Initialize(ppsspp_app_id, &eventHandlers, 0, nullptr); + + initialized_ = true; +} + +void Discord::Shutdown() { + assert(initialized_); + Discord_Shutdown(); + initialized_ = false; +} + +void Discord::Update() { + if (!IsEnabled()) { + if (initialized_) { + Shutdown(); + } + return; + } else { + if (!initialized_) { + Init(); + } + } + +#ifdef DISCORD_DISABLE_IO_THREAD + Discord_UpdateConnection(); +#endif + Discord_RunCallbacks(); +} + +void Discord::SetPresenceGame(const char *gameTitle) { + if (!IsEnabled()) + return; + + if (!initialized_) { + Init(); + } + + DiscordRichPresence discordPresence{}; + discordPresence.state = gameTitle; + discordPresence.details = "Playing"; + discordPresence.startTimestamp = time(0); +#ifdef GOLD + discordPresence.largeImageKey = "icon_gold_png"; +#else + discordPresence.largeImageKey = "icon_regular_png"; +#endif + Discord_UpdatePresence(&discordPresence); +} + +void Discord::SetPresenceMenu() { + if (!IsEnabled()) + return; + + if (!initialized_) { + Init(); + } + + DiscordRichPresence discordPresence{}; + discordPresence.state = "In menu"; + discordPresence.details = ""; + discordPresence.startTimestamp = time(0); +#ifdef GOLD + discordPresence.largeImageKey = "icon_gold_png"; +#else + discordPresence.largeImageKey = "icon_regular_png"; +#endif + Discord_UpdatePresence(&discordPresence); +} diff --git a/UI/DiscordIntegration.h b/UI/DiscordIntegration.h new file mode 100644 index 0000000000..cd700d59ea --- /dev/null +++ b/UI/DiscordIntegration.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +// Simple wrapper around the Discord api. + +// All platforms should call it, but we only actually take action on +// platforms where we want it enabled (only PC initially). + +// All you need to call is FrameCallback, Shutdown, and UpdatePresence. + +class Discord { +public: + ~Discord(); + void Update(); // Call every frame or at least regularly. Will initialize if necessary. + void Shutdown(); + + void SetPresenceGame(const char *gameTitle); + void SetPresenceMenu(); + +private: + void Init(); + bool IsEnabled() const; + + bool initialized_ = false; +}; + +extern Discord g_Discord; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index b4e761e980..391216dd73 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -77,6 +77,7 @@ #include "UI/GameSettingsScreen.h" #include "UI/InstallZipScreen.h" #include "UI/ProfilerDraw.h" +#include "UI/DiscordIntegration.h" #if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) #include "Windows/MainWindow.h" @@ -192,6 +193,10 @@ void EmuScreen::bootGame(const std::string &filename) { g_Config.loadGameConfig(info->id); // Reset views in case controls are in a different place. RecreateViews(); + + g_Discord.SetPresenceGame(info->GetTitle().c_str()); + } else { + g_Discord.SetPresenceGame("(unknown)"); } invalid_ = true; @@ -333,6 +338,7 @@ EmuScreen::~EmuScreen() { startDumping = false; } #endif + g_Discord.SetPresenceMenu(); } void EmuScreen::dialogFinished(const Screen *dialog, DialogResult result) { diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 8ccec4b5e7..5e289b6151 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -642,6 +642,7 @@ void GameSettingsScreen::CreateViews() { networkingSettings->Add(new Choice(n->T("Adhoc Multiplayer forum")))->OnClick.Handle(this, &GameSettingsScreen::OnAdhocGuides); networkingSettings->Add(new CheckBox(&g_Config.bEnableWlan, n->T("Enable networking", "Enable networking/wlan (beta)"))); + networkingSettings->Add(new CheckBox(&g_Config.bDiscordPresence, n->T("Send Discord Presence information"))); #if !defined(MOBILE_DEVICE) && !defined(USING_QT_UI) networkingSettings->Add(new PopupTextInputChoice(&g_Config.proAdhocServer, n->T("Change proAdhocServer Address"), "", 255, screenManager())); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index bd9c3937ee..10850b33df 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -98,6 +98,7 @@ #include "UI/TiltEventProcessor.h" #include "UI/BackgroundAudio.h" #include "UI/TextureUtil.h" +#include "UI/DiscordIntegration.h" #if !defined(MOBILE_DEVICE) #include "Common/KeyMap.h" @@ -352,6 +353,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch InitFastMath(cpu_info.bNEON); SetupAudioFormats(); + g_Discord.SetPresenceMenu(); + // Make sure UI state is MENU. ResetUIState(); @@ -1028,6 +1031,8 @@ void NativeUpdate() { g_DownloadManager.Update(); screenManager->update(); + + g_Discord.Update(); } bool NativeIsAtTopLevel() { @@ -1213,6 +1218,8 @@ void NativeShutdown() { net::Shutdown(); + g_Discord.Shutdown(); + delete logger; logger = nullptr; diff --git a/UI/UI.vcxproj b/UI/UI.vcxproj index 06f979c86b..905c9d9384 100644 --- a/UI/UI.vcxproj +++ b/UI/UI.vcxproj @@ -24,6 +24,7 @@ + @@ -54,6 +55,7 @@ + @@ -80,11 +82,17 @@ + + + {beb0a821-3c7f-410f-a525-63afbc69bf8f} + + {004B8D11-2BE3-4BD9-AB40-2BE04CF2096F} Win32Proj UI - + + diff --git a/UI/UI.vcxproj.filters b/UI/UI.vcxproj.filters index 8332d11762..0b5c2dd240 100644 --- a/UI/UI.vcxproj.filters +++ b/UI/UI.vcxproj.filters @@ -70,6 +70,7 @@ Screens + @@ -141,6 +142,7 @@ Screens + diff --git a/Windows/MainWindow.cpp b/Windows/MainWindow.cpp index 83b5286771..848b8cb5fa 100644 --- a/Windows/MainWindow.cpp +++ b/Windows/MainWindow.cpp @@ -913,7 +913,7 @@ namespace MainWindow InputDevice::StopPolling(); MainThread_Stop(); coreState = CORE_POWERUP; - ResetUIState(); + UpdateUIState(UISTATE_MENU); MainThread_Start(g_Config.iGPUBackend == (int)GPUBackend::OPENGL); InputDevice::BeginPolling(); break; diff --git a/Windows/PPSSPP.sln b/Windows/PPSSPP.sln index 13abef5350..4d4cdc49e7 100644 --- a/Windows/PPSSPP.sln +++ b/Windows/PPSSPP.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 +# Visual Studio 15 +VisualStudioVersion = 15.0.27703.2026 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PPSSPPWindows", "PPSSPP.vcxproj", "{567AF8DB-42C1-4D08-96CD-D70A2DFEFC6B}" ProjectSection(ProjectDependencies) = postProject @@ -77,6 +77,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "glslang", "..\ext\glslang.v EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SPIRV-Cross", "..\ext\SPIRV-Cross.vcxproj", "{4328A62C-F1E9-47ED-B816-A1A81DAF4363}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "discord-rpc", "..\ext\discord-rpc-build\discord-rpc.vcxproj", "{BEB0A821-3C7F-410F-A525-63AFBC69BF8F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -105,7 +107,6 @@ Global {F761046E-6C38-4428-A5F1-38391A37BB34}.Debug|Win32.Build.0 = Debug|Win32 {F761046E-6C38-4428-A5F1-38391A37BB34}.Debug|x64.ActiveCfg = Debug|x64 {F761046E-6C38-4428-A5F1-38391A37BB34}.Debug|x64.Build.0 = Debug|x64 - {F761046E-6C38-4428-A5F1-38391A37BB34}.Release|ARM.ActiveCfg = Release|Win32 {F761046E-6C38-4428-A5F1-38391A37BB34}.Release|Win32.ActiveCfg = Release|Win32 {F761046E-6C38-4428-A5F1-38391A37BB34}.Release|Win32.Build.0 = Release|Win32 {F761046E-6C38-4428-A5F1-38391A37BB34}.Release|x64.ActiveCfg = Release|x64 @@ -114,7 +115,6 @@ Global {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Debug|Win32.Build.0 = Debug|Win32 {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Debug|x64.ActiveCfg = Debug|x64 {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Debug|x64.Build.0 = Debug|x64 - {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Release|ARM.ActiveCfg = Release|Win32 {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Release|Win32.ActiveCfg = Release|Win32 {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Release|Win32.Build.0 = Release|Win32 {457F45D2-556F-47BC-A31D-AFF0D15BEAED}.Release|x64.ActiveCfg = Release|x64 @@ -191,8 +191,19 @@ Global {4328A62C-F1E9-47ED-B816-A1A81DAF4363}.Release|Win32.Build.0 = Release|Win32 {4328A62C-F1E9-47ED-B816-A1A81DAF4363}.Release|x64.ActiveCfg = Release|x64 {4328A62C-F1E9-47ED-B816-A1A81DAF4363}.Release|x64.Build.0 = Release|x64 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Debug|Win32.ActiveCfg = Debug|Win32 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Debug|Win32.Build.0 = Debug|Win32 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Debug|x64.ActiveCfg = Debug|x64 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Debug|x64.Build.0 = Debug|x64 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Release|Win32.ActiveCfg = Release|Win32 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Release|Win32.Build.0 = Release|Win32 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Release|x64.ActiveCfg = Release|x64 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {2FD47774-A031-48F4-B645-A49A3140A29B} + EndGlobalSection EndGlobal diff --git a/ext/discord-rpc-build/discord-rpc.vcxproj b/ext/discord-rpc-build/discord-rpc.vcxproj new file mode 100644 index 0000000000..d7ca25ed8b --- /dev/null +++ b/ext/discord-rpc-build/discord-rpc.vcxproj @@ -0,0 +1,176 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {BEB0A821-3C7F-410F-A525-63AFBC69BF8F} + Win32Proj + discordrpc + 10.0.17134.0 + + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + StaticLibrary + true + v141 + Unicode + + + StaticLibrary + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + false + + + true + + + true + + + false + + + + Level3 + MaxSpeed + true + true + true + NDEBUG;_LIB;%(PreprocessorDefinitions) + true + ..\discord-rpc\include;..\discord-rpc\src;..\rapidjson\include + MultiThreaded + + + Windows + true + true + true + + + + + Level3 + Disabled + true + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + ..\discord-rpc\include;..\discord-rpc\src;..\rapidjson\include + MultiThreadedDebug + + + Windows + true + + + + + Level3 + Disabled + true + _DEBUG;_LIB;%(PreprocessorDefinitions) + true + ..\discord-rpc\include;..\discord-rpc\src;..\rapidjson\include + MultiThreadedDebug + + + Windows + true + + + + + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + ..\discord-rpc\include;..\discord-rpc\src;..\rapidjson\include + MultiThreaded + + + Windows + true + true + true + + + + + + \ No newline at end of file diff --git a/ext/discord-rpc-build/discord-rpc.vcxproj.filters b/ext/discord-rpc-build/discord-rpc.vcxproj.filters new file mode 100644 index 0000000000..ac36b4d139 --- /dev/null +++ b/ext/discord-rpc-build/discord-rpc.vcxproj.filters @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 9c22f6ed55fabf299523c1a62989f55427ebd019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Aug 2018 00:25:08 +0200 Subject: [PATCH 3/5] Don't forget to update the other build systems and try to fix the builds. --- CMakeLists.txt | 1 + UI/DiscordIntegration.cpp | 26 +++++++++++++++++++------- UWP/UI_UWP/UI_UWP.vcxproj | 4 +++- UWP/UI_UWP/UI_UWP.vcxproj.filters | 4 +++- android/jni/Android.mk | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bffaa11320..2e34d5fe76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -822,6 +822,7 @@ endif() list(APPEND NativeAppSource android/jni/TestRunner.cpp + UI/DiscordIntegration.cpp UI/NativeApp.cpp UI/BackgroundAudio.cpp UI/DevScreens.cpp diff --git a/UI/DiscordIntegration.cpp b/UI/DiscordIntegration.cpp index 0f7d4e6544..c57a9a6df9 100644 --- a/UI/DiscordIntegration.cpp +++ b/UI/DiscordIntegration.cpp @@ -6,21 +6,23 @@ #include "Core/Config.h" #include "DiscordIntegration.h" -#include "ext/discord-rpc/include/discord_rpc.h" - -// TODO: Enable on more platforms. Make optional. #ifdef _WIN32 -const bool g_DiscordEnabled = true; +#define ENABLE_DISCORD #else -const bool g_DiscordEnabled = true; - #endif + +#ifdef ENABLE_DISCORD +#include "ext/discord-rpc/include/discord_rpc.h" +#endif + +// TODO: Enable on more platforms. Make optional. + Discord g_Discord; static const char *ppsspp_app_id = "423397985041383434"; @@ -35,23 +37,27 @@ Discord::~Discord() { } bool Discord::IsEnabled() const { - return g_DiscordEnabled && g_Config.bDiscordPresence; + return g_Config.bDiscordPresence; } void Discord::Init() { assert(IsEnabled()); assert(!initialized_); +#ifdef ENABLE_DISCORD DiscordEventHandlers eventHandlers{}; eventHandlers.errored = &handleDiscordError; Discord_Initialize(ppsspp_app_id, &eventHandlers, 0, nullptr); +#endif initialized_ = true; } void Discord::Shutdown() { assert(initialized_); +#ifdef ENABLE_DISCORD Discord_Shutdown(); +#endif initialized_ = false; } @@ -67,10 +73,12 @@ void Discord::Update() { } } +#ifdef ENABLE_DISCORD #ifdef DISCORD_DISABLE_IO_THREAD Discord_UpdateConnection(); #endif Discord_RunCallbacks(); +#endif } void Discord::SetPresenceGame(const char *gameTitle) { @@ -81,6 +89,7 @@ void Discord::SetPresenceGame(const char *gameTitle) { Init(); } +#ifdef ENABLE_DISCORD DiscordRichPresence discordPresence{}; discordPresence.state = gameTitle; discordPresence.details = "Playing"; @@ -91,6 +100,7 @@ void Discord::SetPresenceGame(const char *gameTitle) { discordPresence.largeImageKey = "icon_regular_png"; #endif Discord_UpdatePresence(&discordPresence); +#endif } void Discord::SetPresenceMenu() { @@ -101,6 +111,7 @@ void Discord::SetPresenceMenu() { Init(); } +#ifdef ENABLE_DISCORD DiscordRichPresence discordPresence{}; discordPresence.state = "In menu"; discordPresence.details = ""; @@ -111,4 +122,5 @@ void Discord::SetPresenceMenu() { discordPresence.largeImageKey = "icon_regular_png"; #endif Discord_UpdatePresence(&discordPresence); +#endif } diff --git a/UWP/UI_UWP/UI_UWP.vcxproj b/UWP/UI_UWP/UI_UWP.vcxproj index 7fda5b55f9..3b54be0228 100644 --- a/UWP/UI_UWP/UI_UWP.vcxproj +++ b/UWP/UI_UWP/UI_UWP.vcxproj @@ -304,6 +304,7 @@ + @@ -337,6 +338,7 @@ + @@ -376,4 +378,4 @@ - \ No newline at end of file + diff --git a/UWP/UI_UWP/UI_UWP.vcxproj.filters b/UWP/UI_UWP/UI_UWP.vcxproj.filters index 2dda8c4b86..b3ee44e3c8 100644 --- a/UWP/UI_UWP/UI_UWP.vcxproj.filters +++ b/UWP/UI_UWP/UI_UWP.vcxproj.filters @@ -7,6 +7,7 @@ + @@ -40,6 +41,7 @@ + @@ -65,4 +67,4 @@ - \ No newline at end of file + diff --git a/android/jni/Android.mk b/android/jni/Android.mk index 2b837a0ef2..b6a7c18f53 100644 --- a/android/jni/Android.mk +++ b/android/jni/Android.mk @@ -485,6 +485,7 @@ LOCAL_SRC_FILES := \ $(SRC)/android/jni/native_audio.cpp \ $(SRC)/android/jni/native-audio-so.cpp \ $(SRC)/UI/BackgroundAudio.cpp \ + $(SRC)/UI/DiscordIntegration.cpp \ $(SRC)/UI/DevScreens.cpp \ $(SRC)/UI/DisplayLayoutEditor.cpp \ $(SRC)/UI/DisplayLayoutScreen.cpp \ From 35e1d0c84147881c3baf5831b0462bd7d604f265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Aug 2018 20:14:34 +0200 Subject: [PATCH 4/5] Discord: Translated some messages --- UI/DiscordIntegration.cpp | 15 ++++++++++----- UI/EmuScreen.cpp | 4 +++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/UI/DiscordIntegration.cpp b/UI/DiscordIntegration.cpp index c57a9a6df9..cc5b21b0cb 100644 --- a/UI/DiscordIntegration.cpp +++ b/UI/DiscordIntegration.cpp @@ -5,7 +5,7 @@ #include "Common/Log.h" #include "Core/Config.h" #include "DiscordIntegration.h" - +#include "i18n/i18n.h" #ifdef _WIN32 @@ -13,10 +13,10 @@ #else +// TODO + #endif - - #ifdef ENABLE_DISCORD #include "ext/discord-rpc/include/discord_rpc.h" #endif @@ -90,9 +90,12 @@ void Discord::SetPresenceGame(const char *gameTitle) { } #ifdef ENABLE_DISCORD + I18NCategory *sc = GetI18NCategory("Screen"); + DiscordRichPresence discordPresence{}; discordPresence.state = gameTitle; - discordPresence.details = "Playing"; + std::string details = sc->T("Playing"); + discordPresence.details = details.c_str(); discordPresence.startTimestamp = time(0); #ifdef GOLD discordPresence.largeImageKey = "icon_gold_png"; @@ -112,8 +115,10 @@ void Discord::SetPresenceMenu() { } #ifdef ENABLE_DISCORD + I18NCategory *sc = GetI18NCategory("Screen"); + DiscordRichPresence discordPresence{}; - discordPresence.state = "In menu"; + discordPresence.state = sc->T("In menu"); discordPresence.details = ""; discordPresence.startTimestamp = time(0); #ifdef GOLD diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 391216dd73..e34a8e10c7 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -187,6 +187,8 @@ void EmuScreen::bootGame(const std::string &filename) { if (!bootAllowStorage(filename)) return; + I18NCategory *sc = GetI18NCategory("Screen"); + //pre-emptive loading of game specific config if possible, to get all the settings std::shared_ptr info = g_gameInfoCache->GetInfo(nullptr, filename, 0); if (info && !info->id.empty()) { @@ -196,7 +198,7 @@ void EmuScreen::bootGame(const std::string &filename) { g_Discord.SetPresenceGame(info->GetTitle().c_str()); } else { - g_Discord.SetPresenceGame("(unknown)"); + g_Discord.SetPresenceGame(sc->T("Untitled PSP game")); } invalid_ = true; From c0ba66cf3c9aeafad2bf902772d13007bf2e9fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 13 Aug 2018 23:08:46 +0200 Subject: [PATCH 5/5] Revert some of the sln and vcxproj changes, hoping to appease Travis --- Windows/PPSSPP.sln | 4 ++-- ext/discord-rpc-build/discord-rpc.vcxproj | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Windows/PPSSPP.sln b/Windows/PPSSPP.sln index 4d4cdc49e7..918e2910d6 100644 --- a/Windows/PPSSPP.sln +++ b/Windows/PPSSPP.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.27703.2026 +# Visual Studio 14 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PPSSPPWindows", "PPSSPP.vcxproj", "{567AF8DB-42C1-4D08-96CD-D70A2DFEFC6B}" ProjectSection(ProjectDependencies) = postProject diff --git a/ext/discord-rpc-build/discord-rpc.vcxproj b/ext/discord-rpc-build/discord-rpc.vcxproj index d7ca25ed8b..52c18de82b 100644 --- a/ext/discord-rpc-build/discord-rpc.vcxproj +++ b/ext/discord-rpc-build/discord-rpc.vcxproj @@ -1,5 +1,5 @@ - + Debug @@ -39,7 +39,6 @@ - 15.0 {BEB0A821-3C7F-410F-A525-63AFBC69BF8F} Win32Proj discordrpc @@ -49,26 +48,26 @@ StaticLibrary true - v141 + $(DefaultPlatformToolset)_xp Unicode StaticLibrary false - v141 + $(DefaultPlatformToolset)_xp true Unicode StaticLibrary true - v141 + $(DefaultPlatformToolset)_xp Unicode StaticLibrary false - v141 + $(DefaultPlatformToolset)_xp true Unicode @@ -173,4 +172,4 @@ - \ No newline at end of file +