HomeWildfire Games

Added TILE_CENTERED_HEIGHT_MAP flag to the mapgen scripts. This allows easy…
Concern RaisedrP10878

Description

Added TILE_CENTERED_HEIGHT_MAP flag to the mapgen scripts. This allows easy height based terrain painting if enabled. This is false by default for backwards compatibility.

Details

Auditors
elexis
Committed
quantumstateJan 5 2012, 11:09 PM
Parents
rP10877: wolfskin helmets. wolf textures provided by woxys from deviantart
Branches
Unknown
Tags
Unknown

Event Timeline

elexis raised a concern with this commit.EditedOct 18 2017, 4:14 AM
elexis added a subscriber: elexis.

-> #4825

Problem:

allows easy height based terrain painting

It is easy to add one line, but it is not easy to figure out the effects of that (or even what the purpose of that flag is).

TLDR: The global should be removed and we should just compute the height of the center of the tile if we mean it instead of the height of the corner of the tile.

Background:

There are mapSize tiles on the map.
Each tile consists of 4 vertices which can each have a different height.
So the heightmap of the level has the length mapSize + 1.

In many cases we want to test wheather the center of the tile is for example underwater and then paint the water texture on it.
However then the code needs to test against the height of the center, not the height of any of the corners.

What the intention of the flag is:
The flag intends to address that issue by making the heightmap not save the corners of any tile vertex but make it save the height of the center. Thus the center height can be queried easily.
Furthermore the center height of a tile can be set instead of only the corner.

From wiki:Rmgen_Library,

Setting TILE_CENTERED_HEIGHT_MAP = true; makes the height map define the height of the centers of each terrain grid square (interpolated to the corners at the export stage).

Example:
The flag had been discussed for the Aegean Sea map here
https://wildfiregames.com/forum/index.php?/topic/15494-random-map-scriptaegean-sea/

We observe that disabling the flag implies that the shoreline is wrong for one tile on each island on the bottom and left side:


Same is true on Archipelago (ignore the trees that are just too close to the shoreline, but notice the non-tree shoreline):

What the code does:
The flag is only read from two places:

  1. validH testing wheather a location is on the tile grid
  2. getMapData called when passing the heightmap to the engine.

The height of the vertex of a tile is computed by averaging the heights of the surrounding centers.
WARNING: Thus if TILE_CENTERED_HEIGHT_MAP = true, then the heightmap is interpolated without any notification to the map author!

On Pyrenean Sierra, this becomes very noticeable:


  • Luckily we can observe that _kalis maps with fixed *.hmap heightmaps account for this phenomenon and are of the size mapSize + 1.
  • The `SmoothElevationPainter** has some code which is related to this center computation (the +1) without refering to it, making it hard to grasp (which is how I got here in the first place).
  • We can observe that almost every map that sets the flag to true is every map that uses paintTerrainBasedOnHeight, which also correlates with the commit message.
  • FeXoR added this to heightmap.js in rP18141:

TILE_CENTERED_HEIGHT_MAP should be removed and g_Map.height should never be tile centered

I agree with that. We should always have g_Map.height have the grid size mapSize + 1 when having mapSize tiles, so that all vertices of every tile can receive a custom height.
If something like paintTerrainBasedOnHeight needs to find the height of the center of the tile, it can simply do so by calling a different getter.

I saw underwater terrain painted on the shoreline on Corsica & Sardinia sometimes too, but I don't recall wheather it was me messing with the code or in a committed variant (can't reproduce currently).

There are likely more places (basically all that use getHeight and then do something to that tile having that corner) that need fixing. However these aren't too many, so the end is near.

/ps/trunk/binaries/data/mods/public/maps/random/rmgen/map.js
349

As a matter of fact this smooths the heightmap unannounced!

This commit now has outstanding concerns.Oct 18 2017, 4:14 AM
elexis added inline comments.Oct 18 2017, 1:36 PM
/ps/trunk/binaries/data/mods/public/maps/random/rmgen/map.js
131

and why is there no getter for g_Map.height.length to remove these two duplicate hardcoded accounts of TILE_CENTERED_HEIGHT_MAP, the one in the SmoothElevationPainter and any other future usage of stuff doing things on the heightmap grid?

It would also reveal the reader the difference between the tile and heightmap grid instead of speaking everywhere universally of "mapsize", which is source of all these issues to begin with.

To demonstrate that a lot of places are off by one, here the Rivers map that is also shipped with being off by 1 but would be fixed when setting that messy flag:

Current code (off by 1):

Setting TILE_CENTERED_HEIGHT_MAP = true: