clockwerk-opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 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 | |||
28 | using System; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Reflection; |
||
31 | using NUnit.Framework; |
||
32 | using OpenMetaverse; |
||
33 | using OpenSim.Framework; |
||
34 | using OpenSim.Framework.Communications; |
||
35 | using OpenSim.Region.Framework.Scenes; |
||
36 | using OpenSim.Tests.Common; |
||
37 | using OpenSim.Tests.Common.Mock; |
||
38 | using log4net; |
||
39 | |||
40 | namespace OpenSim.Region.Framework.Scenes.Tests |
||
41 | { |
||
42 | [TestFixture] |
||
43 | public class SceneObjectLinkingTests : OpenSimTestCase |
||
44 | { |
||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
46 | |||
47 | /// <summary> |
||
48 | /// Links to self should be ignored. |
||
49 | /// </summary> |
||
50 | [Test] |
||
51 | public void TestLinkToSelf() |
||
52 | { |
||
53 | TestHelpers.InMethod(); |
||
54 | |||
55 | UUID ownerId = TestHelpers.ParseTail(0x1); |
||
56 | int nParts = 3; |
||
57 | |||
58 | TestScene scene = new SceneHelpers().SetupScene(); |
||
59 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(nParts, ownerId, "TestLinkToSelf_", 0x10); |
||
60 | scene.AddSceneObject(sog1); |
||
61 | scene.LinkObjects(ownerId, sog1.LocalId, new List<uint>() { sog1.Parts[1].LocalId }); |
||
62 | // sog1.LinkToGroup(sog1); |
||
63 | |||
64 | Assert.That(sog1.Parts.Length, Is.EqualTo(nParts)); |
||
65 | } |
||
66 | |||
67 | [Test] |
||
68 | public void TestLinkDelink2SceneObjects() |
||
69 | { |
||
70 | TestHelpers.InMethod(); |
||
71 | |||
72 | bool debugtest = false; |
||
73 | |||
74 | Scene scene = new SceneHelpers().SetupScene(); |
||
75 | SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene); |
||
76 | SceneObjectPart part1 = grp1.RootPart; |
||
77 | SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene); |
||
78 | SceneObjectPart part2 = grp2.RootPart; |
||
79 | |||
80 | grp1.AbsolutePosition = new Vector3(10, 10, 10); |
||
81 | grp2.AbsolutePosition = Vector3.Zero; |
||
82 | |||
83 | // <90,0,0> |
||
84 | // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); |
||
85 | |||
86 | // <180,0,0> |
||
87 | grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); |
||
88 | |||
89 | // Required for linking |
||
90 | grp1.RootPart.ClearUpdateSchedule(); |
||
91 | grp2.RootPart.ClearUpdateSchedule(); |
||
92 | |||
93 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. |
||
94 | Assert.IsFalse(grp1.GroupContainsForeignPrims); |
||
95 | grp1.LinkToGroup(grp2); |
||
96 | Assert.IsTrue(grp1.GroupContainsForeignPrims); |
||
97 | |||
98 | scene.Backup(true); |
||
99 | Assert.IsFalse(grp1.GroupContainsForeignPrims); |
||
100 | |||
101 | // FIXME: Can't do this test yet since group 2 still has its root part! We can't yet null this since |
||
102 | // it might cause SOG.ProcessBackup() to fail due to the race condition. This really needs to be fixed. |
||
103 | Assert.That(grp2.IsDeleted, "SOG 2 was not registered as deleted after link."); |
||
104 | Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained children after delink."); |
||
105 | Assert.That(grp1.Parts.Length == 2); |
||
106 | |||
107 | if (debugtest) |
||
108 | { |
||
109 | m_log.Debug("parts: " + grp1.Parts.Length); |
||
110 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation); |
||
111 | m_log.Debug("Group1: Prim1: OffsetPosition:"+ part1.OffsetPosition+", OffsetRotation:"+part1.RotationOffset); |
||
112 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+part2.RotationOffset); |
||
113 | } |
||
114 | |||
115 | // root part should have no offset position or rotation |
||
116 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity, |
||
117 | "root part should have no offset position or rotation"); |
||
118 | |||
119 | // offset position should be root part position - part2.absolute position. |
||
120 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10), |
||
121 | "offset position should be root part position - part2.absolute position."); |
||
122 | |||
123 | float roll = 0; |
||
124 | float pitch = 0; |
||
125 | float yaw = 0; |
||
126 | |||
127 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. |
||
128 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); |
||
129 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); |
||
130 | |||
131 | if (debugtest) |
||
132 | m_log.Debug(rotEuler1); |
||
133 | |||
134 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); |
||
135 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); |
||
136 | |||
137 | if (debugtest) |
||
138 | m_log.Debug(rotEuler2); |
||
139 | |||
140 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f), |
||
141 | "Not exactly sure what this is asserting..."); |
||
142 | |||
143 | // Delink part 2 |
||
144 | SceneObjectGroup grp3 = grp1.DelinkFromGroup(part2.LocalId); |
||
145 | |||
146 | if (debugtest) |
||
147 | m_log.Debug("Group2: Prim2: OffsetPosition:" + part2.AbsolutePosition + ", OffsetRotation:" + part2.RotationOffset); |
||
148 | |||
149 | Assert.That(grp1.Parts.Length, Is.EqualTo(1), "Group 1 still contained part2 after delink."); |
||
150 | Assert.That(part2.AbsolutePosition == Vector3.Zero, "The absolute position should be zero"); |
||
151 | Assert.NotNull(grp3); |
||
152 | } |
||
153 | |||
154 | [Test] |
||
155 | public void TestLinkDelink2groups4SceneObjects() |
||
156 | { |
||
157 | TestHelpers.InMethod(); |
||
158 | |||
159 | bool debugtest = false; |
||
160 | |||
161 | Scene scene = new SceneHelpers().SetupScene(); |
||
162 | SceneObjectGroup grp1 = SceneHelpers.AddSceneObject(scene); |
||
163 | SceneObjectPart part1 = grp1.RootPart; |
||
164 | SceneObjectGroup grp2 = SceneHelpers.AddSceneObject(scene); |
||
165 | SceneObjectPart part2 = grp2.RootPart; |
||
166 | SceneObjectGroup grp3 = SceneHelpers.AddSceneObject(scene); |
||
167 | SceneObjectPart part3 = grp3.RootPart; |
||
168 | SceneObjectGroup grp4 = SceneHelpers.AddSceneObject(scene); |
||
169 | SceneObjectPart part4 = grp4.RootPart; |
||
170 | |||
171 | grp1.AbsolutePosition = new Vector3(10, 10, 10); |
||
172 | grp2.AbsolutePosition = Vector3.Zero; |
||
173 | grp3.AbsolutePosition = new Vector3(20, 20, 20); |
||
174 | grp4.AbsolutePosition = new Vector3(40, 40, 40); |
||
175 | |||
176 | // <90,0,0> |
||
177 | // grp1.UpdateGroupRotationR(Quaternion.CreateFromEulers(90 * Utils.DEG_TO_RAD, 0, 0)); |
||
178 | |||
179 | // <180,0,0> |
||
180 | grp2.UpdateGroupRotationR(Quaternion.CreateFromEulers(180 * Utils.DEG_TO_RAD, 0, 0)); |
||
181 | |||
182 | // <270,0,0> |
||
183 | // grp3.UpdateGroupRotationR(Quaternion.CreateFromEulers(270 * Utils.DEG_TO_RAD, 0, 0)); |
||
184 | |||
185 | // <0,90,0> |
||
186 | grp4.UpdateGroupRotationR(Quaternion.CreateFromEulers(0, 90 * Utils.DEG_TO_RAD, 0)); |
||
187 | |||
188 | // Required for linking |
||
189 | grp1.RootPart.ClearUpdateSchedule(); |
||
190 | grp2.RootPart.ClearUpdateSchedule(); |
||
191 | grp3.RootPart.ClearUpdateSchedule(); |
||
192 | grp4.RootPart.ClearUpdateSchedule(); |
||
193 | |||
194 | // Link grp2 to grp1. part2 becomes child prim to grp1. grp2 is eliminated. |
||
195 | grp1.LinkToGroup(grp2); |
||
196 | |||
197 | // Link grp4 to grp3. |
||
198 | grp3.LinkToGroup(grp4); |
||
199 | |||
200 | // At this point we should have 4 parts total in two groups. |
||
201 | Assert.That(grp1.Parts.Length == 2, "Group1 children count should be 2"); |
||
202 | Assert.That(grp2.IsDeleted, "Group 2 was not registered as deleted after link."); |
||
203 | Assert.That(grp2.Parts.Length, Is.EqualTo(0), "Group 2 still contained parts after delink."); |
||
204 | Assert.That(grp3.Parts.Length == 2, "Group3 children count should be 2"); |
||
205 | Assert.That(grp4.IsDeleted, "Group 4 was not registered as deleted after link."); |
||
206 | Assert.That(grp4.Parts.Length, Is.EqualTo(0), "Group 4 still contained parts after delink."); |
||
207 | |||
208 | if (debugtest) |
||
209 | { |
||
210 | m_log.Debug("--------After Link-------"); |
||
211 | m_log.Debug("Group1: parts:" + grp1.Parts.Length); |
||
212 | m_log.Debug("Group1: Pos:"+grp1.AbsolutePosition+", Rot:"+grp1.GroupRotation); |
||
213 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); |
||
214 | m_log.Debug("Group1: Prim2: OffsetPosition:"+part2.OffsetPosition+", OffsetRotation:"+ part2.RotationOffset); |
||
215 | |||
216 | m_log.Debug("Group3: parts:" + grp3.Parts.Length); |
||
217 | m_log.Debug("Group3: Pos:"+grp3.AbsolutePosition+", Rot:"+grp3.GroupRotation); |
||
218 | m_log.Debug("Group3: Prim1: OffsetPosition:"+part3.OffsetPosition+", OffsetRotation:"+part3.RotationOffset); |
||
219 | m_log.Debug("Group3: Prim2: OffsetPosition:"+part4.OffsetPosition+", OffsetRotation:"+part4.RotationOffset); |
||
220 | } |
||
221 | |||
222 | // Required for linking |
||
223 | grp1.RootPart.ClearUpdateSchedule(); |
||
224 | grp3.RootPart.ClearUpdateSchedule(); |
||
225 | |||
226 | // root part should have no offset position or rotation |
||
227 | Assert.That(part1.OffsetPosition == Vector3.Zero && part1.RotationOffset == Quaternion.Identity, |
||
228 | "root part should have no offset position or rotation (again)"); |
||
229 | |||
230 | // offset position should be root part position - part2.absolute position. |
||
231 | Assert.That(part2.OffsetPosition == new Vector3(-10, -10, -10), |
||
232 | "offset position should be root part position - part2.absolute position (again)"); |
||
233 | |||
234 | float roll = 0; |
||
235 | float pitch = 0; |
||
236 | float yaw = 0; |
||
237 | |||
238 | // There's a euler anomoly at 180, 0, 0 so expect 180 to turn into -180. |
||
239 | part1.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); |
||
240 | Vector3 rotEuler1 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); |
||
241 | |||
242 | if (debugtest) |
||
243 | m_log.Debug(rotEuler1); |
||
244 | |||
245 | part2.RotationOffset.GetEulerAngles(out roll, out pitch, out yaw); |
||
246 | Vector3 rotEuler2 = new Vector3(roll * Utils.RAD_TO_DEG, pitch * Utils.RAD_TO_DEG, yaw * Utils.RAD_TO_DEG); |
||
247 | |||
248 | if (debugtest) |
||
249 | m_log.Debug(rotEuler2); |
||
250 | |||
251 | Assert.That(rotEuler2.ApproxEquals(new Vector3(-180, 0, 0), 0.001f) || rotEuler2.ApproxEquals(new Vector3(180, 0, 0), 0.001f), |
||
252 | "Not sure what this assertion is all about..."); |
||
253 | |||
254 | // Now we're linking the first group to the third group. This will make the first group child parts of the third one. |
||
255 | grp3.LinkToGroup(grp1); |
||
256 | |||
257 | // Delink parts 2 and 3 |
||
258 | grp3.DelinkFromGroup(part2.LocalId); |
||
259 | grp3.DelinkFromGroup(part3.LocalId); |
||
260 | |||
261 | if (debugtest) |
||
262 | { |
||
263 | m_log.Debug("--------After De-Link-------"); |
||
264 | m_log.Debug("Group1: parts:" + grp1.Parts.Length); |
||
265 | m_log.Debug("Group1: Pos:" + grp1.AbsolutePosition + ", Rot:" + grp1.GroupRotation); |
||
266 | m_log.Debug("Group1: Prim1: OffsetPosition:" + part1.OffsetPosition + ", OffsetRotation:" + part1.RotationOffset); |
||
267 | m_log.Debug("Group1: Prim2: OffsetPosition:" + part2.OffsetPosition + ", OffsetRotation:" + part2.RotationOffset); |
||
268 | |||
269 | m_log.Debug("Group3: parts:" + grp3.Parts.Length); |
||
270 | m_log.Debug("Group3: Pos:" + grp3.AbsolutePosition + ", Rot:" + grp3.GroupRotation); |
||
271 | m_log.Debug("Group3: Prim1: OffsetPosition:" + part3.OffsetPosition + ", OffsetRotation:" + part3.RotationOffset); |
||
272 | m_log.Debug("Group3: Prim2: OffsetPosition:" + part4.OffsetPosition + ", OffsetRotation:" + part4.RotationOffset); |
||
273 | } |
||
274 | |||
275 | Assert.That(part2.AbsolutePosition == Vector3.Zero, "Badness 1"); |
||
276 | Assert.That(part4.OffsetPosition == new Vector3(20, 20, 20), "Badness 2"); |
||
277 | Quaternion compareQuaternion = new Quaternion(0, 0.7071068f, 0, 0.7071068f); |
||
278 | Assert.That((part4.RotationOffset.X - compareQuaternion.X < 0.00003) |
||
279 | && (part4.RotationOffset.Y - compareQuaternion.Y < 0.00003) |
||
280 | && (part4.RotationOffset.Z - compareQuaternion.Z < 0.00003) |
||
281 | && (part4.RotationOffset.W - compareQuaternion.W < 0.00003), |
||
282 | "Badness 3"); |
||
283 | } |
||
284 | |||
285 | /// <summary> |
||
286 | /// Test that a new scene object which is already linked is correctly persisted to the persistence layer. |
||
287 | /// </summary> |
||
288 | [Test] |
||
289 | public void TestNewSceneObjectLinkPersistence() |
||
290 | { |
||
291 | TestHelpers.InMethod(); |
||
292 | //log4net.Config.XmlConfigurator.Configure(); |
||
293 | |||
294 | TestScene scene = new SceneHelpers().SetupScene(); |
||
295 | |||
296 | string rootPartName = "rootpart"; |
||
297 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); |
||
298 | string linkPartName = "linkpart"; |
||
299 | UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); |
||
300 | |||
301 | SceneObjectPart rootPart |
||
302 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) |
||
303 | { Name = rootPartName, UUID = rootPartUuid }; |
||
304 | SceneObjectPart linkPart |
||
305 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) |
||
306 | { Name = linkPartName, UUID = linkPartUuid }; |
||
307 | |||
308 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); |
||
309 | sog.AddPart(linkPart); |
||
310 | scene.AddNewSceneObject(sog, true); |
||
311 | |||
312 | // In a test, we have to crank the backup handle manually. Normally this would be done by the timer invoked |
||
313 | // scene backup thread. |
||
314 | scene.Backup(true); |
||
315 | |||
316 | List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID); |
||
317 | |||
318 | Assert.That(storedObjects.Count, Is.EqualTo(1)); |
||
319 | Assert.That(storedObjects[0].Parts.Length, Is.EqualTo(2)); |
||
320 | Assert.That(storedObjects[0].ContainsPart(rootPartUuid)); |
||
321 | Assert.That(storedObjects[0].ContainsPart(linkPartUuid)); |
||
322 | } |
||
323 | |||
324 | /// <summary> |
||
325 | /// Test that a delink of a previously linked object is correctly persisted to the database |
||
326 | /// </summary> |
||
327 | [Test] |
||
328 | public void TestDelinkPersistence() |
||
329 | { |
||
330 | TestHelpers.InMethod(); |
||
331 | //log4net.Config.XmlConfigurator.Configure(); |
||
332 | |||
333 | TestScene scene = new SceneHelpers().SetupScene(); |
||
334 | |||
335 | string rootPartName = "rootpart"; |
||
336 | UUID rootPartUuid = new UUID("00000000-0000-0000-0000-000000000001"); |
||
337 | string linkPartName = "linkpart"; |
||
338 | UUID linkPartUuid = new UUID("00000000-0000-0000-0001-000000000000"); |
||
339 | |||
340 | SceneObjectPart rootPart |
||
341 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) |
||
342 | { Name = rootPartName, UUID = rootPartUuid }; |
||
343 | |||
344 | SceneObjectPart linkPart |
||
345 | = new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, Vector3.Zero, Quaternion.Identity, Vector3.Zero) |
||
346 | { Name = linkPartName, UUID = linkPartUuid }; |
||
347 | SceneObjectGroup linkGroup = new SceneObjectGroup(linkPart); |
||
348 | scene.AddNewSceneObject(linkGroup, true); |
||
349 | |||
350 | SceneObjectGroup sog = new SceneObjectGroup(rootPart); |
||
351 | scene.AddNewSceneObject(sog, true); |
||
352 | |||
353 | Assert.IsFalse(sog.GroupContainsForeignPrims); |
||
354 | sog.LinkToGroup(linkGroup); |
||
355 | Assert.IsTrue(sog.GroupContainsForeignPrims); |
||
356 | |||
357 | scene.Backup(true); |
||
358 | Assert.AreEqual(1, scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID).Count); |
||
359 | |||
360 | // These changes should occur immediately without waiting for a backup pass |
||
361 | SceneObjectGroup groupToDelete = sog.DelinkFromGroup(linkPart, false); |
||
362 | Assert.IsFalse(groupToDelete.GroupContainsForeignPrims); |
||
363 | |||
364 | scene.DeleteSceneObject(groupToDelete, false); |
||
365 | |||
366 | List<SceneObjectGroup> storedObjects = scene.SimulationDataService.LoadObjects(scene.RegionInfo.RegionID); |
||
367 | |||
368 | Assert.AreEqual(1, storedObjects.Count); |
||
369 | Assert.AreEqual(1, storedObjects[0].Parts.Length); |
||
370 | Assert.IsTrue(storedObjects[0].ContainsPart(rootPartUuid)); |
||
371 | } |
||
372 | } |
||
373 | } |