aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs
diff options
context:
space:
mode:
authorAdam Frisby2009-04-01 09:31:40 +0000
committerAdam Frisby2009-04-01 09:31:40 +0000
commit5cd70a8c0e3786712fa7dc3be8c947829be060c7 (patch)
tree3bd74ef71efbce10631126477b51518c40e0d4ee /OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs
parent* Adds World.Avatars[] to MRM Scripting. Contains an enumerable array contain... (diff)
downloadopensim-SC-5cd70a8c0e3786712fa7dc3be8c947829be060c7.zip
opensim-SC-5cd70a8c0e3786712fa7dc3be8c947829be060c7.tar.gz
opensim-SC-5cd70a8c0e3786712fa7dc3be8c947829be060c7.tar.bz2
opensim-SC-5cd70a8c0e3786712fa7dc3be8c947829be060c7.tar.xz
* MRM Adjustments
* Changes World.Objects from Array IObject[] to IObjectAccessor. * Syntactically identical in most behaviour, however the indexer is now ranges not from 0..Count, but any valid internal LocalID. Additional indexers have been added for UUID. * Example: for(int i=0;i<World.Objects.Count;i++) will not work any more, however foreach(World.Objects) will remain functional. * This prevents us needing to create a list for each access to World.Objects which should [in theory] present a dramatic speed improvement to MRM scripts frequently accessing World.Objects.
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs132
1 files changed, 132 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs
new file mode 100644
index 0000000..ad7182e
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs
@@ -0,0 +1,132 @@
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using OpenMetaverse;
5using OpenSim.Region.Framework.Scenes;
6using IEnumerable=System.Collections.IEnumerable;
7
8namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
9{
10
11 internal class IObjEnum : IEnumerator<IObject>
12 {
13 private readonly Scene m_scene;
14 private readonly IEnumerator<EntityBase> m_sogEnum;
15
16 public IObjEnum(Scene scene)
17 {
18 m_scene = scene;
19 m_sogEnum = m_scene.Entities.GetAllByType<SceneObjectGroup>().GetEnumerator();
20 }
21
22 public void Dispose()
23 {
24 m_sogEnum.Dispose();
25 }
26
27 public bool MoveNext()
28 {
29 return m_sogEnum.MoveNext();
30 }
31
32 public void Reset()
33 {
34 m_sogEnum.Reset();
35 }
36
37 public IObject Current
38 {
39 get
40 {
41 return new SOPObject(m_scene, m_sogEnum.Current.LocalId);
42 }
43 }
44
45 object IEnumerator.Current
46 {
47 get { return Current; }
48 }
49 }
50
51 public class ObjectAccessor : IObjectAccessor
52 {
53 private readonly Scene m_scene;
54
55 public ObjectAccessor(Scene scene)
56 {
57 m_scene = scene;
58 }
59
60 public IObject this[int index]
61 {
62 get
63 {
64 return new SOPObject(m_scene, m_scene.Entities[(uint)index].LocalId);
65 }
66 }
67
68 public IObject this[uint index]
69 {
70 get
71 {
72 return new SOPObject(m_scene, m_scene.Entities[index].LocalId);
73 }
74 }
75
76 public IObject this[UUID index]
77 {
78 get
79 {
80 return new SOPObject(m_scene, m_scene.Entities[index].LocalId);
81 }
82 }
83
84 public IEnumerator<IObject> GetEnumerator()
85 {
86 return new IObjEnum(m_scene);
87 }
88
89 IEnumerator IEnumerable.GetEnumerator()
90 {
91 return GetEnumerator();
92 }
93
94 public void Add(IObject item)
95 {
96 throw new NotSupportedException("Collection is read-only. This is an API TODO FIX, creation of objects is presently impossible.");
97 }
98
99 public void Clear()
100 {
101 throw new NotSupportedException("Collection is read-only. TODO FIX.");
102 }
103
104 public bool Contains(IObject item)
105 {
106 return m_scene.Entities.ContainsKey(item.LocalID);
107 }
108
109 public void CopyTo(IObject[] array, int arrayIndex)
110 {
111 for (int i = arrayIndex; i < Count + arrayIndex; i++)
112 {
113 array[i] = this[i - arrayIndex];
114 }
115 }
116
117 public bool Remove(IObject item)
118 {
119 throw new NotSupportedException("Collection is read-only. TODO FIX.");
120 }
121
122 public int Count
123 {
124 get { return m_scene.Entities.Count; }
125 }
126
127 public bool IsReadOnly
128 {
129 get { return true; }
130 }
131 }
132}