mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 13:04:10 +00:00
Remove SemiRandomElevationPainter from Pyrenean Sierra, which is a painful straight copy of the SmoothElevationPainter introduced in a796800bb1, refs #4805.
It should have been added to the painters file instead of to the map if a copy was acceptable. Add the only simple capability it added (an unnoticeable random elevation difference to each vertex) to the SmoothElevationPainter to make it universally accessible. That painter also had a bug, because it replaced the roughness with 5 if 0 was given. This was SVN commit r20354.
This commit is contained in:
@@ -1,171 +1,4 @@
|
||||
RMS.LoadLibrary("rmgen");
|
||||
|
||||
// Some functions
|
||||
// This is the basic SmoothElevationPainter with a random component thrown in.
|
||||
function SemiRandomElevationPainter(elevation, blendRadius,roughness)
|
||||
{
|
||||
this.elevation = elevation;
|
||||
this.blendRadius = blendRadius;
|
||||
if (!roughness)
|
||||
this.roughness = 5;
|
||||
else
|
||||
this.roughness = roughness;
|
||||
}
|
||||
|
||||
SemiRandomElevationPainter.prototype.checkInArea = function(areaID, x, z)
|
||||
{
|
||||
// Check given tile and its neighbors
|
||||
return (
|
||||
(g_Map.inMapBounds(x, z) && g_Map.area[x][z] == areaID)
|
||||
|| (g_Map.inMapBounds(x-1, z) && g_Map.area[x-1][z] == areaID)
|
||||
|| (g_Map.inMapBounds(x, z-1) && g_Map.area[x][z-1] == areaID)
|
||||
|| (g_Map.inMapBounds(x-1, z-1) && g_Map.area[x-1][z-1] == areaID)
|
||||
);
|
||||
};
|
||||
|
||||
SemiRandomElevationPainter.prototype.paint = function(area)
|
||||
{
|
||||
var pointQ = [];
|
||||
var pts = area.points;
|
||||
var heightPts = [];
|
||||
|
||||
var mapSize = getMapSize()+1;
|
||||
|
||||
var saw = [];
|
||||
var dist = [];
|
||||
var gotHeightPt = [];
|
||||
var newHeight = [];
|
||||
|
||||
// init typed arrays
|
||||
for (var i = 0; i < mapSize; ++i)
|
||||
{
|
||||
saw[i] = new Uint8Array(mapSize); // bool / uint8
|
||||
dist[i] = new Uint16Array(mapSize); // uint16
|
||||
gotHeightPt[i] = new Uint8Array(mapSize); // bool / uint8
|
||||
newHeight[i] = new Float32Array(mapSize); // float32
|
||||
}
|
||||
|
||||
var length = pts.length;
|
||||
var areaID = area.getID();
|
||||
|
||||
// get a list of all points
|
||||
for (var i=0; i < length; i++)
|
||||
{
|
||||
var x = pts[i].x;
|
||||
var z = pts[i].z;
|
||||
|
||||
for (var dx=-1; dx <= 2; dx++)
|
||||
{
|
||||
var nx = x+dx;
|
||||
for (var dz=-1; dz <= 2; dz++)
|
||||
{
|
||||
var nz = z+dz;
|
||||
|
||||
if (g_Map.validH(nx, nz) && !gotHeightPt[nx][nz])
|
||||
{
|
||||
gotHeightPt[nx][nz] = 1;
|
||||
heightPts.push(new PointXZ(nx, nz));
|
||||
newHeight[nx][nz] = g_Map.height[nx][nz];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// push edge points
|
||||
for (var i=0; i < length; i++)
|
||||
{
|
||||
var x = pts[i].x;
|
||||
var z = pts[i].z;
|
||||
for (var dx=-1; dx <= 2; dx++)
|
||||
{
|
||||
var nx = x+dx;
|
||||
for (var dz=-1; dz <= 2; dz++)
|
||||
{
|
||||
var nz = z+dz;
|
||||
|
||||
if (g_Map.validH(nx, nz) && !this.checkInArea(areaID, nx, nz) && !saw[nx][nz])
|
||||
{
|
||||
saw[nx][nz]= 1;
|
||||
dist[nx][nz] = 0;
|
||||
pointQ.push(new PointXZ(nx, nz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// do BFS inwards to find distances to edge
|
||||
while(pointQ.length)
|
||||
{
|
||||
var pt = pointQ.shift();
|
||||
var px = pt.x;
|
||||
var pz = pt.z;
|
||||
var d = dist[px][pz];
|
||||
|
||||
// paint if in area
|
||||
if (g_Map.validH(px, pz) && this.checkInArea(areaID, px, pz))
|
||||
{
|
||||
if (d <= this.blendRadius)
|
||||
{
|
||||
var a = (d-1) / this.blendRadius;
|
||||
newHeight[px][pz] += a*this.elevation + randFloat(-this.roughness,this.roughness);
|
||||
}
|
||||
else
|
||||
{ // also happens when blendRadius == 0
|
||||
newHeight[px][pz] += this.elevation + randFloat(-this.roughness,this.roughness);
|
||||
}
|
||||
}
|
||||
// enqueue neighbours
|
||||
for (var dx=-1; dx <= 1; dx++)
|
||||
{
|
||||
var nx = px+dx;
|
||||
for (var dz=-1; dz <= 1; dz++)
|
||||
{
|
||||
var nz = pz+dz;
|
||||
|
||||
if (g_Map.validH(nx, nz) && this.checkInArea(areaID, nx, nz) && !saw[nx][nz])
|
||||
{
|
||||
saw[nx][nz] = 1;
|
||||
dist[nx][nz] = d+1;
|
||||
pointQ.push(new PointXZ(nx, nz));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
length = heightPts.length;
|
||||
|
||||
// smooth everything out
|
||||
for (var i = 0; i < length; ++i)
|
||||
{
|
||||
var pt = heightPts[i];
|
||||
var px = pt.x;
|
||||
var pz = pt.z;
|
||||
|
||||
if (this.checkInArea(areaID, px, pz))
|
||||
{
|
||||
var sum = 8 * newHeight[px][pz];
|
||||
var count = 8;
|
||||
|
||||
for (var dx=-1; dx <= 1; dx++)
|
||||
{
|
||||
var nx = px+dx;
|
||||
for (var dz=-1; dz <= 1; dz++)
|
||||
{
|
||||
var nz = pz+dz;
|
||||
|
||||
if (g_Map.validH(nx, nz))
|
||||
{
|
||||
sum += newHeight[nx][nz];
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_Map.height[px][pz] = sum/count;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TILE_CENTERED_HEIGHT_MAP = true;
|
||||
|
||||
const tGrassSpecific = ["new_alpine_grass_d","new_alpine_grass_d", "new_alpine_grass_e"];
|
||||
@@ -531,7 +364,7 @@ log ("Creating hills...");
|
||||
createAreas(
|
||||
new ClumpPlacer(scaleByMapSize(60, 120), 0.3, 0.06, 5),
|
||||
[
|
||||
new SemiRandomElevationPainter(7, 4, 1),
|
||||
new SmoothElevationPainter(ELEVATION_MODIFY, 7, 4, 2),
|
||||
new TerrainPainter(tGrassSpecific),
|
||||
paintClass(clHill)
|
||||
],
|
||||
|
||||
@@ -139,12 +139,14 @@ const ELEVATION_MODIFY = 1;
|
||||
* @param type - ELEVATION_MODIFY or ELEVATION_SET.
|
||||
* @param elevation - target height.
|
||||
* @param blendRadius - How steep the elevation change is.
|
||||
* @param randomElevation - maximum random elevation difference added to each vertex.
|
||||
*/
|
||||
function SmoothElevationPainter(type, elevation, blendRadius)
|
||||
function SmoothElevationPainter(type, elevation, blendRadius, randomElevation = 0)
|
||||
{
|
||||
this.type = type;
|
||||
this.elevation = elevation;
|
||||
this.blendRadius = blendRadius;
|
||||
this.randomElevation = randomElevation;
|
||||
|
||||
if (type != ELEVATION_SET && type != ELEVATION_MODIFY)
|
||||
throw new Error("SmoothElevationPainter: invalid type '" + type + "'");
|
||||
@@ -207,7 +209,7 @@ SmoothElevationPainter.prototype.paint = function(area)
|
||||
if (this.type == ELEVATION_SET)
|
||||
newHeight[point.x][point.z] = (1 - a) * g_Map.height[point.x][point.z];
|
||||
|
||||
newHeight[point.x][point.z] += a * this.elevation;
|
||||
newHeight[point.x][point.z] += a * this.elevation + randFloat(-0.5, 0.5) * this.randomElevation;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user