summaryrefslogtreecommitdiff
path: root/src/genworld_gui.cpp
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/genworld_gui.cpp
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/genworld_gui.cpp')
-rw-r--r--src/genworld_gui.cpp26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp
index bf4d327a7..f26d43ac3 100644
--- a/src/genworld_gui.cpp
+++ b/src/genworld_gui.cpp
@@ -29,6 +29,7 @@
#include "error.h"
#include "newgrf_townname.h"
#include "townname_type.h"
+#include "video/video_driver.hpp"
#include "widgets/genworld_widget.h"
@@ -1312,10 +1313,10 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
static_assert(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
assert(cls < GWP_CLASS_COUNT);
- /* Do not run this function if we aren't in a thread */
- if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
-
- if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
+ if (IsGeneratingWorldAborted()) {
+ HandleGeneratingWorldAbortion();
+ return;
+ }
if (total == 0) {
assert(_gws.cls == _generation_class_table[cls]);
@@ -1328,10 +1329,6 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
_gws.percent = percent_table[cls];
}
- /* Don't update the screen too often. So update it once in every once in a while... */
- if (!_network_dedicated && std::chrono::steady_clock::now() < _gws.next_update) return;
- _gws.next_update = std::chrono::steady_clock::now() + std::chrono::milliseconds(MODAL_PROGRESS_REDRAW_TIMEOUT);
-
/* Percentage is about the number of completed tasks, so 'current - 1' */
_gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
@@ -1350,21 +1347,12 @@ static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uin
DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
last_percent = _gws.percent;
- /* Don't continue as dedicated never has a thread running */
return;
}
SetWindowDirty(WC_MODAL_PROGRESS, 0);
- MarkWholeScreenDirty();
-
- /* Release the rights to the map generator, and acquire the rights to the
- * paint thread. The 'other' thread already has the paint thread rights so
- * this ensures us that we are waiting until the paint thread is done
- * before we reacquire the mapgen rights */
- _modal_progress_work_mutex.unlock();
- _modal_progress_paint_mutex.lock();
- _modal_progress_work_mutex.lock();
- _modal_progress_paint_mutex.unlock();
+
+ VideoDriver::GetInstance()->GameLoopPause();
}
/**