From 87b313792821cb842fd54b568302b6877c4e53f8 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Sat, 3 May 2008 20:00:35 +0000 Subject: * Cleaned up code in Terrain, Tree and Map modules. * Fixed a bug with Terragen loader where it would do bad things on a non 256x256 sized terrain. Now loads the array correctly. * Moved MapImageModule.cs to Modules/World/WorldMap * Changed Location.RegionHandle to use Helpers.GetUlong instead of doing it ourselves. --- .../World/Terrain/PaintBrushes/ErodeSphere.cs | 19 +++++++-------- .../World/Terrain/PaintBrushes/FlattenSphere.cs | 17 +++---------- .../World/Terrain/PaintBrushes/LowerSphere.cs | 3 ++- .../World/Terrain/PaintBrushes/NoiseSphere.cs | 5 ++-- .../World/Terrain/PaintBrushes/OlsenSphere.cs | 28 +++++++++------------- .../World/Terrain/PaintBrushes/RaiseSphere.cs | 3 ++- .../World/Terrain/PaintBrushes/RevertSphere.cs | 5 ++-- .../World/Terrain/PaintBrushes/SmoothSphere.cs | 3 ++- .../World/Terrain/PaintBrushes/WeatherSphere.cs | 16 ++++++------- 9 files changed, 43 insertions(+), 56 deletions(-) (limited to 'OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes') diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs index e036988..dae4cf8 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/ErodeSphere.cs @@ -35,20 +35,20 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes /// public class ErodeSphere : ITerrainPaintableEffect { - private double rainHeight = 0.2; - private int rounds = 10; - private NeighbourSystem type = NeighbourSystem.Moore; // Parameter - private double waterSaturation = 0.30; // Can carry 1% of water in height + private const double rainHeight = 0.2; + private const int rounds = 10; + private const NeighbourSystem type = NeighbourSystem.Moore; + private const double waterSaturation = 0.30; #region Supporting Functions - private int[] Neighbours(NeighbourSystem type, int index) + private static int[] Neighbours(NeighbourSystem neighbourType, int index) { int[] coord = new int[2]; index++; - switch (type) + switch (neighbourType) { case NeighbourSystem.Moore: switch (index) @@ -173,7 +173,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { for (y = 0; y < water.Height; y++) { - double solConst = (1.0 / rounds); + const double solConst = (1.0 / rounds); double sedDelta = water[x, y] * solConst; map[x, y] -= sedDelta; sediment[x, y] += sedDelta; @@ -194,9 +194,8 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes double altitudeTotal = 0.0; double altitudeMe = map[x, y] + water[x, y]; - int NEIGHBOUR_ME = 4; - - int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; + const int NEIGHBOUR_ME = 4; + const int NEIGHBOUR_MAX = 9; for (int j = 0; j < NEIGHBOUR_MAX; j++) { diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs index dee455f..0c4e3de 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/FlattenSphere.cs @@ -39,21 +39,16 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes strength = TerrainUtil.MetersToSphericalStrength(strength); int x, y; - double[,] tweak = new double[map.Width,map.Height]; - - double area = strength; - double step = strength / 4.0; double sum = 0.0; double step2 = 0.0; - double avg = 0.0; // compute delta map for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { - double z = SphericalFactor(x, y, rx, ry, strength); + double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { @@ -63,14 +58,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes } } - avg = sum / step2; + double avg = sum / step2; // blend in map for (x = 0; x < map.Width; x++) { for (y = 0; y < map.Height; y++) { - double z = SphericalFactor(x, y, rx, ry, strength) * duration; + double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength) * duration; if (z > 0) // add in non-zero amount { @@ -84,11 +79,5 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes } #endregion - - private double SphericalFactor(double x, double y, double rx, double ry, double size) - { - double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); - return z; - } } } \ No newline at end of file diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs index 092bd29..202ab3b 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/LowerSphere.cs @@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { strength = TerrainUtil.MetersToSphericalStrength(strength); - int x, y; + int x; for (x = 0; x < map.Width; x++) { // Skip everything unlikely to be affected if (Math.Abs(x - rx) > strength * 1.1) continue; + int y; for (y = 0; y < map.Height; y++) { // Skip everything unlikely to be affected diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs index 8ae583e..0824efd 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/NoiseSphere.cs @@ -39,13 +39,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { strength = TerrainUtil.MetersToSphericalStrength(strength); - int x, y; + int x; for (x = 0; x < map.Width; x++) { // Skip everything unlikely to be affected if (Math.Abs(x - rx) > strength * 1.1) continue; + int y; for (y = 0; y < map.Height; y++) { // Skip everything unlikely to be affected @@ -57,7 +58,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes z *= z; z -= ((x - rx) * (x - rx)) + ((y - ry) * (y - ry)); - double noise = TerrainUtil.PerlinNoise2D((double) x / (double) Constants.RegionSize, (double) y / (double) Constants.RegionSize, 8, 1.0); + double noise = TerrainUtil.PerlinNoise2D(x / (double) Constants.RegionSize, y / (double) Constants.RegionSize, 8, 1.0); if (z > 0.0) map[x, y] += noise * z * duration; diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs index ba01a01..f2a1800 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/OlsenSphere.cs @@ -38,18 +38,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes /// public class OlsenSphere : ITerrainPaintableEffect { - private double nConst = 1024.0; - private NeighbourSystem type = NeighbourSystem.Moore; // Parameter + private const double nConst = 1024.0; + private const NeighbourSystem type = NeighbourSystem.Moore; #region Supporting Functions - private int[] Neighbours(NeighbourSystem type, int index) + private static int[] Neighbours(NeighbourSystem neighbourType, int index) { int[] coord = new int[2]; index++; - switch (type) + switch (neighbourType) { case NeighbourSystem.Moore: switch (index) @@ -141,12 +141,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes return coord; } - private double SphericalFactor(double x, double y, double rx, double ry, double size) - { - double z = size * size - ((x - rx) * (x - rx) + (y - ry) * (y - ry)); - return z; - } - private enum NeighbourSystem { Moore, @@ -161,22 +155,22 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { strength = TerrainUtil.MetersToSphericalStrength(strength); - int x, y; + int x; for (x = 0; x < map.Width; x++) { + int y; for (y = 0; y < map.Height; y++) { - double z = SphericalFactor(x, y, rx, ry, strength); + double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { - int NEIGHBOUR_ME = 4; - int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; + const int NEIGHBOUR_ME = 4; + const int NEIGHBOUR_MAX = 9; double max = Double.MinValue; int loc = 0; - double cellmax = 0; for (int j = 0; j < NEIGHBOUR_MAX; j++) @@ -197,7 +191,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes if (coords[1] < 0) continue; - cellmax = map[x, y] - map[coords[0], coords[1]]; + double cellmax = map[x, y] - map[coords[0], coords[1]]; if (cellmax > max) { max = cellmax; @@ -206,7 +200,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes } } - double T = nConst / ((map.Width + map.Height) / 2); + double T = nConst / ((map.Width + map.Height) / 2.0); // Apply results if (0 < max && max <= T) { diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs index 5d6f093..f5344a0 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RaiseSphere.cs @@ -38,13 +38,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { strength = TerrainUtil.MetersToSphericalStrength(strength); - int x, y; + int x; for (x = 0; x < map.Width; x++) { // Skip everything unlikely to be affected if (Math.Abs(x - rx) > strength * 1.1) continue; + int y; for (y = 0; y < map.Height; y++) { // Skip everything unlikely to be affected diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs index b47e041..3deb458 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/RevertSphere.cs @@ -32,7 +32,7 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { public class RevertSphere : ITerrainPaintableEffect { - private ITerrainChannel m_revertmap; + private readonly ITerrainChannel m_revertmap; public RevertSphere(ITerrainChannel revertmap) { @@ -50,13 +50,14 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes if (duration < 0) return; - int x, y; + int x; for (x = 0; x < map.Width; x++) { // Skip everything unlikely to be affected if (Math.Abs(x - rx) > strength * 1.1) continue; + int y; for (y = 0; y < map.Height; y++) { // Skip everything unlikely to be affected diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs index 51d5f0e..49946fd 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/SmoothSphere.cs @@ -40,7 +40,6 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes int x, y; double[,] tweak = new double[map.Width,map.Height]; - double n, l; double area = strength; double step = strength / 4.0; @@ -56,8 +55,10 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes double average = 0.0; int avgsteps = 0; + double n; for (n = 0.0 - area; n < area; n += step) { + double l; for (l = 0.0 - area; l < area; l += step) { avgsteps++; diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs index b48beb8..753d171 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/PaintBrushes/WeatherSphere.cs @@ -34,18 +34,18 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes /// public class WeatherSphere : ITerrainPaintableEffect { - private double talus = 0.2; // Number of meters max difference before stop eroding. Tweakage required. - private NeighbourSystem type = NeighbourSystem.Moore; // Parameter + private const double talus = 0.2; + private const NeighbourSystem type = NeighbourSystem.Moore; #region Supporting Functions - private int[] Neighbours(NeighbourSystem type, int index) + private static int[] Neighbours(NeighbourSystem neighbourType, int index) { int[] coord = new int[2]; index++; - switch (type) + switch (neighbourType) { case NeighbourSystem.Moore: switch (index) @@ -151,19 +151,19 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain.PaintBrushes { strength = TerrainUtil.MetersToSphericalStrength(strength); - int x, y; + int x; for (x = 0; x < map.Width; x++) { + int y; for (y = 0; y < map.Height; y++) { double z = TerrainUtil.SphericalFactor(x, y, rx, ry, strength); if (z > 0) // add in non-zero amount { - int NEIGHBOUR_ME = 4; - - int NEIGHBOUR_MAX = type == NeighbourSystem.Moore ? 9 : 5; + const int NEIGHBOUR_ME = 4; + const int NEIGHBOUR_MAX = 9; for (int j = 0; j < NEIGHBOUR_MAX; j++) { -- cgit v1.1