Commit Graph

34 Commits

Author SHA1 Message Date
Peter Nelson 332cbca36e Codechange: Pass std::string_view from drivers instead of char *. 2024-04-10 22:02:04 +01:00
Patric Stout bad31f2d42
Fix #10079: don't render at 1000fps if HW acceleration + vsync is requested but not active (#12067) 2024-02-12 21:39:23 +00:00
Rubidium 0251786f46 Fix: virtual call from constructor
That fills an instance variable that is only read from the Game Options window
and that is overwritten when the video driver is started. Since you cannot get
into the Game Options window without starting the video driver, it is just
pointless and wrong code that would never be noticed by the end user.
2023-01-06 19:34:35 +01:00
Niels Martin Hansen 345dcd3c7b Add: Show current video driver info in Options window 2022-05-03 21:03:30 +02:00
Patric Stout 74186998a2 Codechange: use _cur_palette the same in all the drivers
It was a bit of a mixed bag. With this change, gfx.cpp is in
control who accesses _cur_palette from the video-drivers.
2021-06-26 20:28:05 +02:00
Rubidium 64e8305874 Fix: [SDL] buffer_locked state not initialised, causing _screen.dst_ptr to be potentially not set 2021-04-12 21:14:01 +02:00
sean 0464a50ab8
Add: Display refresh rate game option (#8813) 2021-03-09 10:22:52 +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 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
Michael Lutz 421b599541 Codechange: [SDL2] Split driver in base-part and default backend 2021-02-22 22:16:07 +01:00
Michael Lutz a77b202767 Codechange: [SDL] Move dirty_rect to class scope. 2021-02-22 22:16:07 +01:00
Patric Stout e75858ce5e Codechange: [SDL2] Allow several places to hook into the SDL driver
This allows future subdrivers to use these to manage their
own flow.
2021-02-22 22:16:07 +01:00
Patric Stout 101e394475 Codechange: [SDL2] Move functions and variables to class-scope
This allows future subdrivers to override them.
2021-02-22 22:16:07 +01:00
Patric Stout 0d58bc9384 Codechange: [SDL2] Move SDLSurface code to its own function
This increases readability, and allow future subdrivers to not
use SDLSurface to draw.
2021-02-22 22:16:07 +01:00
Patric Stout 6098811b49 Codechange: [SDL2] Split Start() in a few more functions
This makes it a bit easier to follow what is going on, and
allow future subdrivers to hook into a few of these functions.

Reworked the code slighly while at it, to return early where
possible.
2021-02-22 22:16:07 +01:00
Patric Stout e1b1608dc6
Fix ec1dd0bf: missing override causing compiler warnings (#8708) 2021-02-20 22:14:26 +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
Patric Stout ec1dd0bf61 Codechange: be consistent in what CheckPaletteAnim() does and when it is called
Additionally, make sure this is a class method. Later commits
will make use of this.
2021-02-20 17:08:44 +01:00
Patric Stout 790fa7102e Codechange: be consistent in naming the paint function Paint()
Also move this function to be a class member. This to allow
further deduplicating of code in a later commit.
2021-02-20 17:08:44 +01:00
Patric Stout 761efbb457 Codechange: use (Un)LockVideoBuffer() to manage video buffer 2021-02-20 17:08:44 +01:00
Patric Stout 661eb39ecc Codechange: move all input-handling of video-drivers into InputLoop 2021-02-20 17:08:44 +01:00
Patric Stout c81c6e5eb7 Add: draw the screen at a steady pace, also during fast-forward
During fast-forward, the game was drawing as fast as it could. This
means that the fast-forward was limited also by how fast we could
draw, something that people in general don't expect.

To give an extreme case, if you are fully zoomed out on a busy
map, fast-forward would be mostly limited because of the time it
takes to draw the screen.

By decoupling the draw-tick and game-tick, we can keep the pace
of the draw-tick the same while speeding up the game-tick. To use
the extreme case as example again, if you are fully zoomed out
now, the screen only redraws 33.33 times per second, fast-forwarding
or not. This means fast-forward is much more likely to go at the
same speed, no matter what you are looking at.
2021-02-19 10:43:15 +01:00
Patric Stout 5bfa014505 Codechange: track _realtime_tick more accurate
_realtime_tick was reset every time the diff was calculated. This
means if it would trigger, say, every N.9 milliseconds, it would
after two iterations already drift a millisecond. This adds up
pretty quick.
2021-02-19 10:43:15 +01:00
Patric Stout 25f6851ca1 Codechange: switch all video drivers to std::chrono for keeping time
On all OSes we tested the std::chrono::steady_clock is of a high
enough resolution to do millisecond measurements, which is all we
need.

By accident, this fixes a Win32 driver bug, where we would never
hit our targets, as the resolution of the clock was too low to
do accurate millisecond measurements with (it was ~16ms resolution
instead).
2021-02-19 10:43:15 +01:00
Patric Stout 30e69c518b Codechange: [SDL2] Rework how palette is updated
It now follows more what the Win32 driver does, and has far less
exceptions and special casing.

MakePalette creates the Palette and prepares surface.
UpdatePalette updates the Palette.
CheckPaletteAnim checks if UpdatePalette needs to be called and
  marks the whole screen dirty so DrawSurfaceToScreen will do a
  full redraw.
2021-01-30 21:43:59 +01:00
Patric Stout 19345908cb Codechange: [SDL2] Split away CreateMainWindow from CreateMainSurface
This makes the code a bit more readable, as both intentions are
more clear, and there is less nesting in the main function.
2021-01-30 21:43:59 +01:00
frosch 0e62a398c7
Add: [SDL2] video driver parameter to put OpenTTD on a particular display on start. By default use the display where the mouse cursor is. (#8572) 2021-01-14 23:29:29 +01:00
Michael Lutz fa60c1f8b9
Feature: Choose a sensible window size on a fresh OTTD config file. (#8536) 2021-01-14 21:53:06 +01:00
Patric Stout d15dc9f40f Add: support for emscripten (play-OpenTTD-in-the-browser)
Emscripten compiles to WASM, which can be loaded via
HTML / JavaScript. This allows you to play OpenTTD inside a
browser.

Co-authored-by: milek7 <me@milek7.pl>
2020-12-15 15:46:39 +01:00
Patric Stout 2da07f7615 Codechange: unroll the SDL2 main loop
This commit prepares for the next commit, as Emscripten needs to
have a way to trigger a single iteration of the main loop. To
keep the real changes more clear, this commit only unrolls the
loop, and makes no changes to the logic itself.
2020-12-15 15:46:39 +01:00
Michael Lutz 37bc2f8064 Codechange: Use std::string in the driver and blitter selection code. 2020-05-21 20:02:34 +02:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Jonathan G Rennison a15ace0f5b Fix #7783, Fix #7816: [SDL2] Fix input handling in edit context
In particular this fixes handling of the shift key
2019-11-10 17:58:42 +00:00
nikolas 2d27e8e685 Add #6173: New SDL 2 based video and sound drivers (#7086) 2019-09-19 17:18:50 +02:00