Changeset - r27844:cf08d34d52cb
[Not reviewed]
master
0 3 0
glx22 - 11 months ago 2023-07-06 16:18:03
glx@openttd.org
Codechange: [Emscripten] Improve syncfs synchronisation on exit/abort
3 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
os/emscripten/pre.js
Show inline comments
 
@@ -43,42 +43,44 @@ Module.preRun.push(function() {
 
            window.openttd_downloaded_opengfx = true;
 
            FS.createPreloadedFile(content_download_dir + '/baseset', 'opengfx-0.6.0.tar', 'https://binaries.openttd.org/installer/emscripten/opengfx-0.6.0.tar', true, true);
 
        } else {
 
            /* Fake dependency increase, so the counter is stable. */
 
            Module.addRunDependency('opengfx');
 
            Module.removeRunDependency('opengfx');
 
        }
 

	
 
        Module.removeRunDependency('syncfs');
 
    });
 

	
 
    window.openttd_syncfs_shown_warning = false;
 
    window.openttd_syncfs = function() {
 
    window.openttd_syncfs = function(callback) {
 
        /* Copy the virtual FS to the persistent storage. */
 
        FS.syncfs(false, function (err) { });
 
        FS.syncfs(false, function (err) {
 
            /* On first time, warn the user about the volatile behaviour of
 
             * persistent storage. */
 
            if (!window.openttd_syncfs_shown_warning) {
 
                window.openttd_syncfs_shown_warning = true;
 
                Module.onWarningFs();
 
            }
 

	
 
        /* On first time, warn the user about the volatile behaviour of
 
         * persistent storage. */
 
        if (!window.openttd_syncfs_shown_warning) {
 
            window.openttd_syncfs_shown_warning = true;
 
            Module.onWarningFs();
 
        }
 
            if (callback) callback();
 
        });
 
    }
 

	
 
    window.openttd_exit = function() {
 
        Module.onExit();
 
        window.openttd_syncfs(Module.onExit);
 
    }
 

	
 
    window.openttd_abort = function() {
 
        Module.onAbort();
 
        window.openttd_syncfs(Module.onAbort);
 
    }
 

	
 
    window.openttd_server_list = function() {
 
        add_server = Module.cwrap("em_openttd_add_server", null, ["string"]);
 

	
 
        /* Add servers that support WebSocket here. Examples:
 
         *  add_server("localhost");
 
         *  add_server("localhost:3979");
 
         *  add_server("127.0.0.1:3979");
 
         *  add_server("[::1]:3979");
 
         */
 
    }
src/openttd.cpp
Show inline comments
 
@@ -109,25 +109,24 @@ NewGRFScanCallback *_request_newgrf_scan
 
 * @note Does NEVER return.
 
 */
 
void UserErrorI(const std::string &str)
 
{
 
	ShowOSErrorBox(str.c_str(), false);
 
	if (VideoDriver::GetInstance() != nullptr) VideoDriver::GetInstance()->Stop();
 

	
 
#ifdef __EMSCRIPTEN__
 
	emscripten_exit_pointerlock();
 
	/* In effect, the game ends here. As emscripten_set_main_loop() caused
 
	 * the stack to be unwound, the code after MainLoop() in
 
	 * openttd_main() is never executed. */
 
	EM_ASM(if (window["openttd_syncfs"]) openttd_syncfs());
 
	EM_ASM(if (window["openttd_abort"]) openttd_abort());
 
#endif
 

	
 
	exit(1);
 
}
 

	
 
/**
 
 * Error handling for fatal non-user errors.
 
 * @param str the string to print.
 
 * @note Does NEVER return.
 
 */
 
void FatalErrorI(const std::string &str)
src/video/sdl2_v.cpp
Show inline comments
 
@@ -606,25 +606,24 @@ void VideoDriver_SDL_Base::LoopOnce()
 
		 * cancel call), but we still have to call the cleanup that is
 
		 * normally done at the end of the main loop for non-Emscripten.
 
		 * After that, Emscripten just halts, and the HTML shows a nice
 
		 * "bye, see you next time" message. */
 
		extern void PostMainLoop();
 
		PostMainLoop();
 

	
 
		emscripten_cancel_main_loop();
 
		emscripten_exit_pointerlock();
 
		/* In effect, the game ends here. As emscripten_set_main_loop() caused
 
		 * the stack to be unwound, the code after MainLoop() in
 
		 * openttd_main() is never executed. */
 
		EM_ASM(if (window["openttd_syncfs"]) openttd_syncfs());
 
		EM_ASM(if (window["openttd_exit"]) openttd_exit());
 
#endif
 
		return;
 
	}
 

	
 
	this->Tick();
 

	
 
/* Emscripten is running an event-based mainloop; there is already some
 
 * downtime between each iteration, so no need to sleep. */
 
#ifndef __EMSCRIPTEN__
 
	this->SleepTillNextTick();
 
#endif
0 comments (0 inline, 0 general)