From 65a8ad2666f1caa70d0adc7383b708ddd70044ff Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sun, 22 Feb 2015 18:47:19 +0100 Subject: [PATCH 1/9] Emscripten: Support passing of command line arguments --- src/emscripten-post.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/emscripten-post.js diff --git a/src/emscripten-post.js b/src/emscripten-post.js new file mode 100644 index 0000000000..0192d00b08 --- /dev/null +++ b/src/emscripten-post.js @@ -0,0 +1,26 @@ +function parseargs() { + var tmp = []; + var ret = []; + var items = location.search.substr(1).split("&"); + for (var index = 0; index < items.length; index++) { + tmp = items[index].split("="); + ret.push("--" + tmp[0]); + if (tmp.length > 1) { + arg = decodeURI(tmp[1]); + // split except if it's a string + if (arg.length > 0) { + if (arg.slice(0) == "\"" && arg.slice(-1) == "\"") { + ret.push(arg.slice(1, -1)); + } else { + var spl = arg.split(" "); + ret = ret.concat(spl); + } + } + + } + } + return ret; +} + +Module.arguments.push("easyrpg-player"); +Module.arguments = Module.arguments.concat(parseargs()); From be9dcc74aead78c13b572bef9e9a8acbdea4f5ee Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sun, 22 Feb 2015 23:09:02 +0100 Subject: [PATCH 2/9] Transitions return to scene loop (= transitions in emscripten) --- src/game_interpreter.cpp | 4 +++- src/game_interpreter.h | 3 ++- src/game_interpreter_map.cpp | 18 +++++++++++---- src/game_interpreter_map.h | 3 ++- src/graphics.cpp | 45 ++++++++++++++++-------------------- src/graphics.h | 5 ++++ src/scene.cpp | 8 +++++++ src/scene_map.cpp | 20 +++++++++++----- src/scene_map.h | 4 ++-- 9 files changed, 70 insertions(+), 40 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 745d1561d0..4124825f24 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -217,6 +217,7 @@ void Game_Interpreter::Update() { if (continuation) { bool result = (this->*continuation)(list[index]); + if (result) continue; else @@ -1308,5 +1309,6 @@ bool Game_Interpreter::CommandGameOver(RPG::EventCommand const& /* com */) { // // Dummy Continuations bool Game_Interpreter::ContinuationOpenShop(RPG::EventCommand const& /* com */) { return true; } -bool Game_Interpreter::ContinuationShowInn(RPG::EventCommand const& /* com */) { return true; } +bool Game_Interpreter::ContinuationShowInnStart(RPG::EventCommand const& /* com */) { return true; } +bool Game_Interpreter::ContinuationShowInnFinish(RPG::EventCommand const& /* com */) { return true; } bool Game_Interpreter::ContinuationEnemyEncounter(RPG::EventCommand const& /* com */) { return true; } diff --git a/src/game_interpreter.h b/src/game_interpreter.h index 0f41cbf9be..0e0b46b464 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -158,7 +158,8 @@ class Game_Interpreter virtual bool DefaultContinuation(RPG::EventCommand const& com); virtual bool ContinuationChoices(RPG::EventCommand const& com); virtual bool ContinuationOpenShop(RPG::EventCommand const& com); - virtual bool ContinuationShowInn(RPG::EventCommand const& com); + virtual bool ContinuationShowInnStart(RPG::EventCommand const& com); + virtual bool ContinuationShowInnFinish(RPG::EventCommand const& com); virtual bool ContinuationEnemyEncounter(RPG::EventCommand const& com); int debug_x; diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 38a3fad813..5d24b4b62d 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -1083,7 +1083,7 @@ bool Game_Interpreter_Map::CommandShowInn(RPG::EventCommand const& com) { // cod if (Game_Temp::inn_price == 0) { // Skip prompt. Game_Message::choice_result = 0; - return ContinuationShowInn(com); + return ContinuationShowInnStart(com); } Game_Message::message_waiting = true; @@ -1136,11 +1136,11 @@ bool Game_Interpreter_Map::CommandShowInn(RPG::EventCommand const& com) { // cod Game_Temp::inn_calling = true; Game_Message::choice_result = 4; - SetContinuation(static_cast(&Game_Interpreter_Map::ContinuationShowInn)); + SetContinuation(static_cast(&Game_Interpreter_Map::ContinuationShowInnStart)); return true; } -bool Game_Interpreter_Map::ContinuationShowInn(RPG::EventCommand const& /* com */) { +bool Game_Interpreter_Map::ContinuationShowInnStart(RPG::EventCommand const& /* com */) { if (Game_Message::visible) { CloseMessageWindow(); return false; @@ -1167,7 +1167,8 @@ bool Game_Interpreter_Map::ContinuationShowInn(RPG::EventCommand const& /* com * actor->RemoveAllStates(); } Graphics::Transition(Graphics::TransitionFadeOut, 36, true); - Graphics::Transition(Graphics::TransitionFadeIn, 36, false); + SetContinuation(static_cast(&Game_Interpreter_Map::ContinuationShowInnFinish)); + return false; } index++; return true; @@ -1179,6 +1180,15 @@ bool Game_Interpreter_Map::ContinuationShowInn(RPG::EventCommand const& /* com * return true; } +bool Game_Interpreter_Map::ContinuationShowInnFinish(RPG::EventCommand const& /* com */) { + continuation = NULL; + + Graphics::Transition(Graphics::TransitionFadeIn, 36, false); + + index++; + return false; +} + bool Game_Interpreter_Map::CommandEnterHeroName(RPG::EventCommand const& com) { // code 10740 Game_Temp::hero_name_id = com.parameters[0]; Game_Temp::hero_name_charset = com.parameters[1]; diff --git a/src/game_interpreter_map.h b/src/game_interpreter_map.h index f53f3a2f55..505e2f4d2c 100644 --- a/src/game_interpreter_map.h +++ b/src/game_interpreter_map.h @@ -128,7 +128,8 @@ class Game_Interpreter_Map : public Game_Interpreter bool CommandHaltAllMovement(RPG::EventCommand const& com); bool ContinuationOpenShop(RPG::EventCommand const& com); - bool ContinuationShowInn(RPG::EventCommand const& com); + bool ContinuationShowInnStart(RPG::EventCommand const& com); + bool ContinuationShowInnFinish(RPG::EventCommand const& com); bool ContinuationEnemyEncounter(RPG::EventCommand const& com); private: diff --git a/src/graphics.cpp b/src/graphics.cpp index 03029e0cc4..b25cf55c5c 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -54,6 +54,7 @@ namespace Graphics { bool frozen; TransitionType transition_type; int transition_duration; + int transition_frames_left; int transition_frame; bool screen_erased; @@ -64,6 +65,7 @@ namespace Graphics { std::list drawable_list; bool zlist_dirty; }; + EASYRPG_SHARED_PTR state; std::vector > stack; EASYRPG_SHARED_PTR global_state; @@ -87,15 +89,14 @@ void Graphics::Init() { fps_mode = 0; timer_wait = 0; frozen_screen = BitmapRef(); + screen_erased = false; + transition_frames_left = 0; black_screen = Bitmap::Create(DisplayUi->GetWidth(), DisplayUi->GetHeight(), Color(0,0,0,255)); - frozen = false; drawable_creation = 0; state.reset(new State()); global_state.reset(new State()); - screen_erased = false; - } void Graphics::Quit() { @@ -122,8 +123,6 @@ void Graphics::Quit() { } void Graphics::Update() { - if (frozen) return; - switch(fps_mode) { case 1: InternUpdate2(); @@ -262,11 +261,18 @@ void Graphics::UpdateTitle() { } void Graphics::DrawFrame() { - if (transition_duration > 0) { + if (transition_frames_left > 0) { UpdateTransition(); + + if (overlay_visible) { + DrawOverlay(); + } + return; + } + + if (screen_erased) { return; } - if (screen_erased) return; if (state->zlist_dirty) { state->drawable_list.sort(SortDrawableList); @@ -321,16 +327,14 @@ BitmapRef Graphics::SnapToBitmap() { void Graphics::Freeze() { frozen_screen = SnapToBitmap(); - frozen = true; } void Graphics::Transition(TransitionType type, int duration, bool erase) { - if (erase && screen_erased) return; - if (type != TransitionNone) { transition_type = type; transition_frame = 0; transition_duration = type == TransitionErase ? 1 : duration; + transition_frames_left = transition_duration; if (state->zlist_dirty) { state->drawable_list.sort(SortDrawableList); @@ -342,7 +346,7 @@ void Graphics::Transition(TransitionType type, int duration, bool erase) { global_state->zlist_dirty = false; } - if (!frozen) Freeze(); + Freeze(); if (erase) { screen1 = frozen_screen; @@ -356,24 +360,13 @@ void Graphics::Transition(TransitionType type, int duration, bool erase) { else screen1 = screen2; } - -#ifndef EMSCRIPTEN - // Fixme: Refactor how transitions work, they should return to the main loop - for (int i = 1; i <= transition_duration; i++) { - Player::Update(); - InternUpdate1(); - } -#endif } - if (!erase) frozen_screen = BitmapRef(); - - frozen = false; screen_erased = erase; +} - transition_duration = 0; - - FrameReset(); +bool Graphics::IsTransitionPending() { + return transition_frames_left > 0; } void Graphics::UpdateTransition() { @@ -386,6 +379,8 @@ void Graphics::UpdateTransition() { int percentage = transition_frame * 100 / transition_duration; + transition_frames_left--; + // Fallback to FadeIn/Out for not implemented transition types: // (Remove from here when implemented below) switch (transition_type) { diff --git a/src/graphics.h b/src/graphics.h index f899ec9dfd..3a70c6893d 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -113,6 +113,11 @@ namespace Graphics { */ void Transition(TransitionType type, int duration, bool erase = false); + /** + * Gets if a screen transition is executing. + */ + bool IsTransitionPending(); + /** * Freezes the screen, and prepares it for a * transition. diff --git a/src/scene.cpp b/src/scene.cpp index 2154040a7b..76bfa723a7 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -65,6 +65,12 @@ Scene::Scene() { void Scene::MainFunction() { static bool init = false; + if (Graphics::IsTransitionPending()) { + Player::Update(); + Graphics::Update(); + return; + } + if (!init) { // Initialization after scene switch switch (push_pop_operation) { @@ -83,6 +89,8 @@ void Scene::MainFunction() { Resume(); init = true; + + return; } // Update scene diff --git a/src/scene_map.cpp b/src/scene_map.cpp index d37a337450..900363e04a 100644 --- a/src/scene_map.cpp +++ b/src/scene_map.cpp @@ -97,6 +97,10 @@ void Scene_Map::TransitionOut() { } void Scene_Map::Update() { + if (Main_Data::game_player->IsTeleporting()) { + FinishTeleportPlayer(); + } + Game_Map::GetInterpreter().Update(); Main_Data::game_party->UpdateTimers(); @@ -107,7 +111,7 @@ void Scene_Map::Update() { spriteset->Update(); message_window->Update(); - UpdateTeleportPlayer(); + StartTeleportPlayer(); if (!Main_Data::game_party->IsAnyAlive()) { // Empty party is allowed @@ -176,13 +180,18 @@ void Scene_Map::Update() { } } -void Scene_Map::UpdateTeleportPlayer() { +void Scene_Map::StartTeleportPlayer() { if (!Main_Data::game_player->IsTeleporting()) return; bool const autotransition = !Game_Temp::transition_erase; - if (autotransition) + if (autotransition) { Graphics::Transition((Graphics::TransitionType)Game_System::GetTransition(Game_System::Transition_TeleportErase), 32, true); + } +} + +void Scene_Map::FinishTeleportPlayer() { + bool const autotransition = !Game_Temp::transition_erase; Main_Data::game_player->PerformTeleport(); Game_Map::PlayBgm(); @@ -191,10 +200,9 @@ void Scene_Map::UpdateTeleportPlayer() { Game_Map::Update(); - if (autotransition) + if (autotransition) { Graphics::Transition((Graphics::TransitionType)Game_System::GetTransition(Game_System::Transition_TeleportShow), 32, false); - - Input::Update(); + } } // Scene calling stuff. diff --git a/src/scene_map.h b/src/scene_map.h index e74386536b..46650c6579 100644 --- a/src/scene_map.h +++ b/src/scene_map.h @@ -55,8 +55,8 @@ class Scene_Map: public Scene { boost::scoped_ptr message_window; private: - void UpdateTeleportPlayer(); - + void StartTeleportPlayer(); + void FinishTeleportPlayer(); boost::scoped_ptr screen; boost::scoped_ptr weather; From 1381888ed6737bceb3cfa2fb9185dab383dbb02f Mon Sep 17 00:00:00 2001 From: Ghabry Date: Sun, 22 Feb 2015 23:12:03 +0100 Subject: [PATCH 3/9] Fix crash when Inn is last event. Fix calling of Inn custom handler when night is free. --- src/game_interpreter.cpp | 7 ++++++- src/game_interpreter_map.cpp | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 4124825f24..0ecf8c2c72 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -216,7 +216,12 @@ void Game_Interpreter::Update() { } if (continuation) { - bool result = (this->*continuation)(list[index]); + bool result; + if (index >= list.size()) { + result = (this->*continuation)(RPG::EventCommand()); + } else { + result = (this->*continuation)(list[index]); + } if (result) continue; diff --git a/src/game_interpreter_map.cpp b/src/game_interpreter_map.cpp index 5d24b4b62d..1283b3500e 100644 --- a/src/game_interpreter_map.cpp +++ b/src/game_interpreter_map.cpp @@ -1083,7 +1083,8 @@ bool Game_Interpreter_Map::CommandShowInn(RPG::EventCommand const& com) { // cod if (Game_Temp::inn_price == 0) { // Skip prompt. Game_Message::choice_result = 0; - return ContinuationShowInnStart(com); + SetContinuation(static_cast(&Game_Interpreter_Map::ContinuationShowInnStart)); + return true; } Game_Message::message_waiting = true; From 2dbf491b13cf05f6ec59298ec00c282049b84182 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 00:05:40 +0100 Subject: [PATCH 4/9] Emscripten: Make save persistent --- src/filefinder.cpp | 10 ++++++++++ src/filefinder.h | 10 ++++++++++ src/player.cpp | 9 +++++++++ src/scene_file.cpp | 10 ++++++++++ src/scene_load.cpp | 4 ++++ src/scene_save.cpp | 20 +++++++++++++++++++- src/scene_title.cpp | 12 +++++++++++- 7 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/filefinder.cpp b/src/filefinder.cpp index 7141d15d20..7db831e8e7 100644 --- a/src/filefinder.cpp +++ b/src/filefinder.cpp @@ -421,6 +421,16 @@ std::string FileFinder::FindDefault(std::string const& name) { return FindDefault(GetProjectTree(), name); } +std::string FileFinder::FindDefault(const ProjectTree& tree, const std::string& dir, const std::string& name) { + static const char* no_exts[] = { "", NULL }; + + boost::optional file = FindFile(tree, dir, name, no_exts); + if (file != boost::none) { + return *file; + } + return ""; +} + std::string FileFinder::FindDefault(const ProjectTree& tree, const std::string& name) { ProjectTree const& p = tree; string_map const& files = p.files; diff --git a/src/filefinder.h b/src/filefinder.h index 43ea073ce8..3bdf21eab7 100644 --- a/src/filefinder.h +++ b/src/filefinder.h @@ -90,6 +90,16 @@ namespace FileFinder { */ std::string FindDefault(const std::string& name); + /** + * Finds a file in a custom project tree. + * + * @param tree Project tree to search + * @param dir directory to check + * @param name the path and name + * @return path to file. + */ + std::string FindDefault(const ProjectTree& tree, const std::string& dir, const std::string& name); + /** * Finds a file in a custom project tree. * diff --git a/src/player.cpp b/src/player.cpp index 059733fe8a..e8b5a77ed4 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -111,6 +111,15 @@ void Player::Init(int argc, char *argv[]) { Output::IgnorePause(true); emscripten_set_canvas_size(SCREEN_TARGET_WIDTH * 2, SCREEN_TARGET_HEIGHT * 2); + + // Retrieve save directory from persistent storage + EM_ASM( + FS.mkdir('/Save'); + FS.mount(IDBFS, {}, '/Save'); + + FS.syncfs(true, function(err) { + }); + ); #endif srand(time(NULL)); diff --git a/src/scene_file.cpp b/src/scene_file.cpp index 302b398911..a9877cc414 100644 --- a/src/scene_file.cpp +++ b/src/scene_file.cpp @@ -45,7 +45,11 @@ void Scene_File::Start() { help_window->SetText(message); // Refresh File Finder Save Folder +#ifdef EMSCRIPTEN + tree = FileFinder::CreateProjectTree(Main_Data::project_path, true); +#else tree = FileFinder::CreateProjectTree(Main_Data::project_path, false); +#endif for (int i = 0; i < 15; i++) { EASYRPG_SHARED_PTR @@ -55,7 +59,13 @@ void Scene_File::Start() { // Try to access file std::stringstream ss; ss << "Save" << (i <= 8 ? "0" : "") << (i+1) << ".lsd"; + +#ifdef EMSCRIPTEN + std::string file = FileFinder::FindDefault(*tree, "Save", ss.str()); +#else std::string file = FileFinder::FindDefault(*tree, ss.str()); +#endif + if (!file.empty()) { // File found std::auto_ptr savegame = diff --git a/src/scene_load.cpp b/src/scene_load.cpp index 572ec0ffad..c830051631 100644 --- a/src/scene_load.cpp +++ b/src/scene_load.cpp @@ -32,7 +32,11 @@ void Scene_Load::Action(int index) { std::stringstream ss; ss << "Save" << (index <= 8 ? "0" : "") << (index + 1) << ".lsd"; +#ifdef EMSCRIPTEN + std::string save_name = FileFinder::FindDefault(*tree, "Save", ss.str()); +#else std::string save_name = FileFinder::FindDefault(*tree, ss.str()); +#endif Player::CreateGameObjects(); diff --git a/src/scene_save.cpp b/src/scene_save.cpp index d52d9bf11a..2d6be61135 100644 --- a/src/scene_save.cpp +++ b/src/scene_save.cpp @@ -27,6 +27,10 @@ #include "scene_save.h" #include "scene_file.h" +#ifdef EMSCRIPTEN +#include +#endif + Scene_Save::Scene_Save() : Scene_File(Data::terms.save_game_message) { Scene::type = Scene::Save; @@ -86,14 +90,28 @@ void Scene_Save::Action(int index) { Game_Map::PrepareSave(); +#ifdef EMSCRIPTEN + std::string save_file = FileFinder::MakePath("Save", ss.str()); + std::string filename = FileFinder::FindDefault(*tree, "Save", ss.str()); +#else + std::string save_file = ss.str(); std::string filename = FileFinder::FindDefault(*tree, ss.str()); +#endif if (filename.empty()) { - filename = FileFinder::MakePath(Main_Data::project_path, ss.str()); + filename = FileFinder::MakePath(Main_Data::project_path, save_file); } LSD_Reader::Save(filename, Main_Data::game_data, Player::encoding); +#ifdef EMSCRIPTEN + // Save changed file system + EM_ASM( + FS.syncfs(function(err) { + }); + ); +#endif + Scene::Pop(); } diff --git a/src/scene_title.cpp b/src/scene_title.cpp index c74987742d..97cc146e69 100644 --- a/src/scene_title.cpp +++ b/src/scene_title.cpp @@ -115,14 +115,24 @@ void Scene_Title::Update() { bool Scene_Title::CheckContinue() { EASYRPG_SHARED_PTR tree; +#ifdef EMSCRIPTEN + tree = FileFinder::CreateProjectTree(Main_Data::project_path, true); +#else tree = FileFinder::CreateProjectTree(Main_Data::project_path, false); +#endif for (int i = 1; i <= 15; i++) { std::stringstream ss; ss << "Save" << (i <= 9 ? "0" : "") << i << ".lsd"; - if (!FileFinder::FindDefault(*tree, ss.str()).empty()) { +#ifdef EMSCRIPTEN + std::string filename = FileFinder::FindDefault(*tree, "Save", ss.str()); +#else + std::string filename = FileFinder::FindDefault(*tree, ss.str()); +#endif + + if (!filename.empty()) { return true; } } From 1232ef8390327171ec522a8a0c1cfe100bc4a548 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 00:57:05 +0100 Subject: [PATCH 5/9] emscripten-post.js: Replace tabs with spaces --- src/emscripten-post.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/emscripten-post.js b/src/emscripten-post.js index 0192d00b08..3ae35550c8 100644 --- a/src/emscripten-post.js +++ b/src/emscripten-post.js @@ -6,16 +6,16 @@ function parseargs() { tmp = items[index].split("="); ret.push("--" + tmp[0]); if (tmp.length > 1) { - arg = decodeURI(tmp[1]); - // split except if it's a string - if (arg.length > 0) { - if (arg.slice(0) == "\"" && arg.slice(-1) == "\"") { - ret.push(arg.slice(1, -1)); - } else { - var spl = arg.split(" "); - ret = ret.concat(spl); - } - } + arg = decodeURI(tmp[1]); + // split except if it's a string + if (arg.length > 0) { + if (arg.slice(0) == "\"" && arg.slice(-1) == "\"") { + ret.push(arg.slice(1, -1)); + } else { + var spl = arg.split(" "); + ret = ret.concat(spl); + } + } } } From f36712a06f0e4343476b3811786de2becdebf924 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 01:43:21 +0100 Subject: [PATCH 6/9] Render FPS and global drawables on top of transitions --- src/graphics.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/graphics.cpp b/src/graphics.cpp index b25cf55c5c..d23268343e 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -261,12 +261,20 @@ void Graphics::UpdateTitle() { } void Graphics::DrawFrame() { + std::list::iterator it_list; + if (transition_frames_left > 0) { UpdateTransition(); + for (it_list = global_state->drawable_list.begin(); it_list != global_state->drawable_list.end(); ++it_list) { + (*it_list)->Draw(); + } + if (overlay_visible) { DrawOverlay(); } + + DisplayUi->UpdateDisplay(); return; } @@ -286,7 +294,6 @@ void Graphics::DrawFrame() { DisplayUi->CleanDisplay(); - std::list::iterator it_list; for (it_list = state->drawable_list.begin(); it_list != state->drawable_list.end(); ++it_list) { (*it_list)->Draw(); } @@ -529,8 +536,6 @@ void Graphics::UpdateTransition() { DisplayUi->CleanDisplay(); break; } - - DisplayUi->UpdateDisplay(); } void Graphics::FrameReset() { From be03b2b2b219440c994efc61b96bc035f1e62eaa Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 01:53:09 +0100 Subject: [PATCH 7/9] Fade to black on program close --- src/player.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index e8b5a77ed4..f473381dbc 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -161,7 +161,7 @@ void Player::Run() { #ifdef EMSCRIPTEN emscripten_set_main_loop(Player::MainLoop, 0, 0); #else - while (Scene::instance->type != Scene::Null) + while (Graphics::IsTransitionPending() || Scene::instance->type != Scene::Null) Player::MainLoop(); #endif } @@ -173,7 +173,7 @@ void Player::MainLoop() { } Scene::old_instances.clear(); - if (Scene::instance->type == Scene::Null) { + if (!Graphics::IsTransitionPending() && Scene::instance->type == Scene::Null) { Player::Exit(); } } From b93bfb8bd758c09a5b342d2c31d8754f1dcfb4a2 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 02:08:34 +0100 Subject: [PATCH 8/9] Emscripten: Don't render FPS on screen (always 0 FPS) --- src/graphics.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/graphics.cpp b/src/graphics.cpp index d23268343e..3c67d261fa 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -81,7 +81,11 @@ unsigned SecondToFrame(float const second) { } void Graphics::Init() { +#ifdef EMSCRIPTEN + overlay_visible = false; +#else overlay_visible = true; +#endif fps_on_screen = false; fps = 0; framerate = DEFAULT_FPS; From 5dc90b451cd9cc35d91b9a3bff4f1bf4745b9bc9 Mon Sep 17 00:00:00 2001 From: Ghabry Date: Mon, 23 Feb 2015 02:08:47 +0100 Subject: [PATCH 9/9] Emscripten: Show shutdown message --- src/player.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/player.cpp b/src/player.cpp index f473381dbc..ebfffd6b01 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -214,7 +214,14 @@ void Player::Update() { void Player::Exit() { #ifdef EMSCRIPTEN emscripten_cancel_main_loop(); + + BitmapRef surface = DisplayUi->GetDisplaySurface(); + std::string error = "You can turn off your browser now."; + + Text::Draw(*surface, 55, DisplayUi->GetHeight() / 2 - 6, Color(255, 255, 255, 255), error); + DisplayUi->UpdateDisplay(); #endif + Main_Data::Cleanup(); Graphics::Quit(); FileFinder::Quit();