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.
This commit is contained in:

committed by
Patric Stout

parent
098d5b2239
commit
970fedd78c
@@ -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();
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -179,6 +179,8 @@ public:
|
||||
this->change_blitter = new_blitter;
|
||||
}
|
||||
|
||||
void GameLoopPause();
|
||||
|
||||
/**
|
||||
* Get the currently active instance of the video driver.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user