More nice touches to DiscordRPC
This commit is contained in:
@@ -5,16 +5,30 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Util {
|
namespace Util {
|
||||||
enum State {
|
struct RPC {
|
||||||
|
enum State {
|
||||||
Idling,
|
Idling,
|
||||||
Playing,
|
Playing,
|
||||||
MovieReplay,
|
MovieReplay,
|
||||||
Paused,
|
Paused,
|
||||||
};
|
};
|
||||||
|
|
||||||
FORCE_INLINE void UpdateRPC(State state, const std::string &game = "", const std::string &movieName = "") {
|
RPC() {
|
||||||
|
Discord_Initialize("1049669178124148806", &handlers, 1, nullptr);
|
||||||
|
startTimestamp = time(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
static RPC &GetInstance() {
|
||||||
|
static RPC instance;
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] FORCE_INLINE const State &GetState() const { return currentState; }
|
||||||
|
|
||||||
|
FORCE_INLINE void Update(State state, const std::string &game = "", const std::string &movieName = "") {
|
||||||
DiscordRichPresence presence{};
|
DiscordRichPresence presence{};
|
||||||
std::string textState, textDetails;
|
std::string textState, textDetails;
|
||||||
|
currentState = state == Paused ? currentState : state;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case Idling:
|
case Idling:
|
||||||
@@ -29,18 +43,34 @@ FORCE_INLINE void UpdateRPC(State state, const std::string &game = "", const std
|
|||||||
textState = "Replaying movie \"" + movieName + "\" in \"" + game + "\"";
|
textState = "Replaying movie \"" + movieName + "\" in \"" + game + "\"";
|
||||||
break;
|
break;
|
||||||
case Paused:
|
case Paused:
|
||||||
|
switch (currentState) {
|
||||||
|
case Playing:
|
||||||
textDetails = "In-game";
|
textDetails = "In-game";
|
||||||
textState = "Playing \"" + game + "\" (Paused)";
|
textState = "Playing \"" + game + "\"";
|
||||||
|
break;
|
||||||
|
case MovieReplay:
|
||||||
|
textDetails = "In-game";
|
||||||
|
textState = "Replaying movie \"" + movieName + "\" in \"" + game + "\"";
|
||||||
|
break;
|
||||||
|
default:;
|
||||||
|
}
|
||||||
|
textState += " (Paused)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
presence.details = textDetails.c_str();
|
presence.details = textDetails.c_str();
|
||||||
presence.state = textState.c_str();
|
presence.state = textState.c_str();
|
||||||
presence.startTimestamp = time(nullptr);
|
presence.startTimestamp = startTimestamp;
|
||||||
presence.largeImageText = "Kaizen";
|
presence.largeImageText = "Kaizen";
|
||||||
presence.largeImageKey = "logo";
|
presence.largeImageKey = "logo";
|
||||||
Discord_UpdatePresence(&presence);
|
Discord_UpdatePresence(&presence);
|
||||||
}
|
}
|
||||||
|
|
||||||
FORCE_INLINE void ClearRPC() { Discord_ClearPresence(); }
|
FORCE_INLINE void Clear() { Discord_ClearPresence(); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
DiscordEventHandlers handlers{};
|
||||||
|
s64 startTimestamp{};
|
||||||
|
State currentState;
|
||||||
|
};
|
||||||
} // namespace Util
|
} // namespace Util
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include <Scheduler.hpp>
|
#include <Scheduler.hpp>
|
||||||
|
|
||||||
namespace n64 {
|
namespace n64 {
|
||||||
Core::Core(ParallelRDP ¶llel) : cpu(std::make_unique<JIT>(parallel)) {}
|
Core::Core(ParallelRDP ¶llel) : cpu(std::make_unique<Interpreter>(parallel)) {}
|
||||||
|
|
||||||
void Core::Stop() {
|
void Core::Stop() {
|
||||||
render = false;
|
render = false;
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ union TASMovieControllerData {
|
|||||||
static_assert(sizeof(TASMovieControllerData) == 4);
|
static_assert(sizeof(TASMovieControllerData) == 4);
|
||||||
|
|
||||||
bool MupenMovie::Load(const fs::path &path) {
|
bool MupenMovie::Load(const fs::path &path) {
|
||||||
|
filename = path.stem().string();
|
||||||
loadedTasMovie = Util::ReadFileBinary(path.string());
|
loadedTasMovie = Util::ReadFileBinary(path.string());
|
||||||
if (!IsLoaded()) {
|
if (!IsLoaded()) {
|
||||||
Util::error("Error loading movie!");
|
Util::error("Error loading movie!");
|
||||||
|
|||||||
@@ -51,9 +51,11 @@ struct MupenMovie {
|
|||||||
bool Load(const fs::path &);
|
bool Load(const fs::path &);
|
||||||
void Reset();
|
void Reset();
|
||||||
n64::Controller NextInputs();
|
n64::Controller NextInputs();
|
||||||
bool IsLoaded() const { return !loadedTasMovie.empty(); }
|
[[nodiscard]] bool IsLoaded() const { return !loadedTasMovie.empty(); }
|
||||||
|
[[nodiscard]] const std::string &GetFilename() const { return filename; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::string filename{};
|
||||||
std::vector<u8> loadedTasMovie = {};
|
std::vector<u8> loadedTasMovie = {};
|
||||||
TASMovieHeader loadedTasMovieHeader = {};
|
TASMovieHeader loadedTasMovieHeader = {};
|
||||||
uint32_t loadedTasMovieIndex = 0;
|
uint32_t loadedTasMovieIndex = 0;
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ public:
|
|||||||
|
|
||||||
void TogglePause() {
|
void TogglePause() {
|
||||||
core.pause = !core.pause;
|
core.pause = !core.pause;
|
||||||
Util::UpdateRPC(core.pause ? Util::Idling : Util::Playing);
|
Util::RPC::GetInstance().Update(core.pause ? Util::RPC::Paused : Util::RPC::GetInstance().GetState(),
|
||||||
|
core.cpu->GetMem().rom.gameNameDB,
|
||||||
|
core.cpu->GetMem().mmio.si.pif.movie.GetFilename());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetRender(bool v) { core.render = v; }
|
void SetRender(bool v) { core.render = v; }
|
||||||
@@ -40,7 +42,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Stop() {
|
void Stop() {
|
||||||
Discord_ClearPresence();
|
Util::RPC::GetInstance().Update(Util::RPC::Idling);
|
||||||
core.rom = {};
|
core.rom = {};
|
||||||
core.pause = true;
|
core.pause = true;
|
||||||
core.Stop();
|
core.Stop();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ KaizenQt::KaizenQt() noexcept : QWidget(nullptr) {
|
|||||||
std::move(mainWindow->view.vulkanWidget->windowInfo), *settingsWindow);
|
std::move(mainWindow->view.vulkanWidget->windowInfo), *settingsWindow);
|
||||||
|
|
||||||
ConnectMainWindowSignalsToSlots();
|
ConnectMainWindowSignalsToSlots();
|
||||||
|
Util::RPC::GetInstance().Update(Util::RPC::Idling);
|
||||||
|
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
@@ -54,7 +55,7 @@ void KaizenQt::LoadROM(const QString &fileName) noexcept {
|
|||||||
emuThread->core.LoadROM(fileName.toStdString());
|
emuThread->core.LoadROM(fileName.toStdString());
|
||||||
auto gameNameDB = emuThread->core.cpu->GetMem().rom.gameNameDB;
|
auto gameNameDB = emuThread->core.cpu->GetMem().rom.gameNameDB;
|
||||||
mainWindow->setWindowTitle(emuThread->core.cpu->GetMem().rom.gameNameDB.c_str());
|
mainWindow->setWindowTitle(emuThread->core.cpu->GetMem().rom.gameNameDB.c_str());
|
||||||
UpdateRPC(Util::Playing, gameNameDB);
|
Util::RPC::GetInstance().Update(Util::RPC::Playing, gameNameDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenQt::Quit() noexcept {
|
void KaizenQt::Quit() noexcept {
|
||||||
@@ -69,7 +70,8 @@ void KaizenQt::Quit() noexcept {
|
|||||||
void KaizenQt::LoadTAS(const QString &fileName) const noexcept {
|
void KaizenQt::LoadTAS(const QString &fileName) const noexcept {
|
||||||
emuThread->core.LoadTAS(fs::path(fileName.toStdString()));
|
emuThread->core.LoadTAS(fs::path(fileName.toStdString()));
|
||||||
auto gameNameDB = emuThread->core.cpu->GetMem().rom.gameNameDB;
|
auto gameNameDB = emuThread->core.cpu->GetMem().rom.gameNameDB;
|
||||||
UpdateRPC(Util::MovieReplay, gameNameDB, fileName.toStdString());
|
auto movieName = fs::path(fileName.toStdString()).stem().string();
|
||||||
|
Util::RPC::GetInstance().Update(Util::RPC::MovieReplay, gameNameDB, movieName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenQt::keyPressEvent(QKeyEvent *e) {
|
void KaizenQt::keyPressEvent(QKeyEvent *e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user