diff --git a/OpenSim/Framework/TerrainData.cs b/OpenSim/Framework/TerrainData.cs index da6fc3f242..2209203584 100644 --- a/OpenSim/Framework/TerrainData.cs +++ b/OpenSim/Framework/TerrainData.cs @@ -31,8 +31,6 @@ using System.IO; using System.IO.Compression; using System.Reflection; -using OpenMetaverse; - using log4net; namespace OpenSim.Framework @@ -361,30 +359,35 @@ namespace OpenSim.Framework public unsafe void GetPatchMinMax(int px, int py, out float zmin, out float zmax) { - zmax = float.MinValue; - zmin = float.MaxValue; - - int mpy = Constants.TerrainPatchSize * py; + float min, max; fixed (float* map = m_heightmap) { - float* p = map + px * m_mapPatchsStride; - float* pend = p + m_mapPatchsStride; - while (p < pend) + float* p = map + px * m_mapPatchsStride + Constants.TerrainPatchSize * py; + float* endp = p + m_mapPatchsStride; + min = max = *p; + float* y = p; + int j = Constants.TerrainPatchSize - 1; + + do { - float* yt = p + mpy; - float* ytend = yt + 16; - while(yt < ytend) + do { - float val = *yt; - if (val > zmax) - zmax = val; - if (val < zmin) - zmin = val; - yt++; + float val = *y++; + if (val > max) + max = val; + else if (val < min) + min = val; } + while(--j > 0); + p += m_mapStride; + y = p; + j = Constants.TerrainPatchSize; } + while (p < endp); } + zmin = min; + zmax = max; } public unsafe void GetPatchBlock(float* block, int px, int py, float sub, float premult) diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs index 58bf9dc02b..f568eafe33 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/FlattenArea.cs @@ -26,6 +26,8 @@ */ using OpenSim.Region.Framework.Interfaces; +using OpenSim.Framework; + namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes { @@ -36,10 +38,27 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { + if(height < 0) + height = 0; + else if(height > Constants.MaxTerrainHeightmap) + height = Constants.MaxTerrainHeightmap; strength *= 0.04f; - if(strength > 1.0f) - strength = 1.0f; + if(strength >= .999f) + { + for (int x = startX; x <= endX; x++) + { + for (int y = startY; y <= endY; y++) + { + if (fillArea[x, y]) + map[x, y] = height; + } + } + return; + } + + if(strength < 1e-3) + return; for (int x = startX; x <= endX; x++) { diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs index ecf7dfbf84..d8e0a61fa9 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/LowerArea.cs @@ -36,10 +36,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { - int x,y; - for (x = startX; x <= endX; ++x) + for (int x = startX; x <= endX; ++x) { - for (y = startY; y <= endY; ++y) + for (int y = startY; y <= endY; ++y) { if (fillArea[x, y]) { diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs index b881fa0133..b4cb99e395 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/NoiseArea.cs @@ -39,16 +39,18 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes int startX, int endX, int startY, int endY) { strength *= 0.08f; - - int x, y; - for (x = startX; x <= endX; x++) + if(strength < 1e-4f) + return; + for (int x = startX; x <= endX; x++) { - for (y = startY; y <= endY; y++) + for (int y = startY; y <= endY; y++) { if (fillArea[x, y]) { float noise = (float)TerrainUtil.PerlinNoise2D((double) x / map.Width, (double) y / map.Height, 8, 1.0); map[x, y] += noise * strength; + if(map[x, y] < 0) + map[x, y] = 0; } } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs index 897ac72b9d..55592d350c 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RaiseArea.cs @@ -36,10 +36,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { - int x,y; - for (x = startX; x <= endX; x++) + for (int x = startX; x <= endX; x++) { - for (y = startY; y <= endY; y++) + for (int y = startY; y <= endY; y++) { if (fillArea[x, y]) { diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs index 973a765ea5..9e6df68d99 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/RevertArea.cs @@ -45,22 +45,37 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes /// /// the current heightmap /// array indicating which sections of the map are to be reverted - /// unused + /// public void FloodEffect(ITerrainChannel map, bool[,] fillArea, float height, float strength, int startX, int endX, int startY, int endY) { - int x, y; strength *= 2f; - if (strength > 1.0f) - strength = 1.0f; - - for (x = startX; x <= endX; x++) + if (strength >= .999f) { - for (y = startY; y <= endY; y++) + for (int x = startX; x <= endX; x++) + { + for (int y = startY; y <= endY; y++) + { + if (fillArea[x, y]) + { + map[x, y] = m_revertmap[x, y]; + } + } + } + return; + } + + if(strength < 1e-4f) + return; + + float OneMinusstrength = 1.0f - strength; + for (int x = startX; x <= endX; x++) + { + for (int y = startY; y <= endY; y++) { if (fillArea[x, y]) { - map[x, y] = map[x, y] * (1.0f - strength) + m_revertmap[x, y] * strength; + map[x, y] = map[x, y] * OneMinusstrength + m_revertmap[x, y] * strength; } } } diff --git a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs index 3e6271250b..e23654befe 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/FloodBrushes/SmoothArea.cs @@ -45,11 +45,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes sy = 4; strength *= 0.002f; + if(strength < 1e-4f) + return; if(strength > 1.0f) strength = 1.0f; - float[,] tweak = new float[endX - startX + 1, endY - startY + 1]; - + float OneMinusstrength = 1.0f - strength; for (int x = startX, i = 0; x <= endX; x++, i++) { for (int y = startY, j = 0; y <= endY; y++, j++) @@ -74,20 +75,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.FloodBrushes } } } - - tweak[i, j] = average / avgsteps; - } - } - - for (int x = startX, i = 0; x <= endX; x++, i++) - { - for (int y = startY, j = 0; y <= endY; y++, j++) - { - float ty = tweak[i, j]; - if (ty == 0.0) - continue; - - map[x, y] = (1.0f - strength) * map[x, y] + strength * ty; + map[x, y] = OneMinusstrength * map[x, y] + strength * average / avgsteps; } } }