Skip to content

Commit

Permalink
Allow resetting display state from API
Browse files Browse the repository at this point in the history
  • Loading branch information
Desdaemon committed Sep 14, 2024
1 parent 708e792 commit 4c08ecc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/platform/emscripten/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <sstream>

#include "async_handler.h"
#include "baseui.h"
#include "filefinder.h"
#include "player.h"
#include "scene_save.h"
Expand Down Expand Up @@ -151,6 +152,12 @@ void Emscripten_Interface::SetSessionToken(std::string t) {
i.session_token.assign(t);
}

bool Emscripten_Interface::ResetCanvas() {
DisplayUi.reset();
DisplayUi = BaseUi::CreateUi(Player::screen_width, Player::screen_height, Player::ParseCommandLine());
return DisplayUi != nullptr;
}

// Binding code
EMSCRIPTEN_BINDINGS(player_interface) {
emscripten::class_<Emscripten_Interface>("api")
Expand All @@ -169,6 +176,7 @@ EMSCRIPTEN_BINDINGS(player_interface) {
.class_function("setMusicVolume", &Emscripten_Interface::SetMusicVolume)
.class_function("setNametagMode", &Emscripten_Interface::SetNametagMode)
.class_function("setSessionToken", &Emscripten_Interface::SetSessionToken, emscripten::allow_raw_pointers())
.class_function("resetCanvas", &Emscripten_Interface::ResetCanvas)
;

emscripten::class_<Emscripten_Interface_Private>("api_private")
Expand Down
1 change: 1 addition & 0 deletions src/platform/emscripten/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Emscripten_Interface {
static void SetMusicVolume(int volume);
static void SetNametagMode(int mode);
static void SetSessionToken(std::string t);
static bool ResetCanvas();
};

class Emscripten_Interface_Private {
Expand Down
7 changes: 6 additions & 1 deletion src/platform/emscripten/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,14 @@ void main_loop() {
Player::MainLoop();
if (!DisplayUi.get()) {
// Yield on shutdown to ensure async operations (e.g. IDBFS saving) can finish
counter = -5;
counter = -10;
}
} else if (counter == -1) {
if (DisplayUi.get()) {
// we previously lost the UI and restored it, so continue doing stuff.
counter = 6;
return;
}
emscripten_cancel_main_loop();
}
}
Expand Down

0 comments on commit 4c08ecc

Please sign in to comment.