Add Discord RPC (#161)

* Add discord-rpc submodule

* Add Discord RPC

* Fix up Discord status

* Fix CMake because MacOS sucks

* Slightly less hacky fix
This commit is contained in:
wheremyfoodat 2023-08-08 00:23:39 +03:00 committed by GitHub
parent 32ad43cb8e
commit 1c11e2df40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 145 additions and 8 deletions

View file

@ -13,7 +13,7 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1;
Emulator::Emulator()
: config(std::filesystem::current_path() / "config.toml"), kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, config),
memory(cpu.getTicksRef()), cheats(memory, kernel.getServiceManager().getHID())
memory(cpu.getTicksRef()), cheats(memory, kernel.getServiceManager().getHID()), running(false), programRunning(false)
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
, httpServer(this)
#endif
@ -34,6 +34,13 @@ Emulator::Emulator()
needOpenGL = needOpenGL || (config.rendererType == RendererType::OpenGL);
#endif
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
if (config.discordRpcEnabled) {
discordRpc.init();
updateDiscord();
}
#endif
if (needOpenGL) {
// Demand 3.3 core for software renderer, or 4.1 core for OpenGL renderer (max available on MacOS)
// MacOS gets mad if we don't explicitly demand a core profile
@ -75,12 +82,16 @@ Emulator::Emulator()
}
}
running = false;
programRunning = false;
reset(ReloadOption::NoReload);
}
Emulator::~Emulator() { config.save(std::filesystem::current_path() / "config.toml"); }
Emulator::~Emulator() {
config.save(std::filesystem::current_path() / "config.toml");
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
discordRpc.stop();
#endif
}
void Emulator::reset(ReloadOption reload) {
cpu.reset();
@ -121,6 +132,7 @@ void Emulator::run() {
#ifdef PANDA3DS_ENABLE_HTTP_SERVER
httpServer.processActions();
#endif
runFrame();
HIDService& hid = kernel.getServiceManager().getHID();
@ -431,6 +443,9 @@ bool Emulator::loadROM(const std::filesystem::path& path) {
if (success) {
romPath = path;
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
updateDiscord();
#endif
} else {
romPath = std::nullopt;
romType = ROMType::None;
@ -487,3 +502,18 @@ bool Emulator::loadELF(std::ifstream& file) {
// Reset our graphics context and initialize the GPU's graphics context
void Emulator::initGraphicsContext() { gpu.initGraphicsContext(window); }
#ifdef PANDA3DS_ENABLE_DISCORD_RPC
void Emulator::updateDiscord() {
if (config.discordRpcEnabled) {
if (romType != ROMType::None) {
const auto name = romPath.value().stem();
discordRpc.update(Discord::RPCStatus::Playing, name.string());
} else {
discordRpc.update(Discord::RPCStatus::Idling, "");
}
}
}
#else
void Emulator::updateDiscord() {}
#endif