Commit Graph

18 Commits

Author SHA1 Message Date
Patric Stout 0e56a73fb8
Fix: disable hardware acceleration when GPU driver crashed the game last attempt (#10928) 2023-06-04 14:40:17 +00:00
Patric Stout cf865597f8
Fix: don't propagate shift/ctrl state till next game-tick (#9381)
When the game-loop is very slow, it was easily possible to start
the loop with _shift_pressed being false, but end with
_shift_pressed being true. This doesn't hurt the game as such,
but for the user this can be very weird: I pressed "Buy Vehicle",
pressed shift a bit later, and I still get a cost indication.
2021-06-17 20:22:57 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
Milek7 20762f9117
Codechange: Acquire video buffer before taking game state lock to prevent erratic fast forward behaviour (#9140) 2021-05-02 19:10:07 +01:00
Michael Lutz 91b8ce073f Codechange: Generalise the delayed blitter change to a generic video driver command queue. 2021-05-02 17:57:24 +02:00
Peter Nelson 4791ff2862 Fix: Recalculate padding and minimum sizes when GUI or Font zoom is changed. 2021-04-30 17:08:15 +01:00
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.
2021-04-11 14:26:00 +02:00
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.
2021-03-10 13:41:18 +01:00
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.
2021-03-08 19:18:55 +01:00
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.
2021-03-08 19:18:55 +01:00
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.
2021-03-08 19:18:55 +01:00
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>
2021-03-08 15:42:39 +01:00
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.
2021-03-01 23:17:30 +01:00
Patric Stout c3dc27e37e Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.
2021-02-28 18:04:51 +00:00
Patric Stout fe451b8dc7 Codechange: remove _realtime_tick variable 2021-02-27 00:36:14 +01:00
Patric Stout 67d3c6aa71 Codechange: [Video] move InteractiveRandom() to the VideoDriver 2021-02-24 21:58:47 +01:00
Patric Stout c409f45ddd Codechange: [Video] make the prototype of PollEvent() the same for all drivers
Additionally, call it from the draw-tick.
2021-02-24 21:58:47 +01:00
Patric Stout 0e76d965f1 Codechange: deduplicate tick-handlers of all video drivers
They were all identical, so better put this in a single place
hoping it is less likely to break.
2021-02-20 17:08:44 +01:00