Changeset View
Standalone View
binaries/data/mods/public/maps/random/rmgen/library.js
Context not available. | |||||
* Constants needed for heightmap_manipulation.js | * Constants needed for heightmap_manipulation.js | ||||
*/ | */ | ||||
const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE; // Engine limit, Roughly 700 meters | const MAX_HEIGHT_RANGE = 0xFFFF / HEIGHT_UNITS_PER_METRE; // Engine limit, Roughly 700 meters | ||||
const MIN_HEIGHT = - SEA_LEVEL; | const MIN_HEIGHT = -SEA_LEVEL; | ||||
/** | /** | ||||
* Length of one tile of the terrain grid in metres. | * Length of one tile of the terrain grid in metres. | ||||
Context not available. | |||||
let obstructionSize = | let obstructionSize = | ||||
obstruction.Static ? | obstruction.Static ? | ||||
new Vector2D(obstruction.Static["@depth"], obstruction.Static["@width"]) : | new Vector2D(obstruction.Static["@depth"], obstruction.Static["@width"]) : | ||||
// Used for gates, should consider the position too | // Used for gates, should consider the position too | ||||
obstruction.Obstructions ? | obstruction.Obstructions ? | ||||
new Vector2D( | new Vector2D( | ||||
Object.keys(obstruction.Obstructions).reduce((depth, key) => Math.max(depth, +obstruction.Obstructions[key]["@depth"]), 0), | Object.keys(obstruction.Obstructions).reduce((depth, key) => Math.max(depth, +obstruction.Obstructions[key]["@depth"]), 0), | ||||
Object.keys(obstruction.Obstructions).reduce((width, key) => width + +obstruction.Obstructions[key]["@width"], 0)) : | Object.keys(obstruction.Obstructions).reduce((width, key) => width + (+obstruction.Obstructions[key]["@width"]), 0)) : | ||||
new Vector2D(0, 0); | new Vector2D(0, 0); | ||||
return obstructionSize.div(TERRAIN_TILE_SIZE).add(new Vector2D(2, 2).mult(margin)); | return obstructionSize.div(TERRAIN_TILE_SIZE).add(new Vector2D(2, 2).mult(margin)); | ||||
} | } | ||||
Context not available. | |||||
} | } | ||||
/** | /** | ||||
* Create an avoid constraint for the given classes by the given distances | |||||
*/ | |||||
function avoidClasses(/*class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new AvoidTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a stay constraint for the given classes by the given distances | |||||
*/ | |||||
function stayClasses(/*class1, dist1, class2, dist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/2; ++i) | |||||
ar.push(new StayInTileClassConstraint(arguments[2*i], arguments[2*i+1])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Create a border constraint for the given classes by the given distances | |||||
*/ | |||||
function borderClasses(/*class1, idist1, odist1, class2, idist2, odist2, etc*/) | |||||
{ | |||||
let ar = []; | |||||
for (let i = 0; i < arguments.length/3; ++i) | |||||
ar.push(new BorderTileClassConstraint(arguments[3*i], arguments[3*i+1], arguments[3*i+2])); | |||||
// Return single constraint | |||||
if (ar.length == 1) | |||||
return ar[0]; | |||||
return new AndConstraint(ar); | |||||
} | |||||
/** | |||||
* Returns a subset of the given heightmap. | * Returns a subset of the given heightmap. | ||||
*/ | */ | ||||
function extractHeightmap(heightmap, topLeft, size) | function extractHeightmap(heightmap, topLeft, size) | ||||
Context not available. | |||||
elexis: I wanted to remove these proxies rather than add new (see last 6 months of revision history on… | |||||
Not Done Inline ActionsNO. No no no no no no no no no no. To be fair I think these proxies should be moved to Constraint.js rather than having them clutter up the main library, but constructing a new instance for every single constraint would be insane. These proxies are extremely convenient, not having them isn't a real option. Good libraries should make coding easier, not harder. aeonios: NO. No no no no no no no no no no. To be fair I think these proxies should be moved to… | |||||
Not Done Inline Actions
YES, yes yes yes yes yes yes yes yes yes yes As I said the argument listing should be moved to the constructor if we need this feature:
But you didn't notice that most proxies like paintClasses were removed already?
Making it easier also implies reducing the complexity while keeping the same features rather than extending the complexity for no reaosn.
Claiming that this function doesn't create a constraint is insane for each function too. elexis: > NO. No no no no no no no no no no.
YES, yes yes yes yes yes yes yes yes yes yes
As I said… | |||||
Not Done Inline ActionsHmm, let's see.. I could type "nearClasses(x, 1, y, 2, z, 3)" or I could type "new NearTileClassesConstraint(x, 1, y, 2, z, 3)". One of those things is short and sweet and the other is incredibly asinine. I don't know anything about paintClasses but I do know that if you feed a texture array into a layeredpainter like you would for random painting with a terrainpainter it unceremoniously crashes. If paintclasses would allow you to avoid that then getting rid of them was the wrong thing to do. In terms of complexity the wrapper functions don't really add any, and in terms of performance I suspect that both ways would end up doing the exact same thing. Except that forcing every map to use the raw classes would require rewriting every single map and also require a serious restructuring of the constraint classes that would accomplish exactly nothing except to increase the amount of typing and likelihood of error on the part of map script designers. There are plenty of features that are either broken or suck, and this isn't one of them. aeonios: Hmm, let's see.. I could type "nearClasses(x, 1, y, 2, z, 3)" or I could type "new… |
I wanted to remove these proxies rather than add new (see last 6 months of revision history on this file).
The argument listing could be moved to the constructor.