summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-03-09 14:53:51 +0100
committerPatric Stout <github@truebrain.nl>2021-03-10 13:41:18 +0100
commit970fedd78cef3f5ef7a26fcaf4fd9db0f6abbe4b (patch)
treeb894a4b222a74f9d8e80832e36bd21d9a16f4f9e /src/video
parent098d5b22395e123e4990b73a2ad7bf703adf068b (diff)
downloadopenttd-970fedd78cef3f5ef7a26fcaf4fd9db0f6abbe4b.tar.xz
Add: make modal windows update more smooth
Basically, modal windows had their own thread-locking for what drawing was possible. This is a bit nonsense now we have a game-thread. And it makes much more sense to do things like NewGRFScan and GenerateWorld in the game-thread, and not in a thread next to the game-thread. This commit changes that: it removes the threads for NewGRFScan and GenerateWorld, and just runs the code in the game-thread. On regular intervals it allows the draw-thread to do a tick, which gives a much smoother look and feel. It does slow down NewGRFScan and GenerateWorld ever so slightly as it spends more time on drawing. But the slowdown is not measureable on my machines (with 700+ NewGRFs / 4kx4k map and a Debug build). Running without a game-thread means NewGRFScan and GenerateWorld are now blocking.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/dedicated_v.cpp14
-rw-r--r--src/video/video_driver.cpp19
-rw-r--r--src/video/video_driver.hpp2
3 files changed, 24 insertions, 11 deletions
diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp
index ea1c14cff..e905a9d2c 100644
--- a/src/video/dedicated_v.cpp
+++ b/src/video/dedicated_v.cpp
@@ -251,19 +251,16 @@ void VideoDriver_Dedicated::MainLoop()
/* If SwitchMode is SM_LOAD_GAME, it means that the user used the '-g' options */
if (_switch_mode != SM_LOAD_GAME) {
StartNewGameWithoutGUI(GENERATE_NEW_SEED);
- SwitchToMode(_switch_mode);
- _switch_mode = SM_NONE;
} else {
- _switch_mode = SM_NONE;
/* First we need to test if the savegame can be loaded, else we will end up playing the
* intro game... */
- if (!SafeLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, GM_NORMAL, BASE_DIR)) {
+ if (SaveOrLoad(_file_to_saveload.name, _file_to_saveload.file_op, _file_to_saveload.detail_ftype, BASE_DIR) == SL_ERROR) {
/* Loading failed, pop out.. */
DEBUG(net, 0, "Loading requested map failed, aborting");
- _networking = false;
+ return;
} else {
/* We can load this game, so go ahead */
- SwitchToMode(SM_LOAD_GAME);
+ _switch_mode = SM_LOAD_GAME;
}
}
@@ -271,11 +268,6 @@ void VideoDriver_Dedicated::MainLoop()
/* Done loading, start game! */
- if (!_networking) {
- DEBUG(net, 0, "Dedicated server could not be started, aborting");
- return;
- }
-
while (!_exit_game) {
if (!_dedicated_forks) DedicatedHandleKeyInput();
diff --git a/src/video/video_driver.cpp b/src/video/video_driver.cpp
index 1b7fc6a4b..bee67e1ea 100644
--- a/src/video/video_driver.cpp
+++ b/src/video/video_driver.cpp
@@ -56,6 +56,25 @@ void VideoDriver::GameThread()
}
}
+/**
+ * Pause the game-loop for a bit, releasing the game-state lock. This allows,
+ * if the draw-tick requested this, the drawing to happen.
+ */
+void VideoDriver::GameLoopPause()
+{
+ /* If we are not called from the game-thread, ignore this request. */
+ if (std::this_thread::get_id() != this->game_thread.get_id()) return;
+
+ this->game_state_mutex.unlock();
+
+ {
+ /* See GameThread() for more details on this lock. */
+ std::lock_guard<std::mutex> lock(this->game_thread_wait_mutex);
+ }
+
+ this->game_state_mutex.lock();
+}
+
/* static */ void VideoDriver::GameThreadThunk(VideoDriver *drv)
{
drv->GameThread();
diff --git a/src/video/video_driver.hpp b/src/video/video_driver.hpp
index 8c2b9d437..7a859565a 100644
--- a/src/video/video_driver.hpp
+++ b/src/video/video_driver.hpp
@@ -179,6 +179,8 @@ public:
this->change_blitter = new_blitter;
}
+ void GameLoopPause();
+
/**
* Get the currently active instance of the video driver.
*/