Commit Graph

717 Commits

Author SHA1 Message Date
Peter Nelson 56085be9bd Codechange: Move includes for common STL headers to stdafx. 2023-05-17 10:14:41 +01:00
Patric Stout 60399e17bd Codechange: C++-ify the Layouter and related functions
They all now access a std::string_view, instead of a "const char *"
or std::string (in some cases).

Additionally, GetCharAtPosition and friends now return an index
instead of a "const char *", as it makes for a more clear interface.
2023-05-08 19:21:42 +02:00
Rubidium 68ff3fd062 Change: include fmt.h C++ headers in stdafx.h
This to prevent compilation issues between runs with and without precompiled
headers. Also remove the headers from the rest of the code base as they are
not needed there anymore, although they do relatively little harm.
2023-05-08 16:49:23 +02:00
Rubidium f74e26ca7e Codechange: replace error/usererror printf variant with fmt variant and rename 2023-04-25 17:55:09 +02:00
PeterN e97bf271dc
Codechange: Make SpriteType, CargoSortType, SourceType and ScriptType enum classes. (#10663)
This avoids a (soft) namespace conflict between the four ST_* enums.
2023-04-16 20:00:55 +01:00
Charles Pigott b282664242 Codechange: Replace all usages of alloca/AllocaM with more modern/less discouraged alternatives 2023-04-15 16:57:00 +01:00
Tyler Trahan 066ae6f3fb Codechange: Simplify some CodeQL-flagged trivial switches 2023-03-25 18:03:16 -04:00
Rubidium 24b5033a06 Fix #10568: "can savegame be loaded check" failed in dedicated server
* If loading fails, it usually returns SL_REINIT which doesn't trigger check
 * If savegame has NewGRFs, it complains NewGRFs are not allowed in intro game
2023-03-15 22:14:29 +01:00
rubidium42 6ba55e663e Codechange: do not hide variables with other variables 2023-01-29 07:21:34 +01:00
Rubidium ae422be979 Cleanup: remove/replace trailing ; with . in comments 2023-01-26 23:47:55 +01:00
Henry Wilson 0b2567d882 Codechange: Remove shift as fast-forward key when _DEBUG is defined 2023-01-26 22:15:06 +01:00
Rubidium 46dfb309bc Fix #10309: [SDL] Uninitialized width and height when turning off full screen 2023-01-07 15:46:00 +01:00
Rubidium 0251786f46 Fix: virtual call from constructor
That fills an instance variable that is only read from the Game Options window
and that is overwritten when the video driver is started. Since you cannot get
into the Game Options window without starting the video driver, it is just
pointless and wrong code that would never be noticed by the end user.
2023-01-06 19:34:35 +01:00
Patric Stout 1fb101eabb
Codechange: address CodeQL issue "Multiplication result converted to larger type" (#10306)
Most are very unlikely to ever be triggered in our codebase; two
stand out: linkgraph and money cheat. Those, potentially, could
wrap earlier than expected.
2023-01-02 20:30:02 +00:00
Peter Nelson 9666e46739 Feature: Variable GUI scale.
GUI scale is now variable from 100% to 500%, and no longer restricted to
powers-of-2.
2022-11-12 18:28:39 +00:00
PeterN 4031894aef
Cleanup: Remove svn-style `$Id$` comments. (#10122) 2022-11-01 18:24:31 -06:00
Bouke Haarsma 45d98f689a Fix #9993: Handle DPI changes on macOS and Windows 2022-10-16 16:52:14 +02:00
Bouke Haarsma f3fd9b5895
Codechange: typo in code comment (#10061) 2022-09-29 00:12:21 +01:00
Niels Martin Hansen 345dcd3c7b Add: Show current video driver info in Options window 2022-05-03 21:03:30 +02:00
Michael Lutz 57b992717b Codechange: Extend DrawSpriteToRgbaBuffer to work with 8bpp blitters. 2022-01-01 12:19:30 +01:00
Michael Lutz 69c8ed9965 Codechange: [OSX] Simplify touchbar button data definition. 2022-01-01 12:19:30 +01:00
Michael Lutz b351cbe490 Fix #9743: [OSX] Only (re-)create touchbar sprites when requested by the main loop. 2022-01-01 12:19:30 +01:00
Michael Lutz f40e82a19d Fix #9743: [OSX] Don't try to render touchbar sprites with invalid zoom level. 2022-01-01 12:19:30 +01:00
Michael Lutz 80fc5fb46c Change: [OSX] Allow touchbar usage on all supported OS versions.
Touchbar support was introduced in 10.12.2. There's no need to limit
support to 10.15+, as the convenience class NSButtonTouchBarItem is
easily replicated.
2022-01-01 12:19:30 +01:00
Charles Pigott 86c295bb3b Change: Ignore refresh_rate setting when vsync is enabled 2021-10-17 19:25:03 +01:00
Danny de Bruijne 753b1d7e15 Feature: Add selected toolbar buttons to MacBook Pro Touch Bar 2021-09-23 21:03:00 +02:00
embeddedt 883e4ea325
Change: [Emscripten] set default scrolling mode to non-pointer-locking (#9191) 2021-06-28 18:39:09 +02:00
Patric Stout 74186998a2 Codechange: use _cur_palette the same in all the drivers
It was a bit of a mixed bag. With this change, gfx.cpp is in
control who accesses _cur_palette from the video-drivers.
2021-06-26 20:28:05 +02:00
Michael Lutz 37116a7575 Codechange: [OSX] Remove old code that has no effect on current OSX versions. 2021-06-22 21:09:37 +02:00
Michael Lutz 883e21dbb7 Codechange: [OSX] We use OpenGL even if Apple doesn't like it. 2021-06-22 21:09:37 +02:00
Michael Lutz 0d5d3083bd Codechange: [OSX] Use more exact enum names where introduced with the 10.12 SDK.
The enum values still have the exact same numerical values, but the 10.12
SDK introduced more explicit names (e.g. like NSEventTypeApplicationDefined
instead of NSApplicationDefined) for several enum constants.
Use them when available.
2021-06-22 21:09:37 +02:00
Patric Stout cf865597f8
Fix: don't propagate shift/ctrl state till next game-tick (#9381)
When the game-loop is very slow, it was easily possible to start
the loop with _shift_pressed being false, but end with
_shift_pressed being true. This doesn't hurt the game as such,
but for the user this can be very weird: I pressed "Buy Vehicle",
pressed shift a bit later, and I still get a cost indication.
2021-06-17 20:22:57 +02:00
Rubidium 357af686dc Cleanup: use true/false instead of 1/0 where applicable 2021-06-17 16:18:30 +02:00
Rubidium f904aef176 Cleanup: use nullptr instead of 0 or NULL 2021-06-17 16:18:30 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
glx22 d485b50813 Fix: [MinGW] Ignore wglGetProcAddress() cast warnings 2021-06-10 23:17:29 +02:00
glx22 744a9e4745 Codechange: [WIN32] Add a wrapper around GetProcAddress() 2021-06-10 23:17:29 +02:00
glx22 2df48a78cc Fix: [MinGW32] Can't convert lambda to stdcall 2021-06-10 23:17:29 +02:00
glx22 f4c7d5577e Codechange: [WIN32] Use VersionHelpers where appropriate 2021-06-10 23:17:29 +02:00
Patric Stout 37ae6b8ae3
Add: adhere the autosave_on_exit setting for Null videodriver (#9343)
This is especially useful for automated-testing, to make a save
when the game quits while using "-vnull:ticks=N".
2021-06-10 19:34:53 +02:00
Patric Stout ca9a7df752
Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)
This to be more explicit the function changes the value, and not
returns yes/no.
2021-05-29 11:21:38 +02:00
Michael Lutz 97722931a9 Fix: [OpenGL] Increase timeout when waiting for the GPU to be done with the drawing buffer.
The old timeout could be too short if v-sync was on on lower refresh rates.
2021-05-23 12:22:59 +02:00
Patric Stout b136e65cf9
Change: reworked the debug levels for network facility (#9251)
It now follows very simple rules:
0 - Fatal, user should know about this
1 - Error, but we are recovering
2 - Warning, wrong but okay if you don't know
3 - Info, information you might care about
4 -
5 - Debug #1 - High level debug messages
6 - Debug #2 - Low level debug messages
7 - Trace information
2021-05-12 16:34:02 +02:00
Patric Stout 56050fc96f
Fix 91b8ce07: dedicated servers could no longer create screenshots (#9232)
Although most commands are not useful on a dedicated server,
screenshot commands should be dequeued.
2021-05-12 16:31:31 +02:00
Milek7 20762f9117
Codechange: Acquire video buffer before taking game state lock to prevent erratic fast forward behaviour (#9140) 2021-05-02 19:10:07 +01:00
Michael Lutz 91b8ce073f Codechange: Generalise the delayed blitter change to a generic video driver command queue. 2021-05-02 17:57:24 +02:00
Peter Nelson 4791ff2862 Fix: Recalculate padding and minimum sizes when GUI or Font zoom is changed. 2021-04-30 17:08:15 +01:00
Michael Lutz f4d5c8d99e
Fix: [OpenGL] Main loop expects to start with the video buffer unmapped. (#9100) 2021-04-25 00:43:38 +02:00
Michael Lutz d1dd997f07 Change: [Win32] Limit the OpenGL video driver to OpenGL 3.2 or newer on Windows. 2021-04-22 21:04:04 +02:00
Michael Lutz ef80baf75c Codechange: [Win32] Try getting an OpenGL 4.5 context first before aiming at 3.2. 2021-04-22 21:04:04 +02:00
Michael Lutz e53313391a Fix: [OpenGL] Check maximum supported texture size against screen resolution. 2021-04-21 22:44:59 +02:00
Michael Lutz 433602b072 Fix #9028: [OpenGL] Clear cursor cache on destroying the OpenGL backend. 2021-04-12 22:40:40 +02:00
Rubidium 468b1c6c5d Fix: [win32] buffer_locked state not initialised, causing _screen.dst_ptr to be potentially not set 2021-04-12 21:14:01 +02:00
Rubidium 8562395413 Fix: [Video] fast forward boolean states not initialised, potentially causing unstoppable fast forward 2021-04-12 21:14:01 +02:00
Rubidium 64e8305874 Fix: [SDL] buffer_locked state not initialised, causing _screen.dst_ptr to be potentially not set 2021-04-12 21:14:01 +02:00
Michael Lutz 5644c00482
Fix: Check for a validly mapped OpenGL screen buffer during driver init. (#9007) 2021-04-11 14:28:29 +02:00
Patric Stout f0f2073006 Feature: allow a toggle to enable/disable vsync
Vsync should be off by default, as for most players it will be
better to play without vsync. Exception exist, mainly people who
play in fullscreen mode.
2021-04-11 14:26:00 +02:00
Jonathan G Rennison 39b7ef31f8 Fix: Data races on cursor state in OpenGL backends 2021-04-10 18:31:42 +02:00
Jonathan G Rennison fbd0a2e65a Fix: Thread unsafe use of sprite cache in OpenGLBackend::DrawMouseCursor
See also: #8870
See also: #8977
2021-04-10 18:31:42 +02:00
Michael Lutz 96d33ab46a Fix #8930: [Win32] Don't handle printable keys on keydown if an edit box is in focus.
Handle printable input only when the matching WM_CHAR message is incoming.
Without an edit box, do the handling in keydown as usual to support hotkeys.
2021-04-09 12:24:27 +02:00
Niels Martin Hansen e0561dbded Fix #8713: Change OTTD2FS and FS2OTTD to return string objects instead of static buffers 2021-04-07 09:31:47 +02:00
Michael Lutz 1cd3a3b070
Fix #8935: [OSX] Crash when clicking 'Save' due to wrongly-threaded OS call. (#8944) 2021-04-05 12:18:45 +02:00
Milek7 7a886cb4d4 Change: Do not disallow persistent buffer mapping on AMD GPUs, as it is actually faster. 2021-03-25 19:37:24 +00:00
Michael Lutz df958dc907 Fix f0f96e31: [OpenGL] Broken window resizing due to invalid buffer pitch on texture creation. 2021-03-21 22:26:55 +01:00
frosch 0230624359
Fix f0f96e31: [OpenGL] warning: comparison of integer expressions of different signedness. (#8881) 2021-03-21 18:38:51 +01:00
Michael Lutz f0f96e3103
Fix #8871: [OpenGL] Initialize all buffers after resize and clear back buffer. (#8877) 2021-03-20 19:43:54 +01:00
Patric Stout 970fedd78c Add: make modal windows update more smooth
Basically, modal windows had their own thread-locking for what
drawing was possible. This is a bit nonsense now we have a
game-thread. And it makes much more sense to do things like
NewGRFScan and GenerateWorld in the game-thread, and not in a
thread next to the game-thread.

This commit changes that: it removes the threads for NewGRFScan
and GenerateWorld, and just runs the code in the game-thread.
On regular intervals it allows the draw-thread to do a tick,
which gives a much smoother look and feel.

It does slow down NewGRFScan and GenerateWorld ever so slightly
as it spends more time on drawing. But the slowdown is not
measureable on my machines (with 700+ NewGRFs / 4kx4k map and
a Debug build).

Running without a game-thread means NewGRFScan and GenerateWorld
are now blocking.
2021-03-10 13:41:18 +01:00
sean 0464a50ab8
Add: Display refresh rate game option (#8813) 2021-03-09 10:22:52 +01:00
Michael Lutz 436cdf1fc8 Fix #8825: [OpenGL] Don't clear cursor cache from the game loop thread. 2021-03-08 21:35:35 +01:00
Patric Stout 8946b41d20 Fix: ensure switching blitter happens in the main thread
This because video-drivers might need to make changes to their
context, which for most video-drivers has to be done in the same
thread as the window was created; main thread in our case.
2021-03-08 19:18:55 +01:00
Patric Stout e56d2c63c3 Add: [Video] move GameLoop into its own thread
This allows drawing to happen while the GameLoop is doing an
iteration too.

Sadly, not much drawing currently can be done while the GameLoop
is running, as for example PollEvent() or UpdateWindows() can
influence the game-state. As such, they first need to acquire a
lock on the game-state before they can be called.

Currently, the main advantage is the time spend in Paint(), which
for non-OpenGL drivers can be a few milliseconds. For OpenGL this
is more like 0.05 milliseconds; in these instances this change
doesn't add any benefits for now.

This is an alternative to the former "draw-thread", which moved
the drawing in a thread for some OSes. It has similar performance
gain as this does, although this implementation allows for more
finer control over what suffers when the GameLoop takes too
long: drawing or the next GameLoop. For now they both suffer
equally.
2021-03-08 19:18:55 +01:00
Michael Lutz 3a4a15cc93 Codechange: don't set the window position when changing blitter
There really is no need to make an extra call to the OS in
these cases.
2021-03-08 19:18:55 +01:00
Patric Stout b9eac7c6dc Codechange: remove the unused lock around Blitter 2021-03-08 19:18:55 +01:00
Patric Stout 4610aa7ae3 Remove: [Video] no longer draw in a thread
Drawing in a thread is a bit odd, and often leads to surprising
issues. For example, OpenGL would only allow it if you move the
full context to the thread. Which is not always easily done on
all OSes.
In general, the advise is to handle system events and drawing
from the main thread, and do everything else in other threads.
So, let's be more like other games.

Additionally, putting the drawing routine in a thread was only
done for a few targets.

Upcoming commit will move the GameLoop in a thread, which will
work for all targets.
2021-03-08 19:18:55 +01:00
Patric Stout 04db99749b
Fix #8784: using alt+enter didn't update the fullscreen toggle visibly (#8820)
Basically, the window was not invalidated, so it was never redrawn.
This made it look like it wasn't working, but it really was.
2021-03-08 16:57:59 +01:00
Michael Lutz 25656a10cb Fix #8808: [OSX, OpenGL] Crash on switching blitters due to double-mapping the video buffer. 2021-03-08 15:43:22 +01:00
Patric Stout b93d7dd3cb
Add: Option to (dis-)allow accelerated video drivers. (#8819)
The video drivers using the OpenGL backend are currently our only
accelerated drivers. The options defaults to off for macOS builds and
to on everywhere else.

Co-authored-by: Michael Lutz <michi@icosahedron.de>
2021-03-08 15:42:39 +01:00
Michael Lutz c656633bea Fix #8775: [Win32] Don't create the main window when alt-tabbing back into fullscreen. 2021-03-01 23:41:39 +01:00
Michael Lutz b7a44983b4 Fix: [Win32] Original window size was lost when tabbing in and out of fullscreen. 2021-03-01 23:41:39 +01:00
Patric Stout abac4b1758
Fix c4df0f95: bootstrap was only showing a black screen (#8788)
The bootstrap has the _switch_mode to SM_MENU, and never leaves
this mode. Neither is it considered a modal window (while in some
sense it really is). So .. we need to add another "draw anyway"
exception, to make sure bootstrap is being drawn.
2021-03-01 23:17:30 +01:00
Owen Rudge 838fd61f29 Fix: [OSX] Hide dock when entering fullscreen 2021-03-01 21:03:18 +00:00
Patric Stout c3dc27e37e Add: settings to limit your fast-forward game speed
By default this setting is set to 2500% normal game speed.
2021-02-28 18:04:51 +00:00
Michael Lutz d79398a1d5 Fix #8763: [OpenGL] Cursor sprite origin can be negative. 2021-02-28 11:12:13 +01:00
Michael Lutz 77854d561b Fix: [OpenGL] Don't use OpenGL on MESA software renderers.
Performance in this case is worse than not using OpenGL, so just let
OTTD fall back to a different video driver.
2021-02-27 19:01:34 +01:00
Patric Stout 1b5d1d074e
Fix: [SDL2] set GL attributes to get the best GL context possible (#8759) 2021-02-27 18:51:20 +01:00
frosch dfa141818b Fix: OpenGL cursor did not consider sprite offsets of cursor sprites. 2021-02-27 14:52:11 +01:00
Patric Stout fe451b8dc7 Codechange: remove _realtime_tick variable 2021-02-27 00:36:14 +01:00
Michael Lutz 311df31fb1 Codechange: [OpenGL] Load all OpenGL functions dynamically. 2021-02-25 00:34:49 +01:00
Michael Lutz a0c1a3f736 Codechange: [OpenGL] Simplify loading OpenGL extension functions. 2021-02-25 00:34:49 +01:00
Michael Lutz e1e8cc3851
Fix #8734: [OpenGL] Apply palette remap to cursor sprites. (#8742) 2021-02-24 22:10:25 +01:00
Patric Stout 6a8c461e38 Codechange: [OSX] GameLoop is really more like MainLoop
MainLoop() is used to bootstrap OSX, where later a callback is
done to GameLoop() to execute OpenTTD. All other video drivers
don't need that, so what is in GameLoop is in MainLoop for all
other drivers. This is rather confusing. So, instead, name
GameLoop MainLoopReal to be more in sync with the other drivers.
2021-02-24 21:58:47 +01:00
Patric Stout 67d3c6aa71 Codechange: [Video] move InteractiveRandom() to the VideoDriver 2021-02-24 21:58:47 +01:00
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