Permalink
Browse files

Basic Discord presence integration.

  • Loading branch information...
hrydgard committed Aug 12, 2018
1 parent eddaf97 commit 785858dbf8238173bfb8d33f74b1fbb85120ae0a
View
@@ -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),
View
@@ -117,6 +117,8 @@ struct Config {
std::vector<std::string> 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.
View
@@ -0,0 +1,114 @@
#include <ctime>
#include <cassert>
#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);
}
View
@@ -0,0 +1,28 @@
#pragma once
#include <string>
// 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;
View
@@ -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) {
@@ -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()));
View
@@ -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;
View
@@ -24,6 +24,7 @@
<ClCompile Include="ControlMappingScreen.cpp" />
<ClCompile Include="CwCheatScreen.cpp" />
<ClCompile Include="DevScreens.cpp" />
<ClCompile Include="DiscordIntegration.cpp" />
<ClCompile Include="DisplayLayoutEditor.cpp" />
<ClCompile Include="DisplayLayoutScreen.cpp" />
<ClCompile Include="EmuScreen.cpp" />
@@ -54,6 +55,7 @@
<ClInclude Include="ComboKeyMappingScreen.h" />
<ClInclude Include="ControlMappingScreen.h" />
<ClInclude Include="DevScreens.h" />
<ClInclude Include="DiscordIntegration.h" />
<ClInclude Include="DisplayLayoutEditor.h" />
<ClInclude Include="DisplayLayoutScreen.h" />
<ClInclude Include="EmuScreen.h" />
@@ -80,11 +82,17 @@
<ClInclude Include="InstallZipScreen.h" />
<ClInclude Include="ui_atlas.h" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ext\discord-rpc-build\discord-rpc.vcxproj">
<Project>{beb0a821-3c7f-410f-a525-63afbc69bf8f}</Project>
</ProjectReference>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{004B8D11-2BE3-4BD9-AB40-2BE04CF2096F}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>UI</RootNamespace>
<WindowsTargetPlatformVersion></WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>
</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
View
@@ -70,6 +70,7 @@
<Filter>Screens</Filter>
</ClCompile>
<ClCompile Include="TextureUtil.cpp" />
<ClCompile Include="DiscordIntegration.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="GameInfoCache.h" />
@@ -141,6 +142,7 @@
<Filter>Screens</Filter>
</ClInclude>
<ClInclude Include="TextureUtil.h" />
<ClInclude Include="DiscordIntegration.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="Screens">
View
@@ -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;
View
@@ -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
Oops, something went wrong.

0 comments on commit 785858d

Please sign in to comment.