Commit Graph

120 Commits (421b599541069318817bd0e0768984a662a84753)

Author SHA1 Message Date
Patric Stout 88959f5595
Codechange: [OSX] remove final bits of old debugging code (#8714) 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 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 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 661eb39ecc Codechange: move all input-handling of video-drivers into InputLoop 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
Michael Lutz 8d780e0607 Add: [OSX] Automatic zoom level suggestion for Cocoa video driver. 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 43326d11d8 Change: [OSX] Use a layer-backed view to speed up drawing. 3 years ago
Michael Lutz 2a8c3a2cf6 Codechange: [OSX] Align backing buffer pitch for a tiny bit performance. 3 years ago
Michael Lutz 94b76ce9a4 Cleanup: [OSX] Move event loop into video driver file. 3 years ago
Michael Lutz f4bd54fedd Codechange: [OSX] Move mouse event handling to our NSView. 3 years ago
Michael Lutz bd42fc94cc Codechange: [OSX] Move some things from video driver to our NSView. 3 years ago
Michael Lutz 965ce12947 Codechange: [OSX] Use newer mouse tracking API. 3 years ago
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.
3 years ago
Michael Lutz 8aaf4ea098 Codechange: [OSX] Split Window and back buffer creation in Cocoa video driver. 3 years ago
Michael Lutz 0eff7de659 Cleanup: [OSX] Doxygen comment style in video driver. 3 years ago
Michael Lutz 8ced72ab10 Codechange: [OSX] Inline some functions that are used in only one place. 3 years ago
Michael Lutz 13134f9d64 Codechange: [OSX] Replace #define with modern code. 3 years ago
Michael Lutz 88f6c7a9f3 Codechange: [OSX] Fold remaining Cocoa video subdriver into the main driver. 3 years ago
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.
3 years ago
Michael Lutz 4db7837d06 Codechange: [OSX] There is only one subdriver left, remove virtual dispatch. 3 years ago
Michael Lutz fa60c1f8b9
Feature: Choose a sensible window size on a fresh OTTD config file. (#8536) 3 years ago
Michael Lutz 979b4af6ca Revert 4ce53cb8: [OSX] Delayed fullscreen switch is not needed anymore.
The fix for #8067 solves the real issue, making this workaround unneeded.
4 years ago
Michael Lutz 6e8be3b03e Fix #8067: [OSX] Calculate title bar height instead of assuming a fixed value. 4 years ago
Michael Lutz 4ce53cb851 Fix: [OSX] Quitting in fullscreen mode would loose the original window size.
This replicates the behaviour on e.g. Windows, which saves the original window size.
4 years ago
Michael Lutz c860a247d3 Change: [OSX] Hide Dock and menu during fullscreen mode. 4 years ago
Michael Lutz 6ad5489d01 Codechange: [OSX] Silence some annoying warnings. 4 years ago
Michael Lutz 7bdaabf5f1 Cleanup: [OSX] Remove cargo cult back-buffer alpha setting on show/hide and instead simply initialise the buffer on allocation. 4 years ago
Michael Lutz a61a741683 Change: [OSX] Compiling the Cocoa/Quartz video driver cannot be disabled anymore. 4 years ago
Michael Lutz 9ccef816f9 Codechange: [OSX] Re-arrange the OSX video driver code by combining all drawing code and moving the window/event handling to a different file.
This is just a code move/rename, not a functionality change.
4 years ago
Michael Lutz f3326d34e7 Codechange: Use std::string in FIO search path handling. 4 years ago
Michael Lutz 0c6e8a8123 Codechange: Store file search paths as std::string. 4 years ago
Michael Lutz 37bc2f8064 Codechange: Use std::string in the driver and blitter selection code. 4 years ago
Michael Lutz 9dd8b3d430 Remove: [OSX] Stuff that is pre-10.7 from the Cocoa/Quartz video driver. 4 years ago
Michael Lutz 0e5be3887c Remove: [OSX] Old fullscreen subdriver for pre 10.7 systems.
Since the move to C++11, building for pre 10.7 is not possible with the native
Apple tools. Also, due to bitrot, the file doesn't even compile anymore. While
this could be fixed, it shows that this subdriver is basically never used anymore.
4 years ago
Michael Lutz a31cbbf67f Remove: [OSX] QuickDraw video subdriver used for OSX versions up to 10.4.
Since the C++11 move, getting OpenTTD to compile and run for anything
below 10.7 basically requires building a custom compiler and libc++.
Also, the QuickDraw subdriver crashes on more modern OSX version. While this
is fixable, keeping the driver around is probably pointless.
4 years ago
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 5 years ago
Michael Lutz d5a9bd404a Codechange: [OSX] Use std::unique_ptr with a custom deleter to simply memory management of Core Foundation types. 5 years ago
Michael Lutz ed6a427fcc Change: [OSX] Recreate backing store if the colour profile of the screen (or the screen) the game window is one changes.
This will result in changing colours if moving OpenTTD from one screen to another, but should avoid performance problems if the window is moved.
5 years ago