Opened 7 years ago

Last modified 6 years ago

#4804 closed defect

Sort rmgen functions by logic — at Version 2

Reported by: elexis Owned by: elexis
Priority: Should Have Milestone: Alpha 23
Component: Maps Keywords:
Cc: Patch:

Description (last modified by elexis)

The old school rmgen directory is a bit messy, because three of the files don't have a clear separation of functions according to logic:

  • utilityfunctions.js contains some frequently used elevation and entity placement helpers.
    • The filename is arbitrary and should be renamed before random unrelated code is added there.
    • It could be split to terrain_helpers.js and placer_helpers.js or similar.
    • Its tileClass hardcodings can lead to reference errors and have to be removed.
  • misc.js
    • contains some frequently helper functions for the starting base that should be moved to a new file startingentities.js. That file will be extended with new helper functions that will replace the duplication of the starting base code in every rmgen file.
    • contains some frequently used terrain and placer helper functions too.
    • contains a lot of linear algebra unrelated to any rmgen implementation and should be moved to a new file
    • contains some rmgen1 brand functions which are deeply connected to the code in constraint.js, tileclass.js and painter.js and hence should be moved there
    • contains the four modifyTilesBasedOnHeight functions. They could be either moved to the three files above or the other short global helpers which don't fit anywhere in library.js.
  • library.js:
    • contains some starting base functions which should be moved to the new file.
    • contains some engine hardcodings, which should be replaced with an engine getter sometime (FeXoR ticket somewhere)
    • contains some useful short globals like fractionToTiles
    • contains a lot of silly proxies like sin = Math.sin and PI = Math.PI which should be deleted
    • contains some unrelated math helpers like getAngle or getDistance which can be moved to the new math file

After that, library.js will be about 100 to 200 lines of code only, misc.js and utilityfunctions.js deleted. So it will be easier for new readers to understand the rmgen library.

placers.js and pathplacer.js will become placer_centered.js (ClumpPlacer, ChainPlacer, can be used at random places meeting a given constraint) and placers_noncentered.js (RectPlacer, PathPlacer, can only be used to place at hardcoded coordinates).

Change History (2)

comment:1 by elexis, 7 years ago

In 20295:

Replace hardcoded trigonometry magic numbers on Corinthian Isthmus with a rotateCoordinates computation, allowing to change the river angle arbitrarily.

The new math library file will contain five more math helpers used by random maps, refs #4804.
These functions are agnostic of random map vocabulary, so could possibly be moved to or unified with globalscripts.

Cleanup and label obscure createArea calls in this map, unify duplicate magic numbers, refs #4805.
Remove three useless LayeredPainter calls that are overwritten by the paintTerrainBasedOnHeight tShore and tWater calls afterwards.

comment:2 by elexis, 7 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.