Commit Graph

625 Commits

Author SHA1 Message Date
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
Niels Martin Hansen b427ddce88 Codechange: Switch to explicit wide strings 2021-02-23 11:25:39 +01:00
Niels Martin Hansen beeb9e0a1b Remove: [Win32] Last pretenses of being able to build for Windows 95 2021-02-23 11:25:39 +01:00
Michael Lutz 06ca147a82 Fix 8706c36f: Change RELEASE code, too. 2021-02-22 23:16:46 +01:00
Michael Lutz 7af1fd3ffb Add: [OSX] OpenGL video driver. 2021-02-22 22:16:07 +01:00
Michael Lutz b4a3bc1ffe Codechange: [OpenGL] Separate context state setup from general init. 2021-02-22 22:16:07 +01:00
Michael Lutz 7f55f0a264 Codechange: [OSX] Add support for (un)locking the video buffer. 2021-02-22 22:16:07 +01:00
Michael Lutz 2f25e9bdf8 Codechange: [OSX] Separate video driver into a base and a Quartz implementation. 2021-02-22 22:16:07 +01:00
Michael Lutz 421b599541 Codechange: [SDL2] Split driver in base-part and default backend 2021-02-22 22:16:07 +01:00
Patric Stout a303940372 Feature: [SDL2] OpenGL support 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
Michael Lutz 86c309ea75 Codechange: [OpenGL] Let OpenGL clear the pixel buffer if possible. 2021-02-22 22:16:07 +01:00
Michael Lutz ae7c63cc35 Codechange: [OpenGL] Use persistently mapped pixel buffers when supported. 2021-02-22 22:16:07 +01:00
Michael Lutz 200be7d20c Add: [OpenGL] Support for a separate animation buffer that stores the palette values of the screen in addition to the colour buffer. 2021-02-22 22:16:07 +01:00
Michael Lutz d62e302768 Change: [Win32] Prioritize the OpenGL video driver over the GDI one. 2021-02-22 22:16:07 +01:00
Michael Lutz 6bcc4884c2 Add: [OpenGL] Accelerated mouse cursor drawing. 2021-02-22 22:16:07 +01:00
Michael Lutz bcd15b4dd2 Codechange: [OpenGL] Initialize backing store to opaque alpha to allow blending effects. 2021-02-22 22:16:07 +01:00
Michael Lutz 3e49aff35c Codechange: Allow video drivers to handle the cursor themselves. 2021-02-22 22:16:07 +01:00
Michael Lutz f94b2e73e1 Codechange: [Win32] Use an OpenGL core context instead of a compatibility one. 2021-02-22 22:16:07 +01:00
Michael Lutz e8fc050b6e Add: [OpenGL] Support for 8bpp blitters. 2021-02-22 22:16:07 +01:00
Michael Lutz 320072c8dc Codechange: [OpenGL] Explicitly assign which framebuffer target receives the colour values. 2021-02-22 22:16:07 +01:00
Michael Lutz 821f30f735 Codechange: [OpenGL] Use GLSL version 1.50 if available. 2021-02-22 22:16:07 +01:00
Michael Lutz 90fd8f8cda Codechange: [OpenGL] Use generic vertex attributes in the shader program. 2021-02-22 22:16:07 +01:00
Michael Lutz acf59f6b68 Codechange: [OpenGL] Use shaders to display the video buffer on screen. 2021-02-22 22:16:07 +01:00
Michael Lutz b181859629 Change: [Win32] Disable VSync for OpenGL by default. 2021-02-22 22:16:07 +01:00
Michael Lutz 9a069faa01 Codechange: [Win32] Try to get an OpenGL 3.2+ context if possible. 2021-02-22 22:16:07 +01:00
Michael Lutz a990c497b5 Codechange: [OpenGL] Use a pixel buffer object to store the video buffer. 2021-02-22 22:16:07 +01:00
Michael Lutz 5af0cfd902 Codechange: [OpenGL] Use a vertex array object to store the vertex state for the video buffer. 2021-02-22 22:16:07 +01:00
Michael Lutz acf2ce35f7 Codechange: [OpenGL] Use a vertex buffer object to store the vertex data for the video buffer. 2021-02-22 22:16:07 +01:00
Michael Lutz 8706c36fc0 Codechange: [Win32] Move remaing global _wnd variables into the video driver. 2021-02-22 22:16:07 +01:00
Michael Lutz d6b6775888 Change: Lock the video buffer when drawing inside the game loop to properly account for threaded drawing. 2021-02-22 22:16:07 +01:00
Michael Lutz 73ed748deb Codechange: [Win32] Move the global video buffer pointer into the driver class. 2021-02-22 22:16:07 +01:00
Michael Lutz 5ad545dcc1 Codechange: [OpenGL] Only update the dirty parts of the video buffer texture. 2021-02-22 22:16:07 +01:00
Michael Lutz 3a77ade6b2 Codechange: [OpenGL] Enable driver debug messages if supported. 2021-02-22 22:16:07 +01:00
Michael Lutz d7b96a424f Codechange: [OpenGL] Use new-style extension testing introduced with OpenGL 3.0. 2021-02-22 22:16:07 +01:00
Michael Lutz ef478ade64 Add: [Win32] Video driver that uses OpenGL to transfer the video buffer to the screen. 2021-02-22 22:16:07 +01:00
Michael Lutz af4d32357c Codechange: [Win32] Move common initialization and finalization to the video driver base class. 2021-02-22 22:16:07 +01:00
Michael Lutz 78b8fc3e4f Codechange: [Win32] Move GDI-specific variables and related functions into the GDI video driver class. 2021-02-22 22:16:07 +01:00
Michael Lutz 8b90d4abe0 Codechange: [Win32] Move GDI specific drawing code into the GDI video driver class. 2021-02-22 22:16:07 +01:00
Michael Lutz 59e0d9618b Codechange: [Win32] Split the video driver into a base class and a GDI backend class. 2021-02-22 22:16:07 +01:00
Patric Stout 78d96dad2a
Fix #6319: [Win32] don't use clipping; draw whole screen every frame (#8726)
When we clip the region that is only been redrawn, something
weird happens on Windows. When pushing 60 frames per second on a
60Hz monitor, it appears that the clipped region is often shown
of another frame, instead of the current.

Examples of this are:
- pause the game, move your mouse to the left, and at the right
  speed it totally disappears.
- fast aircrafts seem to be in several places at once, weirdly
  lagging behind.
- in title screen, moving your mouse gives you the idea it is
  jumping places, instead of smooth movements.

In the end, if you do nothing, everything is correct, so it is
eventually consistent. Just when we are firing many BitBlt in
a clipped region, the in-between is not.

What goes wrong exactly, I honestly do not know. On every frame
that we push to the DC is a mouse painted, but visually it
sometimes appears like it is not. Recording with external software
shows it really is there.
It is also not our eyes playing tricks on us, as the first example
makes it really clear the mouse pointer really is not painted.

And to be clear, with the mouse this is easiest reproduceable,
as high-speed objects are influences by this most. But this happens
for all movement that redraws small regions.

Either way, not using clipped regions resolves the issue completely,
and there appears to be little to no penalty (I failed to measure
any impact of drawing the full screen). So better have a good game
than fast code, I guess?
2021-02-22 21:17:55 +01:00
Patric Stout 88959f5595
Codechange: [OSX] remove final bits of old debugging code (#8714) 2021-02-21 15:58:26 +01:00
Patric Stout e1b1608dc6
Fix ec1dd0bf: missing override causing compiler warnings (#8708) 2021-02-20 22:14:26 +01:00
Michael Lutz d16dc22fdf Codechange: Use C++-ism for zeroing. 2021-02-20 21:14:44 +01:00
Michael Lutz 5ca979b1e2 Fix: [OSX] Don't wait on the event loop for drawing. 2021-02-20 21:14:44 +01:00
Michael Lutz f3c192c63d Codechange: [OSX] Only keep a total dirty rect for drawing.
When drawing an 8bpp screen buffer, palette resolving was done for each
dirty rectangle. In areas with high activity, this would mean a pixel might
have been resolved multiple times. Also, if too many individual updates
were queued, the whole screen would be refreshed, even if unnecessary.

All other drivers only keep one overall dirty rect, so do it here as well.
2021-02-20 21:14:44 +01:00
Patric Stout 058f13bdf9 Remove: [SDL] SDL 1.3 never happened, so remove all the special code for it 2021-02-20 17:08:44 +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 7996fadb91 Change: [Win32] Remove force_full_redraw and display_hz settings
These were special settings only for the win32-drivers, and
introduced in the very first version we track.

Time kinda had caught up with those variables, so it is time to
say farewell.

force_full_redraw was most likely a debug functionality "in case
our dirty-rect fails". This should no longer be needed.

display_hz was cute, as it had a max of 120. That is kinda
out-dated information, but I also doubt anyone was really using
this.
2021-02-20 17:08:44 +01:00
Patric Stout 23d6f4eac9 Codechange: [Win32] simplify when/where GdiFlush() is called 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 38b4ae1c0e Codechange: [Win32] make fast-forward check the same as with other drivers
It was of all the drivers the only one doing this slightly different.
When trying to unify more code, that was rather annoying.
2021-02-20 17:08:44 +01:00
Patric Stout 08821f82b6 Fix: [Win32] run InteractiveRandom() once every tick, not once every message
Win32 was the only video driver doing this. It is just a bit too
much random.
2021-02-20 14:25:56 +01:00
Patric Stout 19fdbac287 Fix: [Win32] now we are drawing on a tick, no longer use WM_PAINT
WM_PAINT hits when-ever Windows feels like, but always after we
marked the screen as dirty. In result, it was lagging behind,
giving a sub-60fps experience.

With the new draw-tick there is no longer a need to be driven by
WM_PAINT, so it is better anyway to drive the drawing ourself. As
an added bonus this makes the win32 driver more like the others.
2021-02-20 14:25:56 +01:00
Patric Stout 932abe6d5c Fix fa170b9: [SDL2] forgot to use GetGameInterval where needed 2021-02-19 11:34:00 +01:00
Patric Stout 15a0ac2735 Fix cd4f0f95: [Allegro] driver failed to build because of missing include 2021-02-19 11:34:00 +01:00
Patric Stout c4df0f95ae Fix: during switching of game-mode, drawing could show closed windows that 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-19 10:43:15 +01:00
Patric Stout fa170b9ace Feature: configurable refresh-rate and change default to 60fps
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-19 10:43:15 +01:00
Patric Stout eb9b1ad68d Change: sleep till the next tick in the main loop
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-19 10:43:15 +01:00
Patric Stout ae7a2b9f02 Change: allow video-drivers to miss deadlines slightly
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-19 10:43:15 +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 8e0d48a0f6
Fix: [SDL2] simplify what to redraw to prevent tearing (#8685)
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-17 21:19:32 +01:00
Patric Stout 6de188d025
Fix 52317bb7: [SDL2] ensure we don't try to blit out of bounds (#8684)
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-17 14:06:12 +01:00
milek7 751f595bb6 Fix: VkMapping declarations violated C++ ODR rule. 2021-02-14 23:19:50 +01:00
Michael Lutz 8d780e0607 Add: [OSX] Automatic zoom level suggestion for Cocoa video driver. 2021-02-14 14:16:40 +01:00
Michael Lutz f175e38666 Add: [Win32] Automatic zoom level suggestion for Win32 video driver.
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-14 14:16:40 +01:00
Michael Lutz 22f5aeab07 Feature: Automatic UI and font zoom levels when supported by the OS. 2021-02-14 14:16:40 +01:00
Michael Lutz f5555a6d26 Fix 9c872192: [OSX] Clear mouse button emulation flag. 2021-02-14 12:58:45 +01:00
Michael Lutz e5c3253642 Add: [OSX] Setting to disable HiDPI graphics rendering. 2021-02-14 11:50:18 +01:00
Michael Lutz 0fc763bc55 Change: [OSX] Render screen in full native resolution on HiDPI displays. 2021-02-14 11:50:18 +01:00
Michael Lutz 8906e9e0fd Codechange: Consistently use screen size and not driver resolution for determining window sizes. 2021-02-14 11:50:18 +01:00
Michael Lutz acca56b6a5 Cleanup: [OSX] Improve some comments. 2021-02-13 22:21:17 +01:00
Michael Lutz c78e559e88 Codechange: [OSX] Remove unused 'app active' flag. 2021-02-13 22:21:17 +01:00
Michael Lutz 9c8721922b Fix: [OSX] An emulated right mouse down event has to be followed by right mouse up. 2021-02-13 22:21:17 +01:00
Michael Lutz 649ff5f9f9 Codechange: [OSX] Use relative mouse handling during scrolling. 2021-02-13 22:21:17 +01:00
Michael Lutz 43326d11d8 Change: [OSX] Use a layer-backed view to speed up drawing. 2021-02-13 22:21:17 +01:00
Michael Lutz 2a8c3a2cf6 Codechange: [OSX] Align backing buffer pitch for a tiny bit performance. 2021-02-13 22:21:17 +01:00
Michael Lutz 94b76ce9a4 Cleanup: [OSX] Move event loop into video driver file. 2021-02-13 22:21:17 +01:00
Michael Lutz 23389e9491 Remove: [OSX] Startup splash screen.
It wasn't displayed anyway as it was never copied to the bundle.
2021-02-13 22:21:17 +01:00
Michael Lutz 063b90b97d Codechange: [OSX] Move key event handling to our view. 2021-02-13 22:21:17 +01:00
Michael Lutz f4bd54fedd Codechange: [OSX] Move mouse event handling to our NSView. 2021-02-13 22:21:17 +01:00
Michael Lutz bd42fc94cc Codechange: [OSX] Move some things from video driver to our NSView. 2021-02-13 22:21:17 +01:00
Michael Lutz 965ce12947 Codechange: [OSX] Use newer mouse tracking API. 2021-02-13 22:21:17 +01:00
Michael Lutz 42af13c141 Codechange: [OSX] Split drawing into its own subview.
This allows the drawing backend code to be independent
of any event or command handling.
2021-02-13 22:21:17 +01:00
Michael Lutz 60f30036f1 Codechange: [OSX] Drain autoreleased objects in each game loop cycle. 2021-02-13 22:21:17 +01:00
Michael Lutz 8aaf4ea098 Codechange: [OSX] Split Window and back buffer creation in Cocoa video driver. 2021-02-13 22:21:17 +01:00
Michael Lutz 0eff7de659 Cleanup: [OSX] Doxygen comment style in video driver. 2021-02-13 22:21:17 +01:00
Michael Lutz 8ced72ab10 Codechange: [OSX] Inline some functions that are used in only one place. 2021-02-13 22:21:17 +01:00
Michael Lutz 13134f9d64 Codechange: [OSX] Replace #define with modern code. 2021-02-13 22:21:17 +01:00
Michael Lutz 88f6c7a9f3 Codechange: [OSX] Fold remaining Cocoa video subdriver into the main driver. 2021-02-13 22:21:17 +01:00
Michael Lutz e6bea3961f Change: [OSX] Replace screen resolution list with suggested window sizes.
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-13 22:21:17 +01:00