summaryrefslogtreecommitdiff
path: root/src/video/opengl.cpp
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/opengl.cpp
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/opengl.cpp')
-rw-r--r--src/video/opengl.cpp23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/video/opengl.cpp b/src/video/opengl.cpp
index 60f2a1bcd..64ea02cf2 100644
--- a/src/video/opengl.cpp
+++ b/src/video/opengl.cpp
@@ -1036,7 +1036,23 @@ void OpenGLBackend::DrawMouseCursor()
_cur_dpi = &_screen;
for (uint i = 0; i < _cursor.sprite_count; ++i) {
SpriteID sprite = _cursor.sprite_seq[i].sprite;
- const Sprite *spr = GetSprite(sprite, ST_NORMAL);
+
+ /* Sprites are cached by PopulateCursorCache(). */
+ if (this->cursor_cache.Contains(sprite)) {
+ const Sprite *spr = GetSprite(sprite, ST_NORMAL);
+
+ this->RenderOglSprite((OpenGLSprite *)this->cursor_cache.Get(sprite)->data, _cursor.sprite_seq[i].pal,
+ _cursor.pos.x + _cursor.sprite_pos[i].x + UnScaleByZoom(spr->x_offs, ZOOM_LVL_GUI),
+ _cursor.pos.y + _cursor.sprite_pos[i].y + UnScaleByZoom(spr->y_offs, ZOOM_LVL_GUI),
+ ZOOM_LVL_GUI);
+ }
+ }
+}
+
+void OpenGLBackend::PopulateCursorCache()
+{
+ for (uint i = 0; i < _cursor.sprite_count; ++i) {
+ SpriteID sprite = _cursor.sprite_seq[i].sprite;
if (!this->cursor_cache.Contains(sprite)) {
Sprite *old = this->cursor_cache.Insert(sprite, (Sprite *)GetRawSprite(sprite, ST_NORMAL, &SimpleSpriteAlloc, this));
@@ -1046,11 +1062,6 @@ void OpenGLBackend::DrawMouseCursor()
free(old);
}
}
-
- this->RenderOglSprite((OpenGLSprite *)this->cursor_cache.Get(sprite)->data, _cursor.sprite_seq[i].pal,
- _cursor.pos.x + _cursor.sprite_pos[i].x + UnScaleByZoom(spr->x_offs, ZOOM_LVL_GUI),
- _cursor.pos.y + _cursor.sprite_pos[i].y + UnScaleByZoom(spr->y_offs, ZOOM_LVL_GUI),
- ZOOM_LVL_GUI);
}
}