Changeset View
Standalone View
binaries/data/mods/public/maps/random/rmgen/painter/DunePainter.js
- This file was added.
/** | |||||
*@param {Bool} type - ELEVATION_MODIFY or ELEVATION_SET | |||||
*@param {Number} scale - Global scale of dune size | |||||
Stan: Missing space after star | |||||
*@param {Number} vertical_scale - Vertical scale of dune size | |||||
*/ | |||||
class DunePainter | |||||
Done Inline Actions@ both scaleVertical and baseHeight: In what unit? State that. (e.g. tiles, meters, engine space units, art length units, ...) FeXoR: @ both scaleVertical and baseHeight: In what unit? State that. (e.g. tiles, meters, engine… | |||||
Done Inline ActionsscaleVertical is a multiplier so its value is adimensional nani: `scaleVertical` is a multiplier so its value is adimensional
`baseHeight` has the same measure… | |||||
{ | |||||
constructor(type = ELEVATION_MODIFY, scale = 1, vertical_scale = 1) | |||||
{ | |||||
this.type = type; | |||||
this.scale = scale; | |||||
this.vertical_scale = vertical_scale; | |||||
} | |||||
/** | |||||
*Dune base shape | |||||
*@param {Number} x [0,1] value | |||||
*@param {Number} xm [0,1] position of the dune crest | |||||
Done Inline ActionsI think we have '-' after the variable name everywhere else Missing final dot :) Stan: I think we have '-' after the variable name everywhere else
Missing final dot :) | |||||
*@param {Bool} d true is dune, false is dome | |||||
*/ | |||||
Done Inline ActionsNice you added the expected value range but a discription is missing ;) FeXoR: Nice you added the expected value range but a discription is missing ;) | |||||
dune(x, crest_x = 0.75, dune = true) | |||||
Done Inline ActionsMissing @return Stan: Missing @return | |||||
{ | |||||
if (x < crest_x) return (1 - Math.cos(Math.PI * x / crest_x)) * 0.5; | |||||
if (dune) return (1 - Math.cos(Math.PI * (x - 1) / (crest_x - 1))) * 0.5; | |||||
return 1 - Math.cos(Math.PI * (x - 1) / (crest_x - 1) * 0.5); | |||||
} | |||||
Done Inline ActionsAny way to optimise this? Stan: Any way to optimise this? | |||||
Done Inline Actionsno nani: no | |||||
paint(area) | |||||
{ | |||||
let points = area.getPoints(); | |||||
let length = points.length; | |||||
Done Inline ActionsJsdoc? Stan: Jsdoc? | |||||
Done Inline Actionspart of rmgen internals, no need nani: part of rmgen internals, no need | |||||
// 1st dune layer | |||||
let height1_1 = PerlinNoise(points, 6, 2, 1, 1.1, true); | |||||
let height1_2 = PerlinNoise(points, 3, 2, 1, 1, true); | |||||
let widht1 = 17.0 * this.scale; | |||||
// 2on dune layer | |||||
let height2_1 = PerlinNoise(points, 8, 1, 2, 2, true); | |||||
let height2_2 = PerlinNoise(points, 4, 2, 2, 2, true); | |||||
Done Inline ActionsTypo. Stan: Typo. | |||||
let width2 = 14.0 * this.scale; | |||||
// Loop all the points | |||||
let elevation_type = this.type ? (i) => g_Map.getHeight(points[i]) : () => 0; | |||||
Done Inline ActionsAny reason for this magic number ? Stan: Any reason for this magic number ? | |||||
for (var i = 0; i < length; i++) | |||||
{ | |||||
// Main dunes creation | |||||
Done Inline Actions"wider than tall" once more. FeXoR: "wider than tall" once more. | |||||
let v1 = ((points[i].x + height1_1[i] * 13 + points[i].y * 0.1) % widht1) / widht1; | |||||
let height1 = this.dune(v1, 0.60, false) * 9 * 0.9 + height1_1[i] * height1_2[i] * 150 * 0.1; | |||||
// Secondary dunes | |||||
Done Inline ActionsLoop over all the points. Not sure if comment is useful Stan: Loop over all the points. Not sure if comment is useful | |||||
let v2 = ((points[i].x + height2_1[i] * 13 + points[i].y * 0.1) % width2) / width2; | |||||
Done Inline Actions++i Stan: ++i | |||||
let height2 = this.dune(v2, 0.60, false) * 9 * 0.9 + height2_2[i] * 50 * 0.1; | |||||
let height = (height1 * 0.8 + height2 * 0.2) * this.vertical_scale * this.scale; | |||||
// Add or set height | |||||
g_Map.setHeight(points[i], height + elevation_type(i)); | |||||
} | |||||
} | |||||
} | |||||
Done Inline ActionsBetter name ? Stan: Better name ? | |||||
Done Inline ActionsTernary? Stan: Ternary? | |||||
Done Inline ActionsThose are magic (optimized by fiddling around and testing aiming for the result you find most appealing I guess - that's OK of cause!) numbers anyway so would'nt it be appropriate to use 8.1 instead of 9*0.9 and 5 instead of 50*0.1? If this multiplication really helps wrapping your head around what's going on leave them as they are I guess. FeXoR: Those are magic (optimized by fiddling around and testing aiming for the result you find most… | |||||
Done Inline Actions0.9 and 0.1 are weights but yes, I prefer to leave the expression expanded for easy modification. nani: 0.9 and 0.1 are weights but yes, I prefer to leave the expression expanded for easy… | |||||
Done Inline ActionsHuh? When does the case "not this.type" happen??? FeXoR: Huh? When does the case "not this.type" happen??? | |||||
Done Inline Actionsthis.type can be ELEVATION_SET = 1 or ELEVATION_MODIFY = 0 nani: this.type can be ELEVATION_SET = 1 or ELEVATION_MODIFY = 0 |
Missing space after star