ExtendedPhysics.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 copyrightD
  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 OpenSim.Framework;
  33. using OpenSim.Region.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.CoreModules;
  37. using Mono.Addins;
  38. using Nini.Config;
  39. using log4net;
  40. using OpenMetaverse;
  41. namespace OpenSim.Region.OptionalModules.Scripting
  42. {
  43. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  44. public class ExtendedPhysics : INonSharedRegionModule
  45. {
  46. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  47. private static string LogHeader = "[EXTENDED PHYSICS]";
  48. private IConfig Configuration { get; set; }
  49. private bool Enabled { get; set; }
  50. private Scene BaseScene { get; set; }
  51. private IScriptModuleComms Comms { get; set; }
  52. #region INonSharedRegionModule
  53. public string Name { get { return this.GetType().Name; } }
  54. public void Initialise(IConfigSource config)
  55. {
  56. BaseScene = null;
  57. Enabled = false;
  58. Configuration = null;
  59. Comms = null;
  60. try
  61. {
  62. if ((Configuration = config.Configs["ExtendedPhysics"]) != null)
  63. {
  64. Enabled = Configuration.GetBoolean("Enabled", Enabled);
  65. }
  66. }
  67. catch (Exception e)
  68. {
  69. m_log.ErrorFormat("{0} Initialization error: {0}", LogHeader, e);
  70. }
  71. m_log.InfoFormat("{0} module {1} enabled", LogHeader, (Enabled ? "is" : "is not"));
  72. }
  73. public void Close()
  74. {
  75. if (BaseScene != null)
  76. {
  77. BaseScene.EventManager.OnObjectAddedToScene -= EventManager_OnObjectAddedToScene;
  78. BaseScene.EventManager.OnSceneObjectPartUpdated -= EventManager_OnSceneObjectPartUpdated;
  79. BaseScene = null;
  80. }
  81. }
  82. public void AddRegion(Scene scene)
  83. {
  84. }
  85. public void RemoveRegion(Scene scene)
  86. {
  87. if (BaseScene != null && BaseScene == scene)
  88. {
  89. Close();
  90. }
  91. }
  92. public void RegionLoaded(Scene scene)
  93. {
  94. if (!Enabled) return;
  95. BaseScene = scene;
  96. Comms = BaseScene.RequestModuleInterface<IScriptModuleComms>();
  97. if (Comms == null)
  98. {
  99. m_log.WarnFormat("{0} ScriptModuleComms interface not defined", LogHeader);
  100. Enabled = false;
  101. return;
  102. }
  103. // Register as LSL functions all the [ScriptInvocation] marked methods.
  104. Comms.RegisterScriptInvocations(this);
  105. // When an object is modified, we might need to update its extended physics parameters
  106. BaseScene.EventManager.OnObjectAddedToScene += EventManager_OnObjectAddedToScene;
  107. BaseScene.EventManager.OnSceneObjectPartUpdated += EventManager_OnSceneObjectPartUpdated;
  108. }
  109. public Type ReplaceableInterface { get { return null; } }
  110. #endregion // INonSharedRegionModule
  111. private void EventManager_OnObjectAddedToScene(SceneObjectGroup obj)
  112. {
  113. throw new NotImplementedException();
  114. }
  115. // Event generated when some property of a prim changes.
  116. private void EventManager_OnSceneObjectPartUpdated(SceneObjectPart sop, bool isFullUpdate)
  117. {
  118. }
  119. [ScriptConstant]
  120. public static int PHYS_CENTER_OF_MASS = 1 << 0;
  121. [ScriptConstant]
  122. public static int PHYS_LINKSET_TYPE_CONSTRAINT = 1;
  123. [ScriptConstant]
  124. public static int PHYS_LINKSET_TYPE_COMPOUND = 2;
  125. [ScriptConstant]
  126. public static int PHYS_LINKSET_TYPE_MANUAL = 3;
  127. [ScriptInvocation]
  128. public string physGetEngineType(UUID hostID, UUID scriptID)
  129. {
  130. string ret = string.Empty;
  131. if (BaseScene.PhysicsScene != null)
  132. {
  133. ret = BaseScene.PhysicsScene.EngineType;
  134. }
  135. return ret;
  136. }
  137. [ScriptInvocation]
  138. public void physSetLinksetType(UUID hostID, UUID scriptID, int linksetType)
  139. {
  140. }
  141. }
  142. }