aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Framework')
-rw-r--r--OpenSim/Region/Framework/Scenes/Border.cs131
-rw-r--r--OpenSim/Region/Framework/Scenes/Cardinals.cs11
-rw-r--r--OpenSim/Region/Framework/Scenes/ScenePresence.cs5
-rw-r--r--OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs312
4 files changed, 455 insertions, 4 deletions
diff --git a/OpenSim/Region/Framework/Scenes/Border.cs b/OpenSim/Region/Framework/Scenes/Border.cs
new file mode 100644
index 0000000..19ecb4f
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Border.cs
@@ -0,0 +1,131 @@
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
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenMetaverse;
32
33namespace OpenSim.Region.Framework.Scenes
34{
35 public class Border
36 {
37
38 /// <summary>
39 /// Line perpendicular to the Direction Cardinal. Z value is the
40 /// </summary>
41 public Vector3 BorderLine = Vector3.Zero;
42
43 /// <summary>
44 /// Direction cardinal of the border, think, 'which side of the region this is'. EX South border: Cardinal.S
45 /// </summary>
46 public Cardinals CrossDirection = Cardinals.N;
47 public uint TriggerRegionX = 0;
48 public uint TriggerRegionY = 0;
49
50 public Border()
51 {
52 }
53
54 /// <summary>
55 /// Creates a Border. The line is perpendicular to the direction cardinal.
56 /// IE: if the direction cardinal is South, the line is West->East
57 /// </summary>
58 /// <param name="lineStart">The starting point for the line of the border.
59 /// The position of an object must be greater then this for this border to trigger.
60 /// Perpendicular to the direction cardinal</param>
61 /// <param name="lineEnd">The ending point for the line of the border.
62 /// The position of an object must be less then this for this border to trigger.
63 /// Perpendicular to the direction cardinal</param>
64 /// <param name="triggerCoordinate">The position that triggers border the border
65 /// cross parallel to the direction cardinal. On the North cardinal, this
66 /// normally 256. On the South cardinal, it's normally 0. Any position past this
67 /// point on the cartesian coordinate will trigger the border cross as long as it
68 /// falls within the line start and the line end.</param>
69 /// <param name="triggerRegionX">When this border triggers, teleport to this regionX
70 /// in the grid</param>
71 /// <param name="triggerRegionY">When this border triggers, teleport to this regionY
72 /// in the grid</param>
73 /// <param name="direction">Cardinal for border direction. Think, 'which side of the
74 /// region is this'</param>
75 public Border(float lineStart, float lineEnd, float triggerCoordinate, uint triggerRegionX,
76 uint triggerRegionY, Cardinals direction)
77 {
78 BorderLine = new Vector3(lineStart,lineEnd,triggerCoordinate);
79 CrossDirection = direction;
80 TriggerRegionX = triggerRegionX;
81 TriggerRegionY = triggerRegionY;
82 }
83
84 public bool TestCross(Vector3 position)
85 {
86 bool result = false;
87 switch (CrossDirection)
88 {
89 case Cardinals.N: // x+0, y+1
90 if (position.X >= BorderLine.X && position.X <=BorderLine.Y && position.Y > BorderLine.Z )
91 {
92 return true;
93 }
94 break;
95 case Cardinals.NE: // x+1, y+1
96 break;
97 case Cardinals.E: // x+1, y+0
98 if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X > BorderLine.Z)
99 {
100 return true;
101 }
102 break;
103 case Cardinals.SE: // x+1, y-1
104 break;
105 case Cardinals.S: // x+0, y-1
106 if (position.X >= BorderLine.X && position.X <= BorderLine.Y && position.Y < BorderLine.Z)
107 {
108 return true;
109 }
110 break;
111 case Cardinals.SW: // x-1, y-1
112 break;
113 case Cardinals.W: // x-1, y+0
114 if (position.Y >= BorderLine.X && position.Y <= BorderLine.Y && position.X < BorderLine.Z)
115 {
116 return true;
117 }
118 break;
119 case Cardinals.NW: // x-1, y+1
120 break;
121
122
123 }
124
125 return result;
126 }
127
128 }
129
130
131}
diff --git a/OpenSim/Region/Framework/Scenes/Cardinals.cs b/OpenSim/Region/Framework/Scenes/Cardinals.cs
new file mode 100644
index 0000000..692389a
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Cardinals.cs
@@ -0,0 +1,11 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Framework.Scenes
6{
7 public enum Cardinals
8 {
9 N = 1, NE, E, SE, S, SW, W, NW
10 }
11}
diff --git a/OpenSim/Region/Framework/Scenes/ScenePresence.cs b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
index ff97183..5281c4f 100644
--- a/OpenSim/Region/Framework/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Framework/Scenes/ScenePresence.cs
@@ -222,10 +222,7 @@ namespace OpenSim.Region.Framework.Scenes
222 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG 222 DIR_CONTROL_FLAG_DOWN_NUDGE = AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG
223 } 223 }
224 224
225 protected enum Cardinals 225
226 {
227 N=1,NE,E,SE,S,SW,W,NW
228 }
229 /// <summary> 226 /// <summary>
230 /// Position at which a significant movement was made 227 /// Position at which a significant movement was made
231 /// </summary> 228 /// </summary>
diff --git a/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
new file mode 100644
index 0000000..6f77062
--- /dev/null
+++ b/OpenSim/Region/Framework/Scenes/Tests/BorderTests.cs
@@ -0,0 +1,312 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenMetaverse;
5using OpenSim.Region.Framework.Scenes;
6
7using NUnit.Framework;
8
9namespace OpenSim.Region.Framework.Tests
10{
11 [TestFixture]
12 public class BorderTests
13 {
14
15 [Test]
16 public void TestCross()
17 {
18 List<Border> testborders = new List<Border>();
19
20 Border NorthBorder = new Border();
21 NorthBorder.BorderLine = new Vector3(0, 256, 256); //<---
22 NorthBorder.CrossDirection = Cardinals.N;
23 testborders.Add(NorthBorder);
24
25 Border SouthBorder = new Border();
26 SouthBorder.BorderLine = new Vector3(0, 256, 0); //--->
27 SouthBorder.CrossDirection = Cardinals.S;
28 testborders.Add(SouthBorder);
29
30 Border EastBorder = new Border();
31 EastBorder.BorderLine = new Vector3(0, 256, 256); //<---
32 EastBorder.CrossDirection = Cardinals.E;
33 testborders.Add(EastBorder);
34
35 Border WestBorder = new Border();
36 WestBorder.BorderLine = new Vector3(0, 256, 0); //--->
37 WestBorder.CrossDirection = Cardinals.W;
38 testborders.Add(WestBorder);
39
40 Vector3 position = new Vector3(200,200,21);
41
42 foreach (Border b in testborders)
43 {
44 Assert.That(!b.TestCross(position));
45
46 }
47
48 position = new Vector3(200,280,21);
49 Assert.That(NorthBorder.TestCross(position));
50
51
52
53 // Test automatic border crossing
54 // by setting the border crossing aabb to be the whole region
55 position = new Vector3(25,25,21); // safely within one 256m region
56
57 // The Z value of the BorderLine is reversed, making all positions within the region
58 // trigger bordercross
59
60 SouthBorder.BorderLine = new Vector3(0,256,256); // automatic border cross in the region
61 Assert.That(SouthBorder.TestCross(position));
62
63 NorthBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region
64 Assert.That(NorthBorder.TestCross(position));
65
66 EastBorder.BorderLine = new Vector3(0, 256, 0); // automatic border cross in the region
67 Assert.That(EastBorder.TestCross(position));
68
69 WestBorder.BorderLine = new Vector3(0, 256, 255); // automatic border cross in the region
70 Assert.That(WestBorder.TestCross(position));
71
72 }
73
74 [Test]
75 public void TestCrossSquare512()
76 {
77 List<Border> testborders = new List<Border>();
78
79 Border NorthBorder = new Border();
80 NorthBorder.BorderLine = new Vector3(0, 512, 512);
81 NorthBorder.CrossDirection = Cardinals.N;
82 testborders.Add(NorthBorder);
83
84 Border SouthBorder = new Border();
85 SouthBorder.BorderLine = new Vector3(0, 512, 0);
86 SouthBorder.CrossDirection = Cardinals.S;
87 testborders.Add(SouthBorder);
88
89 Border EastBorder = new Border();
90 EastBorder.BorderLine = new Vector3(0, 512, 512);
91 EastBorder.CrossDirection = Cardinals.E;
92 testborders.Add(EastBorder);
93
94 Border WestBorder = new Border();
95 WestBorder.BorderLine = new Vector3(0, 512, 0);
96 WestBorder.CrossDirection = Cardinals.W;
97 testborders.Add(WestBorder);
98
99 Vector3 position = new Vector3(450,220,21);
100
101 foreach (Border b in testborders)
102 {
103 Assert.That(!b.TestCross(position));
104
105 }
106
107 //Trigger east border
108 position = new Vector3(513,220,21);
109 foreach (Border b in testborders)
110 {
111 if (b.CrossDirection == Cardinals.E)
112 Assert.That(b.TestCross(position));
113 else
114 Assert.That(!b.TestCross(position));
115
116 }
117
118 //Trigger west border
119 position = new Vector3(-1, 220, 21);
120 foreach (Border b in testborders)
121 {
122 if (b.CrossDirection == Cardinals.W)
123 Assert.That(b.TestCross(position));
124 else
125 Assert.That(!b.TestCross(position));
126
127 }
128
129 //Trigger north border
130 position = new Vector3(220, 513, 21);
131 foreach (Border b in testborders)
132 {
133 if (b.CrossDirection == Cardinals.N)
134 Assert.That(b.TestCross(position));
135 else
136 Assert.That(!b.TestCross(position));
137
138 }
139
140 //Trigger south border
141 position = new Vector3(220, -1, 21);
142 foreach (Border b in testborders)
143 {
144 if (b.CrossDirection == Cardinals.S)
145 Assert.That(b.TestCross(position));
146 else
147 Assert.That(!b.TestCross(position));
148
149 }
150
151 }
152
153 [Test]
154 public void TestCrossRectangle512x256()
155 {
156 List<Border> testborders = new List<Border>();
157
158 Border NorthBorder = new Border();
159 NorthBorder.BorderLine = new Vector3(0, 512, 256);
160 NorthBorder.CrossDirection = Cardinals.N;
161 testborders.Add(NorthBorder);
162
163 Border SouthBorder = new Border();
164 SouthBorder.BorderLine = new Vector3(0, 512, 0);
165 SouthBorder.CrossDirection = Cardinals.S;
166 testborders.Add(SouthBorder);
167
168 Border EastBorder = new Border();
169 EastBorder.BorderLine = new Vector3(0, 256, 512);
170 EastBorder.CrossDirection = Cardinals.E;
171 testborders.Add(EastBorder);
172
173 Border WestBorder = new Border();
174 WestBorder.BorderLine = new Vector3(0, 256, 0);
175 WestBorder.CrossDirection = Cardinals.W;
176 testborders.Add(WestBorder);
177
178 Vector3 position = new Vector3(450, 220, 21);
179
180 foreach (Border b in testborders)
181 {
182 Assert.That(!b.TestCross(position));
183
184 }
185
186 //Trigger east border
187 position = new Vector3(513, 220, 21);
188 foreach (Border b in testborders)
189 {
190 if (b.CrossDirection == Cardinals.E)
191 Assert.That(b.TestCross(position));
192 else
193 Assert.That(!b.TestCross(position));
194
195 }
196
197 //Trigger west border
198 position = new Vector3(-1, 220, 21);
199 foreach (Border b in testborders)
200 {
201 if (b.CrossDirection == Cardinals.W)
202 Assert.That(b.TestCross(position));
203 else
204 Assert.That(!b.TestCross(position));
205
206 }
207
208 //Trigger north border
209 position = new Vector3(220, 257, 21);
210 foreach (Border b in testborders)
211 {
212 if (b.CrossDirection == Cardinals.N)
213 Assert.That(b.TestCross(position));
214 else
215 Assert.That(!b.TestCross(position));
216
217 }
218
219 //Trigger south border
220 position = new Vector3(220, -1, 21);
221 foreach (Border b in testborders)
222 {
223 if (b.CrossDirection == Cardinals.S)
224 Assert.That(b.TestCross(position));
225 else
226 Assert.That(!b.TestCross(position));
227
228 }
229 }
230
231 [Test]
232 public void TestCrossOdd512x512w256hole()
233 {
234 List<Border> testborders = new List<Border>();
235 // 512____
236 // | |
237 // 256__| |___
238 // | |
239 // |______|
240 // 0 | 512
241 // 256
242
243 // Compound North border since the hole is at the top
244 Border NorthBorder1 = new Border();
245 NorthBorder1.BorderLine = new Vector3(0, 256, 512);
246 NorthBorder1.CrossDirection = Cardinals.N;
247 testborders.Add(NorthBorder1);
248
249 Border NorthBorder2 = new Border();
250 NorthBorder2.BorderLine = new Vector3(256, 512, 256);
251 NorthBorder2.CrossDirection = Cardinals.N;
252 testborders.Add(NorthBorder2);
253
254 Border SouthBorder = new Border();
255 SouthBorder.BorderLine = new Vector3(0, 512, 0);
256 SouthBorder.CrossDirection = Cardinals.S;
257 testborders.Add(SouthBorder);
258
259 //Compound East border
260 Border EastBorder1 = new Border();
261 EastBorder1.BorderLine = new Vector3(0, 256, 512);
262 EastBorder1.CrossDirection = Cardinals.E;
263 testborders.Add(EastBorder1);
264
265 Border EastBorder2 = new Border();
266 EastBorder2.BorderLine = new Vector3(257, 512, 256);
267 EastBorder2.CrossDirection = Cardinals.E;
268 testborders.Add(EastBorder2);
269
270
271
272 Border WestBorder = new Border();
273 WestBorder.BorderLine = new Vector3(0, 512, 0);
274 WestBorder.CrossDirection = Cardinals.W;
275 testborders.Add(WestBorder);
276
277 Vector3 position = new Vector3(450, 220, 21);
278
279 foreach (Border b in testborders)
280 {
281 Assert.That(!b.TestCross(position));
282
283 }
284
285 position = new Vector3(220, 450, 21);
286
287 foreach (Border b in testborders)
288 {
289 Assert.That(!b.TestCross(position));
290
291 }
292
293 bool result = false;
294 int bordersTriggered = 0;
295
296 position = new Vector3(450, 450, 21);
297
298 foreach (Border b in testborders)
299 {
300 if (b.TestCross(position))
301 {
302 bordersTriggered++;
303 result = true;
304 }
305 }
306
307 Assert.That(result);
308 Assert.That(bordersTriggered == 2);
309
310 }
311 }
312}