HomeWildfire Games

Use only one coordinate system for locations in the rmgen system.
AuditedrP20396

Description

Use only one coordinate system for locations in the rmgen system.

Thereby fix the distance check of the SimpleObject, refs #4338, D189 and
remove the CELL_SIZE engine constant magic number, refs #4034.

Differential Revision: https://code.wildfiregames.com/D996
Thanks a lot to rapidelectron and temple who independently discovered this!

Event Timeline

s0600204 raised a concern with this commit.Nov 23 2017, 5:35 PM
s0600204 added a subscriber: s0600204.

Do we know if there is any need for the rmgen system to use the scale it does?

I ask because (as far as I can tell from a quick glance):

  • Position component - uses metres
  • Footprint component - uses metres
  • Obstruction component - uses metres
  • Manually created maps (skirmishes/scenarios) - contains positions in metres
  • Player wall-placement code - uses metres
  • rmgen code - uses terrain cells

Thus, rmgen wall-placement (D900) needs to read in metres (from xml templates) and output in terrain cells (that then get converted back to metres in MapReader.cpp)

This commit now has outstanding concerns.Nov 23 2017, 5:35 PM

Do we know if there is any need for the rmgen system to use the scale it does?

It could use metres like the simulation too if one changes every number in every line of every map to use metres instead of tiles, which is why I went for the much shorter variant.

The entire simulation uses the metres thing, the entire rmgen code used terrain tiles except in that one place removed.

If I understand correctly, there is currently no bug in svn but in order to convert the simulation template footprint sizes into the terrain tile sizes used by rmgen the constant would be needed?

If so, then this diff isn't wrong, but the constant should be received through the MapReader.cpp. If you need it I can go look into it, should be easy. (Only a new getter of a scriptinterface in c++)

Do we know if there is any need for the rmgen system to use the scale it does?

It could use metres like the simulation too if one changes every number in every line of every map to use metres instead of tiles, which is why I went for the much shorter variant.

I was vaguely wondering if there was some historical reason for it.

If I understand correctly, there is currently no bug in svn but in order to convert the simulation template footprint sizes into the terrain tile sizes used by rmgen the constant would be needed?

You understand correctly.

If so, then this diff isn't wrong, but the constant should be received through the MapReader.cpp. If you need it I can go look into it, should be easy. (Only a new getter of a scriptinterface in c++)

Yes please šŸ˜„

I was vaguely wondering if there was some historical reason for it.

About the reason code-wise:
It's exactly the hardcoded magic numbers passed to Constraints, such as avoidClasses and stayClasses that must be changed in every map.
Also some hardcoded absolute distances, for instance the distance of the starting resources to the CC.
At least a big minority of calls to scaleByMapSize would be affected.

The historic reason is rP2733 introducing the first maps with tile coordinates and then everything getting copied 60 times in 12 years.
rP9096 introduced the rmgen JS library and contains some more remarks and links to historically relevant versions.

(Changing the coordinate system in every rmgen file is becoming much easier with every rmgen commit in case someone wants to go through the trouble)

We could also make getter functions like RMS.MetresToTiles(getMapSize() / 2) and RMS.TilesToMetres(cmpFootprint.size), but a simple JS const initiated from C++ getter Engine.GetSomeCellSize() + 2 JS functions seems nicer.

Meanwhile you can continue to process D900 as usual - just add back that one line const in your diff and the rebase should be complete. If you want to save time later you could remove the concern now already xP

elexis requested verification of this commit.Nov 23 2017, 10:23 PM

The constant that was removed after removing the only use case was added in rP20504 for the new use case in D900.

This commit now requires verification by auditors.Nov 23 2017, 10:23 PM
s0600204 accepted this commit.Nov 24 2017, 4:34 PM

Concern addressed by D1059 / rP20504.

And thanks for the historical context.

All concerns with this commit have now been addressed.Nov 24 2017, 4:34 PM