summaryrefslogtreecommitdiff
path: root/win32.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-06-01 23:08:33 +0000
committerDarkvater <darkvater@openttd.org>2005-06-01 23:08:33 +0000
commita51cfd58b8b61cbe2aba3b7c2c56f903ac39594b (patch)
treec3ceb927825435dc686caebd0cf953aefc9b7aa7 /win32.c
parentf7dcd2e834c28e7b4e4ba6e7833cf79c3b97b335 (diff)
downloadopenttd-a51cfd58b8b61cbe2aba3b7c2c56f903ac39594b.tar.xz
(svn r2391) - Feature: saving games happen in a seperate thread so you no longer will have to wait such a long time (especially handy on bigger maps and multiplayer games). The mouse also changes into the 'ZZZ' state :P. The thread on windows is currently given a little-bit-less-than-normal priority so it should not interfere that much with the gameplay; it will take a bit longer though. Upon the exit of the game any pending saves are waited upon.
- Fix: fixed GetSavegameFormat() so that it takes the best compressor (highest), or a forced one added with the parameter - Open issues: 1. Don't attempt to load a game while saving is in progress, it will kick you back to the intro-screen with only the vast ocean to look at. 2. The server is disabled from threaded-saving, but might be enabled in the future. 3. Current implementation only allows 1 additional running thread. 4. Stupid global variables.....grrr Big thanks for TrueLight and the amazing memorypool :D
Diffstat (limited to 'win32.c')
-rw-r--r--win32.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/win32.c b/win32.c
index a2ef16322..3c02511f8 100644
--- a/win32.c
+++ b/win32.c
@@ -2242,3 +2242,26 @@ bool InsertTextBufferClipboard(Textbuf *tb)
}
return false;
}
+
+static HANDLE hThread;
+
+bool CreateOTTDThread(void *func, void *param)
+{
+ DWORD dwThreadId;
+ hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)func, param, 0, &dwThreadId);
+ SetThreadPriority(hThread, THREAD_PRIORITY_BELOW_NORMAL);
+
+ return (hThread == NULL) ? false : true;
+}
+
+void CloseOTTDThread(void)
+{
+ if (!CloseHandle(hThread)) DEBUG(misc, 0) ("Failed to close thread?...");
+}
+
+void JoinOTTDThread(void)
+{
+ if (hThread == NULL) return;
+
+ WaitForSingleObject(hThread, INFINITE);
+} \ No newline at end of file