diff options
author | Dev Random | 2014-11-04 21:31:11 -0500 |
---|---|---|
committer | Justin Clark-Casey | 2014-11-19 18:18:18 +0000 |
commit | d3b43a96fbbb2d0c4afab546acbc72f6e3612198 (patch) | |
tree | 470a65af90735880fb8f697d833f008185e14d27 | |
parent | Improved SpecialUIModule so that it sends the floater data properly. (diff) | |
download | opensim-SC_OLD-d3b43a96fbbb2d0c4afab546acbc72f6e3612198.zip opensim-SC_OLD-d3b43a96fbbb2d0c4afab546acbc72f6e3612198.tar.gz opensim-SC_OLD-d3b43a96fbbb2d0c4afab546acbc72f6e3612198.tar.bz2 opensim-SC_OLD-d3b43a96fbbb2d0c4afab546acbc72f6e3612198.tar.xz |
Add 'terrain feature' command
4 files changed, 353 insertions, 2 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs b/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs new file mode 100644 index 0000000..33c3fbe --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/Features/RectangleFeature.cs | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.CoreModules.World.Terrain; | ||
30 | using OpenSim.Region.Framework.Interfaces; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain.Features | ||
33 | { | ||
34 | public class RectangleFeature : TerrainFeature | ||
35 | { | ||
36 | public RectangleFeature(ITerrainModule module) : base(module) | ||
37 | { | ||
38 | } | ||
39 | |||
40 | public override string CreateFeature(ITerrainChannel map, string[] args) | ||
41 | { | ||
42 | string val; | ||
43 | string result; | ||
44 | if (args.Length < 7) | ||
45 | { | ||
46 | result = "Usage: " + GetUsage(); | ||
47 | } | ||
48 | else | ||
49 | { | ||
50 | result = String.Empty; | ||
51 | |||
52 | float targetElevation; | ||
53 | val = base.parseFloat(args[3], out targetElevation); | ||
54 | if (val != String.Empty) | ||
55 | { | ||
56 | result = val; | ||
57 | } | ||
58 | |||
59 | int xOrigin; | ||
60 | val = base.parseInt(args[4], out xOrigin); | ||
61 | if (val != String.Empty) | ||
62 | { | ||
63 | result = val; | ||
64 | } | ||
65 | else if (xOrigin < 0 || xOrigin >= map.Width) | ||
66 | { | ||
67 | result = "x-origin must be within the region"; | ||
68 | } | ||
69 | |||
70 | int yOrigin; | ||
71 | val = base.parseInt(args[5], out yOrigin); | ||
72 | if (val != String.Empty) | ||
73 | { | ||
74 | result = val; | ||
75 | } | ||
76 | else if (yOrigin < 0 || yOrigin >= map.Height) | ||
77 | { | ||
78 | result = "y-origin must be within the region"; | ||
79 | } | ||
80 | |||
81 | int xDelta; | ||
82 | val = base.parseInt(args[6], out xDelta); | ||
83 | if (val != String.Empty) | ||
84 | { | ||
85 | result = val; | ||
86 | } | ||
87 | else if (xDelta <= 0) | ||
88 | { | ||
89 | result = "x-size must be greater than zero"; | ||
90 | } | ||
91 | |||
92 | int yDelta; | ||
93 | if (args.Length > 7) | ||
94 | { | ||
95 | val = base.parseInt(args[7], out yDelta); | ||
96 | if (val != String.Empty) | ||
97 | { | ||
98 | result = val; | ||
99 | } | ||
100 | else if (yDelta <= 0) | ||
101 | { | ||
102 | result = "y-size must be greater than zero"; | ||
103 | } | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | // no y-size.. make it square | ||
108 | yDelta = xDelta; | ||
109 | } | ||
110 | |||
111 | // slightly more complex validation, if required. | ||
112 | if (result == String.Empty) | ||
113 | { | ||
114 | if (xOrigin + xDelta > map.Width) | ||
115 | { | ||
116 | result = "(x-origin + x-size) must be within the region size"; | ||
117 | } | ||
118 | else if (yOrigin + yDelta > map.Height) | ||
119 | { | ||
120 | result = "(y-origin + y-size) must be within the region size"; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | // if it's all good, then do the work | ||
125 | if (result == String.Empty) | ||
126 | { | ||
127 | int yPos = yOrigin + yDelta; | ||
128 | while(--yPos >= yOrigin) | ||
129 | { | ||
130 | int xPos = xOrigin + xDelta; | ||
131 | while(--xPos >= xOrigin) | ||
132 | { | ||
133 | map[xPos, yPos] = (double)targetElevation; | ||
134 | } | ||
135 | } | ||
136 | } | ||
137 | } | ||
138 | |||
139 | return result; | ||
140 | } | ||
141 | |||
142 | public override string GetUsage() | ||
143 | { | ||
144 | return "rectangle <height> <x-origin> <y-origin> <x-size> [<y-size>]"; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | } | ||
149 | |||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/ITerrainFeature.cs b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFeature.cs new file mode 100644 index 0000000..78a43db --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/ITerrainFeature.cs | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using OpenSim.Region.Framework.Interfaces; | ||
30 | |||
31 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
32 | { | ||
33 | public interface ITerrainFeature | ||
34 | { | ||
35 | /// <summary> | ||
36 | /// Creates the feature. | ||
37 | /// </summary> | ||
38 | /// <returns> | ||
39 | /// Empty string if successful, otherwise error message. | ||
40 | /// </returns> | ||
41 | /// <param name='map'> | ||
42 | /// ITerrainChannel holding terrain data. | ||
43 | /// </param> | ||
44 | /// <param name='args'> | ||
45 | /// command-line arguments from console. | ||
46 | /// </param> | ||
47 | string CreateFeature(ITerrainChannel map, string[] args); | ||
48 | |||
49 | /// <summary> | ||
50 | /// Gets a string describing the usage. | ||
51 | /// </summary> | ||
52 | /// <returns> | ||
53 | /// A string describing parameters for creating the feature. | ||
54 | /// Format is "feature-name <arg1> <arg2> ..." | ||
55 | /// </returns> | ||
56 | string GetUsage(); | ||
57 | } | ||
58 | |||
59 | } | ||
60 | |||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs new file mode 100644 index 0000000..701a729 --- /dev/null +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainFeature.cs | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using System; | ||
28 | using System.Reflection; | ||
29 | |||
30 | using OpenSim.Region.Framework.Interfaces; | ||
31 | |||
32 | namespace OpenSim.Region.CoreModules.World.Terrain | ||
33 | { | ||
34 | public abstract class TerrainFeature : ITerrainFeature | ||
35 | { | ||
36 | protected ITerrainModule m_module; | ||
37 | |||
38 | protected TerrainFeature(ITerrainModule module) | ||
39 | { | ||
40 | m_module = module; | ||
41 | } | ||
42 | |||
43 | public abstract string CreateFeature(ITerrainChannel map, string[] args); | ||
44 | |||
45 | public abstract string GetUsage(); | ||
46 | |||
47 | protected string parseFloat(String s, out float f) | ||
48 | { | ||
49 | string result; | ||
50 | double d; | ||
51 | if (Double.TryParse(s, out d)) | ||
52 | { | ||
53 | try | ||
54 | { | ||
55 | f = (float)d; | ||
56 | result = String.Empty; | ||
57 | } | ||
58 | catch(InvalidCastException) | ||
59 | { | ||
60 | result = String.Format("{0} is invalid", s); | ||
61 | f = -1.0f; | ||
62 | } | ||
63 | } | ||
64 | else | ||
65 | { | ||
66 | f = -1.0f; | ||
67 | result = String.Format("{0} is invalid", s); | ||
68 | } | ||
69 | return result; | ||
70 | } | ||
71 | |||
72 | protected string parseInt(String s, out int i) | ||
73 | { | ||
74 | string result; | ||
75 | if (Int32.TryParse(s, out i)) | ||
76 | { | ||
77 | result = String.Empty; | ||
78 | } | ||
79 | else | ||
80 | { | ||
81 | result = String.Format("{0} is invalid", s); | ||
82 | } | ||
83 | return result; | ||
84 | } | ||
85 | |||
86 | } | ||
87 | |||
88 | } | ||
89 | |||
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index cd76693..3bb8040 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -42,6 +42,7 @@ using OpenSim.Framework; | |||
42 | using OpenSim.Framework.Console; | 42 | using OpenSim.Framework.Console; |
43 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | 43 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; |
44 | using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; | 44 | using OpenSim.Region.CoreModules.World.Terrain.FileLoaders; |
45 | using OpenSim.Region.CoreModules.World.Terrain.Features; | ||
45 | using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; | 46 | using OpenSim.Region.CoreModules.World.Terrain.FloodBrushes; |
46 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; | 47 | using OpenSim.Region.CoreModules.World.Terrain.PaintBrushes; |
47 | using OpenSim.Region.Framework.Interfaces; | 48 | using OpenSim.Region.Framework.Interfaces; |
@@ -74,6 +75,14 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
74 | 75 | ||
75 | #endregion | 76 | #endregion |
76 | 77 | ||
78 | /// <summary> | ||
79 | /// Terrain Features | ||
80 | /// </summary> | ||
81 | public enum TerrainFeatures: byte | ||
82 | { | ||
83 | Rectangle = 1, | ||
84 | } | ||
85 | |||
77 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 86 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
78 | 87 | ||
79 | #pragma warning disable 414 | 88 | #pragma warning disable 414 |
@@ -90,8 +99,12 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
90 | private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = | 99 | private readonly Dictionary<StandardTerrainEffects, ITerrainPaintableEffect> m_painteffects = |
91 | new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); | 100 | new Dictionary<StandardTerrainEffects, ITerrainPaintableEffect>(); |
92 | 101 | ||
93 | private ITerrainChannel m_channel; | ||
94 | private Dictionary<string, ITerrainEffect> m_plugineffects; | 102 | private Dictionary<string, ITerrainEffect> m_plugineffects; |
103 | |||
104 | private Dictionary<string, ITerrainFeature> m_featureEffects = | ||
105 | new Dictionary<string, ITerrainFeature>(); | ||
106 | |||
107 | private ITerrainChannel m_channel; | ||
95 | private ITerrainChannel m_revert; | 108 | private ITerrainChannel m_revert; |
96 | private Scene m_scene; | 109 | private Scene m_scene; |
97 | private volatile bool m_tainted; | 110 | private volatile bool m_tainted; |
@@ -648,6 +661,9 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
648 | m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); | 661 | m_floodeffects[StandardTerrainEffects.Flatten] = new FlattenArea(); |
649 | m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); | 662 | m_floodeffects[StandardTerrainEffects.Revert] = new RevertArea(m_revert); |
650 | 663 | ||
664 | // Terrain Feature effects | ||
665 | m_featureEffects["rectangle"] = new RectangleFeature(this); | ||
666 | |||
651 | // Filesystem load/save loaders | 667 | // Filesystem load/save loaders |
652 | m_loaders[".r32"] = new RAW32(); | 668 | m_loaders[".r32"] = new RAW32(); |
653 | m_loaders[".f32"] = m_loaders[".r32"]; | 669 | m_loaders[".f32"] = m_loaders[".r32"]; |
@@ -1622,7 +1638,7 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1622 | "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); | 1638 | "Enables experimental brushes which replace the standard terrain brushes. WARNING: This is a debug setting and may be removed at any time."); |
1623 | experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); | 1639 | experimentalBrushesCommand.AddArgument("Enabled?", "true / false - Enable new brushes", "Boolean"); |
1624 | 1640 | ||
1625 | //Plugins | 1641 | // Plugins |
1626 | Command pluginRunCommand = | 1642 | Command pluginRunCommand = |
1627 | new Command("effect", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRunPluginEffect, "Runs a specified plugin effect"); | 1643 | new Command("effect", CommandIntentions.COMMAND_HAZARDOUS, InterfaceRunPluginEffect, "Runs a specified plugin effect"); |
1628 | pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String"); | 1644 | pluginRunCommand.AddArgument("name", "The plugin effect you wish to run, or 'list' to see all plugins", "String"); |
@@ -1648,9 +1664,46 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1648 | 1664 | ||
1649 | // Add this to our scene so scripts can call these functions | 1665 | // Add this to our scene so scripts can call these functions |
1650 | m_scene.RegisterModuleCommander(m_commander); | 1666 | m_scene.RegisterModuleCommander(m_commander); |
1667 | |||
1668 | // Add Feature command to Scene, since Command object requires fixed-length arglists | ||
1669 | m_scene.AddCommand("Terrain", this, "terrain feature", | ||
1670 | "terrain feature <type> <parameters...>", "Constructs a feature of the requested type.", FeatureCommand); | ||
1671 | |||
1651 | } | 1672 | } |
1652 | 1673 | ||
1674 | public void FeatureCommand(string module, string[] cmd) | ||
1675 | { | ||
1676 | string result; | ||
1677 | if (cmd.Length > 2) | ||
1678 | { | ||
1679 | string featureType = cmd[2]; | ||
1653 | 1680 | ||
1681 | ITerrainFeature feature; | ||
1682 | if (!m_featureEffects.TryGetValue(featureType, out feature)) | ||
1683 | { | ||
1684 | result = String.Format("Terrain Feature \"{0}\" not found.", featureType); | ||
1685 | } | ||
1686 | else if ((cmd.Length > 3) && (cmd[3] == "usage")) | ||
1687 | { | ||
1688 | result = "Usage: " + feature.GetUsage(); | ||
1689 | } | ||
1690 | else | ||
1691 | { | ||
1692 | result = feature.CreateFeature(m_channel, cmd); | ||
1693 | } | ||
1694 | |||
1695 | if(result == String.Empty) | ||
1696 | { | ||
1697 | result = "Created Feature"; | ||
1698 | m_log.DebugFormat("Created terrain feature {0}", featureType); | ||
1699 | } | ||
1700 | } | ||
1701 | else | ||
1702 | { | ||
1703 | result = "Usage: <feature-name> <arg1> <arg2>..."; | ||
1704 | } | ||
1705 | MainConsole.Instance.Output(result); | ||
1706 | } | ||
1654 | #endregion | 1707 | #endregion |
1655 | 1708 | ||
1656 | } | 1709 | } |