FS#6583 - Scrolling down/right out of map on a 255 high flat map bounces viewport back to edge of map

Attached to Project: OpenTTD
Opened by James (james1101) - Saturday, 08 July 2017, 05:26 GMT
Type Bug
Category Interface
Status New
Assigned To No-one
Operating System Windows
Severity Low
Priority Normal
Reported Version 1.7.1
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


When you scroll down right (SE) on a 255-high flat map, instead of stopping at the edge, the game lets me continue about another few hundred pixels before bouncing your viewport back to the edge of map.

How to Reproduce:
1. Download the attached save and load it into OpenTTD.
2. Scroll down right out of the edge of the map.
After a couple hundred pixels out of bounds, the viewport bounces back to the edge of the map.

Possible Reason: The tile height isn't taken into account when checking for viewport out of bounds SE and SW. But after a couple hundred pixels, the tile to scroll to is calculated once the game realizes the viewport is out of bounds. The viewport scrolls back to that calculated tile, inside the map, taking the height into account. The threshold for number of pixels out before bounce back varies with the height of the tiles at the SW and SE edges.

Also applies for the following directions: Down left (SW), and straight down (S). But not up left (NW), up right (NE), or straight up (N).

Using Win 7 Ultimate 32 bit.
This task depends upon

Comment by Grzegorz Duczyński (adf88) - Monday, 10 July 2017, 04:29 GMT
More height levels overcomplicated some things a bit.
I removed faulty piece of it - ClampXYToMap is gone. We already had similar functionality, I just had to extract it out of TranslateXYToTileCoord. And so I did, new InverseRemapCoords2 function (inverse of RemapCoords2) works like a charm.

Comment by Grzegorz Duczyński (adf88) - Monday, 10 July 2017, 05:06 GMT
Just one correction - foundations shouldn't be taken into account so I added a switch to InverseRemapCoords2 that allows to disable them.
Comment by Grzegorz Duczyński (adf88) - Saturday, 15 July 2017, 05:10 GMT
I further investigated the code and this is a deep problem in general. "More height levels" is reinventing the wheel (duplicated functionality) and fixes imaginary problems (like the terraforming "issue"). Currently I'm yak-shaving this and removing/unifying stuff. Some functions return inconsistent values. TileHeight and TileHeightOutsideMap return different values for the same tile (when at southern border). TranslateXYToTileCoord has totally different model for tiles outside map then *OutsideMap function family. Tile slopes are also not consistent, based on method used to read it.

I would like to change the code in a way that tile heights at map edges always matter and TileHeight is always a "valid" value. Make sure that all functions return consistent values when called on the same tiles. Make sure that functions return consistent values when called on neighbor tiles (near map edges too). Unify "tile outside map" model. Deduplicate and removed unneeded "more height levels" stuff.

In the end, I change my mind about foundations - they don't harm and may stay just for convenience.
Comment by Grzegorz Duczyński (adf88) - Saturday, 22 July 2017, 19:41 GMT
How I've said, I did.

Here's entire patch queue.