diff --git a/modules/dynamic/heightmap-selection.js b/modules/dynamic/heightmap-selection.js index 5b3f6484..8bc8b9d5 100644 --- a/modules/dynamic/heightmap-selection.js +++ b/modules/dynamic/heightmap-selection.js @@ -323,14 +323,14 @@ async function drawPrecreatedHeightmap(id) { } function drawTemplatePreview(id) { - const heights = generateHeightmap(id); + const heights = HeightmapGenerator.fromTemplate(graph, id); const dataUrl = drawHeights(heights); const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`); article.querySelector("img").src = dataUrl; } async function drawPrecreatedHeightmap(id) { - const heights = await HeightmapGenerator.fromPrecreated(id); + const heights = await HeightmapGenerator.fromPrecreated(graph, id); const dataUrl = drawHeights(heights); const article = byId("heightmapSelection").querySelector(`[data-id="${id}"]`); article.querySelector("img").src = dataUrl; diff --git a/modules/heightmap-generator.js b/modules/heightmap-generator.js index cb297f2e..66696953 100644 --- a/modules/heightmap-generator.js +++ b/modules/heightmap-generator.js @@ -510,7 +510,6 @@ window.HeightmapGenerator = (function () { const powered = lightness < 0.2 ? lightness : 0.2 + (lightness - 0.2) ** 0.8; heights[i] = minmax(Math.floor(powered * 100), 0, 100); } - return heights; } return { diff --git a/modules/submap.js b/modules/submap.js index 85408487..263d3294 100644 --- a/modules/submap.js +++ b/modules/submap.js @@ -41,7 +41,6 @@ window.Submap = (function () { // create new grid applyMapSize(); grid = generateGrid(); - drawScaleBar(scale); const resampler = (points, qtree, f) => { diff --git a/utils/arrayUtils.js b/utils/arrayUtils.js index 9c7dc121..241d2fac 100644 --- a/utils/arrayUtils.js +++ b/utils/arrayUtils.js @@ -96,3 +96,19 @@ function deepCopy(obj) { return dcAny(obj); } + +function getTypedArray(maxValue) { + console.assert( + Number.isInteger(maxValue) && maxValue >= 0 && maxValue <= 4294967295, + `Array maxValue must be an integer between 0 and 4294967295, got ${maxValue}` + ); + + if (maxValue <= 255) return Uint8Array; + if (maxValue <= 65535) return Uint16Array; + if (maxValue <= 4294967295) return Uint32Array; + return Uint32Array; +} + +function createTypedArray({maxValue, length}) { + return new (getTypedArray(maxValue))(length); +}