Differential D4687 Diff 20413 binaries/data/mods/public/maps/random/rmgen/painter/HeightmapPainter.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/maps/random/rmgen/painter/HeightmapPainter.js
Show All 12 Lines | function HeightmapPainter(heightmap, normalMinHeight = undefined, normalMaxHeight = undefined) | ||||
this.bicubicInterpolation = bicubicInterpolation; | this.bicubicInterpolation = bicubicInterpolation; | ||||
this.verticesPerSide = heightmap.length; | this.verticesPerSide = heightmap.length; | ||||
this.normalMinHeight = normalMinHeight; | this.normalMinHeight = normalMinHeight; | ||||
this.normalMaxHeight = normalMaxHeight; | this.normalMaxHeight = normalMaxHeight; | ||||
} | } | ||||
HeightmapPainter.prototype.getScale = function() | HeightmapPainter.prototype.getScale = function() | ||||
{ | { | ||||
return this.verticesPerSide / (g_Map.getSize() + 1); | return this.verticesPerSide / (g_Map.getSize()); | ||||
}; | }; | ||||
HeightmapPainter.prototype.scaleHeight = function(height) | HeightmapPainter.prototype.scaleHeight = function(height) | ||||
{ | { | ||||
if (this.normalMinHeight === undefined || this.normalMaxHeight === undefined) | if (this.normalMinHeight === undefined || this.normalMaxHeight === undefined) | ||||
return height / this.getScale() / HEIGHT_UNITS_PER_METRE; | return height / this.getScale() / HEIGHT_UNITS_PER_METRE; | ||||
let minHeight = this.normalMinHeight * (g_Map.getSize() + 1) / 321; | let minHeight = this.normalMinHeight * (g_Map.getSize()) / 321; | ||||
Lint: prefer-const: 'minHeight' is never reassigned. Use 'const' instead. | |||||
let maxHeight = this.normalMaxHeight * (g_Map.getSize() + 1) / 321; | let maxHeight = this.normalMaxHeight * (g_Map.getSize()) / 321; | ||||
Lint: prefer-const 'maxHeight' is never reassigned. Use 'const' instead. Lint: prefer-const: 'maxHeight' is never reassigned. Use 'const' instead. | |||||
return minHeight + (maxHeight - minHeight) * height / 0xFFFF; | return minHeight + (maxHeight - minHeight) * height / 0xFFFF; | ||||
}; | }; | ||||
HeightmapPainter.prototype.paint = function(area) | HeightmapPainter.prototype.paint = function(area) | ||||
{ | { | ||||
let scale = this.getScale(); | let scale = this.getScale(); | ||||
let leftBottom = new Vector2D(0, 0); | let leftBottom = new Vector2D(0, 0); | ||||
let rightTop = new Vector2D(this.verticesPerSide, this.verticesPerSide); | let rightTop = new Vector2D(this.verticesPerSide, this.verticesPerSide); | ||||
let brushSize = new Vector2D(3, 3); | let brushSize = new Vector2D(3, 3); | ||||
let brushCenter = new Vector2D(1, 1); | let brushCenter = new Vector2D(1, 1); | ||||
// Additional complexity to process all 4 vertices of each tile, i.e the last row too | // Additional complexity to process all 4 vertices of each tile, i.e the last row too | ||||
let seen = new Array(g_Map.height.length).fill(0).map(zero => new Uint8Array(g_Map.height.length).fill(0)); | let seen = new Array(g_Map.height.length).fill(0).map(zero => new Uint8Array(g_Map.height.length).fill(0)); | ||||
for (let point of area.getPoints()) | for (let point of area.getPoints()) | ||||
for (let vertex of g_TileVertices) | for (let vertex of g_TileVertices) | ||||
{ | { | ||||
let vertexPos = Vector2D.add(point, vertex); | let vertexPos = Vector2D.add(point, vertex); | ||||
if (!g_Map.validHeight(vertexPos) || seen[vertexPos.x][vertexPos.y]) | if (!g_Map.validVertex(vertexPos) || seen[vertexPos.x][vertexPos.y]) | ||||
continue; | continue; | ||||
seen[vertexPos.x][vertexPos.y] = 1; | seen[vertexPos.x][vertexPos.y] = 1; | ||||
let sourcePos = Vector2D.mult(vertexPos, scale); | let sourcePos = Vector2D.mult(vertexPos, scale); | ||||
let sourceTilePos = sourcePos.clone().floor(); | let sourceTilePos = sourcePos.clone().floor(); | ||||
let brushPosition = Vector2D.max( | let brushPosition = Vector2D.max( | ||||
leftBottom, | leftBottom, | ||||
Vector2D.min( | Vector2D.min( | ||||
Vector2D.sub(sourceTilePos, brushCenter), | Vector2D.sub(sourceTilePos, brushCenter), | ||||
Vector2D.sub(rightTop, brushSize).sub(brushCenter))); | Vector2D.sub(rightTop, brushSize).sub(brushCenter))); | ||||
g_Map.setHeight(vertexPos, bicubicInterpolation( | g_Map.setVertexHeight(vertexPos, bicubicInterpolation( | ||||
Vector2D.sub(sourcePos, brushPosition).sub(brushCenter), | Vector2D.sub(sourcePos, brushPosition).sub(brushCenter), | ||||
...getPointsInBoundingBox(getBoundingBox([brushPosition, Vector2D.add(brushPosition, brushSize)])).map(pos => | ...getPointsInBoundingBox(getBoundingBox([brushPosition, Vector2D.add(brushPosition, brushSize)])).map(pos => | ||||
this.scaleHeight(this.heightmap[pos.x][pos.y])))); | this.scaleHeight(this.heightmap[pos.x][pos.y])))); | ||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator
'minHeight' is never reassigned. Use 'const' instead.