Changeset View
Standalone View
binaries/data/mods/public/maps/random/rmgen/painter/DunePainter.js
- This file was added.
/** | |||||
* @param {Boolean} type - ELEVATION_MODIFY or ELEVATION_SET. | |||||
* @param {Number} scale - Global scale of dune size. > 1 bigger, < 1 smaller. | |||||
Stan: Missing space after star | |||||
* @param {Number} scaleVertical - Vertical scale of dune size. > 1 taller, < 1 smaller. | |||||
* @param {Number} baseHeight - Dunes base altitude if type == ELEVATION_SET. | |||||
*/ | |||||
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… | |||||
class DunePainter { | |||||
constructor(type = ELEVATION_MODIFY, scale = 1, scaleVertical = 1, baseHeight = 0) { | |||||
this.type = type; | |||||
this.scale = scale; | |||||
this.scaleVertical = scaleVertical; | |||||
this.baseHeight = baseHeight; | |||||
} | |||||
/** | |||||
* Dune profile shape primitive. | |||||
* @param {Number} x - [0,1] value. | |||||
* @param {Number} xCrest - (0,1) position of the dune crest relative to the dune width. | |||||
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 {Boolean} dune - True is dune, false is dome. | |||||
* @returns {Number} [0,1] - Height of the dune at point x | |||||
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 ;) | |||||
*/ | |||||
Done Inline ActionsMissing @return Stan: Missing @return | |||||
duneProfile(x, xCrest = 0.75, dune = true) { | |||||
return x < xCrest ? (1 - Math.cos(Math.PI * x / xCrest)) * 0.5 : | |||||
dune ? (1 - Math.cos(Math.PI * (x - 1) / (xCrest - 1))) * 0.5 : | |||||
1 - Math.cos(Math.PI * (x - 1) / (xCrest - 1) * 0.5); | |||||
} | |||||
Done Inline ActionsAny way to optimise this? Stan: Any way to optimise this? | |||||
Done Inline Actionsno nani: no | |||||
paint(area) { | |||||
// Dunes width. | |||||
let width = 20.0 * this.scale; | |||||
Done Inline ActionsJsdoc? Stan: Jsdoc? | |||||
Done Inline Actionspart of rmgen internals, no need nani: part of rmgen internals, no need | |||||
let mod = (val, period) => val % period < 0 ? period + val % period : val % period; | |||||
for (let p of area.getPoints()) { | |||||
let x = p.x; | |||||
let y = p.y; | |||||
Done Inline ActionsTypo. Stan: Typo. | |||||
// Main dunes creation height. | |||||
let height1; | |||||
{ | |||||
Done Inline ActionsAny reason for this magic number ? Stan: Any reason for this magic number ? | |||||
let xProfile = x + | |||||
this.scale * 20 * valueNoise2d(x / (3 * width), y / (3 * width)) + | |||||
this.scale * 5 * valueNoise2d(x / width, y / width); | |||||
Done Inline Actions"wider than tall" once more. FeXoR: "wider than tall" once more. | |||||
xProfile = mod(xProfile / width, 1); | |||||
let duneLongintudinalScale = valueNoise2d(x / (3 * width), y / (3 * width)) * 0.5 + 0.5; | |||||
height1 = this.duneProfile(xProfile, 0.70, false) * duneLongintudinalScale; | |||||
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 | |||||
} | |||||
Done Inline Actions++i Stan: ++i | |||||
// Secondary dunes creation height. | |||||
let height2; | |||||
{ | |||||
// Rotate slightly | |||||
let rx = Math.cos(3.14 / 20); | |||||
let ry = Math.sin(3.14 / 20); | |||||
Done Inline ActionsBetter name ? Stan: Better name ? | |||||
[x, y] = [x * rx - y * ry, x * ry + y * rx]; | |||||
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… | |||||
let xProfile = x + | |||||
this.scale * 20 * valueNoise2d(x / (3 * width), y / (3 * width)) + | |||||
this.scale * 5 * valueNoise2d(x / width, y / width); | |||||
xProfile = mod(xProfile / width, 1); | |||||
Done Inline ActionsTernary? Stan: Ternary? | |||||
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 | |||||
height2 = this.duneProfile(xProfile, 0.60, false); | |||||
} | |||||
let height = (height1 * 0.8 + height2 * 0.2) * 12 * this.scale * this.scaleVertical; | |||||
// Add or set height. | |||||
let base = this.type == ELEVATION_MODIFY ? g_Map.getHeight(p) : baseHeight; | |||||
g_Map.setHeight(p, base + height); | |||||
} | |||||
} | |||||
} |
Missing space after star