From 161b58863144b9677ce8d8cdce0f23be33ddab49 Mon Sep 17 00:00:00 2001 From: rubidium Date: Sat, 19 Apr 2008 10:18:38 +0000 Subject: (svn r12784) -Codechange: handle the asynchronious save 'handlers' in saveload.cpp instead of openttd.cpp. --- src/openttd.cpp | 38 ++------------------------------------ 1 file changed, 2 insertions(+), 36 deletions(-) (limited to 'src/openttd.cpp') diff --git a/src/openttd.cpp b/src/openttd.cpp index ae7b0ced5..bc12123df 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -92,6 +92,7 @@ void DoPaletteAnimations(); void MusicLoop(); void ResetMusic(); void ResetOldNames(); +void ProcessAsyncSaveFinish(); extern void SetDifficultyLevel(int mode, GameOptions *gm_opt); extern Player* DoStartupNewPlayer(bool is_ai); @@ -645,39 +646,6 @@ void HandleExitGameRequest() } } - -/** Mutex so that only one thread can communicate with the main program - * at any given time */ -static ThreadMsg _message = MSG_OTTD_NO_MESSAGE; - -static inline void OTTD_ReleaseMutex() {_message = MSG_OTTD_NO_MESSAGE;} -static inline ThreadMsg OTTD_PollThreadEvent() {return _message;} - -/** Called by running thread to execute some action in the main game. - * It will stall as long as the mutex is not freed (handled) by the game */ -void OTTD_SendThreadMessage(ThreadMsg msg) -{ - if (_exit_game) return; - while (_message != MSG_OTTD_NO_MESSAGE) CSleep(10); - - _message = msg; -} - - -/** Handle the user-messages sent to us - * @param message message sent - */ -static void ProcessSentMessage(ThreadMsg message) -{ - switch (message) { - case MSG_OTTD_SAVETHREAD_DONE: SaveFileDone(); break; - case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break; - default: NOT_REACHED(); - } - - OTTD_ReleaseMutex(); // release mutex so that other threads, messages can be handled -} - static void ShowScreenshotResult(bool b) { if (b) { @@ -1095,9 +1063,7 @@ static void HandleKeyScrolling() void GameLoop() { - ThreadMsg message; - - if ((message = OTTD_PollThreadEvent()) != 0) ProcessSentMessage(message); + ProcessAsyncSaveFinish(); /* autosave game? */ if (_do_autosave) { -- cgit v1.2.3-70-g09d2