#4804 closed defect (fixed)
Sort rmgen functions by logic
Reported by: | elexis | Owned by: | elexis |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 23 |
Component: | Maps | Keywords: | |
Cc: | Patch: |
Description (last modified by )
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
andplacer_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
andpainter.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 inlibrary.js
.
- contains some frequently helper functions for the starting base that should be moved to a new file
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
andPI = Math.PI
which should be deleted - contains some unrelated math helpers like
getAngle
orgetDistance
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 (34)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
Description: | modified (diff) |
---|
comment:3 by , 7 years ago
After the functions were moved to separate files as mentioned above,
the files can be grouped by logic in new rmgen libraries, allowing us to
build a clean software stack afterwards.
Layer 0 (Pyrogenesis C++): C++ random map engine
Layer 1 (Pyrogenesis Interface): JS library providing a blank interface to the engine
Layer 2 (Map Generation): functions handling entities, terrain and height changes (free of 0ad vocabulary):
2a. rmgen1-core: placers, painters (area shaping and texturing, entity assembly and placement, used by every map, still could be exchanged by a mod)
2b. rmgen1-collision (tileclasses to provide resource collisions. opt-in, as FeXoR prefers to avoid that)
2c. heightmap library (diamond square algorithm)
Layer 3 (Mod): functions often used by 0ad and non-fictional RTS (containing 0ad vocabulary, some alien mod might want to delete)
3a. terrain helpers (mountains, hills, rivers, ...)
3b. placer helpers (starting bases, wallbuilder, forests, mines, ...)
3c. rmgen2 (rmgen1 dialect)
Layer 4 (Application instance): random maps scripts
4a. Actual maps. They should ideally only provide some artistic numbers, reducing logic that can bug intrinsically
4b. Random mapgen libraries that are only relevant for very few maps. For instance the three Unknown maps (Phab:D252)
The effort to unify truckloads of rmgen duplication tracked in #4805 can be understood as part of this stack building process where logic is moved to the lower layers if it is not application or mod logic.
comment:22 by , 6 years ago
Milestone: | Alpha 23 → Backlog |
---|---|
Owner: | removed |
Status: | assigned → new |
comment:23 by , 6 years ago
Milestone: | Backlog → Alpha 23 |
---|
The plan in comment:3 is not finished yet, but calling it finished otherwise as the files themselves are cleaned for the most part.
In 20295: