CMEntityCollection.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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(System.Collections.Generic.List<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. if (m_CMEntityHash.ContainsKey(temp.UUID))
  101. {
  102. foreach (SceneObjectPart part in temp.Children.Values)
  103. if (!((ContentManagementEntity)m_CMEntityHash[temp.UUID]).HasChildPrim(part.UUID))
  104. missingList.Add(part);
  105. }
  106. else //Entire group is missing from revision. (and is a new part in region)
  107. {
  108. foreach (SceneObjectPart part in temp.Children.Values)
  109. missingList.Add(part);
  110. }
  111. }
  112. return missingList;
  113. }
  114. public void ClearAll()
  115. {
  116. m_CMEntityHash.Clear();
  117. m_NewlyCreatedEntityAura.Clear();
  118. }
  119. // Old uuid and new sceneobjectgroup
  120. public AuraMetaEntity CreateAuraForNewlyCreatedEntity(SceneObjectPart part)
  121. {
  122. AuraMetaEntity ent = new AuraMetaEntity(part.ParentGroup.Scene,
  123. part.GetWorldPosition(),
  124. MetaEntity.TRANSLUCENT,
  125. new Vector3(0,254,0),
  126. part.Scale
  127. );
  128. m_NewlyCreatedEntityAura.Add(part.UUID, ent);
  129. return ent;
  130. }
  131. // Old uuid and new sceneobjectgroup
  132. public ContentManagementEntity CreateNewEntity(SceneObjectGroup group)
  133. {
  134. ContentManagementEntity ent = new ContentManagementEntity(group, false);
  135. m_CMEntityHash.Add(group.UUID, ent);
  136. return ent;
  137. }
  138. public ContentManagementEntity CreateNewEntity(String xml, Scene scene)
  139. {
  140. ContentManagementEntity ent = new ContentManagementEntity(xml, scene, false);
  141. if (ent == null)
  142. return null;
  143. m_CMEntityHash.Add(ent.UnchangedEntity.UUID, ent);
  144. return ent;
  145. }
  146. public bool RemoveEntity(UUID uuid)
  147. {
  148. if (!m_CMEntityHash.ContainsKey(uuid))
  149. return false;
  150. m_CMEntityHash.Remove(uuid);
  151. return true;
  152. }
  153. public bool RemoveNewlyCreatedEntityAura(UUID uuid)
  154. {
  155. if (!m_NewlyCreatedEntityAura.ContainsKey(uuid))
  156. return false;
  157. m_NewlyCreatedEntityAura.Remove(uuid);
  158. return true;
  159. }
  160. #endregion Public Methods
  161. }
  162. }