diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/PhysicsParameters')
-rwxr-xr-x | OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs | 268 |
1 files changed, 268 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs new file mode 100755 index 0000000..3083a33 --- /dev/null +++ b/OpenSim/Region/OptionalModules/PhysicsParameters/PhysicsParameters.cs | |||
@@ -0,0 +1,268 @@ | |||
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 System.Reflection; | ||
30 | using System.Collections.Generic; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using Nini.Config; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Framework.Console; | ||
36 | using OpenSim.Region.CoreModules.Framework.InterfaceCommander; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Physics.Manager; | ||
40 | |||
41 | namespace OpenSim.Region.OptionalModules.PhysicsParameters | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// </summary> | ||
45 | /// <remarks> | ||
46 | /// </remarks> | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "PhysicsParameters")] | ||
48 | public class PhysicsParameters : ISharedRegionModule | ||
49 | { | ||
50 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | // private static string LogHeader = "[PHYSICS PARAMETERS]"; | ||
52 | |||
53 | private List<Scene> m_scenes = new List<Scene>(); | ||
54 | private static bool m_commandsLoaded = false; | ||
55 | |||
56 | #region ISharedRegionModule | ||
57 | public string Name { get { return "Runtime Physics Parameter Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("{0}: INITIALIZED MODULE", LogHeader); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[{0}: POST INITIALIZED MODULE", LogHeader); | ||
69 | InstallInterfaces(); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | // m_log.DebugFormat("{0}: CLOSED MODULE", LogHeader); | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene scene) | ||
78 | { | ||
79 | // m_log.DebugFormat("{0}: REGION {1} ADDED", LogHeader, scene.RegionInfo.RegionName); | ||
80 | m_scenes.Add(scene); | ||
81 | } | ||
82 | |||
83 | public void RemoveRegion(Scene scene) | ||
84 | { | ||
85 | // m_log.DebugFormat("{0}: REGION {1} REMOVED", LogHeader, scene.RegionInfo.RegionName); | ||
86 | if (m_scenes.Contains(scene)) | ||
87 | m_scenes.Remove(scene); | ||
88 | } | ||
89 | |||
90 | public void RegionLoaded(Scene scene) | ||
91 | { | ||
92 | // m_log.DebugFormat("{0}: REGION {1} LOADED", LogHeader, scene.RegionInfo.RegionName); | ||
93 | } | ||
94 | #endregion INonSharedRegionModule | ||
95 | |||
96 | private const string getInvocation = "physics get [<param>|ALL]"; | ||
97 | private const string setInvocation = "physics set <param> [<value>|TRUE|FALSE] [localID|ALL]"; | ||
98 | private const string listInvocation = "physics list"; | ||
99 | private void InstallInterfaces() | ||
100 | { | ||
101 | if (!m_commandsLoaded) | ||
102 | { | ||
103 | MainConsole.Instance.Commands.AddCommand( | ||
104 | "Regions", false, "physics set", | ||
105 | setInvocation, | ||
106 | "Set physics parameter from currently selected region", | ||
107 | ProcessPhysicsSet); | ||
108 | |||
109 | MainConsole.Instance.Commands.AddCommand( | ||
110 | "Regions", false, "physics get", | ||
111 | getInvocation, | ||
112 | "Get physics parameter from currently selected region", | ||
113 | ProcessPhysicsGet); | ||
114 | |||
115 | MainConsole.Instance.Commands.AddCommand( | ||
116 | "Regions", false, "physics list", | ||
117 | listInvocation, | ||
118 | "List settable physics parameters", | ||
119 | ProcessPhysicsList); | ||
120 | |||
121 | m_commandsLoaded = true; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | // TODO: extend get so you can get a value from an individual localID | ||
126 | private void ProcessPhysicsGet(string module, string[] cmdparms) | ||
127 | { | ||
128 | if (cmdparms.Length != 3) | ||
129 | { | ||
130 | WriteError("Parameter count error. Invocation: " + getInvocation); | ||
131 | return; | ||
132 | } | ||
133 | string parm = cmdparms[2]; | ||
134 | |||
135 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
136 | { | ||
137 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | Scene scene = SceneManager.Instance.CurrentScene; | ||
142 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
143 | if (physScene != null) | ||
144 | { | ||
145 | if (parm.ToLower() == "all") | ||
146 | { | ||
147 | foreach (PhysParameterEntry ppe in physScene.GetParameterList()) | ||
148 | { | ||
149 | string val = string.Empty; | ||
150 | if (physScene.GetPhysicsParameter(ppe.name, out val)) | ||
151 | { | ||
152 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, val); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, ppe.name, "unknown"); | ||
157 | } | ||
158 | } | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | string val = string.Empty; | ||
163 | if (physScene.GetPhysicsParameter(parm, out val)) | ||
164 | { | ||
165 | WriteOut(" {0}/{1} = {2}", scene.RegionInfo.RegionName, parm, val); | ||
166 | } | ||
167 | else | ||
168 | { | ||
169 | WriteError("Failed fetch of parameter '{0}' from region '{1}'", parm, scene.RegionInfo.RegionName); | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | WriteError("Region '{0}' physics engine has no gettable physics parameters", scene.RegionInfo.RegionName); | ||
176 | } | ||
177 | return; | ||
178 | } | ||
179 | |||
180 | private void ProcessPhysicsSet(string module, string[] cmdparms) | ||
181 | { | ||
182 | if (cmdparms.Length < 4 || cmdparms.Length > 5) | ||
183 | { | ||
184 | WriteError("Parameter count error. Invocation: " + getInvocation); | ||
185 | return; | ||
186 | } | ||
187 | string parm = "xxx"; | ||
188 | string valparm = String.Empty; | ||
189 | uint localID = (uint)PhysParameterEntry.APPLY_TO_NONE; // set default value | ||
190 | try | ||
191 | { | ||
192 | parm = cmdparms[2]; | ||
193 | valparm = cmdparms[3].ToLower(); | ||
194 | if (cmdparms.Length > 4) | ||
195 | { | ||
196 | if (cmdparms[4].ToLower() == "all") | ||
197 | localID = (uint)PhysParameterEntry.APPLY_TO_ALL; | ||
198 | else | ||
199 | localID = uint.Parse(cmdparms[2], Culture.NumberFormatInfo); | ||
200 | } | ||
201 | } | ||
202 | catch | ||
203 | { | ||
204 | WriteError(" Error parsing parameters. Invocation: " + setInvocation); | ||
205 | return; | ||
206 | } | ||
207 | |||
208 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
209 | { | ||
210 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | Scene scene = SceneManager.Instance.CurrentScene; | ||
215 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
216 | if (physScene != null) | ||
217 | { | ||
218 | if (!physScene.SetPhysicsParameter(parm, valparm, localID)) | ||
219 | { | ||
220 | WriteError("Failed set of parameter '{0}' for region '{1}'", parm, scene.RegionInfo.RegionName); | ||
221 | } | ||
222 | } | ||
223 | else | ||
224 | { | ||
225 | WriteOut("Region '{0}'s physics engine has no settable physics parameters", scene.RegionInfo.RegionName); | ||
226 | } | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | private void ProcessPhysicsList(string module, string[] cmdparms) | ||
231 | { | ||
232 | if (SceneManager.Instance == null || SceneManager.Instance.CurrentScene == null) | ||
233 | { | ||
234 | WriteError("Error: no region selected. Use 'change region' to select a region."); | ||
235 | return; | ||
236 | } | ||
237 | Scene scene = SceneManager.Instance.CurrentScene; | ||
238 | |||
239 | IPhysicsParameters physScene = scene.PhysicsScene as IPhysicsParameters; | ||
240 | if (physScene != null) | ||
241 | { | ||
242 | WriteOut("Available physics parameters:"); | ||
243 | PhysParameterEntry[] parms = physScene.GetParameterList(); | ||
244 | foreach (PhysParameterEntry ent in parms) | ||
245 | { | ||
246 | WriteOut(" {0}: {1}", ent.name, ent.desc); | ||
247 | } | ||
248 | } | ||
249 | else | ||
250 | { | ||
251 | WriteError("Current regions's physics engine has no settable physics parameters"); | ||
252 | } | ||
253 | return; | ||
254 | } | ||
255 | |||
256 | private void WriteOut(string msg, params object[] args) | ||
257 | { | ||
258 | // m_log.InfoFormat(msg, args); | ||
259 | MainConsole.Instance.OutputFormat(msg, args); | ||
260 | } | ||
261 | |||
262 | private void WriteError(string msg, params object[] args) | ||
263 | { | ||
264 | // m_log.ErrorFormat(msg, args); | ||
265 | MainConsole.Instance.OutputFormat(msg, args); | ||
266 | } | ||
267 | } | ||
268 | } | ||