mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 06:46:04 +00:00
reduce time of some rndm map generation, i.e. alpine_lakes is about 3 times faster now
This was SVN commit r16422.
This commit is contained in:
@@ -155,8 +155,8 @@ for (var i = 0; i < numPlayers; i++)
|
||||
// get the x and z in tiles
|
||||
var fx = fractionToTiles(playerX[i]);
|
||||
var fz = fractionToTiles(playerZ[i]);
|
||||
ix = round(fx);
|
||||
iz = round(fz);
|
||||
var ix = round(fx);
|
||||
var iz = round(fz);
|
||||
addToClass(ix, iz, clPlayer);
|
||||
addToClass(ix+5, iz, clPlayer);
|
||||
addToClass(ix, iz+5, clPlayer);
|
||||
@@ -256,6 +256,8 @@ RMS.SetProgress(20);
|
||||
log("Creating hills...");
|
||||
createMountains(tCliff, avoidClasses(clPlayer, 20, clHill, 8), clHill, scaleByMapSize(10, 40) * numPlayers, floor(scaleByMapSize(40, 60)), floor(scaleByMapSize(4, 5)), floor(scaleByMapSize(7, 15)), floor(scaleByMapSize(5, 15)));
|
||||
|
||||
RMS.SetProgress(30);
|
||||
|
||||
var lakeAreas = [];
|
||||
var playerConstraint = new AvoidTileClassConstraint(clPlayer, 20);
|
||||
var waterConstraint = new AvoidTileClassConstraint(clWater, 8);
|
||||
@@ -278,7 +280,7 @@ for (var i = 0; i < numLakes; ++i)
|
||||
if (!lakeAreaLen)
|
||||
break;
|
||||
|
||||
chosenPoint = lakeAreas[randInt(0, lakeAreaLen)];
|
||||
chosenPoint = lakeAreas[randInt(lakeAreaLen)];
|
||||
|
||||
placer = new ChainPlacer(1, floor(scaleByMapSize(4, 8)), floor(scaleByMapSize(40, 180)), 0.7, chosenPoint[0], chosenPoint[1]);
|
||||
var terrainPainter = new LayeredPainter(
|
||||
@@ -292,17 +294,17 @@ for (var i = 0; i < numLakes; ++i)
|
||||
avoidClasses(clPlayer, 20, clWater, 8),
|
||||
1, 1
|
||||
);
|
||||
|
||||
if (newLake !== undefined)
|
||||
|
||||
if (newLake && newLake.length)
|
||||
{
|
||||
var temp = []
|
||||
var n = 0;
|
||||
for (var j = 0; j < lakeAreaLen; ++j)
|
||||
{
|
||||
var x = lakeAreas[j][0], z = lakeAreas[j][1];
|
||||
if (playerConstraint.allows(x, z) && waterConstraint.allows(x, z))
|
||||
temp.push([x, z]);
|
||||
lakeAreas[n++] = lakeAreas[j];
|
||||
}
|
||||
lakeAreas = temp;
|
||||
lakeAreas.length = n;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -446,4 +448,4 @@ setWaterWaviness(3.0);
|
||||
setWaterType("clap");
|
||||
|
||||
// Export map data
|
||||
ExportMap();
|
||||
ExportMap();
|
||||
|
||||
@@ -240,7 +240,7 @@ for (var i = 0; i < numIslands; ++i)
|
||||
if (!landAreaLen)
|
||||
break;
|
||||
|
||||
chosenPoint = landAreas[randInt(0, landAreaLen)];
|
||||
chosenPoint = landAreas[randInt(landAreaLen)];
|
||||
|
||||
// create big islands
|
||||
placer = new ChainPlacer(floor(scaleByMapSize(4, 8)), floor(scaleByMapSize(8, 14)), floor(scaleByMapSize(25, 60)), 0.07, chosenPoint[0], chosenPoint[1], scaleByMapSize(30,70));
|
||||
@@ -256,16 +256,16 @@ for (var i = 0; i < numIslands; ++i)
|
||||
avoidClasses(clLand, 3, clPlayer, 3),
|
||||
1, 1
|
||||
);
|
||||
if (newIsland !== undefined)
|
||||
if (newIsland && newIsland.length)
|
||||
{
|
||||
var temp = []
|
||||
for (var j = 0; j < landAreaLen; ++j)
|
||||
var n = 0;
|
||||
for (var j = 0; j < lakeAreaLen; ++j)
|
||||
{
|
||||
var x = landAreas[j][0], z = landAreas[j][1];
|
||||
if (playerConstraint.allows(x, z) && landConstraint.allows(x, z))
|
||||
temp.push([x, z]);
|
||||
var x = lakeAreas[j][0], z = lakeAreas[j][1];
|
||||
if (playerConstraint.allows(x, z) && waterConstraint.allows(x, z))
|
||||
lakeAreas[n++] = lakeAreas[j];
|
||||
}
|
||||
landAreas = temp;
|
||||
lakeAreas.length = n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -585,15 +585,6 @@ function createMountain(maxHeight, minRadius, maxRadius, numCircles, constraint,
|
||||
|
||||
var edges = [[x, z]]
|
||||
var circles = [];
|
||||
var pointHeights = []
|
||||
for (var ix = sx; ix <= lx; ++ix)
|
||||
{
|
||||
pointHeights.push([]);
|
||||
for (var iz = sz; iz <= lz; ++iz)
|
||||
{
|
||||
pointHeights.push(g_Map.getHeight(ix, iz));
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < numCircles; ++i)
|
||||
{
|
||||
|
||||
@@ -136,19 +136,21 @@ TileClass.prototype.countInRadius = function(cx, cy, radius, returnMembers)
|
||||
}
|
||||
else // Simply check the tiles one by one to find the number
|
||||
{
|
||||
var xmax = cx + radius;
|
||||
for (var x = cx-radius; x <= xmax; x++)
|
||||
var dy = (iy - cy);
|
||||
var xmin = Math.floor(cx - radius);
|
||||
var xmax = Math.ceil(cx + radius);
|
||||
xmin = (xmin >= 0) ? xmin : 0;
|
||||
xmax = ( xmax < size) ? xmax : size - 1;
|
||||
for (var ix = xmin; ix <= xmax; ++ix)
|
||||
{
|
||||
var ix = Math.floor(x);
|
||||
var dx = (ix - cx);
|
||||
var dy = (iy - cy);
|
||||
if (dx*dx + dy*dy <= radius2)
|
||||
{
|
||||
if (this.inclusionCount[ix] && this.inclusionCount[ix][iy] && this.inclusionCount[ix][iy] > 0)
|
||||
{
|
||||
members += 1;
|
||||
}
|
||||
else
|
||||
nonMembers += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1119,7 +1119,7 @@ else if (md == 8) //lakes
|
||||
if (!lakeAreaLen)
|
||||
break;
|
||||
|
||||
chosenPoint = lakeAreas[randInt(0, lakeAreaLen)];
|
||||
chosenPoint = lakeAreas[randInt(lakeAreaLen)];
|
||||
|
||||
placer = new ChainPlacer(1, floor(scaleByMapSize(4, 8)), floor(scaleByMapSize(40, 180)), 0.7, chosenPoint[0], chosenPoint[1]);
|
||||
terrainPainter = new LayeredPainter(
|
||||
@@ -1133,19 +1133,18 @@ else if (md == 8) //lakes
|
||||
avoidClasses(clPlayer, 20, clWater, 8),
|
||||
1, 1
|
||||
);
|
||||
|
||||
if (newLake !== undefined)
|
||||
|
||||
if (newLake && newLake.length)
|
||||
{
|
||||
var temp = []
|
||||
var n = 0;
|
||||
for (var j = 0; j < lakeAreaLen; ++j)
|
||||
{
|
||||
var x = lakeAreas[j][0], z = lakeAreas[j][1];
|
||||
if (playerConstraint.allows(x, z) && waterConstraint.allows(x, z))
|
||||
temp.push([x, z]);
|
||||
lakeAreas[n++] = lakeAreas[j];
|
||||
}
|
||||
lakeAreas = temp;
|
||||
}
|
||||
|
||||
lakeAreas.length = n;
|
||||
}
|
||||
}
|
||||
}
|
||||
//********************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user