1
0

SceneCommandsModule.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Monitoring;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.OptionalModules.Avatar.Attachments
  42. {
  43. /// <summary>
  44. /// A module that just holds commands for inspecting avatar appearance.
  45. /// </summary>
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")]
  47. public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule
  48. {
  49. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private Scene m_scene;
  51. public string Name { get { return "Scene Commands Module"; } }
  52. public Type ReplaceableInterface { get { return null; } }
  53. public void Initialise(IConfigSource source)
  54. {
  55. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE");
  56. }
  57. public void PostInitialise()
  58. {
  59. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE");
  60. }
  61. public void Close()
  62. {
  63. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE");
  64. }
  65. public void AddRegion(Scene scene)
  66. {
  67. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  68. m_scene = scene;
  69. m_scene.RegisterModuleInterface<ISceneCommandsModule>(this);
  70. }
  71. public void RemoveRegion(Scene scene)
  72. {
  73. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  74. }
  75. public void RegionLoaded(Scene scene)
  76. {
  77. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  78. scene.AddCommand(
  79. "Debug", this, "debug scene get",
  80. "debug scene get",
  81. "List current scene options.",
  82. "If active is false then main scene update and maintenance loops are suspended.\n"
  83. + "If animations is true then extra animations debug information is logged.\n"
  84. + "If collisions is false then collisions with other objects are turned off.\n"
  85. + "If pbackup is false then periodic scene backup is turned off.\n"
  86. + "If physics is false then all physics objects are non-physical.\n"
  87. + "If scripting is false then no scripting operations happen.\n"
  88. + "If teleport is true then some extra teleport debug information is logged.\n"
  89. + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
  90. HandleDebugSceneGetCommand);
  91. scene.AddCommand(
  92. "Debug", this, "debug scene set",
  93. "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false",
  94. "Turn on scene debugging options.",
  95. "If active is false then main scene update and maintenance loops are suspended.\n"
  96. + "If animations is true then extra animations debug information is logged.\n"
  97. + "If collisions is false then collisions with other objects are turned off.\n"
  98. + "If pbackup is false then periodic scene backup is turned off.\n"
  99. + "If physics is false then all physics objects are non-physical.\n"
  100. + "If scripting is false then no scripting operations happen.\n"
  101. + "If teleport is true then some extra teleport debug information is logged.\n"
  102. + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
  103. HandleDebugSceneSetCommand);
  104. scene.AddCommand(
  105. "Regions",
  106. this, "show borders", "show borders", "Show border information for regions", HandleShowBordersCommand);
  107. }
  108. private void HandleShowBordersCommand(string module, string[] args)
  109. {
  110. StringBuilder sb = new StringBuilder();
  111. sb.AppendFormat("Borders for {0}:\n", m_scene.Name);
  112. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  113. cdt.AddColumn("Cross Direction", 15);
  114. cdt.AddColumn("Line", 34);
  115. cdt.AddColumn("Trigger Region", 14);
  116. foreach (Border b in m_scene.NorthBorders)
  117. cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
  118. foreach (Border b in m_scene.EastBorders)
  119. cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
  120. foreach (Border b in m_scene.SouthBorders)
  121. cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
  122. foreach (Border b in m_scene.WestBorders)
  123. cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
  124. cdt.AddToStringBuilder(sb);
  125. MainConsole.Instance.Output(sb.ToString());
  126. }
  127. private void HandleDebugSceneGetCommand(string module, string[] args)
  128. {
  129. if (args.Length == 3)
  130. {
  131. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  132. return;
  133. OutputSceneDebugOptions();
  134. }
  135. else
  136. {
  137. MainConsole.Instance.Output("Usage: debug scene get");
  138. }
  139. }
  140. private void OutputSceneDebugOptions()
  141. {
  142. ConsoleDisplayList cdl = new ConsoleDisplayList();
  143. cdl.AddRow("active", m_scene.Active);
  144. cdl.AddRow("animations", m_scene.DebugAnimations);
  145. cdl.AddRow("pbackup", m_scene.PeriodicBackup);
  146. cdl.AddRow("physics", m_scene.PhysicsEnabled);
  147. cdl.AddRow("scripting", m_scene.ScriptsEnabled);
  148. cdl.AddRow("teleport", m_scene.DebugTeleporting);
  149. cdl.AddRow("updates", m_scene.DebugUpdates);
  150. MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name);
  151. MainConsole.Instance.Output(cdl.ToString());
  152. }
  153. private void HandleDebugSceneSetCommand(string module, string[] args)
  154. {
  155. if (args.Length == 5)
  156. {
  157. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  158. return;
  159. string key = args[3];
  160. string value = args[4];
  161. SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } });
  162. MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value);
  163. }
  164. else
  165. {
  166. MainConsole.Instance.Output(
  167. "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false");
  168. }
  169. }
  170. public void SetSceneDebugOptions(Dictionary<string, string> options)
  171. {
  172. if (options.ContainsKey("active"))
  173. {
  174. bool active;
  175. if (bool.TryParse(options["active"], out active))
  176. m_scene.Active = active;
  177. }
  178. if (options.ContainsKey("animations"))
  179. {
  180. bool active;
  181. if (bool.TryParse(options["animations"], out active))
  182. m_scene.DebugAnimations = active;
  183. }
  184. if (options.ContainsKey("pbackup"))
  185. {
  186. bool active;
  187. if (bool.TryParse(options["pbackup"], out active))
  188. m_scene.PeriodicBackup = active;
  189. }
  190. if (options.ContainsKey("scripting"))
  191. {
  192. bool enableScripts = true;
  193. if (bool.TryParse(options["scripting"], out enableScripts))
  194. m_scene.ScriptsEnabled = enableScripts;
  195. }
  196. if (options.ContainsKey("physics"))
  197. {
  198. bool enablePhysics;
  199. if (bool.TryParse(options["physics"], out enablePhysics))
  200. m_scene.PhysicsEnabled = enablePhysics;
  201. }
  202. // if (options.ContainsKey("collisions"))
  203. // {
  204. // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow
  205. // // the avatar themselves to collide with the ground.
  206. // }
  207. if (options.ContainsKey("teleport"))
  208. {
  209. bool enableTeleportDebugging;
  210. if (bool.TryParse(options["teleport"], out enableTeleportDebugging))
  211. m_scene.DebugTeleporting = enableTeleportDebugging;
  212. }
  213. if (options.ContainsKey("updates"))
  214. {
  215. bool enableUpdateDebugging;
  216. if (bool.TryParse(options["updates"], out enableUpdateDebugging))
  217. {
  218. m_scene.DebugUpdates = enableUpdateDebugging;
  219. GcNotify.Enabled = enableUpdateDebugging;
  220. }
  221. }
  222. }
  223. }
  224. }