Changeset - r27842:f010c32f7293
[Not reviewed]
master
0 2 0
Patric Stout - 10 months ago 2023-08-31 09:10:11
truebrain@openttd.org
Fix: [Emscripten] config not saved on exit game (#11248)

When changing a Game Option and pressing Exit Game, the changes
were not actually stored. This because the post-mainloop code
was never executed for Emscripten.
2 files changed with 20 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/openttd.cpp
Show inline comments
 
@@ -456,12 +456,28 @@ struct AfterNewGRFScan : NewGRFScanCallb
 

	
 
		/* After the scan we're not used anymore. */
 
		delete this;
 
	}
 
};
 

	
 
void PostMainLoop()
 
{
 
	WaitTillSaved();
 

	
 
	/* only save config if we have to */
 
	if (_save_config) {
 
		SaveToConfig();
 
		SaveHotkeysToConfig();
 
		WindowDesc::SaveToConfig();
 
		SaveToHighScore();
 
	}
 

	
 
	/* Reset windowing system, stop drivers, free used memory, ... */
 
	ShutdownGame();
 
}
 

	
 
#if defined(UNIX)
 
extern void DedicatedFork();
 
#endif
 

	
 
/** Options of OpenTTD. */
 
static const OptionData _options[] = {
 
@@ -782,24 +798,13 @@ int openttd_main(int argc, char *argv[])
 

	
 
	/* ScanNewGRFFiles now has control over the scanner. */
 
	RequestNewGRFScan(scanner.release());
 

	
 
	VideoDriver::GetInstance()->MainLoop();
 

	
 
	WaitTillSaved();
 

	
 
	/* only save config if we have to */
 
	if (_save_config) {
 
		SaveToConfig();
 
		SaveHotkeysToConfig();
 
		WindowDesc::SaveToConfig();
 
		SaveToHighScore();
 
	}
 

	
 
	/* Reset windowing system, stop drivers, free used memory, ... */
 
	ShutdownGame();
 
	PostMainLoop();
 
	return ret;
 
}
 

	
 
void HandleExitGameRequest()
 
{
 
	if (_game_mode == GM_MENU || _game_mode == GM_BOOTSTRAP) { // do not ask to quit on the main screen
src/video/sdl2_v.cpp
Show inline comments
 
@@ -604,12 +604,15 @@ void VideoDriver_SDL_Base::LoopOnce()
 
		/* Emscripten is event-driven, and as such the main loop is inside
 
		 * the browser. So if _exit_game goes true, the main loop ends (the
 
		 * 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());
0 comments (0 inline, 0 general)