SceneBase.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 string m_datastore;
  61. private uint m_nextLocalId = 8880000;
  62. private AssetCache m_assetCache;
  63. public AssetCache AssetCache
  64. {
  65. get { return m_assetCache; }
  66. set { m_assetCache = value; }
  67. }
  68. protected RegionStatus m_regStatus;
  69. public RegionStatus Region_Status
  70. {
  71. get { return m_regStatus; }
  72. set { m_regStatus = value; }
  73. }
  74. #endregion
  75. #region Update Methods
  76. /// <summary>
  77. /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
  78. /// </summary>
  79. public abstract void Update();
  80. #endregion
  81. #region Terrain Methods
  82. /// <summary>
  83. /// Loads the World heightmap
  84. /// </summary>
  85. public abstract void LoadWorldMap();
  86. /// <summary>
  87. /// Send the region heightmap to the client
  88. /// </summary>
  89. /// <param name="RemoteClient">Client to send to</param>
  90. public virtual void SendLayerData(IClientAPI RemoteClient)
  91. {
  92. RemoteClient.SendLayerData(Heightmap.GetFloatsSerialised());
  93. }
  94. #endregion
  95. #region Add/Remove Agent/Avatar
  96. /// <summary>
  97. ///
  98. /// </summary>
  99. /// <param name="remoteClient"></param>
  100. /// <param name="agentID"></param>
  101. /// <param name="child"></param>
  102. public abstract void AddNewClient(IClientAPI client, bool child);
  103. /// <summary>
  104. ///
  105. /// </summary>
  106. /// <param name="agentID"></param>
  107. public abstract void RemoveClient(LLUUID agentID);
  108. public abstract void CloseAllAgents(uint circuitcode);
  109. #endregion
  110. /// <summary>
  111. ///
  112. /// </summary>
  113. /// <returns></returns>
  114. public virtual RegionInfo RegionInfo
  115. {
  116. get { return m_regInfo; }
  117. }
  118. public uint NextLocalId
  119. {
  120. get { return m_nextLocalId++; }
  121. }
  122. #region admin stuff
  123. /// <summary>
  124. /// Region Restart - Seconds till restart.
  125. /// </summary>
  126. /// <param name="seconds"></param>
  127. public virtual void Restart(int seconds)
  128. {
  129. m_log.Error("[REGION]: passing Restart Message up the namespace");
  130. restart handlerPhysicsCrash = OnRestart;
  131. if (handlerPhysicsCrash != null)
  132. handlerPhysicsCrash(RegionInfo);
  133. }
  134. public virtual bool PresenceChildStatus(LLUUID avatarID)
  135. {
  136. return false;
  137. }
  138. public abstract bool OtherRegionUp(RegionInfo thisRegion);
  139. public virtual string GetSimulatorVersion()
  140. {
  141. return "OpenSimulator v0.5 SVN";
  142. }
  143. #endregion
  144. #region Shutdown
  145. /// <summary>
  146. /// Tidy before shutdown
  147. /// </summary>
  148. public virtual void Close()
  149. {
  150. try
  151. {
  152. EventManager.TriggerShutdown();
  153. }
  154. catch (Exception e)
  155. {
  156. m_log.Error("[SCENE]: SceneBase.cs: Close() - Failed with exception " + e.ToString());
  157. }
  158. }
  159. #endregion
  160. /// <summary>
  161. /// XXX These two methods are very temporary
  162. /// </summary>
  163. protected Dictionary<LLUUID, string> capsPaths = new Dictionary<LLUUID, string>();
  164. public string GetCapsPath(LLUUID agentId)
  165. {
  166. if (capsPaths.ContainsKey(agentId))
  167. {
  168. return capsPaths[agentId];
  169. }
  170. return null;
  171. }
  172. }
  173. }