summaryrefslogtreecommitdiff
path: root/src/video
AgeCommit message (Collapse)Author
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-14Add: [OSX] Automatic zoom level suggestion for Cocoa video driver.Michael Lutz
2021-02-14Add: [Win32] Automatic zoom level suggestion for Win32 video driver.Michael Lutz
The zoom level suggestion is based on the DPI scaling set in Windows. We use 150% scaling as the threshold for 2X zoom and 300% scaling as the threshold for 4X zoom.
2021-02-14Feature: Automatic UI and font zoom levels when supported by the OS.Michael Lutz
2021-02-14Fix 9c872192: [OSX] Clear mouse button emulation flag.Michael Lutz
2021-02-14Add: [OSX] Setting to disable HiDPI graphics rendering.Michael Lutz
2021-02-14Change: [OSX] Render screen in full native resolution on HiDPI displays.Michael Lutz
2021-02-14Codechange: Consistently use screen size and not driver resolution for ↵Michael Lutz
determining window sizes.
2021-02-13Cleanup: [OSX] Improve some comments.Michael Lutz
2021-02-13Codechange: [OSX] Remove unused 'app active' flag.Michael Lutz
2021-02-13Fix: [OSX] An emulated right mouse down event has to be followed by right ↵Michael Lutz
mouse up.
2021-02-13Codechange: [OSX] Use relative mouse handling during scrolling.Michael Lutz
2021-02-13Change: [OSX] Use a layer-backed view to speed up drawing.Michael Lutz
2021-02-13Codechange: [OSX] Align backing buffer pitch for a tiny bit performance.Michael Lutz
2021-02-13Cleanup: [OSX] Move event loop into video driver file.Michael Lutz
2021-02-13Remove: [OSX] Startup splash screen.Michael Lutz
It wasn't displayed anyway as it was never copied to the bundle.
2021-02-13Codechange: [OSX] Move key event handling to our view.Michael Lutz
2021-02-13Codechange: [OSX] Move mouse event handling to our NSView.Michael Lutz
2021-02-13Codechange: [OSX] Move some things from video driver to our NSView.Michael Lutz
2021-02-13Codechange: [OSX] Use newer mouse tracking API.Michael Lutz
2021-02-13Codechange: [OSX] Split drawing into its own subview.Michael Lutz
This allows the drawing backend code to be independent of any event or command handling.
2021-02-13Codechange: [OSX] Drain autoreleased objects in each game loop cycle.Michael Lutz
2021-02-13Codechange: [OSX] Split Window and back buffer creation in Cocoa video driver.Michael Lutz
2021-02-13Cleanup: [OSX] Doxygen comment style in video driver.Michael Lutz
2021-02-13Codechange: [OSX] Inline some functions that are used in only one place.Michael Lutz
2021-02-13Codechange: [OSX] Replace #define with modern code.Michael Lutz
2021-02-13Codechange: [OSX] Fold remaining Cocoa video subdriver into the main driver.Michael Lutz
2021-02-13Change: [OSX] Replace screen resolution list with suggested window sizes.Michael Lutz
We never change the real screen resolution on OSX. As such, offering a list of resolutions is pointless. Instead of that, offer the user a list of commonly used window sizes up to the current screen size.
2021-02-13Codechange: [OSX] There is only one subdriver left, remove virtual dispatch.Michael Lutz
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