diff options
author | Patric Stout <truebrain@openttd.org> | 2021-02-24 15:22:23 +0100 |
---|---|---|
committer | Patric Stout <github@truebrain.nl> | 2021-03-08 19:18:55 +0100 |
commit | e56d2c63c306dd087de26088729d09233b1122c2 (patch) | |
tree | dfebf7ee7f39a113b22d696a01bb5b1eefd72d42 /src/video/win32_v.cpp | |
parent | 3a4a15cc93015ce5bed4f7720d4f0f05178c09e9 (diff) | |
download | openttd-e56d2c63c306dd087de26088729d09233b1122c2.tar.xz |
Add: [Video] move GameLoop into its own thread
This allows drawing to happen while the GameLoop is doing an
iteration too.
Sadly, not much drawing currently can be done while the GameLoop
is running, as for example PollEvent() or UpdateWindows() can
influence the game-state. As such, they first need to acquire a
lock on the game-state before they can be called.
Currently, the main advantage is the time spend in Paint(), which
for non-OpenGL drivers can be a few milliseconds. For OpenGL this
is more like 0.05 milliseconds; in these instances this change
doesn't add any benefits for now.
This is an alternative to the former "draw-thread", which moved
the drawing in a thread for some OSes. It has similar performance
gain as this does, although this implementation allows for more
finer control over what suffers when the GameLoop takes too
long: drawing or the next GameLoop. For now they both suffer
equally.
Diffstat (limited to 'src/video/win32_v.cpp')
-rw-r--r-- | src/video/win32_v.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 894d1e05d..8030380ce 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -864,12 +864,16 @@ bool VideoDriver_Win32Base::PollEvent() void VideoDriver_Win32Base::MainLoop() { + this->StartGameThread(); + for (;;) { if (_exit_game) break; this->Tick(); this->SleepTillNextTick(); } + + this->StopGameThread(); } void VideoDriver_Win32Base::ClientSizeChanged(int w, int h, bool force) @@ -995,6 +999,8 @@ const char *VideoDriver_Win32GDI::Start(const StringList ¶m) MarkWholeScreenDirty(); + this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread"); + return nullptr; } @@ -1115,13 +1121,7 @@ void VideoDriver_Win32GDI::Paint() break; case Blitter::PALETTE_ANIMATION_BLITTER: { - bool need_buf = _screen.dst_ptr == nullptr; - if (need_buf) _screen.dst_ptr = this->GetVideoPointer(); blitter->PaletteAnimate(_local_palette); - if (need_buf) { - this->ReleaseVideoPointer(); - _screen.dst_ptr = nullptr; - } break; } @@ -1291,6 +1291,8 @@ const char *VideoDriver_Win32OpenGL::Start(const StringList ¶m) MarkWholeScreenDirty(); + this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread"); + return nullptr; } @@ -1371,6 +1373,11 @@ bool VideoDriver_Win32OpenGL::AfterBlitterChange() return true; } +void VideoDriver_Win32OpenGL::PopulateSystemSprites() +{ + OpenGLBackend::Get()->PopulateCursorCache(); +} + void VideoDriver_Win32OpenGL::ClearSystemSprites() { OpenGLBackend::Get()->ClearCursorCache(); |