summaryrefslogtreecommitdiff
path: root/saveload.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-09-02 16:05:59 +0000
committerDarkvater <darkvater@openttd.org>2005-09-02 16:05:59 +0000
commita181446829c3de933ccccffcc652c0c7b19f9968 (patch)
tree770995fa006874ecf7f11983a589bd239a3e85a0 /saveload.c
parentae356b641d0b208e7973ce9c30472909b75fb9af (diff)
downloadopenttd-a181446829c3de933ccccffcc652c0c7b19f9968.tar.xz
(svn r2906) Fix some threaded saving problems. Now the thread only interfaces with the main program through a sort of mutex. Communication uses the function OTTD_SendThreadMessage() with the approiate message which is handled in ProcessSentMessage() during the main loop.
Diffstat (limited to 'saveload.c')
-rw-r--r--saveload.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/saveload.c b/saveload.c
index cf525e561..88c8a69c4 100644
--- a/saveload.c
+++ b/saveload.c
@@ -1255,7 +1255,7 @@ static inline SaveOrLoadResult AbortSaveLoad(void)
/** Update the gui accordingly when starting saving
* and set locks on saveload. Also turn off fast-forward cause with that
* saving takes Aaaaages */
-static inline void SaveFileStart(void)
+void SaveFileStart(void)
{
_ts.ff_state = _fast_forward;
_fast_forward = false;
@@ -1267,7 +1267,7 @@ static inline void SaveFileStart(void)
/** Update the gui accordingly when saving is done and release locks
* on saveload */
-static inline void SaveFileDone(void)
+void SaveFileDone(void)
{
_fast_forward = _ts.ff_state;
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE);
@@ -1276,10 +1276,17 @@ static inline void SaveFileDone(void)
_ts.saveinprogress = false;
}
+/** Show a gui message when saving has failed */
+void SaveFileError(void)
+{
+ ShowErrorMessage(STR_4007_GAME_SAVE_FAILED, STR_NULL, 0, 0);
+ SaveFileDone();
+}
+
/** We have written the whole game into memory, _save_pool, now find
* and appropiate compressor and start writing to file.
*/
-static void* SaveFileToDisk(void* arg)
+static void* SaveFileToDisk(void *arg)
{
const SaveLoadFormat *fmt = GetSavegameFormat(_savegame_format);
/* XXX - backup _sl.buf cause it is used internally by the writer
@@ -1287,6 +1294,8 @@ static void* SaveFileToDisk(void* arg)
static byte *tmp = NULL;
uint32 hdr[2];
+ OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_START);
+
tmp = _sl.buf;
/* XXX - Setup setjmp error handler if an error occurs anywhere deep during
@@ -1297,9 +1306,7 @@ static void* SaveFileToDisk(void* arg)
_sl.excpt_uninit();
ShowInfoF("Save game failed: %s.", _sl.excpt_msg);
- ShowErrorMessage(STR_4007_GAME_SAVE_FAILED, STR_NULL, 0, 0);
-
- SaveFileDone();
+ OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_ERROR);
return NULL;
}
@@ -1334,7 +1341,7 @@ static void* SaveFileToDisk(void* arg)
GetSavegameFormat("memory")->uninit_write(); // clean the memorypool
fclose(_sl.fh);
- SaveFileDone();
+ OTTD_SendThreadMessage(MSG_OTTD_SAVETHREAD_DONE);
return NULL;
}
@@ -1405,10 +1412,10 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
if (mode == SL_LOAD) {
ShowInfoF("Load game failed: %s.", _sl.excpt_msg);
return SL_REINIT;
- } else {
- ShowInfoF("Save game failed: %s.", _sl.excpt_msg);
- return SL_ERROR;
}
+
+ ShowInfoF("Save game failed: %s.", _sl.excpt_msg);
+ return SL_ERROR;
}
/* We first initialize here to avoid: "warning: variable `version' might
@@ -1434,7 +1441,6 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode)
SlWriteFill(); // flush the save buffer
/* Write to file */
- SaveFileStart();
if (_network_server ||
(save_thread = OTTDCreateThread(&SaveFileToDisk, NULL)) == NULL) {
DEBUG(misc, 1) ("cannot create savegame thread, reverting to single-threaded mode...");