Add "has" helper function to TileClass, so that one can find out if the given tile is marked with that class or not without having to fallback to Constraints.

Performance improvement for Ambush, refs #5011.

This was SVN commit r21414.
This commit is contained in:
elexis 2018-03-02 16:16:45 +00:00
parent e9fb0f62ed
commit 85a3a889e7
4 changed files with 8 additions and 3 deletions

View file

@ -35,7 +35,7 @@ addElements([
"avoid": [g_TileClasses.bluffIgnore, 0],
"sizes": ["normal", "big", "huge"],
"mixes": ["same"],
"amounts": ["tons"]
"amounts": ["many"]
},
{
"func": addHills,

View file

@ -143,7 +143,7 @@ for (var ix = 0; ix <= mapSize; ix++)
var pn = playerNearness(x, z);
let c = startAngle ? z : x;
let distToWater = stayClasses(clWater, 1).allows(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5));
let distToWater = clWater.has(position) ? 0 : (0.5 - WATER_WIDTH - Math.abs(c - 0.5));
let h = distToWater ? heightHill * (1 - Math.abs(c - 0.5) / (0.5 - WATER_WIDTH)) : g_Map.getHeight(position);
// add some base noise

View file

@ -174,7 +174,7 @@ if (!isNomad())
for (let i = 0; i < getNumPlayers(); ++i)
{
g_Map.logger.printDuration();
setBiome(climateZones.find(zone => stayClasses(zone.tileClass, 1).allows(playerPosition[i])).biome);
setBiome(climateZones.find(zone => zone.tileClass.has(playerPosition[i])).biome);
createArea(
new ClumpPlacer(diskArea(defaultPlayerBaseRadius() * 0.8), 0.95, 0.6, Infinity, playerPosition[i]),

View file

@ -76,6 +76,11 @@ function TileClass(size)
}
}
TileClass.prototype.has = function(position)
{
return !!this.inclusionCount[position.x] && !!this.inclusionCount[position.x][position.y];
}
TileClass.prototype.add = function(position)
{
if (!this.inclusionCount[position.x][position.y] && g_Map.validTile(position))