SceneCommandsModule.cs 16 KB

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