diff options
author | MW | 2007-10-11 10:50:55 +0000 |
---|---|---|
committer | MW | 2007-10-11 10:50:55 +0000 |
commit | 86e5f82cb12dc5e854fe33526aee0ce899715410 (patch) | |
tree | 99066d2e40c53eb0355262c91704ecad6640208d /OpenSim/Region/Environment/Types | |
parent | * Added FormatProvider to Culture (diff) | |
download | opensim-SC_OLD-86e5f82cb12dc5e854fe33526aee0ce899715410.zip opensim-SC_OLD-86e5f82cb12dc5e854fe33526aee0ce899715410.tar.gz opensim-SC_OLD-86e5f82cb12dc5e854fe33526aee0ce899715410.tar.bz2 opensim-SC_OLD-86e5f82cb12dc5e854fe33526aee0ce899715410.tar.xz |
Some changes to the sending of updates of SceneObjects to clients, that I did a few weeks ago but never committed (and never completely finished what I had planned).
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Types/BasicQuadTreeNode.cs | 402 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Types/UpdateQueue.cs | 100 |
2 files changed, 279 insertions, 223 deletions
diff --git a/OpenSim/Region/Environment/Types/BasicQuadTreeNode.cs b/OpenSim/Region/Environment/Types/BasicQuadTreeNode.cs index 2b8d92e..fd1307a 100644 --- a/OpenSim/Region/Environment/Types/BasicQuadTreeNode.cs +++ b/OpenSim/Region/Environment/Types/BasicQuadTreeNode.cs | |||
@@ -1,174 +1,230 @@ | |||
1 | using System.Collections.Generic; | 1 | using System.Collections.Generic; |
2 | using OpenSim.Region.Environment.Scenes; | 2 | using OpenSim.Region.Environment.Scenes; |
3 | 3 | ||
4 | namespace OpenSim.Region.Environment.Types | 4 | namespace OpenSim.Region.Environment.Types |
5 | { | 5 | { |
6 | public class BasicQuadTreeNode | 6 | public class BasicQuadTreeNode |
7 | { | 7 | { |
8 | private List<SceneObjectGroup> m_objects = new List<SceneObjectGroup>(); | 8 | private List<SceneObjectGroup> m_objects = new List<SceneObjectGroup>(); |
9 | private BasicQuadTreeNode[] m_childNodes = null; | 9 | private BasicQuadTreeNode[] m_childNodes = null; |
10 | private BasicQuadTreeNode m_parent = null; | 10 | private BasicQuadTreeNode m_parent = null; |
11 | 11 | ||
12 | private short m_leftX; | 12 | private short m_leftX; |
13 | private short m_leftY; | 13 | private short m_leftY; |
14 | private short m_width; | 14 | private short m_width; |
15 | private short m_height; | 15 | private short m_height; |
16 | 16 | //private int m_quadNumber; | |
17 | public BasicQuadTreeNode(BasicQuadTreeNode parent, short leftX, short leftY, short width, short height) | 17 | private string m_quadID; |
18 | { | 18 | |
19 | m_parent = parent; | 19 | public BasicQuadTreeNode(BasicQuadTreeNode parent, string quadID, short leftX, short leftY, short width, short height) |
20 | m_leftX = leftX; | 20 | { |
21 | m_leftY = leftY; | 21 | m_parent = parent; |
22 | m_width = width; | 22 | m_quadID = quadID; |
23 | m_height = height; | 23 | m_leftX = leftX; |
24 | } | 24 | m_leftY = leftY; |
25 | 25 | m_width = width; | |
26 | public void AddObject(SceneObjectGroup obj) | 26 | m_height = height; |
27 | { | 27 | // Console.WriteLine("creating quadtree node " + m_quadID); |
28 | if (m_childNodes == null) | 28 | } |
29 | { | 29 | |
30 | if (!m_objects.Contains(obj)) | 30 | public void AddObject(SceneObjectGroup obj) |
31 | { | 31 | { |
32 | m_objects.Add(obj); | 32 | if (m_childNodes == null) |
33 | } | 33 | { |
34 | } | 34 | if (!m_objects.Contains(obj)) |
35 | else | 35 | { |
36 | { | 36 | m_objects.Add(obj); |
37 | if (obj.AbsolutePosition.X < (m_leftX + (m_width/2))) | 37 | } |
38 | { | 38 | } |
39 | if (obj.AbsolutePosition.Y < (m_leftY + (m_height/2))) | 39 | else |
40 | { | 40 | { |
41 | m_childNodes[0].AddObject(obj); | 41 | if (obj.AbsolutePosition.X < (m_leftX + (m_width / 2))) |
42 | } | 42 | { |
43 | else | 43 | if (obj.AbsolutePosition.Y < (m_leftY + (m_height / 2))) |
44 | { | 44 | { |
45 | m_childNodes[2].AddObject(obj); | 45 | m_childNodes[0].AddObject(obj); |
46 | } | 46 | } |
47 | } | 47 | else |
48 | else | 48 | { |
49 | { | 49 | m_childNodes[2].AddObject(obj); |
50 | if (obj.AbsolutePosition.Y < (m_leftY + (m_height/2))) | 50 | } |
51 | { | 51 | } |
52 | m_childNodes[1].AddObject(obj); | 52 | else |
53 | } | 53 | { |
54 | else | 54 | if (obj.AbsolutePosition.Y < (m_leftY + (m_height / 2))) |
55 | { | 55 | { |
56 | m_childNodes[3].AddObject(obj); | 56 | m_childNodes[1].AddObject(obj); |
57 | } | 57 | } |
58 | } | 58 | else |
59 | } | 59 | { |
60 | } | 60 | m_childNodes[3].AddObject(obj); |
61 | 61 | } | |
62 | public void Subdivide() | 62 | } |
63 | { | 63 | } |
64 | if (m_childNodes == null) | 64 | } |
65 | { | 65 | |
66 | m_childNodes = new BasicQuadTreeNode[4]; | 66 | public void Subdivide() |
67 | m_childNodes[0] = | 67 | { |
68 | new BasicQuadTreeNode(this, m_leftX, m_leftY, (short) (m_width/2), (short) (m_height/2)); | 68 | if (m_childNodes == null) |
69 | m_childNodes[1] = | 69 | { |
70 | new BasicQuadTreeNode(this, (short) (m_leftX + (m_width/2)), m_leftY, (short) (m_width/2), | 70 | m_childNodes = new BasicQuadTreeNode[4]; |
71 | (short) (m_height/2)); | 71 | m_childNodes[0] = new BasicQuadTreeNode(this, m_quadID + "1/", m_leftX, m_leftY, (short)(m_width / 2), (short)(m_height / 2)); |
72 | m_childNodes[2] = | 72 | m_childNodes[1] = new BasicQuadTreeNode(this, m_quadID + "2/", (short)(m_leftX + (m_width / 2)), m_leftY, (short)(m_width / 2), (short)(m_height / 2)); |
73 | new BasicQuadTreeNode(this, m_leftX, (short) (m_leftY + (m_height/2)), (short) (m_width/2), | 73 | m_childNodes[2] = new BasicQuadTreeNode(this, m_quadID + "3/", m_leftX, (short)(m_leftY + (m_height / 2)), (short)(m_width / 2), (short)(m_height / 2)); |
74 | (short) (m_height/2)); | 74 | m_childNodes[3] = new BasicQuadTreeNode(this, m_quadID + "4/", (short)(m_leftX + (m_width / 2)), (short)(m_height + (m_height / 2)), (short)(m_width / 2), (short)(m_height / 2)); |
75 | m_childNodes[3] = | 75 | } |
76 | new BasicQuadTreeNode(this, (short) (m_leftX + (m_width/2)), (short) (m_height + (m_height/2)), | 76 | else |
77 | (short) (m_width/2), (short) (m_height/2)); | 77 | { |
78 | } | 78 | for (int i = 0; i < m_childNodes.Length; i++) |
79 | else | 79 | { |
80 | { | 80 | m_childNodes[i].Subdivide(); |
81 | for (int i = 0; i < m_childNodes.Length; i++) | 81 | } |
82 | { | 82 | } |
83 | m_childNodes[i].Subdivide(); | 83 | } |
84 | } | 84 | |
85 | } | 85 | public List<SceneObjectGroup> GetObjectsFrom(float x, float y) |
86 | } | 86 | { |
87 | 87 | if (m_childNodes == null) | |
88 | public List<SceneObjectGroup> GetObjectsFrom(int x, int y) | 88 | { |
89 | { | 89 | return new List<SceneObjectGroup>(m_objects); |
90 | if (m_childNodes == null) | 90 | } |
91 | { | 91 | else |
92 | return m_objects; | 92 | { |
93 | } | 93 | if (x < m_leftX + (m_width / 2)) |
94 | else | 94 | { |
95 | { | 95 | if (y < m_leftY + (m_height / 2)) |
96 | if (x < (m_leftX + (m_width/2))) | 96 | { |
97 | { | 97 | return m_childNodes[0].GetObjectsFrom(x, y); |
98 | if (y < (m_leftY + (m_height/2))) | 98 | } |
99 | { | 99 | else |
100 | return m_childNodes[0].GetObjectsFrom(x, y); | 100 | { |
101 | } | 101 | return m_childNodes[2].GetObjectsFrom(x, y); |
102 | else | 102 | } |
103 | { | 103 | } |
104 | return m_childNodes[2].GetObjectsFrom(x, y); | 104 | else |
105 | } | 105 | { |
106 | } | 106 | if (y < m_leftY + (m_height / 2)) |
107 | else | 107 | { |
108 | { | 108 | return m_childNodes[1].GetObjectsFrom(x, y); |
109 | if (y < (m_leftY + (m_height/2))) | 109 | } |
110 | { | 110 | else |
111 | return m_childNodes[1].GetObjectsFrom(x, y); | 111 | { |
112 | } | 112 | return m_childNodes[3].GetObjectsFrom(x, y); |
113 | else | 113 | } |
114 | { | 114 | } |
115 | return m_childNodes[3].GetObjectsFrom(x, y); | 115 | } |
116 | } | 116 | } |
117 | } | 117 | |
118 | } | 118 | public List<SceneObjectGroup> GetObjectsFrom(string nodeName) |
119 | } | 119 | { |
120 | 120 | if (nodeName == m_quadID) | |
121 | public void Update() | 121 | { |
122 | { | 122 | return new List<SceneObjectGroup>(m_objects); |
123 | if (m_childNodes != null) | 123 | } |
124 | { | 124 | else if (m_childNodes != null) |
125 | for (int i = 0; i < 4; i++) | 125 | { |
126 | { | 126 | for (int i = 0; i < 4; i++) |
127 | m_childNodes[i].Update(); | 127 | { |
128 | } | 128 | List<SceneObjectGroup> retVal; |
129 | } | 129 | retVal = m_childNodes[i].GetObjectsFrom(nodeName); |
130 | else | 130 | if (retVal != null) |
131 | { | 131 | { |
132 | List<SceneObjectGroup> outBounds = new List<SceneObjectGroup>(); | 132 | return retVal; |
133 | foreach (SceneObjectGroup group in m_objects) | 133 | } |
134 | { | 134 | } |
135 | if (((group.AbsolutePosition.X > m_leftX) && (group.AbsolutePosition.X < (m_leftX + m_width))) && | 135 | } |
136 | ((group.AbsolutePosition.Y > m_leftY) && (group.AbsolutePosition.Y < (m_leftY + m_height)))) | 136 | return null; |
137 | { | 137 | } |
138 | //still in bounds | 138 | |
139 | } | 139 | public string GetNodeID(float x, float y) |
140 | else | 140 | { |
141 | { | 141 | if (m_childNodes == null) |
142 | outBounds.Add(group); | 142 | { |
143 | } | 143 | return m_quadID; |
144 | } | 144 | } |
145 | 145 | else | |
146 | foreach (SceneObjectGroup removee in outBounds) | 146 | { |
147 | { | 147 | if (x < m_leftX + (m_width / 2)) |
148 | m_objects.Remove(removee); | 148 | { |
149 | if (m_parent != null) | 149 | if (y < m_leftY + (m_height / 2)) |
150 | { | 150 | { |
151 | m_parent.PassUp(removee); | 151 | return m_childNodes[0].GetNodeID(x, y); |
152 | } | 152 | } |
153 | } | 153 | else |
154 | outBounds.Clear(); | 154 | { |
155 | } | 155 | return m_childNodes[2].GetNodeID(x, y); |
156 | } | 156 | } |
157 | 157 | } | |
158 | public void PassUp(SceneObjectGroup group) | 158 | else |
159 | { | 159 | { |
160 | if (((group.AbsolutePosition.X > m_leftX) && (group.AbsolutePosition.X < (m_leftX + m_width))) && | 160 | if (y < m_leftY + (m_height / 2)) |
161 | ((group.AbsolutePosition.Y > m_leftY) && (group.AbsolutePosition.Y < (m_leftY + m_height)))) | 161 | { |
162 | { | 162 | return m_childNodes[1].GetNodeID(x, y); |
163 | AddObject(group); | 163 | } |
164 | } | 164 | else |
165 | else | 165 | { |
166 | { | 166 | return m_childNodes[3].GetNodeID(x, y); |
167 | if (m_parent != null) | 167 | } |
168 | { | 168 | } |
169 | m_parent.PassUp(group); | 169 | } |
170 | } | 170 | } |
171 | } | 171 | |
172 | } | 172 | public void Update() |
173 | } | 173 | { |
174 | if (m_childNodes != null) | ||
175 | { | ||
176 | for (int i = 0; i < 4; i++) | ||
177 | { | ||
178 | m_childNodes[i].Update(); | ||
179 | } | ||
180 | } | ||
181 | else | ||
182 | { | ||
183 | List<SceneObjectGroup> outBounds = new List<SceneObjectGroup>(); | ||
184 | foreach (SceneObjectGroup group in m_objects) | ||
185 | { | ||
186 | if (((group.AbsolutePosition.X > m_leftX) && (group.AbsolutePosition.X < (m_leftX + m_width))) && ((group.AbsolutePosition.Y > m_leftY) && (group.AbsolutePosition.Y < (m_leftY + m_height)))) | ||
187 | { | ||
188 | //still in bounds | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | outBounds.Add(group); | ||
193 | } | ||
194 | } | ||
195 | |||
196 | foreach (SceneObjectGroup removee in outBounds) | ||
197 | { | ||
198 | m_objects.Remove(removee); | ||
199 | if (m_parent != null) | ||
200 | { | ||
201 | m_parent.PassUp(removee); | ||
202 | } | ||
203 | } | ||
204 | outBounds.Clear(); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | public void PassUp(SceneObjectGroup group) | ||
209 | { | ||
210 | if (((group.AbsolutePosition.X > m_leftX) && (group.AbsolutePosition.X < (m_leftX + m_width))) && ((group.AbsolutePosition.Y > m_leftY) && (group.AbsolutePosition.Y < (m_leftY + m_height)))) | ||
211 | { | ||
212 | AddObject(group); | ||
213 | } | ||
214 | else | ||
215 | { | ||
216 | if (m_parent != null) | ||
217 | { | ||
218 | m_parent.PassUp(group); | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | |||
223 | public string[] GetNeighbours(string nodeName) | ||
224 | { | ||
225 | string[] retVal = new string[1]; | ||
226 | retVal[0] = ""; | ||
227 | return retVal; | ||
228 | } | ||
229 | } | ||
174 | } \ No newline at end of file | 230 | } \ No newline at end of file |
diff --git a/OpenSim/Region/Environment/Types/UpdateQueue.cs b/OpenSim/Region/Environment/Types/UpdateQueue.cs index c1fb161..0d341ae 100644 --- a/OpenSim/Region/Environment/Types/UpdateQueue.cs +++ b/OpenSim/Region/Environment/Types/UpdateQueue.cs | |||
@@ -1,51 +1,51 @@ | |||
1 | using System.Collections.Generic; | 1 | using System.Collections.Generic; |
2 | using libsecondlife; | 2 | using libsecondlife; |
3 | using OpenSim.Region.Environment.Scenes; | 3 | using OpenSim.Region.Environment.Scenes; |
4 | 4 | ||
5 | namespace OpenSim.Region.Environment.Types | 5 | namespace OpenSim.Region.Environment.Types |
6 | { | 6 | { |
7 | public class UpdateQueue | 7 | public class UpdateQueue |
8 | { | 8 | { |
9 | private Queue<SceneObjectPart> m_queue; | 9 | private Queue<SceneObjectPart> m_queue; |
10 | 10 | ||
11 | private List<LLUUID> m_ids; | 11 | private List<LLUUID> m_ids; |
12 | 12 | ||
13 | public int Count | 13 | public int Count |
14 | { | 14 | { |
15 | get { return m_queue.Count; } | 15 | get { return m_queue.Count; } |
16 | } | 16 | } |
17 | 17 | ||
18 | public UpdateQueue() | 18 | public UpdateQueue() |
19 | { | 19 | { |
20 | m_queue = new Queue<SceneObjectPart>(); | 20 | m_queue = new Queue<SceneObjectPart>(); |
21 | m_ids = new List<LLUUID>(); | 21 | m_ids = new List<LLUUID>(); |
22 | } | 22 | } |
23 | 23 | ||
24 | public void Enqueue(SceneObjectPart part) | 24 | public void Enqueue(SceneObjectPart part) |
25 | { | 25 | { |
26 | lock (m_ids) | 26 | lock (m_ids) |
27 | { | 27 | { |
28 | if (!m_ids.Contains(part.UUID)) | 28 | if (!m_ids.Contains(part.UUID)) |
29 | { | 29 | { |
30 | m_ids.Add(part.UUID); | 30 | m_ids.Add(part.UUID); |
31 | m_queue.Enqueue(part); | 31 | m_queue.Enqueue(part); |
32 | } | 32 | } |
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | public SceneObjectPart Dequeue() | 36 | public SceneObjectPart Dequeue() |
37 | { | 37 | { |
38 | SceneObjectPart part = null; | 38 | SceneObjectPart part = null; |
39 | if (m_queue.Count > 0) | 39 | if (m_queue.Count > 0) |
40 | { | 40 | { |
41 | part = m_queue.Dequeue(); | 41 | part = m_queue.Dequeue(); |
42 | lock (m_ids) | 42 | lock (m_ids) |
43 | { | 43 | { |
44 | m_ids.Remove(part.UUID); | 44 | m_ids.Remove(part.UUID); |
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | return part; | 48 | return part; |
49 | } | 49 | } |
50 | } | 50 | } |
51 | } \ No newline at end of file | 51 | } \ No newline at end of file |