CMEntityCollection.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. #region Header
  28. // CMEntityCollection.cs created with MonoDevelop
  29. // User: bongiojp at 10:09 AM 7/7/2008
  30. //
  31. // Creates, Deletes, Stores ContentManagementEntities
  32. //
  33. #endregion Header
  34. using System;
  35. using System.Collections;
  36. using System.Collections.Generic;
  37. using System.Threading;
  38. using OpenMetaverse;
  39. using Nini.Config;
  40. using OpenSim;
  41. using OpenSim.Framework;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. using OpenSim.Region.Physics.Manager;
  45. using log4net;
  46. namespace OpenSim.Region.OptionalModules.ContentManagement
  47. {
  48. public class CMEntityCollection
  49. {
  50. #region Fields
  51. // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  52. // Any ContentManagementEntities that represent old versions of current SceneObjectGroups or
  53. // old versions of deleted SceneObjectGroups will be stored in this hash table.
  54. // The UUID keys are from the SceneObjectGroup RootPart UUIDs
  55. protected Hashtable m_CMEntityHash = Hashtable.Synchronized(new Hashtable()); //UUID to ContentManagementEntity
  56. // SceneObjectParts that have not been revisioned will be given green auras stored in this hashtable
  57. // The UUID keys are from the SceneObjectPart that they are supposed to be on.
  58. protected Hashtable m_NewlyCreatedEntityAura = Hashtable.Synchronized(new Hashtable()); //UUID to AuraMetaEntity
  59. #endregion Fields
  60. #region Constructors
  61. public CMEntityCollection()
  62. {
  63. }
  64. #endregion Constructors
  65. #region Public Properties
  66. public Hashtable Auras
  67. {
  68. get {return m_NewlyCreatedEntityAura; }
  69. }
  70. public Hashtable Entities
  71. {
  72. get { return m_CMEntityHash; }
  73. }
  74. #endregion Public Properties
  75. #region Public Methods
  76. public bool AddAura(ContentManagementEntity aura)
  77. {
  78. if (m_NewlyCreatedEntityAura.ContainsKey(aura.UUID))
  79. return false;
  80. m_NewlyCreatedEntityAura.Add(aura.UUID, aura);
  81. return true;
  82. }
  83. public bool AddEntity(ContentManagementEntity ent)
  84. {
  85. if (m_CMEntityHash.ContainsKey(ent.UUID))
  86. return false;
  87. m_CMEntityHash.Add(ent.UUID, ent);
  88. return true;
  89. }
  90. // Check if there are SceneObjectGroups in the list that do not have corresponding ContentManagementGroups in the CMEntityHash
  91. public System.Collections.ArrayList CheckForMissingEntities(EntityBase[] currList)
  92. {
  93. System.Collections.ArrayList missingList = new System.Collections.ArrayList();
  94. SceneObjectGroup temp = null;
  95. foreach (EntityBase currObj in currList)
  96. {
  97. if (!(currObj is SceneObjectGroup))
  98. continue;
  99. temp = (SceneObjectGroup) currObj;
  100. lock (temp.Children)
  101. {
  102. if (m_CMEntityHash.ContainsKey(temp.UUID))
  103. {
  104. foreach (SceneObjectPart part in temp.Children.Values)
  105. if (!((ContentManagementEntity)m_CMEntityHash[temp.UUID]).HasChildPrim(part.UUID))
  106. missingList.Add(part);
  107. }
  108. else //Entire group is missing from revision. (and is a new part in region)
  109. {
  110. foreach (SceneObjectPart part in temp.Children.Values)
  111. missingList.Add(part);
  112. }
  113. }
  114. }
  115. return missingList;
  116. }
  117. public void ClearAll()
  118. {
  119. m_CMEntityHash.Clear();
  120. m_NewlyCreatedEntityAura.Clear();
  121. }
  122. // Old uuid and new sceneobjectgroup
  123. public AuraMetaEntity CreateAuraForNewlyCreatedEntity(SceneObjectPart part)
  124. {
  125. AuraMetaEntity ent = new AuraMetaEntity(part.ParentGroup.Scene,
  126. part.GetWorldPosition(),
  127. MetaEntity.TRANSLUCENT,
  128. new Vector3(0,254,0),
  129. part.Scale
  130. );
  131. m_NewlyCreatedEntityAura.Add(part.UUID, ent);
  132. return ent;
  133. }
  134. // Old uuid and new sceneobjectgroup
  135. public ContentManagementEntity CreateNewEntity(SceneObjectGroup group)
  136. {
  137. ContentManagementEntity ent = new ContentManagementEntity(group, false);
  138. m_CMEntityHash.Add(group.UUID, ent);
  139. return ent;
  140. }
  141. public ContentManagementEntity CreateNewEntity(String xml, Scene scene)
  142. {
  143. ContentManagementEntity ent = new ContentManagementEntity(xml, scene, false);
  144. if (ent == null)
  145. return null;
  146. m_CMEntityHash.Add(ent.UnchangedEntity.UUID, ent);
  147. return ent;
  148. }
  149. public bool RemoveEntity(UUID uuid)
  150. {
  151. if (!m_CMEntityHash.ContainsKey(uuid))
  152. return false;
  153. m_CMEntityHash.Remove(uuid);
  154. return true;
  155. }
  156. public bool RemoveNewlyCreatedEntityAura(UUID uuid)
  157. {
  158. if (!m_NewlyCreatedEntityAura.ContainsKey(uuid))
  159. return false;
  160. m_NewlyCreatedEntityAura.Remove(uuid);
  161. return true;
  162. }
  163. #endregion Public Methods
  164. }
  165. }