diff --git a/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs b/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs deleted file mode 100644 index 33c3fbe35b..0000000000 --- a/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -using System; -using OpenSim.Region.CoreModules.World.Terrain; -using OpenSim.Region.Framework.Interfaces; - -namespace OpenSim.Region.CoreModules.World.Terrain.Features -{ - public class RectangleFeature : TerrainFeature - { - public RectangleFeature(ITerrainModule module) : base(module) - { - } - - public override string CreateFeature(ITerrainChannel map, string[] args) - { - string val; - string result; - if (args.Length < 7) - { - result = "Usage: " + GetUsage(); - } - else - { - result = String.Empty; - - float targetElevation; - val = base.parseFloat(args[3], out targetElevation); - if (val != String.Empty) - { - result = val; - } - - int xOrigin; - val = base.parseInt(args[4], out xOrigin); - if (val != String.Empty) - { - result = val; - } - else if (xOrigin < 0 || xOrigin >= map.Width) - { - result = "x-origin must be within the region"; - } - - int yOrigin; - val = base.parseInt(args[5], out yOrigin); - if (val != String.Empty) - { - result = val; - } - else if (yOrigin < 0 || yOrigin >= map.Height) - { - result = "y-origin must be within the region"; - } - - int xDelta; - val = base.parseInt(args[6], out xDelta); - if (val != String.Empty) - { - result = val; - } - else if (xDelta <= 0) - { - result = "x-size must be greater than zero"; - } - - int yDelta; - if (args.Length > 7) - { - val = base.parseInt(args[7], out yDelta); - if (val != String.Empty) - { - result = val; - } - else if (yDelta <= 0) - { - result = "y-size must be greater than zero"; - } - } - else - { - // no y-size.. make it square - yDelta = xDelta; - } - - // slightly more complex validation, if required. - if (result == String.Empty) - { - if (xOrigin + xDelta > map.Width) - { - result = "(x-origin + x-size) must be within the region size"; - } - else if (yOrigin + yDelta > map.Height) - { - result = "(y-origin + y-size) must be within the region size"; - } - } - - // if it's all good, then do the work - if (result == String.Empty) - { - int yPos = yOrigin + yDelta; - while(--yPos >= yOrigin) - { - int xPos = xOrigin + xDelta; - while(--xPos >= xOrigin) - { - map[xPos, yPos] = (double)targetElevation; - } - } - } - } - - return result; - } - - public override string GetUsage() - { - return "rectangle []"; - } - } - -} - diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs new file mode 100644 index 0000000000..b31bab1afe --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/NoiseModifier.cs @@ -0,0 +1,110 @@ +/* + * Copyright (c) Contributors, http://opensimulator.org/ + * See CONTRIBUTORS.TXT for a full list of copyright holders. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the OpenSimulator Project nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +using System; +using OpenSim.Region.CoreModules.World.Terrain; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers +{ + public class NoiseModifier : TerrainModifier + { + public NoiseModifier(ITerrainModule module) : base(module) + { + } + + public override string ModifyTerrain(ITerrainChannel map, string[] args) + { + string val; + string result; + if (args.Length < 3) + { + result = "Usage: " + GetUsage(); + } + else + { + TerrainModifierData data; + result = this.parseParameters(args, out data); + + // Context-specific validation + if (result == String.Empty) + { + if (data.bevel == "taper") + { + if (data.bevelevation < 0.0 || data.bevelevation > 1.0) + { + result = String.Format("Taper must be 0.0 to 1.0: {0}", data.bevelevation); + } + } + else + { + data.bevelevation = 1.0f; + } + + if (data.elevation < 0.0 || data.elevation > 1.0) + { + result = String.Format("Noise strength must be 0.0 to 1.0: {0}", data.elevation); + } + + if (data.shape == String.Empty) + { + data.shape = "rectangle"; + data.x0 = 0; + data.y0 = 0; + data.dx = map.Width; + data.dy = map.Height; + } + } + + // if it's all good, then do the work + if (result == String.Empty) + { + this.applyModification(map, data); + } + } + + return result; + } + + public override string GetUsage() + { + string val = "noise [ -rec=x1,y1,dx[,dy] | -ell=x0,y0,rx[,ry] ] [-taper=]" + + "\nAdds noise to all points within the specified range."; + return val; + } + + public override double operate(double[,] map, TerrainModifierData data, int x, int y) + { + double factor = this.computeBevel(data, x, y); + double noise = TerrainUtil.PerlinNoise2D((double)x / map.GetLength(0), (double)y / map.GetLength(1), 8, 1.0); + return map[x, y] + (data.elevation - (data.elevation - data.bevelevation) * factor) * (noise - .5); + } + + } + +} + diff --git a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs index 1731cd8f18..72b172c5d1 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/Modifiers/SmoothModifier.cs @@ -56,7 +56,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers { if (data.bevelevation < 0.01 || data.bevelevation > 0.99) { - result = String.Format("Taper must be 0.01 to 0.99 {0}", data.bevelevation); + result = String.Format("Taper must be 0.01 to 0.99: {0}", data.bevelevation); } } else @@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain.Modifiers if (data.elevation < 0.0 || data.elevation > 1.0) { - result = String.Format("Scaling factor must be 0.0 to 1.0: {0}", data.elevation); + result = String.Format("Smoothing strength must be 0.0 to 1.0: {0}", data.elevation); } if (data.shape == String.Empty) diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs deleted file mode 100644 index 701a729d2e..0000000000 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) Contributors, http://opensimulator.org/ - * See CONTRIBUTORS.TXT for a full list of copyright holders. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the OpenSimulator Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -using System; -using System.Reflection; - -using OpenSim.Region.Framework.Interfaces; - -namespace OpenSim.Region.CoreModules.World.Terrain -{ - public abstract class TerrainFeature : ITerrainFeature - { - protected ITerrainModule m_module; - - protected TerrainFeature(ITerrainModule module) - { - m_module = module; - } - - public abstract string CreateFeature(ITerrainChannel map, string[] args); - - public abstract string GetUsage(); - - protected string parseFloat(String s, out float f) - { - string result; - double d; - if (Double.TryParse(s, out d)) - { - try - { - f = (float)d; - result = String.Empty; - } - catch(InvalidCastException) - { - result = String.Format("{0} is invalid", s); - f = -1.0f; - } - } - else - { - f = -1.0f; - result = String.Format("{0} is invalid", s); - } - return result; - } - - protected string parseInt(String s, out int i) - { - string result; - if (Int32.TryParse(s, out i)) - { - result = String.Empty; - } - else - { - result = String.Format("{0} is invalid", s); - } - return result; - } - - } - -} - diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index 02f21b9b2d..05c5fca014 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs @@ -41,7 +41,6 @@ using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Region.CoreModules.Framework.InterfaceCommander; using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; -using OpenSim.Region.CoreModules.World.Terrain.Features; using OpenSim.Region.CoreModules.World.Terrain.Modifiers; using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; @@ -75,14 +74,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain #endregion - /// - /// Terrain Features - /// - public enum TerrainFeatures: byte - { - Rectangle = 1, - } - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); #pragma warning disable 414 @@ -96,8 +87,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain private readonly Dictionary m_painteffects = new Dictionary(); private Dictionary m_plugineffects; - private Dictionary m_featureEffects = - new Dictionary(); private Dictionary m_modifyOperations = new Dictionary(); private ITerrainChannel m_channel; @@ -657,9 +646,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); - // Terrain Feature effects - m_featureEffects["rectangle"] = new RectangleFeature(this); - // Terrain Modifier operations m_modifyOperations["min"] = new MinModifier(this); m_modifyOperations["max"] = new MaxModifier(this); @@ -667,6 +653,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain m_modifyOperations["lower"] = new LowerModifier(this); m_modifyOperations["fill"] = new FillModifier(this); m_modifyOperations["smooth"] = new SmoothModifier(this); + m_modifyOperations["noise"] = new NoiseModifier(this); // Filesystem load/save loaders m_loaders[".r32"] = new RAW32(); @@ -1671,9 +1658,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain // Add this to our scene so scripts can call these functions m_scene.RegisterModuleCommander(m_commander); - // Add Feature command to Scene, since Command object requires fixed-length arglists - m_scene.AddCommand("Terrain", this, "terrain feature", - "terrain feature ", "Constructs a feature of the requested type.", FeatureCommand); // Add Modify command to Scene, since Command object requires fixed-length arglists m_scene.AddCommand("Terrain", this, "terrain modify", "terrain modify [] []", @@ -1689,40 +1673,6 @@ namespace OpenSim.Region.CoreModules.World.Terrain } - public void FeatureCommand(string module, string[] cmd) - { - string result; - if (cmd.Length > 2) - { - string featureType = cmd[2]; - - ITerrainFeature feature; - if (!m_featureEffects.TryGetValue(featureType, out feature)) - { - result = String.Format("Terrain Feature \"{0}\" not found.", featureType); - } - else if ((cmd.Length > 3) && (cmd[3] == "usage")) - { - result = "Usage: " + feature.GetUsage(); - } - else - { - result = feature.CreateFeature(m_channel, cmd); - } - - if (result == String.Empty) - { - result = "Created Feature"; - m_log.DebugFormat("Created terrain feature {0}", featureType); - } - } - else - { - result = "Usage: ..."; - } - MainConsole.Instance.Output(result); - } - public void ModifyCommand(string module, string[] cmd) { string result;