SceneBase.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 OpenSim 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.Reflection;
  30. using libsecondlife;
  31. using log4net;
  32. using OpenSim.Framework;
  33. using OpenSim.Framework.Communications.Cache;
  34. using OpenSim.Region.Environment.Interfaces;
  35. namespace OpenSim.Region.Environment.Scenes
  36. {
  37. public abstract class SceneBase : IScene
  38. {
  39. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  40. #region Events
  41. public event restart OnRestart;
  42. #endregion
  43. #region Fields
  44. private readonly ClientManager m_clientManager = new ClientManager();
  45. public ClientManager ClientManager
  46. {
  47. get { return m_clientManager; }
  48. }
  49. protected ulong m_regionHandle;
  50. protected string m_regionName;
  51. protected RegionInfo m_regInfo;
  52. //public TerrainEngine Terrain;
  53. public ITerrainChannel Heightmap;
  54. public ILandChannel LandChannel;
  55. protected EventManager m_eventManager;
  56. public EventManager EventManager
  57. {
  58. get { return m_eventManager; }
  59. }
  60. protected SceneExternalChecks m_externalChecks;
  61. public SceneExternalChecks ExternalChecks
  62. {
  63. get { return m_externalChecks; }
  64. }
  65. protected string m_datastore;
  66. private uint m_nextLocalId = 8880000;
  67. private AssetCache m_assetCache;
  68. public AssetCache AssetCache
  69. {
  70. get { return m_assetCache; }
  71. set { m_assetCache = value; }
  72. }
  73. protected RegionStatus m_regStatus;
  74. public RegionStatus Region_Status
  75. {
  76. get { return m_regStatus; }
  77. set { m_regStatus = value; }
  78. }
  79. #endregion
  80. #region Update Methods
  81. /// <summary>
  82. /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
  83. /// </summary>
  84. public abstract void Update();
  85. #endregion
  86. #region Terrain Methods
  87. /// <summary>
  88. /// Loads the World heightmap
  89. /// </summary>
  90. public abstract void LoadWorldMap();
  91. /// <summary>
  92. /// Send the region heightmap to the client
  93. /// </summary>
  94. /// <param name="RemoteClient">Client to send to</param>
  95. public virtual void SendLayerData(IClientAPI RemoteClient)
  96. {
  97. RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
  98. }
  99. #endregion
  100. #region Add/Remove Agent/Avatar
  101. /// <summary>
  102. ///
  103. /// </summary>
  104. /// <param name="remoteClient"></param>
  105. /// <param name="agentID"></param>
  106. /// <param name="child"></param>
  107. public abstract void AddNewClient(IClientAPI client, bool child);
  108. /// <summary>
  109. ///
  110. /// </summary>
  111. /// <param name="agentID"></param>
  112. public abstract void RemoveClient(LLUUID agentID);
  113. public abstract void CloseAllAgents(uint circuitcode);
  114. #endregion
  115. /// <summary>
  116. ///
  117. /// </summary>
  118. /// <returns></returns>
  119. public virtual RegionInfo RegionInfo
  120. {
  121. get { return m_regInfo; }
  122. }
  123. public uint NextLocalId
  124. {
  125. get { return m_nextLocalId++; }
  126. }
  127. #region admin stuff
  128. /// <summary>
  129. /// Region Restart - Seconds till restart.
  130. /// </summary>
  131. /// <param name="seconds"></param>
  132. public virtual void Restart(int seconds)
  133. {
  134. m_log.Error("[REGION]: passing Restart Message up the namespace");
  135. restart handlerPhysicsCrash = OnRestart;
  136. if (handlerPhysicsCrash != null)
  137. handlerPhysicsCrash(RegionInfo);
  138. }
  139. public virtual bool PresenceChildStatus(LLUUID avatarID)
  140. {
  141. return false;
  142. }
  143. public abstract bool OtherRegionUp(RegionInfo thisRegion);
  144. public virtual string GetSimulatorVersion()
  145. {
  146. return "OpenSimulator v0.5 SVN";
  147. }
  148. #endregion
  149. #region Shutdown
  150. /// <summary>
  151. /// Tidy before shutdown
  152. /// </summary>
  153. public virtual void Close()
  154. {
  155. try
  156. {
  157. EventManager.TriggerShutdown();
  158. }
  159. catch (Exception e)
  160. {
  161. m_log.Error("[SCENE]: SceneBase.cs: Close() - Failed with exception " + e.ToString());
  162. }
  163. }
  164. #endregion
  165. /// <summary>
  166. /// XXX These two methods are very temporary
  167. /// </summary>
  168. protected Dictionary<LLUUID, string> capsPaths = new Dictionary<LLUUID, string>();
  169. public string GetCapsPath(LLUUID agentId)
  170. {
  171. if (capsPaths.ContainsKey(agentId))
  172. {
  173. return capsPaths[agentId];
  174. }
  175. return null;
  176. }
  177. }
  178. }