Commit Graph

587 Commits (b284d34277f1ffa6e23ec21c557e13897ab508a8)

Author SHA1 Message Date
Patric Stout f183ded9fe Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.

(cherry picked from commit c3dc27e37e)

# Conflicts:
#	src/gfx.cpp
#	src/gfx_func.h
#	src/settings_type.h
#	src/video/cocoa/cocoa_v.mm
#	src/video/video_driver.cpp
#	src/video/win32_v.cpp
3 years ago
Patric Stout 535fdb5c89 Codechange: remove _realtime_tick variable
(cherry picked from commit fe451b8dc7)

# Conflicts:
#	src/debug.cpp
#	src/debug.h
#	src/video/video_driver.cpp
3 years ago
Jonathan G Rennison d58989f552 Merge branch 'master' into jgrpp
# Conflicts:
#	src/lang/english_US.txt
3 years ago
Michael Lutz af4d32357c Codechange: [Win32] Move common initialization and finalization to the video driver base class. 3 years ago
Michael Lutz 78b8fc3e4f Codechange: [Win32] Move GDI-specific variables and related functions into the GDI video driver class. 3 years ago
Michael Lutz 8b90d4abe0 Codechange: [Win32] Move GDI specific drawing code into the GDI video driver class. 3 years ago
Michael Lutz 59e0d9618b Codechange: [Win32] Split the video driver into a base class and a GDI backend class. 3 years ago
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?
3 years ago
Jonathan G Rennison 1c1d272b57 Merge branch 'master' into jgrpp 3 years ago
Patric Stout 88959f5595
Codechange: [OSX] remove final bits of old debugging code (#8714) 3 years ago
Jonathan G Rennison dfecdf3afb Merge branch 'master' into jgrpp
# Conflicts:
#	src/dock_gui.cpp
#	src/rail_gui.cpp
#	src/road_gui.cpp
#	src/terraform_gui.cpp
#	src/vehicle.cpp
#	src/video/allegro_v.cpp
#	src/video/cocoa/cocoa_v.mm
#	src/video/dedicated_v.cpp
#	src/video/sdl2_v.cpp
#	src/video/sdl_v.cpp
#	src/video/win32_v.cpp
3 years ago
Patric Stout e1b1608dc6
Fix ec1dd0bf: missing override causing compiler warnings (#8708) 3 years ago
Michael Lutz d16dc22fdf Codechange: Use C++-ism for zeroing. 3 years ago
Michael Lutz 5ca979b1e2 Fix: [OSX] Don't wait on the event loop for drawing. 3 years ago
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.
3 years ago
Patric Stout 058f13bdf9 Remove: [SDL] SDL 1.3 never happened, so remove all the special code for it 3 years ago
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.
3 years ago
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.
3 years ago
Patric Stout 23d6f4eac9 Codechange: [Win32] simplify when/where GdiFlush() is called 3 years ago
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.
3 years ago
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.
3 years ago
Patric Stout 761efbb457 Codechange: use (Un)LockVideoBuffer() to manage video buffer 3 years ago
Patric Stout 661eb39ecc Codechange: move all input-handling of video-drivers into InputLoop 3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
Jonathan G Rennison e95216b59d Merge branch 'master' into jgrpp
# Conflicts:
#	src/company_cmd.cpp
#	src/core/geometry_func.cpp
#	src/date.cpp
#	src/genworld_gui.cpp
#	src/gfx.cpp
#	src/object_gui.cpp
#	src/openttd.cpp
#	src/settings_type.h
#	src/video/allegro_v.cpp
#	src/video/dedicated_v.cpp
#	src/video/null_v.cpp
#	src/video/sdl2_v.cpp
#	src/video/sdl_v.cpp
#	src/video/win32_v.cpp
3 years ago
Patric Stout 932abe6d5c Fix fa170b9: [SDL2] forgot to use GetGameInterval where needed 3 years ago
Patric Stout 15a0ac2735 Fix cd4f0f95: [Allegro] driver failed to build because of missing include 3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
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.
3 years ago
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).
3 years ago
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.
3 years ago
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.
3 years ago
milek7 751f595bb6 Fix: VkMapping declarations violated C++ ODR rule. 3 years ago
Michael Lutz 8d780e0607 Add: [OSX] Automatic zoom level suggestion for Cocoa video driver. 3 years ago
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.
3 years ago
Michael Lutz 22f5aeab07 Feature: Automatic UI and font zoom levels when supported by the OS. 3 years ago
Michael Lutz f5555a6d26 Fix 9c872192: [OSX] Clear mouse button emulation flag. 3 years ago
Michael Lutz e5c3253642 Add: [OSX] Setting to disable HiDPI graphics rendering. 3 years ago
Michael Lutz 0fc763bc55 Change: [OSX] Render screen in full native resolution on HiDPI displays. 3 years ago
Michael Lutz 8906e9e0fd Codechange: Consistently use screen size and not driver resolution for determining window sizes. 3 years ago
Michael Lutz acca56b6a5 Cleanup: [OSX] Improve some comments. 3 years ago
Michael Lutz c78e559e88 Codechange: [OSX] Remove unused 'app active' flag. 3 years ago
Michael Lutz 9c8721922b Fix: [OSX] An emulated right mouse down event has to be followed by right mouse up. 3 years ago
Michael Lutz 649ff5f9f9 Codechange: [OSX] Use relative mouse handling during scrolling. 3 years ago