Merge branch 'master' into d3d12

This commit is contained in:
Triang3l 2019-08-03 16:53:37 +03:00
commit e04dfe8833
7 changed files with 48 additions and 25 deletions

BIN
assets/discord/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

View File

@ -20,7 +20,7 @@ void HandleDiscordJoinGame(const char* joinSecret) {}
void HandleDiscordJoinRequest(const DiscordUser* request) {} void HandleDiscordJoinRequest(const DiscordUser* request) {}
void HandleDiscordSpectateGame(const char* spectateSecret) {} void HandleDiscordSpectateGame(const char* spectateSecret) {}
void DiscordPresence::InitializeDiscord() { void DiscordPresence::Initialize() {
DiscordEventHandlers handlers = {}; DiscordEventHandlers handlers = {};
handlers.ready = &HandleDiscordReady; handlers.ready = &HandleDiscordReady;
handlers.errored = &HandleDiscordError; handlers.errored = &HandleDiscordError;
@ -34,23 +34,25 @@ void DiscordPresence::NotPlaying() {
DiscordRichPresence discordPresence = {}; DiscordRichPresence discordPresence = {};
discordPresence.state = "Idle"; discordPresence.state = "Idle";
discordPresence.details = "Standby"; discordPresence.details = "Standby";
discordPresence.largeImageKey = "default"; discordPresence.largeImageKey = "app";
discordPresence.instance = 1; discordPresence.instance = 1;
Discord_UpdatePresence(&discordPresence); Discord_UpdatePresence(&discordPresence);
} }
void DiscordPresence::PlayingTitle(std::wstring game_title) { void DiscordPresence::PlayingTitle(const std::wstring& game_title) {
auto discord_game_title = xe::to_string(game_title); auto discord_game_title = xe::to_string(game_title);
DiscordRichPresence discordPresence = {}; DiscordRichPresence discordPresence = {};
discordPresence.state = "In Game"; discordPresence.state = "In Game";
discordPresence.details = discord_game_title.c_str(); discordPresence.details = discord_game_title.c_str();
discordPresence.smallImageKey = "default"; // TODO(gibbed): we don't have state icons yet.
discordPresence.largeImageKey = "defaultgame"; // discordPresence.smallImageKey = "app";
// discordPresence.largeImageKey = "state_ingame";
discordPresence.largeImageKey = "app";
discordPresence.instance = 1; discordPresence.instance = 1;
Discord_UpdatePresence(&discordPresence); Discord_UpdatePresence(&discordPresence);
} }
void DiscordPresence::ShutdownDiscord() { Discord_Shutdown(); } void DiscordPresence::Shutdown() { Discord_Shutdown(); }
} // namespace discord } // namespace discord
} // namespace xe } // namespace xe

View File

@ -17,10 +17,10 @@ namespace discord {
class DiscordPresence { class DiscordPresence {
public: public:
static void InitializeDiscord(); static void Initialize();
static void NotPlaying(); static void NotPlaying();
static void PlayingTitle(std::wstring game_title); static void PlayingTitle(const std::wstring& game_title);
static void ShutdownDiscord(); static void Shutdown();
}; };
} // namespace discord } // namespace discord

View File

@ -13,7 +13,6 @@
#include "build/version.h" #include "build/version.h"
#include "third_party/imgui/imgui.h" #include "third_party/imgui/imgui.h"
#include "xenia/app/discord/discord_presence.h"
#include "xenia/base/clock.h" #include "xenia/base/clock.h"
#include "xenia/base/cvar.h" #include "xenia/base/cvar.h"
#include "xenia/base/debugging.h" #include "xenia/base/debugging.h"
@ -29,7 +28,6 @@
#include "xenia/ui/imgui_drawer.h" #include "xenia/ui/imgui_drawer.h"
DECLARE_bool(debug); DECLARE_bool(debug);
DEFINE_bool(discord, false, "Enable Discord rich presence", "General");
namespace xe { namespace xe {
namespace app { namespace app {
@ -85,11 +83,6 @@ bool EmulatorWindow::Initialize() {
return false; return false;
} }
if (cvars::discord) {
discord::DiscordPresence::InitializeDiscord();
discord::DiscordPresence::NotPlaying();
}
UpdateTitle(); UpdateTitle();
window_->on_closed.AddListener([this](UIEvent* e) { loop_->Quit(); }); window_->on_closed.AddListener([this](UIEvent* e) { loop_->Quit(); });
@ -344,9 +337,6 @@ void EmulatorWindow::FileOpen() {
void EmulatorWindow::FileClose() { void EmulatorWindow::FileClose() {
if (emulator_->is_title_open()) { if (emulator_->is_title_open()) {
emulator_->TerminateTitle(); emulator_->TerminateTitle();
if (cvars::discord) {
discord::DiscordPresence::NotPlaying();
}
} }
} }
@ -444,9 +434,6 @@ void EmulatorWindow::UpdateTitle() {
auto game_title = emulator()->game_title(); auto game_title = emulator()->game_title();
title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(), title += xe::format_string(L" | [%.8X] %s", emulator()->title_id(),
game_title.c_str()); game_title.c_str());
if (cvars::discord) {
discord::DiscordPresence::PlayingTitle(game_title);
}
} }
auto graphics_system = emulator()->graphics_system(); auto graphics_system = emulator()->graphics_system();

View File

@ -7,6 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include "xenia/app/discord/discord_presence.h"
#include "xenia/app/emulator_window.h" #include "xenia/app/emulator_window.h"
#include "xenia/base/cvar.h" #include "xenia/base/cvar.h"
#include "xenia/base/debugging.h" #include "xenia/base/debugging.h"
@ -59,6 +60,8 @@ DEFINE_bool(mount_cache, false, "Enable cache mount", "General");
CmdVar(target, "", "Specifies the target .xex or .iso to execute."); CmdVar(target, "", "Specifies the target .xex or .iso to execute.");
DECLARE_bool(debug); DECLARE_bool(debug);
DEFINE_bool(discord, true, "Enable Discord rich presence", "General");
namespace xe { namespace xe {
namespace app { namespace app {
@ -160,6 +163,11 @@ int xenia_main(const std::vector<std::wstring>& args) {
Profiler::Initialize(); Profiler::Initialize();
Profiler::ThreadEnter("main"); Profiler::ThreadEnter("main");
if (cvars::discord) {
discord::DiscordPresence::Initialize();
discord::DiscordPresence::NotPlaying();
}
// Figure out where content should go. // Figure out where content should go.
std::wstring content_root = xe::to_wstring(cvars::content_root); std::wstring content_root = xe::to_wstring(cvars::content_root);
std::wstring config_folder; std::wstring config_folder;
@ -271,11 +279,21 @@ int xenia_main(const std::vector<std::wstring>& args) {
} }
auto evt = xe::threading::Event::CreateAutoResetEvent(false); auto evt = xe::threading::Event::CreateAutoResetEvent(false);
emulator->on_launch.AddListener([&]() { emulator->on_launch.AddListener([&](auto title_id, const auto& game_title) {
if (cvars::discord) {
discord::DiscordPresence::PlayingTitle(
game_title.empty() ? L"Unknown Title" : game_title);
}
emulator_window->UpdateTitle(); emulator_window->UpdateTitle();
evt->Set(); evt->Set();
}); });
emulator->on_terminate.AddListener([&]() {
if (cvars::discord) {
discord::DiscordPresence::NotPlaying();
}
});
emulator_window->window()->on_closing.AddListener([&](ui::UIEvent* e) { emulator_window->window()->on_closing.AddListener([&](ui::UIEvent* e) {
// This needs to shut down before the graphics context. // This needs to shut down before the graphics context.
Profiler::Shutdown(); Profiler::Shutdown();
@ -286,6 +304,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
exiting = true; exiting = true;
evt->Set(); evt->Set();
if (cvars::discord) {
discord::DiscordPresence::Shutdown();
}
// TODO(DrChat): Remove this code and do a proper exit. // TODO(DrChat): Remove this code and do a proper exit.
XELOGI("Cheap-skate exit!"); XELOGI("Cheap-skate exit!");
exit(0); exit(0);
@ -333,6 +355,10 @@ int xenia_main(const std::vector<std::wstring>& args) {
debug_window.reset(); debug_window.reset();
emulator.reset(); emulator.reset();
if (cvars::discord) {
discord::DiscordPresence::Shutdown();
}
Profiler::Dump(); Profiler::Dump();
Profiler::Shutdown(); Profiler::Shutdown();
emulator_window.reset(); emulator_window.reset();

View File

@ -53,6 +53,7 @@ namespace xe {
Emulator::Emulator(const std::wstring& command_line, Emulator::Emulator(const std::wstring& command_line,
const std::wstring& content_root) const std::wstring& content_root)
: on_launch(), : on_launch(),
on_terminate(),
on_exit(), on_exit(),
command_line_(command_line), command_line_(command_line),
content_root_(content_root), content_root_(content_root),
@ -233,6 +234,7 @@ X_STATUS Emulator::TerminateTitle() {
kernel_state_->TerminateTitle(); kernel_state_->TerminateTitle();
title_id_ = 0; title_id_ = 0;
game_title_ = L""; game_title_ = L"";
on_terminate();
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }
@ -627,6 +629,11 @@ std::string Emulator::FindLaunchModule() {
X_STATUS Emulator::CompleteLaunch(const std::wstring& path, X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
const std::string& module_path) { const std::string& module_path) {
// Reset state.
title_id_ = 0;
game_title_ = L"";
display_window_->SetIcon(nullptr, 0);
// Allow xam to request module loads. // Allow xam to request module loads.
auto xam = kernel_state()->GetKernelModule<kernel::xam::XamModule>("xam.xex"); auto xam = kernel_state()->GetKernelModule<kernel::xam::XamModule>("xam.xex");
@ -671,7 +678,7 @@ X_STATUS Emulator::CompleteLaunch(const std::wstring& path,
} }
main_thread_ = main_thread; main_thread_ = main_thread;
on_launch(); on_launch(title_id_, game_title_);
return X_STATUS_SUCCESS; return X_STATUS_SUCCESS;
} }

View File

@ -145,7 +145,8 @@ class Emulator {
void WaitUntilExit(); void WaitUntilExit();
public: public:
xe::Delegate<> on_launch; xe::Delegate<uint32_t, const std::wstring&> on_launch;
xe::Delegate<> on_terminate;
xe::Delegate<> on_exit; xe::Delegate<> on_exit;
private: private: