diff --git a/binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js b/binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js index 7bb26cc25b..c803777ae8 100644 --- a/binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js +++ b/binaries/data/mods/public/maps/random/rmgen-common/gaia_terrain.js @@ -528,7 +528,6 @@ function createTributaryRivers(riverAngle, riverCount, riverWidth, heightRiverbe * @property {number} endWidth * @property {number} [startHeight] - Fixed height to be used if the height at the location shouldn't be used. * @property {number} [endHeight] - * @property {number} [maxHeight] - If given, do not touch any terrain above this height. * @property {number} smoothWidth - Number of tiles at the passage border to apply height interpolation. * @property {number} [tileClass] - Marks the passage with this tile class. * @property {string} [terrain] - Texture to be painted on the passage area. diff --git a/binaries/data/mods/public/maps/random/rmgen/Constraint.js b/binaries/data/mods/public/maps/random/rmgen/Constraint.js index 59346bd679..73e5e9e3af 100644 --- a/binaries/data/mods/public/maps/random/rmgen/Constraint.js +++ b/binaries/data/mods/public/maps/random/rmgen/Constraint.js @@ -185,3 +185,29 @@ SlopeConstraint.prototype.allows = function(position) { return this.minSlope <= g_Map.getSlope(position) && g_Map.getSlope(position) <= this.maxSlope; }; + +/** + * The StaticConstraint is used for performance improvements of existing Constraints. + * It is evaluated for the entire map when the Constraint is created. + * So when a createAreas or createObjectGroups call uses this, it can rely on the cache, + * rather than reevaluating it for every randomized coordinate. + * Account for the fact that the cache is never updated! + */ +function StaticConstraint(constraints) +{ + let mapSize = g_Map.getSize(); + let constraint = new AndConstraint(constraints); + + this.cache = []; + for (let x = 0; x < mapSize; ++x) + { + this.cache[x] = new Uint8Array(mapSize); + for (let y = 0; y < mapSize; ++y) + this.cache[x][y] = constraint.allows(new Vector2D(x, y)); + } +} + +StaticConstraint.prototype.allows = function(position) +{ + return !!this.cache[position.x][position.y]; +};