Feature: Add/extend console commands to enable screenshot automation #9771
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Problem
Given a series of save files from the same running game, it's possible to use a
game_start.scr
script in conjunction withopenttd -g
to quickly run through each save file and automatically generate screenshots. Such screenshots can be useful to generate a video of how a map progressed and changed over time. This works great for "whole map/world" screenshot types, likeminimap
or evengiant
screenshots of small- to moderately-sized games.If you have a larger-sized game, or if you have a particularly interesting smaller area of the map, then you might want to instead make a series of "visible area" screenshots. However, your save files might have been made whilst the game was at different zoom levels or different locations, and unfortunately
scrollto
command exists, there's nozoomto
, andscrollto
exists, taking ascreenshot
immediately afterscrollto
doesn't correctly reflect the new map location.These changes would benefit the "model railway" group of players who want to storytell (e.g. to "replicate historical scenarios").
Description
This patchset enables a
game_start.scr
script like the following to be used:zoomto
is a new console command that allows the zoom level of the main window viewport to be manipulated, whereas the optionalinstant
argument forscrollto
makes thescreenshot
command work correctly (the fact it doesn't work today might be considered a bug and there might exist some other way to do this, see next section).Discussion
in implementing
zoomto
, I settled on twowhile()
s that call intoDoZoomInOutWindow()
, but this might be doing too much work if jumping multiple zoom levels; I also tried other alternatives that seemed to work just fine (e.g. settingvp->zoom
directly, updatingvp->virtual_width
/vp->virtual_height
w/ScaleByZoom()
, callingMarkWholeScreenDirty()
), but I wasn't sure if these would be as safe asDoZoomInOutWindow()
calling
scrollto
followed immediately byscreenshot
in a script doesn't work without this patch allowingscrollto
to be "instant" (without "instant", you will get a screenshot of where the map was before asking for thescrollto
), and initially one would think that this is due to smooth scrolling being enabled, but even turning that off before callingscrollto
doesn't fix the problem; callingScrollMainWindowToTile()
with itsinstant
flag enabled does fix the problem, though, so theinstant
argument here surfaces that to the console... but alternatively...instant=true
should always be passed?,or
scrollto
in such a way withoutinstant=true
thatscreenshot
will work?,or
screenshot
command or in something likeSetupScreenshotViewport()
?Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.