mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
heightmap selection - refactor, make generation immutable to get predictable result
This commit is contained in:
parent
4f372c7a46
commit
662163176b
12 changed files with 197 additions and 158 deletions
|
|
@ -1,7 +1,5 @@
|
|||
"use strict";
|
||||
// FMG utils related to arrays
|
||||
|
||||
// return the last element of array
|
||||
function last(array) {
|
||||
return array[array.length - 1];
|
||||
}
|
||||
|
|
@ -37,9 +35,24 @@ function deepCopy(obj) {
|
|||
[Set, s => [...s.values()].map(dcAny)],
|
||||
[Date, d => new Date(d.getTime())],
|
||||
[Object, dcObject]
|
||||
// other types will be referenced
|
||||
// ... extend here to implement their custom deep copy
|
||||
]);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue