From bd4ec5f26c8cc038e5155d6913e5a4601f724271 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Thu, 27 Aug 2015 22:36:14 +0100 Subject: [PATCH] restrict terrain PaintBrushes to the requested area --- .../World/Terrain/ITerrainPaintableEffect.cs | 3 +- .../World/Terrain/PaintBrushes/ErodeSphere.cs | 29 +++++++++------ .../Terrain/PaintBrushes/FlattenSphere.cs | 3 +- .../World/Terrain/PaintBrushes/LowerSphere.cs | 28 +++----------- .../World/Terrain/PaintBrushes/NoiseSphere.cs | 13 ++++--- .../World/Terrain/PaintBrushes/OlsenSphere.cs | 12 +++--- .../World/Terrain/PaintBrushes/RaiseSphere.cs | 30 ++++----------- .../Terrain/PaintBrushes/RevertSphere.cs | 12 +++--- .../Terrain/PaintBrushes/SmoothSphere.cs | 16 +++++--- .../Terrain/PaintBrushes/WeatherSphere.cs | 10 ++--- .../World/Terrain/TerrainModule.cs | 37 +++++++++++++------ .../World/Terrain/Tests/TerrainTest.cs | 6 ++- 12 files changed, 97 insertions(+), 102 deletions(-) diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs index b73defdd6f..d0b05e4f1f 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainPaintableEffect.cs @@ -31,6 +31,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain { 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); } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs index 7a78cd8f28..7358ba3bc7 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/ErodeSphere.cs @@ -151,7 +151,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes #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); @@ -163,18 +164,23 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes ITerrainChannel sediment = new TerrainChannel(map.Width, map.Height); // Fill with rain - for (x = 0; x < water.Width; 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 (x = startX; x <= endX; x++) + { + 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++) { // 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); double sedDelta = water[x, y] * solConst; @@ -185,9 +191,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes } // 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) continue; @@ -296,7 +302,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes double sedimentDeposit = sediment[x, y] - waterCapacity; if (sedimentDeposit > 0) { - if (mask[x,y]) + if (mask[x, y]) { sediment[x, y] -= sedimentDeposit; map[x, y] += sedimentDeposit; @@ -309,10 +315,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes // Deposit any remainder (should be minimal) for (x = 0; x < water.Width; x++) 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]; } - #endregion } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs index 9aa3dfff64..34bed8b228 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/FlattenSphere.cs @@ -35,7 +35,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes { #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); diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs index 68145f2017..bbf94076f0 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/LowerSphere.cs @@ -34,34 +34,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes { #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 x; - 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; + int x, y; - if (xFrom < 0) - 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++) + for (x = startX; x <= endX; x++) { - int y; - for (y = yFrom; y < yTo; y++) + for (y = startY; y <= endY; y++) { - if (!mask[x,y]) + if (!mask[x, y]) continue; // Calculate a cos-sphere and add it to the heighmap diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs index e7df3f8d4c..46d47b4d4a 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/NoiseSphere.cs @@ -35,17 +35,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes { #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); - int x; - for (x = 0; x < map.Width; x++) + int x, y; + + for (x = startX; x <= endX; x++) { - int y; - for (y = 0; y < map.Height; y++) + for (y = startY; y <= endY; y++) { - if (!mask[x,y]) + if (!mask[x, y]) continue; // Calculate a sphere and add it to the heighmap diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs index b199df358d..281690d6e5 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/OlsenSphere.cs @@ -152,18 +152,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes #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); - int x; + int x, y; - for (x = 0; x < map.Width; x++) + for (x = startX; x <= endX; x++) { - int y; - for (y = 0; y < map.Height; y++) + for (y = startY; y <= endY; y++) { - if (!mask[x,y]) + if (!mask[x, y]) continue; double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs index bd9a8a0031..1b704bbc76 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RaiseSphere.cs @@ -35,38 +35,22 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes #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 x; - 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; + int x,y; - if (xFrom < 0) - 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++) + for (x = startX; x <= endX; x++) { - int y; - for (y = yFrom; y < yTo; y++) + for (y = startY; y <= endY; y++) { - if (!mask[x,y]) + if (!mask[x, y]) continue; // 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)); if (z > 0.0) map[x, y] += z * duration; diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs index 4b282755ed..2fb05d1d9a 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/RevertSphere.cs @@ -41,7 +41,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes #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); duration = 0.03; //MCP Should be read from ini file @@ -51,13 +52,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes if (duration < 0) return; - int x; - for (x = 0; x < map.Width; x++) + int x,y; + for (x = startX; x <= endX; x++) { - int y; - for (y = 0; y < map.Height; y++) + for (y = startY; y < endY; y++) { - if (!mask[x,y]) + if (!mask[x, y]) continue; // Calculate a sphere and add it to the heighmap diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs index 4834c8697d..cc618fd6d7 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/SmoothSphere.cs @@ -34,7 +34,8 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes { #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); @@ -47,10 +48,13 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes // 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); if (z > 0) // add in non-zero amount @@ -73,11 +77,11 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes } } // 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; double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); diff --git a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs index f31c8b6865..c9facc7a35 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/PaintBrushes/WeatherSphere.cs @@ -148,16 +148,16 @@ namespace OpenSim.Region.CoreModules.World.Terrain.PaintBrushes #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); - int x; + int x,y; - for (x = 0; x < map.Width; x++) + for (x = startX; x <= endX; x++) { - int y; - for (y = 0; y < map.Height; y++) + for (y = startY; y < endY; y++) { if (!mask[x,y]) continue; diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index a5efeb8b7f..7bae9ec572 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs @@ -1128,20 +1128,32 @@ namespace OpenSim.Region.CoreModules.World.Terrain int zx = (int) (west + 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; - int y = zy + dy; - if (x>=0 && y>=0 && x 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[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.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 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).");