OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
SceneCommandsModule.cs
Go to the documentation of this file.
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.Collections.Generic;
30 using System.Linq;
31 using System.Reflection;
32 using System.Text;
33 using System.Threading;
34 using log4net;
35 using Mono.Addins;
36 using Nini.Config;
37 using OpenMetaverse;
38 using OpenSim.Framework;
39 using OpenSim.Framework.Console;
40 using OpenSim.Framework.Monitoring;
41 using OpenSim.Region.Framework.Interfaces;
42 using OpenSim.Region.Framework.Scenes;
43 
44 namespace OpenSim.Region.OptionalModules.Avatar.Attachments
45 {
49  [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")]
51  {
52 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
53 
54  private Scene m_scene;
55 
56  public string Name { get { return "Scene Commands Module"; } }
57 
58  public Type ReplaceableInterface { get { return null; } }
59 
60  public void Initialise(IConfigSource source)
61  {
62 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE");
63  }
64 
65  public void PostInitialise()
66  {
67 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE");
68  }
69 
70  public void Close()
71  {
72 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE");
73  }
74 
75  public void AddRegion(Scene scene)
76  {
77 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
78 
79  m_scene = scene;
80 
81  m_scene.RegisterModuleInterface<ISceneCommandsModule>(this);
82  }
83 
84  public void RemoveRegion(Scene scene)
85  {
86 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
87  }
88 
89  public void RegionLoaded(Scene scene)
90  {
91 // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
92 
93  scene.AddCommand(
94  "Debug", this, "debug scene get",
95  "debug scene get",
96  "List current scene options.",
97  "active - if false then main scene update and maintenance loops are suspended.\n"
98  + "animations - if true then extra animations debug information is logged.\n"
99  + "appear-refresh - if true then appearance is resent to other avatars every 60 seconds.\n"
100  + "child-repri - how far an avatar must move in meters before we update the position of its child agents in neighbouring regions.\n"
101  + "client-pos-upd - the tolerance before clients are updated with new rotation information for an avatar.\n"
102  + "client-rot-upd - the tolerance before clients are updated with new rotation information for an avatar.\n"
103  + "client-vel-upd - the tolerance before clients are updated with new velocity information for an avatar.\n"
104  + "root-upd-per - if greater than 1, terse updates are only sent to root agents other than the originator on every n updates.\n"
105  + "child-upd-per - if greater than 1, terse updates are only sent to child agents on every n updates.\n"
106  + "collisions - if false then collisions with other objects are turned off.\n"
107  + "pbackup - if false then periodic scene backup is turned off.\n"
108  + "physics - if false then all physics objects are non-physical.\n"
109  + "scripting - if false then no scripting operations happen.\n"
110  + "teleport - if true then some extra teleport debug information is logged.\n"
111  + "update-on-timer - If true then the scene is updated via a timer. If false then a thread with sleep is used.\n"
112  + "updates - if true then any frame which exceeds double the maximum desired frame time is logged.",
113  HandleDebugSceneGetCommand);
114 
115  scene.AddCommand(
116  "Debug", this, "debug scene set",
117  "debug scene set <param> <value>",
118  "Turn on scene debugging options.",
119  "active - if false then main scene update and maintenance loops are suspended.\n"
120  + "animations - if true then extra animations debug information is logged.\n"
121  + "appear-refresh - if true then appearance is resent to other avatars every 60 seconds.\n"
122  + "child-repri - how far an avatar must move in meters before we update the position of its child agents in neighbouring regions.\n"
123  + "client-pos-upd - the tolerance before clients are updated with new rotation information for an avatar.\n"
124  + "client-rot-upd - the tolerance before clients are updated with new rotation information for an avatar.\n"
125  + "client-vel-upd - the tolerance before clients are updated with new velocity information for an avatar.\n"
126  + "root-upd-per - if greater than 1, terse updates are only sent to root agents other than the originator on every n updates.\n"
127  + "child-upd-per - if greater than 1, terse updates are only sent to child agents on every n updates.\n"
128  + "collisions - if false then collisions with other objects are turned off.\n"
129  + "pbackup - if false then periodic scene backup is turned off.\n"
130  + "physics - if false then all physics objects are non-physical.\n"
131  + "scripting - if false then no scripting operations happen.\n"
132  + "teleport - if true then some extra teleport debug information is logged.\n"
133  + "update-on-timer - If true then the scene is updated via a timer. If false then a thread with sleep is used.\n"
134  + "updates - if true then any frame which exceeds double the maximum desired frame time is logged.",
135  HandleDebugSceneSetCommand);
136  }
137 
138  private void HandleDebugSceneGetCommand(string module, string[] args)
139  {
140  if (args.Length == 3)
141  {
143  return;
144 
145  OutputSceneDebugOptions();
146  }
147  else
148  {
149  MainConsole.Instance.Output("Usage: debug scene get");
150  }
151  }
152 
153  private void OutputSceneDebugOptions()
154  {
156  cdl.AddRow("active", m_scene.Active);
157  cdl.AddRow("animations", m_scene.DebugAnimations);
158  cdl.AddRow("appear-refresh", m_scene.SendPeriodicAppearanceUpdates);
159  cdl.AddRow("child-repri", m_scene.ChildReprioritizationDistance);
160  cdl.AddRow("client-pos-upd", m_scene.RootPositionUpdateTolerance);
161  cdl.AddRow("client-rot-upd", m_scene.RootRotationUpdateTolerance);
162  cdl.AddRow("client-vel-upd", m_scene.RootVelocityUpdateTolerance);
163  cdl.AddRow("root-upd-per", m_scene.RootTerseUpdatePeriod);
164  cdl.AddRow("child-upd-per", m_scene.ChildTerseUpdatePeriod);
165  cdl.AddRow("pbackup", m_scene.PeriodicBackup);
166  cdl.AddRow("physics", m_scene.PhysicsEnabled);
167  cdl.AddRow("scripting", m_scene.ScriptsEnabled);
168  cdl.AddRow("teleport", m_scene.DebugTeleporting);
169 // cdl.AddRow("update-on-timer", m_scene.UpdateOnTimer);
170  cdl.AddRow("updates", m_scene.DebugUpdates);
171 
172  MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name);
173  MainConsole.Instance.Output(cdl.ToString());
174  }
175 
176  private void HandleDebugSceneSetCommand(string module, string[] args)
177  {
178  if (args.Length == 5)
179  {
181  return;
182 
183  string key = args[3];
184  string value = args[4];
185  SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } });
186 
187  MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value);
188  }
189  else
190  {
191  MainConsole.Instance.Output("Usage: debug scene set <param> <value>");
192  }
193  }
194 
195  public void SetSceneDebugOptions(Dictionary<string, string> options)
196  {
197  if (options.ContainsKey("active"))
198  {
199  bool active;
200 
201  if (bool.TryParse(options["active"], out active))
202  m_scene.Active = active;
203  }
204 
205  if (options.ContainsKey("animations"))
206  {
207  bool active;
208 
209  if (bool.TryParse(options["animations"], out active))
210  m_scene.DebugAnimations = active;
211  }
212 
213  if (options.ContainsKey("appear-refresh"))
214  {
215  bool newValue;
216 
217  // FIXME: This can only come from the console at the moment but might not always be true.
218  if (ConsoleUtil.TryParseConsoleBool(MainConsole.Instance, options["appear-refresh"], out newValue))
219  m_scene.SendPeriodicAppearanceUpdates = newValue;
220  }
221 
222  if (options.ContainsKey("child-repri"))
223  {
224  double newValue;
225 
226  // FIXME: This can only come from the console at the moment but might not always be true.
227  if (ConsoleUtil.TryParseConsoleDouble(MainConsole.Instance, options["child-repri"], out newValue))
228  m_scene.ChildReprioritizationDistance = (float)newValue;
229  }
230 
231  if (options.ContainsKey("client-pos-upd"))
232  {
233  float newValue;
234 
235  // FIXME: This can only come from the console at the moment but might not always be true.
236  if (ConsoleUtil.TryParseConsoleFloat(MainConsole.Instance, options["client-pos-upd"], out newValue))
237  m_scene.RootPositionUpdateTolerance = newValue;
238  }
239 
240  if (options.ContainsKey("client-rot-upd"))
241  {
242  float newValue;
243 
244  // FIXME: This can only come from the console at the moment but might not always be true.
245  if (ConsoleUtil.TryParseConsoleFloat(MainConsole.Instance, options["client-rot-upd"], out newValue))
246  m_scene.RootRotationUpdateTolerance = newValue;
247  }
248 
249  if (options.ContainsKey("client-vel-upd"))
250  {
251  float newValue;
252 
253  // FIXME: This can only come from the console at the moment but might not always be true.
254  if (ConsoleUtil.TryParseConsoleFloat(MainConsole.Instance, options["client-vel-upd"], out newValue))
255  m_scene.RootVelocityUpdateTolerance = newValue;
256  }
257 
258  if (options.ContainsKey("root-upd-per"))
259  {
260  int newValue;
261 
262  // FIXME: This can only come from the console at the moment but might not always be true.
263  if (ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, options["root-upd-per"], out newValue))
264  m_scene.RootTerseUpdatePeriod = newValue;
265  }
266 
267  if (options.ContainsKey("child-upd-per"))
268  {
269  int newValue;
270 
271  // FIXME: This can only come from the console at the moment but might not always be true.
272  if (ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, options["child-upd-per"], out newValue))
273  m_scene.ChildTerseUpdatePeriod = newValue;
274  }
275 
276  if (options.ContainsKey("pbackup"))
277  {
278  bool active;
279 
280  if (bool.TryParse(options["pbackup"], out active))
281  m_scene.PeriodicBackup = active;
282  }
283 
284  if (options.ContainsKey("scripting"))
285  {
286  bool enableScripts = true;
287  if (bool.TryParse(options["scripting"], out enableScripts))
288  m_scene.ScriptsEnabled = enableScripts;
289  }
290 
291  if (options.ContainsKey("physics"))
292  {
293  bool enablePhysics;
294  if (bool.TryParse(options["physics"], out enablePhysics))
295  m_scene.PhysicsEnabled = enablePhysics;
296  }
297 
298 // if (options.ContainsKey("collisions"))
299 // {
300 // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow
301 // // the avatar themselves to collide with the ground.
302 // }
303 
304  if (options.ContainsKey("teleport"))
305  {
306  bool enableTeleportDebugging;
307  if (bool.TryParse(options["teleport"], out enableTeleportDebugging))
308  m_scene.DebugTeleporting = enableTeleportDebugging;
309  }
310 
311  if (options.ContainsKey("update-on-timer"))
312  {
313  bool enableUpdateOnTimer;
314  if (bool.TryParse(options["update-on-timer"], out enableUpdateOnTimer))
315  {
316 // m_scene.UpdateOnTimer = enableUpdateOnTimer;
317  m_scene.Active = false;
318 
319  while (m_scene.IsRunning)
320  Thread.Sleep(20);
321 
322  m_scene.Active = true;
323  }
324  }
325 
326  if (options.ContainsKey("updates"))
327  {
328  bool enableUpdateDebugging;
329  if (bool.TryParse(options["updates"], out enableUpdateDebugging))
330  {
331  m_scene.DebugUpdates = enableUpdateDebugging;
332  GcNotify.Enabled = enableUpdateDebugging;
333  }
334  }
335  }
336  }
337 }
Used to generated a formatted table for the console.
static bool TryParseConsoleDouble(ICommandConsole console, string rawConsoleInput, out double i)
Convert a console input to a double, automatically complaining if a console is given.
Definition: ConsoleUtil.cs:225
static bool TryParseConsoleBool(ICommandConsole console, string rawConsoleString, out bool b)
Convert a console input to a bool, automatically complaining if a console is given.
Definition: ConsoleUtil.cs:165
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString key
Definition: ICM_Api.cs:31
A module that just holds commands for inspecting avatar appearance.
void Close()
This is the inverse to Initialise. After a Close(), this instance won't be usable anymore...
void SetSceneDebugOptions(Dictionary< string, string > options)
Sets the scene debug options.
static ICommandConsole Instance
Definition: MainConsole.cs:35
static bool TryParseConsoleFloat(ICommandConsole console, string rawConsoleInput, out float i)
Convert a console input to a float, automatically complaining if a console is given.
Definition: ConsoleUtil.cs:205
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
static bool TryParseConsoleNaturalInt(ICommandConsole console, string rawConsoleInt, out int i)
Convert a console integer to a natural int, automatically complaining if a console is given...
Definition: ConsoleUtil.cs:245
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...