restrict terrain PaintBrushes to the requested area

avinationmerge
UbitUmarov 2015-08-27 22:36:14 +01:00
parent f9efa23d5e
commit bd4ec5f26c
12 changed files with 97 additions and 102 deletions

View File

@ -31,6 +31,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain
{ {
public interface ITerrainPaintableEffect public interface ITerrainPaintableEffect
{ {
void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z, double strength, double duration); void PaintEffect(ITerrainChannel map, bool[,] allowMask, double x, double y, double z,
double strength, double duration, int startX, int endX, int startY, int endY);
} }
} }

View File

@ -151,7 +151,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
@ -163,18 +164,23 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height);
// Fill with rain // Fill with rain
for (x = 0; x < water.Width; x++) for (x = startX; x <= endX; x++)
for (y = 0; y < water.Height; y++) {
water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration); for (y = startY; y <= endY; y++)
{
if (mask[x, y])
water[x, y] = Math.Max(0.0, TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * rainHeight * duration);
}
}
for (int i = 0; i < rounds; i++) for (int i = 0; i < rounds; i++)
{ {
// Erode underlying terrain // Erode underlying terrain
for (x = 0; x < water.Width; x++) for (x = startX; x <= endX; x++)
{ {
for (y = 0; y < water.Height; y++) for (y = startY; y <= endY; y++)
{ {
if (mask[x,y]) if (mask[x, y])
{ {
const double solConst = (1.0 / rounds); const double solConst = (1.0 / rounds);
double sedDelta = water[x, y] * solConst; double sedDelta = water[x, y] * solConst;
@ -185,9 +191,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
} }
// Move water // Move water
for (x = 0; x < water.Width; x++) for (x = startX; x <= endX; x++)
{ {
for (y = 0; y < water.Height; y++) for (y = startY; y <= endY; y++)
{ {
if (water[x, y] <= 0) if (water[x, y] <= 0)
continue; continue;
@ -296,7 +302,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
double sedimentDeposit = sediment[x, y] - waterCapacity; double sedimentDeposit = sediment[x, y] - waterCapacity;
if (sedimentDeposit > 0) if (sedimentDeposit > 0)
{ {
if (mask[x,y]) if (mask[x, y])
{ {
sediment[x, y] -= sedimentDeposit; sediment[x, y] -= sedimentDeposit;
map[x, y] += sedimentDeposit; map[x, y] += sedimentDeposit;
@ -309,10 +315,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
// Deposit any remainder (should be minimal) // Deposit any remainder (should be minimal)
for (x = 0; x < water.Width; x++) for (x = 0; x < water.Width; x++)
for (y = 0; y < water.Height; y++) for (y = 0; y < water.Height; y++)
if (mask[x,y] && sediment[x, y] > 0) if (mask[x, y] && sediment[x, y] > 0)
map[x, y] += sediment[x, y]; map[x, y] += sediment[x, y];
} }
#endregion #endregion
} }
} }

View File

@ -35,7 +35,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
{ {
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);

View File

@ -34,34 +34,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
{ {
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
int s = (int) (Math.Pow(2, strength) + 0.5); int s = (int) (Math.Pow(2, strength) + 0.5);
int x; int x, y;
int xFrom = (int)(rx-s+0.5);
int xTo = (int)(rx+s+0.5) + 1;
int yFrom = (int)(ry-s+0.5);
int yTo = (int)(ry+s+0.5) + 1;
if (xFrom < 0) for (x = startX; x <= endX; x++)
xFrom = 0;
if (yFrom < 0)
yFrom = 0;
if (xTo > map.Width)
xTo = map.Width;
if (yTo > map.Width)
yTo = map.Width;
for (x = xFrom; x < xTo; x++)
{ {
int y; for (y = startY; y <= endY; y++)
for (y = yFrom; y < yTo; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
// Calculate a cos-sphere and add it to the heighmap // Calculate a cos-sphere and add it to the heighmap

View File

@ -35,17 +35,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
{ {
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
int x; int x, y;
for (x = 0; x < map.Width; x++)
for (x = startX; x <= endX; x++)
{ {
int y; for (y = startY; y <= endY; y++)
for (y = 0; y < map.Height; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
// Calculate a sphere and add it to the heighmap // Calculate a sphere and add it to the heighmap

View File

@ -152,18 +152,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
int x; int x, y;
for (x = 0; x < map.Width; x++) for (x = startX; x <= endX; x++)
{ {
int y; for (y = startY; y <= endY; y++)
for (y = 0; y < map.Height; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);

View File

@ -35,38 +35,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
int s = (int) (Math.Pow(2, strength) + 0.5); int s = (int) (Math.Pow(2, strength) + 0.5);
int x; int x,y;
int xFrom = (int)(rx-s+0.5);
int xTo = (int)(rx+s+0.5) + 1;
int yFrom = (int)(ry-s+0.5);
int yTo = (int)(ry+s+0.5) + 1;
if (xFrom < 0) for (x = startX; x <= endX; x++)
xFrom = 0;
if (yFrom < 0)
yFrom = 0;
if (xTo > map.Width)
xTo = map.Width;
if (yTo > map.Width)
yTo = map.Width;
for (x = xFrom; x < xTo; x++)
{ {
int y; for (y = startY; y <= endY; y++)
for (y = yFrom; y < yTo; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
// Calculate a cos-sphere and add it to the heighmap // Calculate a cos-sphere and add it to the heighmap
double r = Math.Sqrt((x-rx) * (x-rx) + ((y-ry) * (y-ry))); double r = Math.Sqrt((x - rx) * (x - rx) + ((y - ry) * (y - ry)));
double z = Math.Cos(r * Math.PI / (s * 2)); double z = Math.Cos(r * Math.PI / (s * 2));
if (z > 0.0) if (z > 0.0)
map[x, y] += z * duration; map[x, y] += z * duration;

View File

@ -41,7 +41,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
duration = 0.03; //MCP Should be read from ini file duration = 0.03; //MCP Should be read from ini file
@ -51,13 +52,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
if (duration < 0) if (duration < 0)
return; return;
int x; int x,y;
for (x = 0; x < map.Width; x++) for (x = startX; x <= endX; x++)
{ {
int y; for (y = startY; y < endY; y++)
for (y = 0; y < map.Height; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
// Calculate a sphere and add it to the heighmap // Calculate a sphere and add it to the heighmap

View File

@ -34,7 +34,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
{ {
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
@ -47,10 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
// compute delta map // compute delta map
for (x = 0; x < map.Width; x++) for (x = startX; x <= endX; x++)
{ {
for (y = 0; y < map.Height; y++) for (y = startY; y < endY; y++)
{ {
if (!mask[x, y])
continue;
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);
if (z > 0) // add in non-zero amount if (z > 0) // add in non-zero amount
@ -73,11 +77,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
} }
} }
// blend in map // blend in map
for (x = 0; x < map.Width; x++) for (x = startX; x <= endX; x++)
{ {
for (y = 0; y < map.Height; y++) for (y = startY; y < endY; y++)
{ {
if (!mask[x,y]) if (!mask[x, y])
continue; continue;
double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength);

View File

@ -148,16 +148,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes
#region ITerrainPaintableEffect Members #region ITerrainPaintableEffect Members
public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz, double strength, double duration) public void PaintEffect(ITerrainChannel map, bool[,] mask, double rx, double ry, double rz,
double strength, double duration, int startX, int endX, int startY, int endY)
{ {
strength = TerrainUtil.MetersToSphericalStrength(strength); strength = TerrainUtil.MetersToSphericalStrength(strength);
int x; int x,y;
for (x = 0; x < map.Width; x++) for (x = startX; x <= endX; x++)
{ {
int y; for (y = startY; y < endY; y++)
for (y = 0; y < map.Height; y++)
{ {
if (!mask[x,y]) if (!mask[x,y])
continue; continue;

View File

@ -1128,20 +1128,32 @@ namespace OpenSim.Region.CoreModules.World.Terrain
int zx = (int) (west + 0.5); int zx = (int) (west + 0.5);
int zy = (int) (north + 0.5); int zy = (int) (north + 0.5);
int dx,dy;
for (dx=-n; dx<=n; dx++) int startX = zx - n;
if (startX < 0)
startX = 0;
int startY = zy - n;
if (startY < 0)
startY = 0;
int endX = zx + n;
if (endX >= m_channel.Width)
endX = m_channel.Width - 1;
int endY = zy + n;
if (endY >= m_channel.Height)
endY = m_channel.Height - 1;
int x, y;
for (x = startX; x <= endX; x++)
{ {
for (dy=-n; dy<=n; dy++) for (y = startY; y <= endY; y++)
{ {
int x = zx + dx; if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x, y, 0)))
int y = zy + dy;
if (x>=0 && y>=0 && x<m_channel.Width && y<m_channel.Height)
{ {
if (m_scene.Permissions.CanTerraformLand(agentId, new Vector3(x,y,0))) allowMask[x, y] = true;
{ allowed = true;
allowMask[x, y] = true;
allowed = true;
}
} }
} }
} }
@ -1149,7 +1161,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain
{ {
StoreUndoState(); StoreUndoState();
m_painteffects[(StandardTerrainEffects) action].PaintEffect( m_painteffects[(StandardTerrainEffects) action].PaintEffect(
m_channel, allowMask, west, south, height, size, seconds); m_channel, allowMask, west, south, height, size, seconds,
startX, endX, startY, endY);
//block changes outside estate limits //block changes outside estate limits
if (!god) if (!god)

View File

@ -60,7 +60,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize); TerrainChannel map = new TerrainChannel((int)Constants.RegionSize, (int)Constants.RegionSize);
ITerrainPaintableEffect effect = new RaiseSphere(); ITerrainPaintableEffect effect = new RaiseSphere();
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
0, midRegion - 1,0, (int)Constants.RegionSize -1);
Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128)."); Assert.That(map[127, midRegion] > 0.0, "Raise brush should raising value at this point (127,128).");
Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128)."); Assert.That(map[125, midRegion] > 0.0, "Raise brush should raising value at this point (124,128).");
Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128)."); Assert.That(map[120, midRegion] == 0.0, "Raise brush should not change value at this point (120,128).");
@ -79,7 +80,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Tests
} }
effect = new LowerSphere(); effect = new LowerSphere();
effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0); effect.PaintEffect(map, allowMask, midRegion, midRegion, -1.0, 2, 6.0,
0, (int)Constants.RegionSize -1,0, (int)Constants.RegionSize -1);
Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128)."); Assert.That(map[127, midRegion] >= 0.0, "Lower should not lowering value below 0.0 at this point (127,128).");
Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128)."); Assert.That(map[127, midRegion] == 0.0, "Lower brush should lowering value to 0.0 at this point (127,128).");
Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128)."); Assert.That(map[125, midRegion] < 1.0, "Lower brush should lowering value at this point (124,128).");