Commit Graph

623 Commits (36e22f3a7bc0f86c650a293e2f624ac5ddfffa84)

Author SHA1 Message Date
Milek7 20762f9117
Codechange: Acquire video buffer before taking game state lock to prevent erratic fast forward behaviour (#9140) 3 years ago
Michael Lutz 91b8ce073f Codechange: Generalise the delayed blitter change to a generic video driver command queue. 3 years ago
Peter Nelson 4791ff2862 Fix: Recalculate padding and minimum sizes when GUI or Font zoom is changed. 3 years ago
Michael Lutz f4d5c8d99e
Fix: [OpenGL] Main loop expects to start with the video buffer unmapped. (#9100) 3 years ago
Michael Lutz d1dd997f07 Change: [Win32] Limit the OpenGL video driver to OpenGL 3.2 or newer on Windows. 3 years ago
Michael Lutz ef80baf75c Codechange: [Win32] Try getting an OpenGL 4.5 context first before aiming at 3.2. 3 years ago
Michael Lutz e53313391a Fix: [OpenGL] Check maximum supported texture size against screen resolution. 3 years ago
Michael Lutz 433602b072 Fix #9028: [OpenGL] Clear cursor cache on destroying the OpenGL backend. 4 years ago
Rubidium 468b1c6c5d Fix: [win32] buffer_locked state not initialised, causing _screen.dst_ptr to be potentially not set 4 years ago
Rubidium 8562395413 Fix: [Video] fast forward boolean states not initialised, potentially causing unstoppable fast forward 4 years ago
Rubidium 64e8305874 Fix: [SDL] buffer_locked state not initialised, causing _screen.dst_ptr to be potentially not set 4 years ago
Michael Lutz 5644c00482
Fix: Check for a validly mapped OpenGL screen buffer during driver init. (#9007) 4 years ago
Patric Stout f0f2073006 Feature: allow a toggle to enable/disable vsync
Vsync should be off by default, as for most players it will be
better to play without vsync. Exception exist, mainly people who
play in fullscreen mode.
4 years ago
Jonathan G Rennison 39b7ef31f8 Fix: Data races on cursor state in OpenGL backends 4 years ago
Jonathan G Rennison fbd0a2e65a Fix: Thread unsafe use of sprite cache in OpenGLBackend::DrawMouseCursor
See also: #8870
See also: #8977
4 years ago
Michael Lutz 96d33ab46a Fix #8930: [Win32] Don't handle printable keys on keydown if an edit box is in focus.
Handle printable input only when the matching WM_CHAR message is incoming.
Without an edit box, do the handling in keydown as usual to support hotkeys.
4 years ago
Niels Martin Hansen e0561dbded Fix #8713: Change OTTD2FS and FS2OTTD to return string objects instead of static buffers 4 years ago
Michael Lutz 1cd3a3b070
Fix #8935: [OSX] Crash when clicking 'Save' due to wrongly-threaded OS call. (#8944) 4 years ago
Milek7 7a886cb4d4 Change: Do not disallow persistent buffer mapping on AMD GPUs, as it is actually faster. 4 years ago
Michael Lutz df958dc907 Fix f0f96e31: [OpenGL] Broken window resizing due to invalid buffer pitch on texture creation. 4 years ago
frosch 0230624359
Fix f0f96e31: [OpenGL] warning: comparison of integer expressions of different signedness. (#8881) 4 years ago
Michael Lutz f0f96e3103
Fix #8871: [OpenGL] Initialize all buffers after resize and clear back buffer. (#8877) 4 years ago
Patric Stout 970fedd78c 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.
4 years ago
sean 0464a50ab8
Add: Display refresh rate game option (#8813) 4 years ago
Michael Lutz 436cdf1fc8 Fix #8825: [OpenGL] Don't clear cursor cache from the game loop thread. 4 years ago
Patric Stout 8946b41d20 Fix: ensure switching blitter happens in the main thread
This because video-drivers might need to make changes to their
context, which for most video-drivers has to be done in the same
thread as the window was created; main thread in our case.
4 years ago
Patric Stout e56d2c63c3 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.
4 years ago
Michael Lutz 3a4a15cc93 Codechange: don't set the window position when changing blitter
There really is no need to make an extra call to the OS in
these cases.
4 years ago
Patric Stout b9eac7c6dc Codechange: remove the unused lock around Blitter 4 years ago
Patric Stout 4610aa7ae3 Remove: [Video] no longer draw in a thread
Drawing in a thread is a bit odd, and often leads to surprising
issues. For example, OpenGL would only allow it if you move the
full context to the thread. Which is not always easily done on
all OSes.
In general, the advise is to handle system events and drawing
from the main thread, and do everything else in other threads.
So, let's be more like other games.

Additionally, putting the drawing routine in a thread was only
done for a few targets.

Upcoming commit will move the GameLoop in a thread, which will
work for all targets.
4 years ago
Patric Stout 04db99749b
Fix #8784: using alt+enter didn't update the fullscreen toggle visibly (#8820)
Basically, the window was not invalidated, so it was never redrawn.
This made it look like it wasn't working, but it really was.
4 years ago
Michael Lutz 25656a10cb Fix #8808: [OSX, OpenGL] Crash on switching blitters due to double-mapping the video buffer. 4 years ago
Patric Stout b93d7dd3cb
Add: Option to (dis-)allow accelerated video drivers. (#8819)
The video drivers using the OpenGL backend are currently our only
accelerated drivers. The options defaults to off for macOS builds and
to on everywhere else.

Co-authored-by: Michael Lutz <michi@icosahedron.de>
4 years ago
Michael Lutz c656633bea Fix #8775: [Win32] Don't create the main window when alt-tabbing back into fullscreen. 4 years ago
Michael Lutz b7a44983b4 Fix: [Win32] Original window size was lost when tabbing in and out of fullscreen. 4 years ago
Patric Stout abac4b1758
Fix c4df0f95: bootstrap was only showing a black screen (#8788)
The bootstrap has the _switch_mode to SM_MENU, and never leaves
this mode. Neither is it considered a modal window (while in some
sense it really is). So .. we need to add another "draw anyway"
exception, to make sure bootstrap is being drawn.
4 years ago
Owen Rudge 838fd61f29 Fix: [OSX] Hide dock when entering fullscreen 4 years ago
Patric Stout c3dc27e37e Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.
4 years ago
Michael Lutz d79398a1d5 Fix #8763: [OpenGL] Cursor sprite origin can be negative. 4 years ago
Michael Lutz 77854d561b Fix: [OpenGL] Don't use OpenGL on MESA software renderers.
Performance in this case is worse than not using OpenGL, so just let
OTTD fall back to a different video driver.
4 years ago
Patric Stout 1b5d1d074e
Fix: [SDL2] set GL attributes to get the best GL context possible (#8759) 4 years ago
frosch dfa141818b Fix: OpenGL cursor did not consider sprite offsets of cursor sprites. 4 years ago
Patric Stout fe451b8dc7 Codechange: remove _realtime_tick variable 4 years ago
Michael Lutz 311df31fb1 Codechange: [OpenGL] Load all OpenGL functions dynamically. 4 years ago
Michael Lutz a0c1a3f736 Codechange: [OpenGL] Simplify loading OpenGL extension functions. 4 years ago
Michael Lutz e1e8cc3851
Fix #8734: [OpenGL] Apply palette remap to cursor sprites. (#8742) 4 years ago
Patric Stout 6a8c461e38 Codechange: [OSX] GameLoop is really more like MainLoop
MainLoop() is used to bootstrap OSX, where later a callback is
done to GameLoop() to execute OpenTTD. All other video drivers
don't need that, so what is in GameLoop is in MainLoop for all
other drivers. This is rather confusing. So, instead, name
GameLoop MainLoopReal to be more in sync with the other drivers.
4 years ago
Patric Stout 67d3c6aa71 Codechange: [Video] move InteractiveRandom() to the VideoDriver 4 years ago
Patric Stout c409f45ddd Codechange: [Video] make the prototype of PollEvent() the same for all drivers
Additionally, call it from the draw-tick.
4 years ago
Niels Martin Hansen b427ddce88 Codechange: Switch to explicit wide strings 4 years ago