1
0

ObjectAccessor.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using IEnumerable=System.Collections.IEnumerable;
  34. namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
  35. {
  36. internal class IObjEnum : System.MarshalByRefObject, IEnumerator<IObject>
  37. {
  38. private readonly Scene m_scene;
  39. private readonly IEnumerator<EntityBase> m_sogEnum;
  40. private readonly ISecurityCredential m_security;
  41. public IObjEnum(Scene scene, ISecurityCredential security)
  42. {
  43. m_scene = scene;
  44. m_security = security;
  45. m_sogEnum = m_scene.Entities.GetAllByType<SceneObjectGroup>().GetEnumerator();
  46. }
  47. public void Dispose()
  48. {
  49. m_sogEnum.Dispose();
  50. }
  51. public bool MoveNext()
  52. {
  53. return m_sogEnum.MoveNext();
  54. }
  55. public void Reset()
  56. {
  57. m_sogEnum.Reset();
  58. }
  59. public IObject Current
  60. {
  61. get
  62. {
  63. return new SOPObject(m_scene, m_sogEnum.Current.LocalId, m_security);
  64. }
  65. }
  66. object IEnumerator.Current
  67. {
  68. get { return Current; }
  69. }
  70. }
  71. public class ObjectAccessor : System.MarshalByRefObject, IObjectAccessor
  72. {
  73. private readonly Scene m_scene;
  74. private readonly ISecurityCredential m_security;
  75. public ObjectAccessor(Scene scene, ISecurityCredential security)
  76. {
  77. m_scene = scene;
  78. m_security = security;
  79. }
  80. public IObject this[int index]
  81. {
  82. get
  83. {
  84. return new SOPObject(m_scene, m_scene.Entities[(uint)index].LocalId, m_security);
  85. }
  86. }
  87. public IObject this[uint index]
  88. {
  89. get
  90. {
  91. return new SOPObject(m_scene, m_scene.Entities[index].LocalId, m_security);
  92. }
  93. }
  94. public IObject this[UUID index]
  95. {
  96. get
  97. {
  98. return new SOPObject(m_scene, m_scene.Entities[index].LocalId, m_security);
  99. }
  100. }
  101. public IObject Create(Vector3 position)
  102. {
  103. return Create(position, Quaternion.Identity);
  104. }
  105. public IObject Create(Vector3 position, Quaternion rotation)
  106. {
  107. SceneObjectGroup sog = m_scene.AddNewPrim(m_security.owner.GlobalID,
  108. UUID.Zero,
  109. position,
  110. rotation,
  111. PrimitiveBaseShape.CreateBox());
  112. IObject ret = new SOPObject(m_scene, sog.LocalId, m_security);
  113. return ret;
  114. }
  115. public IEnumerator<IObject> GetEnumerator()
  116. {
  117. return new IObjEnum(m_scene, m_security);
  118. }
  119. IEnumerator IEnumerable.GetEnumerator()
  120. {
  121. return GetEnumerator();
  122. }
  123. public void Add(IObject item)
  124. {
  125. throw new NotSupportedException("Collection is read-only. This is an API TODO FIX, creation of objects is presently impossible.");
  126. }
  127. public void Clear()
  128. {
  129. throw new NotSupportedException("Collection is read-only. TODO FIX.");
  130. }
  131. public bool Contains(IObject item)
  132. {
  133. return m_scene.Entities.ContainsKey(item.LocalID);
  134. }
  135. public void CopyTo(IObject[] array, int arrayIndex)
  136. {
  137. for (int i = arrayIndex; i < Count + arrayIndex; i++)
  138. {
  139. array[i] = this[i - arrayIndex];
  140. }
  141. }
  142. public bool Remove(IObject item)
  143. {
  144. throw new NotSupportedException("Collection is read-only. TODO FIX.");
  145. }
  146. public int Count
  147. {
  148. get { return m_scene.Entities.Count; }
  149. }
  150. public bool IsReadOnly
  151. {
  152. get { return true; }
  153. }
  154. }
  155. }