aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
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
parent* Adds World.Avatars[] to MRM Scripting. Contains an enumerable array contain... (diff)
downloadopensim-SC_OLD-5cd70a8c0e3786712fa7dc3be8c947829be060c7.zip
opensim-SC_OLD-5cd70a8c0e3786712fa7dc3be8c947829be060c7.tar.gz
opensim-SC_OLD-5cd70a8c0e3786712fa7dc3be8c947829be060c7.tar.bz2
opensim-SC_OLD-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')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/IObjectAccessor.cs12
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/ObjectAccessor.cs132
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs19
4 files changed, 150 insertions, 15 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObjectAccessor.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObjectAccessor.cs
new file mode 100644
index 0000000..feddf67
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObjectAccessor.cs
@@ -0,0 +1,12 @@
1using System.Collections.Generic;
2using OpenMetaverse;
3
4namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
5{
6 public interface IObjectAccessor : ICollection<IObject>
7 {
8 IObject this[int index] { get; }
9 IObject this[uint index] { get; }
10 IObject this[UUID index] { get; }
11 }
12} \ No newline at end of file
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs
index bfa6b65..1b1ce92 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs
@@ -33,7 +33,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
33{ 33{
34 public interface IWorld 34 public interface IWorld
35 { 35 {
36 IObject[] Objects { get; } 36 IObjectAccessor Objects { get; }
37 IAvatar[] Avatars { get; } 37 IAvatar[] Avatars { get; }
38 IHeightmap Terrain { get; } 38 IHeightmap Terrain { get; }
39 } 39 }
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}
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs
index 4ba6778..987868a 100644
--- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs
@@ -35,27 +35,18 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
35 private readonly Scene m_internalScene; 35 private readonly Scene m_internalScene;
36 private readonly Heightmap m_heights; 36 private readonly Heightmap m_heights;
37 37
38 private ObjectAccessor m_objs;
39
38 public World(Scene internalScene) 40 public World(Scene internalScene)
39 { 41 {
40 m_internalScene = internalScene; 42 m_internalScene = internalScene;
41 m_heights = new Heightmap(m_internalScene); 43 m_heights = new Heightmap(m_internalScene);
44 m_objs = new ObjectAccessor(m_internalScene);
42 } 45 }
43 46
44 public IObject[] Objects 47 public IObjectAccessor Objects
45 { 48 {
46 get 49 get { return m_objs; }
47 {
48 List<EntityBase> ents = m_internalScene.Entities.GetAllByType<SceneObjectGroup>();
49 IObject[] rets = new IObject[ents.Count];
50
51 for (int i = 0; i < ents.Count; i++)
52 {
53 EntityBase ent = ents[i];
54 rets[i] = new SOPObject(m_internalScene, ent.LocalId);
55 }
56
57 return rets;
58 }
59 } 50 }
60 51
61 public IAvatar[] Avatars 52 public IAvatar[] Avatars