summaryrefslogtreecommitdiff
path: root/src/video/cocoa
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-02-24 15:22:23 +0100
committerPatric Stout <github@truebrain.nl>2021-03-08 19:18:55 +0100
commite56d2c63c306dd087de26088729d09233b1122c2 (patch)
treedfebf7ee7f39a113b22d696a01bb5b1eefd72d42 /src/video/cocoa
parent3a4a15cc93015ce5bed4f7720d4f0f05178c09e9 (diff)
downloadopenttd-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/cocoa')
-rw-r--r--src/video/cocoa/cocoa_ogl.h2
-rw-r--r--src/video/cocoa/cocoa_ogl.mm7
-rw-r--r--src/video/cocoa/cocoa_v.mm6
3 files changed, 15 insertions, 0 deletions
diff --git a/src/video/cocoa/cocoa_ogl.h b/src/video/cocoa/cocoa_ogl.h
index 9d95cd606..fe8490932 100644
--- a/src/video/cocoa/cocoa_ogl.h
+++ b/src/video/cocoa/cocoa_ogl.h
@@ -33,6 +33,8 @@ public:
void ClearSystemSprites() override;
+ void PopulateSystemSprites() override;
+
bool HasAnimBuffer() override { return true; }
uint8 *GetAnimBuffer() override { return this->anim_buffer; }
diff --git a/src/video/cocoa/cocoa_ogl.mm b/src/video/cocoa/cocoa_ogl.mm
index c75de1e04..8d02428e0 100644
--- a/src/video/cocoa/cocoa_ogl.mm
+++ b/src/video/cocoa/cocoa_ogl.mm
@@ -214,6 +214,8 @@ const char *VideoDriver_CocoaOpenGL::Start(const StringList &param)
this->UpdateVideoModes();
MarkWholeScreenDirty();
+ this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
+
return nullptr;
}
@@ -227,6 +229,11 @@ void VideoDriver_CocoaOpenGL::Stop()
CGLReleaseContext(this->gl_context);
}
+void VideoDriver_CocoaOpenGL::PopulateSystemSprites()
+{
+ OpenGLBackend::Get()->PopulateCursorCache();
+}
+
void VideoDriver_CocoaOpenGL::ClearSystemSprites()
{
CGLSetCurrentContext(this->gl_context);
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm
index 56d559f0d..8d1fd4447 100644
--- a/src/video/cocoa/cocoa_v.mm
+++ b/src/video/cocoa/cocoa_v.mm
@@ -435,6 +435,8 @@ void VideoDriver_Cocoa::InputLoop()
/** Main game loop. */
void VideoDriver_Cocoa::MainLoopReal()
{
+ this->StartGameThread();
+
for (;;) {
@autoreleasepool {
if (_exit_game) {
@@ -447,6 +449,8 @@ void VideoDriver_Cocoa::MainLoopReal()
this->SleepTillNextTick();
}
}
+
+ this->StopGameThread();
}
@@ -558,6 +562,8 @@ const char *VideoDriver_CocoaQuartz::Start(const StringList &param)
this->GameSizeChanged();
this->UpdateVideoModes();
+ this->is_game_threaded = !GetDriverParamBool(param, "no_threads") && !GetDriverParamBool(param, "no_thread");
+
return nullptr;
}