summaryrefslogtreecommitdiff
path: root/src/video/sdl2_v.cpp
AgeCommit message (Collapse)Author
2021-02-20Codechange: Use C++-ism for zeroing.Michael Lutz
2021-02-20Codechange: deduplicate tick-handlers of all video driversPatric Stout
They were all identical, so better put this in a single place hoping it is less likely to break.
2021-02-20Codechange: be consistent in what CheckPaletteAnim() does and when it is calledPatric Stout
Additionally, make sure this is a class method. Later commits will make use of this.
2021-02-20Codechange: be consistent in naming the paint function Paint()Patric Stout
Also move this function to be a class member. This to allow further deduplicating of code in a later commit.
2021-02-20Codechange: use (Un)LockVideoBuffer() to manage video bufferPatric Stout
2021-02-20Codechange: move all input-handling of video-drivers into InputLoopPatric Stout
2021-02-19Fix fa170b9: [SDL2] forgot to use GetGameInterval where neededPatric Stout
2021-02-19Fix: during switching of game-mode, drawing could show closed windows that ↵Patric Stout
shouldn't be closed yet The higher your refresh-rate, the more likely this is. Mostly you notice this when creating a new game or when abandoning a game. This is a bit of a hack to keep the old behaviour, as before this patch the game was already freezing your mouse while it was changing game-mode, and it does this too after this patch. Just now it freezes too a few frames earlier, to prevent not drawing windows people still expect to see.
2021-02-19Feature: configurable refresh-rate and change default to 60fpsPatric Stout
Most modern games run on 60 fps, and for good reason. This gives a much smoother experiences. As some people have monitors that can do 144Hz or even 240Hz, allow people to configure the refresh rate. Of course, the higher you set the value, the more time the game spends on drawing pixels instead of simulating the game, which has an effect on simulation speed. The simulation will still always run at 33.33 fps, and is not influences by this setting.
2021-02-19Change: sleep till the next tick in the main loopPatric Stout
Sleep for 1ms (which is always (a lot) more than 1ms) is just randomly guessing and hoping you hit your deadline, give or take. But given we can calculate when our next frame is happening, we can just sleep for that exact amount. As these values are often a bit larger, it is also more likely the OS can schedule us back in close to our requested target. This means it is more likely we hit our deadlines, which makes the FPS a lot more stable.
2021-02-19Change: allow video-drivers to miss deadlines slightlyPatric Stout
Before, every next frame was calculated from the current time. If for some reason the current frame was drifting a bit, the next would too, and the next more, etc etc. This meant we rarely hit the targets we would like, like 33.33fps. Instead, allow video-drivers to drift slightly, and schedule the next frame based on the time the last should have happened. Only if the drift gets too much, that deadlines are missed for longer period of times, schedule the next frame based on the current time. This makes the FPS a lot smoother, as sleeps aren't as exact as you might think.
2021-02-19Add: draw the screen at a steady pace, also during fast-forwardPatric Stout
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-19Codechange: track _realtime_tick more accuratePatric Stout
_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-19Codechange: switch all video drivers to std::chrono for keeping timePatric Stout
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-17Fix: [SDL2] simplify what to redraw to prevent tearing (#8685)Patric Stout
When there are a lot of rects to redraw, of which one of the last ones is almost the full screen, visual tearing happens over the vertical axis. This is most visible when scrolling the map. This can be prevented by using less rects. To simplify the situation, and as solutions like OpenGL need this anyway, keep a single rect that shows the biggest size that updates everything correctly. Although this means it needs a bit more time redrawing where it is strictly seen not needed, it also means less commands have to be executed in the backend. In the end, this is a trade-off, and from experiments it seems the approach of this commit gives a better result.
2021-02-17Fix 52317bb7: [SDL2] ensure we don't try to blit out of bounds (#8684)Patric Stout
During resizing, there can still be dirty-rects ready to blit based on the old dimensions. X11 with shared memory enabled crashes if you try to do this. So, instead, if we resize, reset the dirty-rects. This is fine, as moments later we mark the whole (new) screen as dirty anyway.
2021-02-14Fix: VkMapping declarations violated C++ ODR rule.milek7
2021-02-11Change: [SDL2] Remove unneeded delay of redrawing the screenPatric Stout
In testing, I could find no reason why this statement is here. The comment is rather unclear (it states what it does, but not why it would be needed). This line of code was introduced with f4f40448, which gives no further insight on why it would be needed to have it here. As such, let's remove it and see if anyone else reports any problems with it. If so, this commit can be reverted and a more clear comment should be added what this line of code is dealing with (the WHY, not the WHAT).
2021-02-11Codechange: [SDL2] Don't use globals if we can do with localsPatric Stout
2021-02-11Codechange: [SDL2] Name paint function Paint(), like other drivers doPatric Stout
This reduces confusion when reading different drivers.
2021-02-11Fix 30e69c51: palette was not marked dirty when creating a newPatric Stout
This means the code depended that the caller did this for us before MakePalette() is executed, which is neither a requirement nor a promise the code makes.
2021-02-06Fix #8029: [SDL2] disable draw-thread on wayland SDL video driver (#8648)Patric Stout
When the wayland SDL video driver is used, an EGL context is created in the main thread. It is not allowed to update this context from another thread, which is exactly what our draw-thread is trying. The other solution would be to move all of SDL into the draw-thread, but that would introduce a whole scala of different problems. The wayland SDL backend is significantly faster than the X11 SDL backend, but there is a performance hit nevertheless.
2021-02-05Codechange: Apply coding style (#8640)SamuXarick
* Fix: Missing or needed spaces * Codechange: Remove space * Codechange: Remove space * Codechange: More missing spaces * Codechange: Missing spaces * Codechange: Remove space * Codechange: Remove space
2021-01-30Codechange: [SDL2] Use MakeDirty() to force a redrawPatric Stout
The original code is "strictly correct", but just reads really weird, and we use MakeDirty() in several other places instead too.
2021-01-30Codechange: [SDL2] Rework how palette is updatedPatric Stout
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-30Fix: [SDL2] Display why SDL_CreateWindow() failed in case it doesPatric Stout
All SDL_NNN errors print SDL_GetError, except for this one place.
2021-01-30Codechange: [SDL2] Split away CreateMainWindow from CreateMainSurfacePatric Stout
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-30Codechange: [SDL2] reworked the different surfaces to make it more readablePatric Stout
2021-01-30Codechange: [SDL2] Only prepare "caption" if you are going to us itPatric Stout
2021-01-30Codechange: [SDL2] Minor code cleanup to remove silly variablePatric Stout
2021-01-30Codechange: [SDL2] Only set _cur_palette, never _local_palettePatric Stout
2021-01-30Codechange: [SDL2] Move FindStartupDisplay to its own functionPatric Stout
2021-01-30Codechange: [SDL2] reworked FindResolutions to be more like the restPatric Stout
There was no default resolution fallback, and the code was different from the win32 driver. It is now named the same and much more similar.
2021-01-30Codechange: [SDL2] remove include-protectionPatric Stout
This is already done by CMake: if SDL2 is not detected, this file is not included.
2021-01-17Codechange: [SDL2/Win32] Be consistent how 0bpp blitters are not allowedPatric Stout
Sometimes it returned an usererror(), sometimes Start() failed. Now it always fails on Start(), so nothing else has to check again what blitter is used. AfterBlitterChange() can never change to a 0bpp, so it is sufficient to guard this with an assert().
2021-01-16Fix 0e62a398c7f: Only center the window, when it is smaller than the screen. ↵frosch
(#8581)
2021-01-14Add: [SDL2] video driver parameter to put OpenTTD on a particular display on ↵frosch
start. By default use the display where the mouse cursor is. (#8572)
2021-01-14Feature: Choose a sensible window size on a fresh OTTD config file. (#8536)Michael Lutz
2021-01-08Codechange: Remove min/max functions in favour of STL variants (#8502)Charles Pigott
2020-12-27Codechange: Use std::string in FIO search path handling.Michael Lutz
2020-12-15Add: [Emscripten] use "relative mouse mode" with SDL2Patric Stout
This mode doesn't wrap the mouse constantly, but requests SDL to lock the mouse pointer. This is needed, as with Emscripten you are not allowed to change the mouse poisition (only to lock it into place).
2020-12-15Add: support for emscripten (play-OpenTTD-in-the-browser)Patric Stout
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-15Codechange: unroll the SDL2 main loopPatric Stout
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-06-18Fix #8104: Always add WINDOW_RESIZABLE flag to SDL2 (#8211)nikolas
This fixes a bug that can reproduced with these steps: * Start openttd in fullscreen mode * Turn off fullscreen mode * Try to resize the window. The window can't be resized.
2020-06-04Codechange: Realign SDL driver with SDL2 driver to ease maintenance and ↵TechGeekNZ
emphasise differences.
2020-05-21Codechange: Use std::string in the driver and blitter selection code.Michael Lutz
2020-01-15Fix: [SDL2] Correct name of the video driver in debug logxdavidwu
SDL_GetVideoDriver(0) returns name of first video driver included in the library, not the driver currently used. SDL_GetCurrentVideoDriver() does what we want here.
2019-11-10Cleanup: Removed SVN headersS. D. Cloudt
2019-11-10Fix #7783, Fix #7816: [SDL2] Fix input handling in edit contextJonathan G Rennison
In particular this fixes handling of the shift key
2019-11-10Change: [SDL2] Add an "unprintable" flag to struct VkMappingJonathan G Rennison
SDL_Keysym::sym is not suitable for checking whether the character is printable or not