(svn r12784) -Codechange: handle the asynchronious save 'handlers' in saveload.cpp instead of openttd.cpp.

This commit is contained in:
rubidium
2008-04-19 10:18:38 +00:00
parent 1b867382d6
commit 0670ec6ee1
4 changed files with 34 additions and 55 deletions

View File

@@ -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) {